#include <bits/stdc++.h>   template <class T>   bool read(T &x) {     char *s;     s = (char *)malloc(10);     if (sizeof(x) == 1)       strcpy(s + 1,   %c );     else if (sizeof(x) == 4)       strcpy(s + 1,  %d );     else if (sizeof(x) == 8)       strcpy(s + 1,  %lld );     int k = scanf(s + 1, &x);     free(s);     return k != -1;   }   using namespace std;   char s[2000000];   int sz1, sz2, len, pos[2000000], neg[2000000];   int main() {     scanf( %s , s + 1);     len = strlen(s + 1);     s[0] =  0 ;     for (int i = len; i >= 0; i--) {       if (s[i] ==  0 ) continue;       if (s[i] ==  2 ) {         s[i - 1]++;         continue;       }       if (s[i] ==  1  and i > 0 and s[i - 1] ==  1 ) {         neg[++sz2] = len - i;         s[i - 1]++;         continue;       }       pos[++sz1] = len - i;     }     cout << sz1 + sz2 << endl;     for (int i = 1; i <= sz1; i++) printf( +2^%d n , pos[i]);     for (int i = 1; i <= sz2; i++) printf( -2^%d n , neg[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long quickMod(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       b >>= 1;       a = a * a % c;     }     return ans;   }   long long Euler(long long x) {     long long res = x;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         res = res - res / i;         while (x % i == 0) x /= i;       }     }     if (x > 1) res = res - res / x;     return res;   }   int main() {     long long c, tmp, ans, phi, result;     char b[1000005], n[1000005];     scanf( %s%s%lld , b, n, &c);     phi = Euler(c);     tmp = 0;     for (long long i = 0; b[i]; i++) tmp = (tmp * 10 + b[i] -  0 ) % c;     ans = 0;     bool flag = false;     for (long long i = 0; n[i]; i++) {       ans = ans * 10 + n[i] -  0 ;       if (ans > phi) {         flag = true;         ans %= phi;       }     }     if (flag) ans += phi;     ans--;     if (tmp == 0) tmp = c;     result = (((tmp + c - 1) % c) * quickMod(tmp, ans, c)) % c;     printf( %lld n , result ? result : c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;       b /= 2;       a = ((a % m) * (a % m)) % m;     }     return ans % m;   }   long long a[10];   long long fac[202];   void factorial() {     fac[0] = 1;     for (int i = 1; i < 200; i++) {       fac[i] = fac[i - 1] * i;       fac[i] %= (long long)(1000 * 1000 * 1000 + 7);     }   }   long long c(long long n, long long k) {     long long nemo = fac[n];     long long deno = fac[k] * fac[n - k];     deno %= (long long)(1000 * 1000 * 1000 + 7);     long long invdeno = pow(deno, (long long)(1000 * 1000 * 1000 + 7) - 2,                             (long long)(1000 * 1000 * 1000 + 7));     long long pro = nemo * invdeno;     pro %= (long long)(1000 * 1000 * 1000 + 7);     return pro;   }   long long dp[105][10];   long long solve(int len, int curnum) {     if (len < 0) return 0;     if (curnum == 9) {       return len >= a[9];     }     long long ans = 0;     if (dp[len][curnum] != -1) return dp[len][curnum];     if (curnum == 0) {       for (int i = a[curnum]; i < len; i++) {         ans += solve(len - i, curnum + 1) * c(len - 1, i);         ans %= (long long)(1000 * 1000 * 1000 + 7);       }     } else {       for (int i = a[curnum]; i <= len; i++) {         ans += solve(len - i, curnum + 1) * c(len, i);         ans %= (long long)(1000 * 1000 * 1000 + 7);       }     }     return dp[len][curnum] = (ans % (long long)(1000 * 1000 * 1000 + 7));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     factorial();     for (int i = 0; i < 10; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i <= n; i++) {       if (i >= a[9])         dp[i][9] = 1;       else         dp[i][9] = 0;     }     for (int k = 0; k <= n; k++) {       for (int j = 8; j >= 0; j--) {         if (j != 0) {           for (int l = a[j]; l <= k; l++) {             dp[k][j] += dp[k - l][j + 1] * c(k, l);             dp[k][j] %= (long long)(1000 * 1000 * 1000 + 7);           }         } else {           for (int l = a[j]; l <= k; l++) {             dp[k][j] += dp[k - l][j + 1] * c(k - 1, l);             dp[k][j] %= (long long)(1000 * 1000 * 1000 + 7);           }         }       }     }     for (int i = 1; i <= n; i++) {       ans += dp[i][0];       ans %= (long long)(1000 * 1000 * 1000 + 7);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 0x7FFFFFFF;   template <class T>   void show(T a, int n) {     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void show(T a, int r, int l) {     for (int i = 0; i < r; ++i) show(a[i], l);     cout << endl;   }   int k[7];   int main() {     int i, j, ans;     int a, b, c, x, y, z;     cin >> a >> b >> c >> x >> y >> z;     for (i = 0; i < 6; i++) cin >> k[i];     ans = 0;     if (a > x) {       ans += k[5];     } else if (a < 0)       ans += k[4];     if (b > y)       ans += k[1];     else if (b < 0)       ans += k[0];     if (c > z)       ans += k[3];     else if (c < 0)       ans += k[2];     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       long long p, f, s, w, cntS, cntW;       cin >> p >> f >> cntS >> cntW >> s >> w;       if (s > w) {         swap(cntS, cntW);         swap(s, w);       }       long long ans = 0;       for (long long i = 0; i <= cntS; i++) {         if (i * s > p) break;         long long sf = i;         long long ss = min(f / s, cntS - i);         long long leftf = p - sf * s;         long long lefts = f - ss * s;         long long wf = min(cntW, leftf / w);         long long ws = min(cntW - wf, lefts / w);         ans = max(ans, ss + sf + wf + ws);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 9;   const int MOD = 1e9 + 7;   const int MAXN = 300005;   long long N, k, m;   long long cook[MAXN], t[MAXN], l[MAXN];   vector<int> ch[MAXN];   int good, bad;   template <class T, class Operation = plus<T>>   struct SegmentTree {     int n;     vector<T> st;     Operation op;     const T identity;     T query(int L, int R) {       T resl = identity, resr = identity;       for (L += n, R += n; L < R; L >>= 1, R >>= 1) {         if (L & 1) resl = op(resl, st[L++]);         if (R & 1) resr = op(st[--R], resr);       }       return op(resl, resr);     }     void update(int p, T val) {       for (st[p += n] = val; p > 1; p >>= 1) st[p >> 1] = op(st[p], st[p ^ 1]);     }     SegmentTree(const vector<T> &A, const T &identity = 0,                 const Operation &op = Operation())         : n((int)A.size()), st(n << 1), op(op), identity(identity) {       copy(A.begin(), A.end(), st.begin() + n);       for (int i = n - 1; i > 0; --i)         st[i] = this->op(st[i << 1], st[i << 1 | 1]);     }   };   struct Op {     pair<long long, long long> operator()(const pair<long long, long long> &a,                                           const pair<long long, long long> &b) {       return pair<long long, long long>(a.first + b.first, a.second + b.second);     }   };   SegmentTree<pair<long long, long long>, Op> st(       vector<pair<long long, long long>>(1000006),       pair<long long, long long>(0, 0));   long long calc(int u) {     pair<long long, long long> val = st.query(t[u], t[u] + 1);     st.update(t[u],               st.op(val, pair<long long, long long>(cook[u], cook[u] * t[u])));     long long maxi1 = 0, maxi2 = 0;     for (int i = 0; i < (int)ch[u].size(); i++) {       if (k - l[ch[u][i]] >= 0) {         k -= l[ch[u][i]];         long long chdp = calc(ch[u][i]);         if (chdp > maxi1) {           maxi2 = maxi1;           maxi1 = chdp;         } else if (chdp > maxi2) {           maxi2 = chdp;         }         k += l[ch[u][i]];       }     }     int lo = 0, hi = min(k + 2, (long long)1000004);     while (lo + 1 < hi) {       int med = lo + (hi - lo) / 2;       pair<long long, long long> sum = st.query(0, med);       if (sum.second > k) {         hi = med;       } else {         lo = med;       }     }     pair<long long, long long> sum = st.query(0, lo);     long long f = sum.first;     if (lo > 0) f += min((k - sum.second) / lo, st.st[st.n + lo].first);     st.update(t[u], val);     if (u == 0) {       return max(f, maxi1);     } else {       return max(f, maxi2);     }   }   int main() {     cin >> N >> k;     for (int i = 0; i < N; i++) {       cin >> cook[i];     }     for (int i = 0; i < N; i++) {       cin >> t[i];     }     for (int i = 1; i < N; i++) {       cin >> m >> l[i];       l[i] *= 2;       ch[m - 1].push_back(i);     }     cout << calc(0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n, long long m) {     long long ret = n % m;     if (ret < 0) ret += m;     return ret;   }   long long gcd(long long a, long long b) {     return (b == 0LL ? a : gcd(b, a % b));   }   long long exp(long long a, long long b, long long m) {     if (b == 0LL) return 1LL;     if (b == 1LL) return mod(a, m);     long long k = mod(exp(a, b / 2, m), m);     if (b & 1LL) {       return mod(a * mod(k * k, m), m);     } else       return mod(k * k, m);   }   const long long N = 150;   long long a[N];   long long b[N * N];   long long n, k;   long long ok() {     long long sum = 0;     for (long long i = 1; i <= k; i++) {       sum += b[i];     }     long long s2 = sum;     long long tam = n;     for (long long i = k + 1; i <= tam; i++) {       s2 -= a[i - k];       s2 += a[i];       if (s2 != sum) return false;     }     return true;   }   long long T;   long long go(long long n, long long m, long long obj, long long t) {     if (n == obj) {       T = min(T, t);       return t;     }     if (n > obj) return 1e9;     long long has = 1e9;     for (long long x = m; x >= 0; x--) {       has = min(has, go(n + x + m, m + x, obj, t + 1));     }     return has;   }   void go2(long long n, long long m, long long obj, long long t) {     if (n == obj) {       return;     }     for (long long x = m; x >= 0; x--) {       if (go(n + x + m, m + x, obj, t + 1) == T) {         cout << x <<    ;         go2(n + x + m, m + x, obj, t + 1);         return;       }     }   }   void solve(long long coisa = 0) {     long long n, m;     if (coisa == 0)       cin >> n;     else       n = coisa;     if (n == 3) {       cout << 1 <<   n ;       cout << 1 <<   n ;       return;     }     long long t = 0;     for (long long i = 30; i >= 0; i--) {       if (n & (1LL << i)) {         t = i;         break;       }     }     cout << t <<   n ;     T = t;     if (n < 10) {       go2(1, 1, n, 0);       cout <<   n ;     } else if ((1 << t) == n) {       long long has = 1;       for (long long x = 1; x <= t; x++) {         if (x == 1)           cout << 0 <<    ;         else {           cout << has <<    ;           has = has + has;         }       }       cout <<   n ;     } else {       long long has = 1;       long long m = 1;       for (long long x = 1; x < t - 1; x++) {         cout << has <<    ;         m = m + has + has;         has = has + has;       }       long long op1 = m + has + has;       long long has2 = has + has;       op1 = op1 + has2;       if (n < (op1)) {         for (long long x = 1; x <= has; x *= 2) {           has2 = has + x;           long long m2 = m + has2;           if (n - m2 - has2 <= has2 and n - m2 - has2 >= 0) {           } else             continue;           cout << x <<    ;           has += x;           m += has;           cout << n - m - has <<   n ;         }       } else {         cout << has <<    ;         has += has;         m += has;         cout << n - m - has <<   n ;       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   template <typename T>   void debug(vector<T> x) {     for (auto e : x) {       cout << e <<    ;     }     cout <<   n ;   }   void solve() {     long long n, m, x, y;     cin >> n >> m >> x >> y;     vector<pair<long long, long long>> ans;     stack<pair<long long, long long>> st;     long long mat[n + 1][m + 1];     for (long long i = 1; i <= n; i++)       for (long long j = 1; j <= m; j++) mat[i][j] = 0;     st.push({x, y});     while (!st.empty()) {       pair<long long, long long> cur = st.top();       if (mat[cur.first][cur.second] == 0) {         mat[cur.first][cur.second] = 1;         ans.push_back({cur.first, cur.second});       }       st.pop();       for (long long i = 1; i <= n; i++) {         if (mat[i][cur.second] == 0) {           st.push({i, cur.second});         }       }       for (long long j = 1; j <= m; j++) {         if (mat[cur.first][j] == 0) {           st.push({cur.first, j});         }       }     }     for (auto x : ans) {       cout << x.first <<     << x.second <<   n ;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int N, cn = 0, Z = 0, max = 0;     cin >> N;     int arr[N];     for (int i = 0; i < N; i++) {       cin >> arr[i];     }     for (int i = 0; i < N; i++) {       cn = 0;       for (int j = i + 1; j < N; j++) {         if (arr[i] == arr[j] && arr[j] != 0) {           cn++;           arr[j] = 0;         }       }       if (max <= cn) {         max = cn;       }       if (cn >= 1) {         Z += cn;       }     }     cout << max + 1 <<     << N - Z;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ui32 = unsigned;   using ui64 = unsigned long long;   using i64 = long long;   using i32 = int;   static constexpr bool debug = false;   struct node {     node *c[2] = {0, 0};     int cnt = 0;   };   node *root = new node;   void insert_rec(node *nd, ui32 number, int i) {     ++nd->cnt;     if (i != -1) {       int bit = (number >> i) & 1;       if (nd->c[bit] == nullptr) nd->c[bit] = new node;       insert_rec(nd->c[bit], number, i - 1);     }   }   void insert(ui32 number) { insert_rec(root, number, 31); }   bool remove_rec(node *nd, ui32 number, int i) {     if (i != -1) {       int bit = (number >> i) & 1;       if (remove_rec(nd->c[bit], number, i - 1)) nd->c[bit] = nullptr;     }     if (--nd->cnt == 0) {       delete nd;       return true;     } else {       return false;     }   }   void remove(ui32 number) { remove_rec(root, number, 31); }   void print_numbers_rec(node *nd, ui32 number, int i) {     if (nd == nullptr) return;     if (i == -1) {       for (int j = 0; j < nd->cnt; ++j) {         cerr << number <<    ;       }     }     print_numbers_rec(nd->c[0], number << 1, i - 1);     print_numbers_rec(nd->c[1], (number << 1) | 1, i - 1);   }   void print_numbers() {     print_numbers_rec(root, 0, 31);     cerr << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     vector<ui32> a(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       ui32 t;       cin >> t;       insert(t);     }     vector<int> o(n);     for (int i = 0; i < n; ++i) {       node *cur = root;       ui32 xored = 0;       for (int j = 31; j >= 0; --j) {         int bit = (a[i] >> j) & 1;         if (cur->c[bit] != nullptr) {           cur = cur->c[bit];           xored = (xored << 1) | bit;         } else {           cur = cur->c[bit ^ 1];           xored = (xored << 1) | (bit ^ 1);         }       }       o[i] = a[i] ^ xored;       remove(xored);     }     for (int i = 0; i < n; ++i) {       cout << o[i] <<    n [i + 1 == n];     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 55;   const int inf = 1e9 + 77;   const int MOD = 1e9 + 7;   const double eps = 1e-7;   map<int, int> mp;   pair<int, int> pi;   vector<long long> v;   map<char, int> mp1;   deque<int> d;   int x[MAX], y[MAX];   char c[MAX];   int cnt[MAX];   int main() {     int n;     cin >> n;     long long even = 0;     long long odd = 0;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       if (a % 2 != 0)         odd++;       else         even++;     }     if (odd == 0)       cout <<  Second ;     else       cout <<  First ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k == 0 || k == n) {       cout <<  0 0 ;       return 0;     }     cout << min(1LL, n - k) <<     << min(n - k, k * 2LL);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, tx, ty, ans = 0;     vector<int> x, y;     cin >> n;     for (int i = 0; i <= n; i++) {       cin >> tx >> ty;       x.push_back(tx), y.push_back(ty);     }     for (int i = 1; i < n; i++) {       int fx = x[i + 1], fy = y[i + 1];       int cx = x[i], cy = y[i];       int px = x[i - 1], py = y[i - 1];       if ((fy > cy && cx > px) || (cx > fx && cy > py) || (fy < cy && cx < px) ||           (fx > cx && cy < py))         ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int INF = 9223372036854775807;   const long long int mod = 1000000007;   long long int MOD(long long int a, long long int b) {     if (a > b)       return a - b;     else       return b - a;   }   long long int max3(long long int a, long long int b, long long int c) {     return max(c, max(a, b));   }   long long int min3(long long int a, long long int b, long long int c) {     return min(a, min(b, c));   }   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int power1(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res % mod;   }   long long int logg(long long int a) {     long long int x = 0;     while (a > 1) {       x++;       a /= 2;     }     return x;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int abso(long long int x) {     if (x < 0) {       return -x;     }     return x;   }   long long int ceiling(long long int a, long long int b) {     if (a % b == 0) {       return a / b;     } else {       return a / b + 1;     }   }   long long int modinv(long long int x) { return power1(x, mod - 2); }   vector<vector<int>> mat;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, p;     cin >> n >> p;     mat.resize(p);     string str;     cin >> str;     for (int i = 0; i < p; i++) {       mat[i].resize(p);       for (int j = 0; j < p; j++) {         cin >> mat[i][j];       }     }     vector<vector<vector<int>>> pair_masks(p);     vector<int> cnt(p);     for (int i = 0; i < n; i++) {       cnt[str[i] -  a ]++;     }     for (int i = 0; i < p; i++) {       pair_masks[i].resize(p);       for (int j = 0; j < p; j++) {         pair_masks[i][j].resize(1 << p);       }     }     for (int i = 0; i < p; i++) {       for (int j = 0; j < p; j++) {         int prev = -1;         int mask = 0;         for (int k = 0; k < n; k++) {           if (str[k] ==  a  + i || str[k] ==  a  + j) {             if (prev == -1) {               prev = str[k] -  a ;               mask = 0;             } else {               if (i != j) {                 if (prev == str[k] -  a ) {                   mask = 0;                 } else {                   pair_masks[i][j][mask] = 1;                   prev = str[k] -  a ;                   mask = 0;                 }               } else {                 pair_masks[i][j][mask] = 1;                 prev = str[k] -  a ;                 mask = 0;               }             }           } else {             mask = mask | 1 << (str[k] -  a );           }         }       }     }     for (int i = 0; i < p; i++) {       for (int j = 0; j < p; j++) {         for (int m = 0; m < p; m++) {           for (int k = 0; k < (1 << p); k++) {             if (m != i && m != j) {               pair_masks[i][j][k | 1 << m] += pair_masks[i][j][k];             }           }         }       }     }     for (int i = 0; i < p; i++) {       for (int j = 0; j < p; j++) {         for (int k = 0; k < (1 << p); k++) {           pair_masks[i][j][k] = min(1, pair_masks[i][j][k]);         }       }     }     vector<int> dp(1 << p, 0);     dp[0] = 1;     for (int mask = 1; mask < (1 << p); mask++) {       bool c = false;       for (int i = 0; i < p; i++) {         for (int j = 0; j < p; j++) {           if (pair_masks[i][j][mask] && !mat[i][j]) {             c = true;             break;           }         }         if (c) {           break;         }       }       if (c) {         dp[mask] = 0;         continue;       }       for (int i = 0; i < p; i++) {         if (mask & (1 << i)) {           if (dp[mask ^ (1 << i)]) {             dp[mask] = 1;           }         }       }     }     int ans = n;     for (int mask = 0; mask < (1 << p); mask++) {       if (dp[mask]) {         int len = n;         for (int k = 0; k < p; k++) {           if (mask & 1 << k) {             len -= cnt[k];           }         }         ans = min(ans, len);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long INF = 1e18;   int INFi = 2e9;   double eps = 1e-6;   long long mod = 1e9 + 7;   vector<char> used;   vector<vector<int>> edge;   vector<int> p;   vector<int> cnt;   int sz = 0;   void add(int beg, int end) {     while (beg != end) {       cnt[beg]++;       beg = p[beg];     }   }   void sub(int beg) {     while (used[beg] == 2) {       cnt[beg]--;       beg = p[beg];     }   }   void dfs(int v) {     used[v] = 1;     for (int u : edge[v]) {       if (used[u] == -1) {         continue;       }       if (used[u] == 2) {         sub(u);         continue;       }       if (used[u] == 1) {         add(v, u);         sz++;         continue;       }       p[u] = v;       dfs(u);     }     used[v] = 2;   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     edge.resize(n);     used.resize(n);     p.resize(n);     cnt.resize(n);     int t1, t2;     for (int i = 0; i < m; i++) {       cin >> t1 >> t2;       t1--;       t2--;       edge[t1].push_back(t2);     }     for (int i = 0; i < n; i++) {       if (!used[i]) dfs(i);       for (int j = 0; j < n; j++) {         if (used[j] == 2) used[j] = -1;       }     }     for (int i = 0; i < n; i++) {       if (cnt[i] == sz) {         cout <<  YES n ;         return 0;       }     }     if (sz == 1) {       cout <<  YES n ;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   double slope(long long int x1, long long int y1, long long int x2,                long long int y2) {     return (double)((double)(y2 - y1) / (x2 - x1));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int ax, ay, bx, by, cx, cy;     cin >> ax >> ay >> bx >> by >> cx >> cy;     long long int dab = power((bx - ax), 2) + power((by - ay), 2);     long long int dbc = power((cx - bx), 2) + power((cy - by), 2);     if (dab != dbc) {       cout <<  No n ;     } else if (slope(ax, ay, bx, by) == slope(bx, by, cx, cy)) {       cout <<  No n ;     } else {       cout <<  Yes n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int n, m, ROOT, head;   bool vis[MAXN];   int depth[MAXN], deg[MAXN];   vector<int> adj[MAXN];   vector<int> c;   stack<int> stk;   pair<bool, vector<int> > independentSet() {     set<pair<int, int> > s;     vector<int> v;     for (auto i = 0; i < (n); i++) s.insert(make_pair(deg[i], i));     while (!s.empty()) {       int node = s.begin()->second;       s.erase(s.begin());       if (vis[node]) continue;       v.push_back(node);       vis[node] = true;       for (auto u : adj[node]) {         if (vis[u]) continue;         vis[u] = true;         for (auto v : adj[u]) {           if (v == u) continue;           --deg[v];           s.insert(make_pair(deg[v], v));         }       }     }     if (v.size() >= ROOT)       return make_pair(true, v);     else       return make_pair(false, vector<int>{});   }   void simpleCycle() {     while (!stk.empty() && stk.top() != head) {       c.push_back(stk.top());       stk.pop();     }     c.push_back(head);     reverse(c.begin(), c.end());     cout <<  2 n  << c.size() <<   n ;     for (auto u : c) cout << u + 1 <<    ;     exit(0);   }   void dfs(int node, int d) {     if (depth[node] > 0) {       if (d - depth[node] == ROOT) {         head = node;         simpleCycle();       }       return;     }     depth[node] = d;     stk.push(node);     for (auto u : adj[node]) {       dfs(u, d + 1);     }     stk.pop();   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (auto i = 0; i < (m); i++) {       int u, v;       cin >> u >> v;       --u;       --v;       adj[u].push_back(v);       adj[v].push_back(u);       ++deg[u];       ++deg[v];     }     ROOT = (int)sqrt(n);     if (ROOT * ROOT < n) ++ROOT;     auto is = independentSet();     if (is.first) {       cout <<  1 n ;       for (auto i = 0; i < (ROOT); i++) cout << is.second[i] + 1 <<    ;       exit(0);     } else {       dfs(0, 1);     }   }


#include <bits/stdc++.h>   using namespace std;   namespace whatever {   int readu() {     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     int value = ch -  0 ;     ch = getchar();     while (isdigit(ch)) {       value = value * 10 + ch -  0 ;       ch = getchar();     }     return value;   }   long long readull() {     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     long long value = ch -  0 ;     ch = getchar();     while (isdigit(ch)) {       value = value * 10 + ch -  0 ;       ch = getchar();     }     return value;   }   void writeull(long long n) {     if (n < 10)       putchar(n +  0 );     else {       writeull(n / 10);       putchar(n % 10 +  0 );     }   }   void run() {     int n = readu();     long long t = readull();     static int a[200000];     for (int i = 0; i < n; ++i) a[i] = readu();     long long result = 0;     while (n != 0) {       long long sum = accumulate(a, a + n, 0ll);       result += t / sum * n;       t %= sum;       for (int i = 0; i < n; ++i)         if (t >= a[i]) {           t -= a[i];           ++result;         }       n = remove_if(a, a + n, [t](int a) { return a > t; }) - a;     }     writeull(result);     putchar(  n );   }   }  // namespace whatever   int main() { whatever::run(); }


#include <bits/stdc++.h>   using namespace std;   const int buffer_size = 1 << 20;   int rd_char() {     static char buf[buffer_size];     static int l = buffer_size, r = buffer_size;     if (l == r && r == buffer_size) {       r = fread(buf, sizeof(char), 1 << 20, stdin);       l = 0;     }     if (l == r) return EOF;     return buf[l++];   }   unsigned int rd_uint() {     int c;     unsigned int x = 0;     while ( 0  <= (c = rd_char())) x = x * 10 + c -  0 ;     return x;   }   int rd_int() {     bool neg = false;     int c = rd_char();     long long x = 0;     if (c ==  - )       neg = true;     else       x = c -  0 ;     while ( 0  <= (c = rd_char())) x = x * 10 + c -  0 ;     return neg ? -x : x;   }   unsigned long long rd_ull() {     int c;     unsigned long long x = 0;     while ( 0  <= (c = rd_char())) x = x * 10 + c -  0 ;     return x;   }   long long rd_ll() {     bool neg = false;     int c = rd_char();     long long x = 0;     if (c ==  - )       neg = true;     else       x = c -  0 ;     while ( 0  <= (c = rd_char())) x = x * 10 + c -  0 ;     return neg ? -x : x;   }   string rd_str() {     string ret;     int c;     while ((c = rd_char()) !=   n  && c !=     && c != EOF) ret += c;     return ret;   }   struct writer_struct {     char buf[buffer_size];     int l = 0;     ~writer_struct() { fwrite(buf, sizeof(char), l, stdout); }   } writer;   void flush() {     fwrite(writer.buf, sizeof(char), writer.l, stdout);     fflush(stdout);     writer.l = 0;   }   void wt(char c) {     if (writer.l == buffer_size) {       fwrite(writer.buf, sizeof(char), buffer_size, stdout);       writer.l = 0;     }     writer.buf[writer.l++] = c;   }   void wt(unsigned int x) {     if (x == 0)       wt( 0 );     else {       char f[10];       int sz = 0;       while (x) {         f[sz++] = x % 10 +  0 ;         x /= 10;       }       while (sz) wt(f[--sz]);     }   }   void wt(int x) {     if (x < 0) wt( - ), x = -x;     wt((unsigned int)x);   }   void wt(unsigned long long x) {     if (x == 0)       wt( 0 );     else {       char f[20];       int sz = 0;       while (x) {         f[sz++] = x % 10 +  0 ;         x /= 10;       }       while (sz) wt(f[--sz]);     }   }   void wt(long long x) {     if (x < 0) wt( - ), x = -x;     wt((unsigned long long)x);   }   void wt(const char* s) {     while (*s !=   0 ) wt(*s++);   }   void wt(const string& s) {     for (char c : s) wt(c);   }   const int LIM = 3e6;   int N, C[LIM + 1];   long long cnt[LIM + 1];   int main() {     N = rd_uint();     for (int i = 0; i < N; i++) C[rd_uint()]++;     for (int i = 1; i <= LIM; i++) {       if ((long long)i * i <= LIM)         cnt[i * i] += (long long)C[i] * (C[i] - 1);       else         cnt[LIM] += (long long)C[i] * (C[i] - 1);       int rest = N - C[i];       for (int j = 1; (long long)i * j <= LIM; j++) {         if (i != j) cnt[i * j] += (long long)C[i] * C[j], rest -= C[j];       }       cnt[LIM] += (long long)C[i] * rest;     }     for (int i = LIM; i >= 1; i--) cnt[i - 1] += cnt[i];     int M = rd_uint();     for (; M--;) {       int p = rd_uint();       wt(cnt[p]);       wt(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, i;     vector<int> arr, sol, orig;     cin >> n;     arr.resize(n);     for (i = 0; i < n; ++i) {       cin >> arr[i];     }     orig = arr;     sort(orig.begin(), orig.end());     for (i = 0; i < n; ++i) {       for (int k = 0; k + 1 < arr.size(); ++k) {         while (arr[i] - arr[i + 1] >= 2) ++arr[i + 1], --arr[i];         while (arr[i] - arr[i + 1] <= -2) --arr[i + 1], ++arr[i];       }       int j = -1, x = -1;       for (int k = 0; k < arr.size(); ++k) {         if (arr[k] > x) {           x = arr[k];           j = k;         }       }       sol.push_back(arr[j]);       arr.erase(arr.begin() + j);     }     reverse(sol.begin(), sol.end());     cout << (sol == orig ?  YES  :  NO ) <<   n ;   }


#include<bits/stdc++.h>   using namespace std;   int main()   {         int t,p,k,q,b;       cin>>t;       string s;       while(t--)       {           cin>>s;           k=0; q=0; b=0; p=0;           for(int i=0;i<s.size();i++)           {               if(s[0]== ) || s[s.size()-1]== ( )               {                   p=0; break;}               else if( s[i]== ( )               {                   k++;               }               else if(s[i]== ? )                 q++;                else if(s[i]== ) )                b++;           }                      if(k==b && q%2!=0 && k>0)           p=0;           else if(k==b&& q%2==0&& k>0)           p=1;           else if(q== abs(k-b) && k>0)           p=1;           if(p==1)           cout<< yes <<endl;           else           cout<< NO <<endl;       }   }


#include<bits/stdc++.h>   using namespace std;   #define il inline   #define rg register   #define int long long   #define M 998244353   const int P=3,Pn=332748118;   il int read()   {      int re=0,k=1;char ch=getchar();       while(ch> 9 ||ch< 0 ){if(ch== - )k=-1;ch=getchar();}       while(ch<= 9 &&ch>= 0 ){re=re*10+ch-48;ch=getchar();}       return re*k;   }   il void write(long long x)   {       if(x<0)return putchar( - ),write(-x),void();       if(x<10)return putchar(x+ 0 ),void();       return write(x/10),putchar(x%10+ 0 ),void();   }   signed main()   {    int T,a,b,c,d;    T=read();    while(T--)    {     d=read();a=read();b=read();c=read();     int ans=min((a-d%a)%a,min((b-d%b)%b,(c-d%c)%c));     write(ans);puts(  );    }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   const double eps = 1e-8;   const double pi = acos(-1);   int main() {     int T;     cin >> T;     while (T--) {       string s;       cin >> s;       int cnt = 0;       bool flag0 = false, flag1 = false, flag2 = false;       for (int i = 0; i < s.size() - 1; i++) {         if (s[i] ==  0 ) flag0 = true;         if (s[i] ==  1 ) flag1 = true;         if (s[i] ==  2 ) flag2 = true;         if (s[i] ==  0  && s[i + 1] !=  0 ) cnt++;       }       if (s[s.size() - 1] ==  0 ) cnt++;       if (s[s.size() - 1] ==  0 ) flag0 = true;       if (s[s.size() - 1] ==  1 ) flag1 = true;       if (s[s.size() - 1] ==  2 ) flag2 = true;       if (!flag0)         cnt = min(cnt, 0);       else if (!flag1)         cnt = min(cnt, 1);       else if (!flag2)         cnt = min(cnt, 2);       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 5;   int readint() {     int x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       (s = getchar());     }     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       (s = getchar());     }     return x * f;   }   long long dp[maxn][maxn];   int a[maxn];   int q[maxn];   int main() {     int n = readint(), k = readint(), x = readint();     for (int i = 1; i <= n; i++) {       a[i] = readint();     }     memset(dp, -0x3f, sizeof(dp));     dp[0][0] = 0;     for (int j = 1; j <= x; j++) {       int head = 1, tail = 0;       q[++tail] = 0;       for (int i = 1; i <= n; i++) {         while (head <= tail && i - q[head] > k) head++;         dp[i][j] = dp[q[head]][j - 1] + a[i] + 0ll;         while (head <= tail && dp[q[tail]][j - 1] <= dp[i][j - 1]) tail--;         q[++tail] = i;       }     }     long long ans = -1;     for (int i = n; i >= n - k + 1; i--) {       ans = max(ans, dp[i][x]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.1415926535897932384626433;   const long long mod = 1000000007;   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   template <class T>   T gcd(T a, T b) {     if (!b) return a;     return gcd(b, a % b);   }   const int maxn = 1e5 + 10;   vector<int> edg[maxn], vi, ans;   int now[maxn], nxt[maxn], len1, len2, n, m, vis[maxn], st[maxn], flg;   void dfs(int u) {     if (st[u] < 0) flg = 0;     if (flg == 0) return;     vis[u] = 1;     ans.push_back(u);     for (int i = 0; i < edg[u].size(); i++) {       int nxt = edg[u][i];       if (st[nxt] < 0) flg = 0;       if (!vis[nxt]) dfs(nxt);     }   }   int deal(int *a1, int *a2) {     int len = min(len1, len2);     for (int i = 0; i < len; i++) {       if (a1[i] < a2[i]) {         edg[a2[i]].push_back(a1[i]);         return 1;       } else if (a1[i] > a2[i]) {         vi.push_back(a1[i]);         if (st[a1[i]] == -1 || st[a2[i]] == 1) return 0;         st[a1[i]] = 1;         st[a2[i]] = -1;         return 1;       }     }     return len1 <= len2;   }   int solve() {     memset(st, 0, sizeof(st));     int *a1 = now, *a2 = nxt;     scanf( %d , &len1);     for (int i = 0; i < len1; i++) scanf( %d , &a1[i]);     flg = 1;     for (int t = 1; t < n; t++) {       scanf( %d , &len2);       for (int i = 0; i < len2; i++) scanf( %d , &a2[i]);       if (deal(a1, a2) == 0) flg = 0;       swap(a1, a2);       len1 = len2;     }     memset(vis, 0, sizeof(vis));     for (int i = 0; i < vi.size(); i++)       if (!vis[vi[i]]) dfs(vi[i]);     return flg;   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     if (solve()) {       printf( Yes n%d n , ans.size());       for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);       puts(  );     } else {       printf( No n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, a[5000] = {0};     cin >> n >> k;     for (int i = 1; i <= k; i++) {       int la = 0;       cin >> la;       if (la == 1) {         int p, q;         cin >> p >> q;         a[p] = 1;         a[q] = 1;       } else if (la == 2) {         int p;         cin >> p;         a[p] = 1;       }     }     int w = 0;     for (int i = 1; i < n; i++) {       if (a[i] == 0) {         w++;       }     }     int max = w, min = w + 1;     for (int i = 1; i <= n; i++) {       if (a[i] == 0 && a[i + 1] == 0) {         min--;         i++;       }     }     cout << min <<     << max << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2001;   const int inf = 1000000000;   int d[maxn], a[maxn], n, k;   bool check(int x) {     int ans = inf;     for (int i = 1; i <= n; i++) {       d[i] = i - 1;       for (int j = 1; j < i; j++)         if (abs(a[i] - a[j]) <= (i - j) * 1ll * x)           d[i] = min(d[i], d[j] + i - j - 1);       ans = min(ans, d[i] + n - i);     }     if (ans <= k) return true;     return false;   }   int main() {     cin >> n >> k;     int l = -1, r = 0, mid;     for (int i = 1; i <= n; i++) {       cin >> a[i];       r = max(r, (i == 1 ? r : abs(a[i] - a[i - 1])));     }     while (r - l > 1) {       mid = (l + 0ll + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int INF = 1e9;   const int maxn = 1e6 + 10;   const double eps = 1e-8;   int add(int x, int y) {     x += y;     return x >= mod ? x - mod : x;   }   int sub(int x, int y) {     x -= y;     return x < 0 ? x + mod : x;   }   int mul(int x, int y) { return 1LL * x * y % mod; }   int dep[maxn], tot, ans;   vector<pair<int, int> > g[maxn];   queue<pair<int, int> > q;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     bool ok = false;     for (int i = 1; i <= n; i++) {       vector<int> fac;       int x;       cin >> x;       for (int d = 2; d * d <= x; d++)         if (x % d == 0) {           int cnt = 0;           while (x % d == 0) cnt++, x /= d;           if (cnt & 1) fac.push_back(d);         }       if (x > 1) fac.push_back(x);       if (fac.size() == 2) {         int p = fac[0], q = fac[1];         g[p].push_back(pair<int, int>{q, ++tot}),             g[q].push_back(pair<int, int>{p, tot});       } else if (fac.size() == 1) {         int p = fac[0];         g[p].push_back(pair<int, int>{1, ++tot}),             g[1].push_back(pair<int, int>{p, tot});       } else         ok = true;     }     if (ok) {       cout << 1 << endl;       return 0;     }     ans = INF;     fill(dep + 1, dep + 1000000 + 1, INF);     for (int i = 1; i <= 1000; i++) {       vector<int> save;       dep[i] = 0, q.push(pair<int, int>{i, 0});       while (!q.empty()) {         pair<int, int> x = q.front();         q.pop();         int u = x.first, pre = x.second;         save.push_back(u);         for (auto e : g[u]) {           int v = e.first, id = e.second;           if (id == pre) continue;           if (dep[v] == INF) {             dep[v] = dep[u] + 1;             q.push(pair<int, int>{v, id});           } else             ans = min(ans, dep[u] + dep[v] + 1);         }       }       for (auto x : save) dep[x] = INF;     }     if (ans == INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2010;   int n;   int t[maxn], c[maxn];   long long d[maxn][maxn];   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> t[i] >> c[i];     for (int i = 0; i < n + 1; i++) d[0][i] = 1ll << 62;     d[0][0] = 0;     for (int i = 1; i < n + 1; i++) {       d[i][0] = 0;       for (int j = 1; j < n + 1; j++) {         d[i][j] = d[i - 1][j];         int tmp = max(0, j - t[i - 1] - 1);         if (d[i - 1][tmp] + c[i - 1] < d[i][j])           d[i][j] = d[i - 1][tmp] + c[i - 1];       }     }     cout << d[n][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[500000], r[500000];   long long a[500000];   int L, R;   int n, q;   int main() {     scanf( %d%d , &n, &q);     a[0] = 0;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = n; i >= 1; i--) a[i] = abs(a[i] - a[i - 1]);     stack<int> S;     for (int i = 2; i <= n; i++) {       while (!S.empty() && a[i] >= a[S.top()]) {         r[S.top()] = i - 1;         S.pop();       }       if (!S.empty())         l[i] = S.top() + 1;       else         l[i] = 2;       S.push(i);     }     while (!S.empty()) {       r[S.top()] = n;       S.pop();     }     while (q--) {       scanf( %d%d , &L, &R);       L++;       long long ans = 0;       for (int i = L; i <= R; i++) {         ans += (long long)(i - max(L, l[i]) + 1) *                (long long)(min(R, r[i]) - i + 1) * a[i];       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int> val[33];   long long sum[33];   int n = 0;   int calc() {     long long allsum = 0;     int res = 0;     for (int i = 0; i < 30; i++) {       if (val[i].empty()) continue;       if (allsum * 2 < *(val[i].begin())) res++;       allsum += sum[i];     }     return res;   }   int main() {     int q;     scanf( %d , &q);     while (q--) {       char s[2];       int x;       scanf( %s%d , s, &x);       int mn = 0;       for (int i = 0; i < 30; i++)         if (x >> i & 1) mn = i;       if (s[0] ==  - ) {         n--;         sum[mn] -= x;         val[mn].erase(val[mn].find(x));       } else {         sum[mn] += x;         val[mn].insert(x);         n++;       }       printf( %d n , n - calc());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   const int sz = 1 << 20;   char a[sz + 5], b[sz + 5], *p1 = a, *p2 = a, *t = b, p[105];   inline char gc() {     return getchar();     if (p1 == p2) p2 = (p1 = a) + fread(a, 1, sz, stdin);     return *p1++;   }   template <class T>   inline T read() {     T ret = 0;     char c = gc();     int f = 1;     for (; c <  0  || c >  9 ; c = gc())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = gc()) ret = ret * 10 + (c -  0 );     return ret * f;   }   template <class T>   inline void read(T& ret) {     ret = read<T>();   }   inline void flush() { fwrite(b, 1, t - b, stdout), t = b; }   inline void pc(char x) {     *t++ = x;     if (t - b == sz) flush();   }   template <class T>   inline void print(T x, char c =   n ) {     if (x < 0) x = -x, pc( - );     if (x == 0) pc( 0 );     int t = 0;     for (; x; x /= 10) p[++t] = x % 10 +  0 ;     for (; t; --t) pc(p[t]);     pc(c);   }   struct F {     ~F() { flush(); }   } f;   }  // namespace IO   using IO::print;   using IO::read;   const int mo = 1e9 + 7;   inline int add(int a, int b) { return a + b < mo ? a + b : a + b - mo; }   inline int dec(int a, int b) { return a < b ? a + mo - b : a - b; }   inline int mul(int a, int b) { return 1LL * a * b % mo; }   const int N = 1e3 + 10;   int k;   int c[N], s[N];   int C[N][N];   int f[N];   int main() {     for (int i = 0; i <= 1000; i++) C[i][0] = C[0][i] = 1;     C[0][0] = 0;     for (int i = 1; i <= 1000; i++)       for (int j = 1; j <= 1000; j++) C[i][j] = add(C[i - 1][j], C[i][j - 1]);     read(k);     for (int i = 1; i <= k; read(c[i]), s[i] = add(s[i - 1], c[i]), i++)       ;     f[1] = 1;     for (int i = 2; i <= k; i++) f[i] = mul(f[i - 1], C[s[i - 1]][c[i] - 1]);     print(f[k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010, M = N * 2, mod = 1e9 + 7;   const double PI = acos(-1.0), eps = 1e-6;   int T, n, m, k, c1, c2;   int a[N * 10], b[N], tot, cnt[N], s[N * 10], ans;   map<int, int> mp;   vector<int> v;   string g[N * 10];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> g[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (i - 1 >= 0 && g[i - 1][j] ==  X  && j - 1 >= 0 && g[i][j - 1] ==  X )           a[j + 1] = 1;     for (int i = 1; i <= m; i++) s[i] = s[i - 1] + a[i];     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       if (s[r] - s[l] > 0)         cout <<  NO  <<   n ;       else         cout <<  YES  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, bool> mapa;   long long _abs(long long a) {     if (a >= 0)       return a;     else       return -a;   }   int main() {     long long b1, q, l, m;     cin >> b1 >> q >> l >> m;     for (int i = 0; i < m; i++) {       long long a;       cin >> a;       mapa[a] = 1;     }     if (b1 == 0LL) {       if (!mapa.count(0))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     }     if (q == 0LL) {       if (_abs(b1) > l)         cout <<  0 n ;       else if (!mapa.count(0))         cout <<  inf n ;       else if (!mapa.count(b1))         cout <<  1 n ;       else         cout <<  0 n ;       return 0;     } else if (q == 1LL) {       if (_abs(b1) <= l && !mapa.count(b1))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     } else if (q == -1LL) {       if (_abs(b1) > l)         cout <<  0 n ;       else if (!mapa.count(b1) || !mapa.count(-b1))         cout <<  inf n ;       else         cout <<  0 n ;       return 0;     }     long long val = b1;     int cont = 0;     while (_abs(val) <= l) {       if (!mapa.count(val)) cont++;       val *= q;     }     cout << cont <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, p;   int tot, head[100010], next1[100010 << 1], to[100010 << 1];   int deep[100010], cnt[100010];   void add(int x, int y) {     to[++tot] = y;     next1[tot] = head[x];     head[x] = tot;   }   void dfs(int x, int f) {     deep[x] = deep[f] + 1;     cnt[deep[x]]++;     for (int i = head[x]; i; i = next1[i]) {       int y = to[i];       if (y == f) continue;       dfs(y, x);     }   }   int main() {     scanf( %d%d%d , &n, &k, &p);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     sort(deep + 1, deep + n + 1);     int l = 2, r = 2, ans = 1, tmp = 0;     while (1) {       if (l >= n || r >= n) break;       r++;       if (deep[r] != deep[r - 1]) tmp += (r - l);       while (tmp > p || r - l + 1 > k) {         tmp -= (deep[r] - deep[l]);         l++;       }       ans = max(ans, (r - l + 1));     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int k, b, n;     cin >> k >> b >> n;     map<int, int> freq;     freq[0]++;     int cont_zeros = 0;     int cur_mod = 0;     long long total_zeros = 0;     long long total_mod = 0;     for (int i = 0; i < n; ++i) {       int u;       cin >> u;       if (u == 0) {         cont_zeros++;         total_zeros += cont_zeros;       } else {         cont_zeros = 0;       }       cur_mod = (cur_mod + u) % (k - 1);       int tt = (k - 1 + cur_mod - b) % (k - 1);       total_mod += freq[tt];       freq[cur_mod]++;     }     if (b == 0) {       cout << total_zeros <<   n ;     } else if (b == k - 1) {       cout << total_mod - total_zeros <<   n ;     } else {       cout << total_mod <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   const int N = 1E5 + 5;   long long n, l, r, ql, qr;   long long arr[N], pre[N];   int main() {     fast();     cin >> n >> l >> r >> ql >> qr;     for (int i = 1; i <= n; i++) cin >> arr[i];     for (int i = 1; i <= n; ++i) {       pre[i] = arr[i] + pre[i - 1];     }     long long mini =         min(pre[n] * l + (ql * (n - 1)), pre[n] * r + (qr * (n - 1)));     for (int i = 1; i <= n; ++i) {       long long x = (pre[i] * l) + ((pre[n] - pre[i]) * r);       int takenL = i, takenR = n - i;       if (takenL < takenR) {         x += (takenR - takenL - 1) * qr;       } else if (takenR < takenL)         x += (takenL - takenR - 1) * ql;       mini = min(mini, x);     }     cout << mini <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     bool w, l;     int a[26];     node() {       w = false;       l = false;       memset(a, -1, sizeof a);     }   };   node a[100030];   long long cnt;   char second[100010];   void insert(long long n) {     int curr = 0;     int i = 0;     while (curr < n) {       if (a[i].a[second[curr] -  a ] == -1) {         a[i].a[second[curr] -  a ] = ++cnt;       }       i = a[i].a[second[curr] -  a ];       curr++;     }   }   void dfs(long long curr) {     if (curr == -1) {       return;     }     int cnt = 0;     for (int i = 0; i < 26; i++) {       if (a[curr].a[i] != -1) {         cnt++;         dfs(a[curr].a[i]);         if (a[a[curr].a[i]].w == false) {           a[curr].w = true;         }         if (a[a[curr].a[i]].l == false) {           a[curr].l = true;         }       }     }     if (cnt == 0) {       a[curr].w = false;       a[curr].l = true;     }   }   int main() {     long long n, k;     cnt = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %s , second);       insert(strlen(second));     }     dfs(0);     if (a[0].w == true && a[0].l == true) {       cout <<  First  << endl;     } else if (a[0].w == false) {       cout <<  Second  << endl;     } else if (a[0].w == true && a[0].l == false) {       if (k % 2 == 1) {         cout <<  First  << endl;       } else {         cout <<  Second  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   struct point {     int x, y;   } s[N], t[N];   vector<int> q[2];   int cntx, cnty, vis[N], n, now, dis[N], S, ax[N], ay[N];   set<pair<int, int> > a[N];   set<pair<int, int> >::iterator it;   int lowbit(int x) { return x & (-x); }   void upd(int x, pair<int, int> y) {     while (x <= cntx) {       a[x].insert(y);       x += lowbit(x);     }   }   void get(int x, int y, int id) {     while (x) {       it = a[x].begin();       for (pair<int, int> i : a[x]) {         if (i.first > y) break;         it++;         if (vis[i.second]) continue;         q[now].push_back(i.second);         vis[i.second] = id;       }       a[x].erase(a[x].begin(), it);       x -= lowbit(x);     }   }   void bfs(int d) {     if (!q[now].size()) return;     if (vis[n]) return;     now ^= 1;     q[now].clear();     for (int x : q[now ^ 1]) get(t[x].x, t[x].y, x);     for (int x : q[now]) dis[x] = d;     bfs(d + 1);   }   int main() {     scanf( %d , &n);     memset(dis, 0x3f, sizeof(dis));     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &s[i].x, &s[i].y, &t[i].x, &t[i].y);       if (s[i].x == 0 && s[i].y == 0) {         q[0].push_back(i);         dis[i] = 1, vis[i] = -1;       }       ax[++cntx] = s[i].x, ax[++cntx] = t[i].x;       ay[++cnty] = s[i].y, ay[++cnty] = t[i].y;     }     sort(ax + 1, ax + cntx + 1);     sort(ay + 1, ay + cnty + 1);     cntx = unique(ax + 1, ax + cntx + 1) - ax - 1;     cnty = unique(ay + 1, ay + cnty + 1) - ay - 1;     for (int i = 1; i <= n; i++) {       s[i].x = lower_bound(ax + 1, ax + cntx + 1, s[i].x) - ax;       s[i].y = lower_bound(ay + 1, ay + cnty + 1, s[i].y) - ay;       upd(s[i].x, make_pair(s[i].y, i));       t[i].x = lower_bound(ax + 1, ax + cntx + 1, t[i].x) - ax;       t[i].y = lower_bound(ay + 1, ay + cnty + 1, t[i].y) - ay;     }     now = 0;     bfs(2);     if (!vis[n])       puts( -1 );     else {       printf( %d n , dis[n]);       int x = n, cnt = 0, ans[N];       while (x != -1) {         ans[++cnt] = x;         x = vis[x];       }       for (int i = cnt; i >= 1; i--) printf( %d  , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const long long M = 1000000007;   const long double PI = acos((long double)-1.0);   template <typename T>   struct SegmentTree {     T data[N << 2];     T calc(const T &x, const T &y) const { return max(x, y); }     void push_up(int rt) { data[rt] = calc(data[rt << 1], data[rt << 1 | 1]); }     void build(int l, int r, int rt) {       data[rt] = 0;       if (l == r) {         return;       }       int m = (l + r) >> 1;       build(l, m, rt << 1);       build(m + 1, r, rt << 1 | 1);     }     void update(int p, T val, int l, int r, int rt) {       if (l == r) {         data[rt] = val;         return;       }       int m = (l + r) >> 1;       if (p <= m) {         update(p, val, l, m, rt << 1);       } else {         update(p, val, m + 1, r, rt << 1 | 1);       }       push_up(rt);     }     T query(int L, int R, int l, int r, int rt) {       if (L > R) {         return 0;       }       if (L <= l && r <= R) {         return data[rt];       }       int m = (l + r) >> 1;       T ret = 0;       if (L <= m) {         ret = calc(ret, query(L, R, l, m, rt << 1));       }       if (m < R) {         ret = calc(ret, query(L, R, m + 1, r, rt << 1 | 1));       }       return ret;     }   };   SegmentTree<long long> st;   int n;   struct Node {     long long v;     int id;   } a[N];   bool cmp(const Node &a, const Node &b) {     return a.v < b.v || (a.v == b.v && a.id > b.id);   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; i++) {         long long r, h;         scanf( %I64d%I64d , &r, &h);         a[i].v = r * r * h;         a[i].id = i;       }       sort(a + 1, a + n + 1, cmp);       st.build(1, n, 1);       long long ans = a[0].v;       for (int i = 1; i <= n; i++) {         long long val = st.query(1, a[i].id - 1, 1, n, 1);         st.update(a[i].id, val + a[i].v, 1, n, 1);         ans = max(ans, val + a[i].v);       }       printf( %.10f n , double(PI * ans));     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1ll;   long long lim = 0, Ans = 0;   struct Plan {     long long pos;     long long c, p;   } a[N];   struct Tree {     long long c, p;     Tree() { c = p = 0; };   } t[N << 2ll];   struct Acht {     long long a, b;     Acht() { a = b = 0; };   };   bool ctrl(Plan u, Plan v) { return u.pos < v.pos; }   inline void pushup(long long u) {     t[u].c = t[u << 1ll].c + t[u << 1ll | 1ll].c;     t[u].p = t[u << 1ll].p + t[u << 1ll | 1ll].p;   }   void update(long long u, long long l, long long r, long long pos) {     if (l == r && l == a[pos].p) {       t[u].c += a[pos].c;       t[u].p += a[pos].c * a[pos].p;       return;     }     long long mid = (l + r) >> 1ll;     if (a[pos].p <= mid)       update(u << 1ll, l, mid, pos);     else       update(u << 1ll | 1ll, mid + 1ll, r, pos);     pushup(u);   }   Acht query(long long u, long long l, long long r, long long rnk) {     if (l == r) {       Acht res;       if (rnk == t[u].c)         res.a = l;       else         res.a = l - 1ll, res.b = l * rnk;       return res;     }     if (t[u].c == rnk) {       Acht res;       res.a = r;       return res;     }     long long mid = (l + r) >> 1ll;     if (t[u << 1ll].c >= rnk) return query(u << 1ll, l, mid, rnk);     return query(u << 1ll | 1ll, mid + 1ll, r, rnk - t[u << 1ll].c);   }   long long query(long long u, long long l, long long r, long long a,                   long long b) {     if (a <= l && r <= b) return t[u].p;     long long mid = (l + r) >> 1ll;     long long res = 0;     if (a <= mid) res += query(u << 1ll, l, mid, a, b);     if (b > mid) res += query(u << 1ll | 1ll, mid + 1ll, r, a, b);     return res;   }   signed main() {     long long n, k, m;     scanf( %lld%lld%lld , &n, &k, &m);     for (long long i = 1ll; i <= m; ++i) {       long long y = i << 1ll, x = y - 1ll;       scanf( %lld%lld%lld%lld , &a[x].pos, &a[y].pos, &a[x].c, &a[x].p);       a[y].pos++, a[y].c = -a[x].c, a[y].p = a[x].p;       lim = max(lim, a[x].p);     }     sort(a + 1ll, a + (m << 1ll | 1ll), ctrl);     update(1ll, 1ll, lim, 1ll);     for (long long i = 2; i <= (m << 1ll); ++i) {       long long itv = a[i].pos - a[i - 1ll].pos;       if (t[1ll].c <= k)         Ans += t[1ll].p * itv;       else {         Acht tmp = query(1ll, 1ll, lim, k);         long long res = tmp.b;         if (tmp.a) res += query(1ll, 1ll, lim, 1ll, tmp.a);         Ans += res * itv;       }       update(1ll, 1ll, lim, i);     }     printf( %lld , Ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct s {     int x;     int y;     int str;     s(int a, int b, int st) {       x = a;       y = b;       str = st;     }   };   bool func(s x, s y) { return x.str > y.str; }   int main() {     int n;     cin >> n;     vector<s> v;     for (int i = 2; i <= 2 * n; i++) {       for (int j = 1; j < i; j++) {         int d;         cin >> d;         v.push_back(s(i, j, d));       }     }     sort(v.begin(), v.end(), func);     map<int, int> m;     for (int i = 0; i < v.size(); i++) {       if (m.find(v[i].x) != m.end() || m.find(v[i].y) != m.end()) {         continue;       }       m[v[i].x] = v[i].y;       m[v[i].y] = v[i].x;     }     for (int i = 1; i <= 2 * n; i++) {       cout << m[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T read1() {     T t = 0;     bool vis = 0;     char k;     do (k = getchar()) ==  -  && (vis = 1);     while ( 0  > k || k >  9 );     while ( 0  <= k && k <=  9 )       t = (t << 3) + (t << 1) + (k ^  0 ), k = getchar();     return vis ? -t : t;   }   vector<long long> x[500005];   vector<pair<int, int> > G[500005];   int s, k;   long long dfs(int n, int f) {     long long t = 0;     for (int i = 0; i < G[n].size(); ++i)       if (G[n][i].first ^ f) {         long long o = dfs(G[n][i].first, n);         t += o;         x[n].back() += G[n][i].second - o;       }     sort(x[n].begin(), x[n].end());     reverse(x[n].begin(), x[n].end());     int j = 0;     while (j + 1 < k && j < x[n].size() && x[n][j] > 0) t += x[n][j++];     x[f].push_back(t);     if (j < x[n].size() && x[n][j] > 0) t += x[n][j];     return t;   }   int main() {     for (int T = read1<int>(); T--;) {       s = read1<int>(), k = read1<int>();       for (int i = 0; i <= s; ++i) G[i].clear(), x[i].clear();       for (int i = 1; i < s; ++i) {         int u = read1<int>(), v = read1<int>(), t = read1<int>();         G[u].push_back(make_pair(v, t));         G[v].push_back(make_pair(u, t));       }       printf( %lld n , dfs(1, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, ans;     while (cin >> a >> b) {       if (a == 0 && b == 0)         cout <<  NO  << endl;       else {         ans = abs(a - b);         if (ans <= 1)           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   inline int readChar();   template <class T = int>   inline T readInt();   template <class T>   inline void writeInt(T x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 4096;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) {       pos = 0, len = fread(buf, 1, buf_size, stdin);     }     if (pos == len) {       return -1;     }     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) {       c = getChar();     }     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   const int MAXN = 100228;   const int MAXK = 10;   const double eps = 1e-7;   struct point {     int x, y;   };   point v[MAXK];   struct query {     double a;     int x, y, z;   };   query w[MAXN * 2];   bool compv(const point &a, const point &b) {     return atan2(a.y, a.x) < atan2(b.y, b.x);   }   bool compw(const query &a, const query &b) {     return (fabs(a.a - b.a) < eps ? a.z < b.z : a.a < b.a);   }   int a[MAXN], c[MAXN];   int cn, sx, sy;   int px[MAXN], py[MAXN], t[MAXN];   long long ans[MAXN], s[MAXN];   inline void add(int k, int x) {     for (; k <= MAXN; k += k & -k) {       s[k] += x;     }   }   int x[MAXN], y[MAXN];   long long sum(int k) {     long long res = 0;     for (; k; k -= k & -k) {       res += s[k];     }     return res;   }   int main() {     int k = readInt(), n = readInt(), q = readInt();     for (int i = 1; i <= k; i++) {       v[i].x = readInt();       v[i].y = readInt();       if (v[i].x < 0) {         v[i].x = -v[i].x;         v[i].y = -v[i].y;       }       if (!v[i].x && v[i].y < 0) {         v[i].y = -v[i].y;       }       sx += v[i].x, sy += v[i].y;     }     sort(v + 1, v + k + 1, compv);     for (int i = 1; i <= n; i++) {       c[i] = x[i] = readInt(), y[i] = readInt(), a[i] = readInt();     }     sort(c + 1, c + n + 1);     cn = unique(c + 1, c + n + 1) - c - 1;     for (int i = 1; i <= q; i++) {       px[i] = readInt(), py[i] = readInt(), t[i] = readInt();       px[i] -= sx * t[i];       py[i] -= sy * t[i];       t[i] <<= 1;     }     for (int i = 1; i <= k; i++) {       if (!v[i].x) {         for (int j = 1; j <= q; j++) {           py[j] += v[i].y * t[j];         }         continue;       }       for (int j = 1; j <= n; j++) {         w[j] = (query){y[j] - (double)x[j] * v[i].y / v[i].x, x[j], a[j], 0};       }       for (int j = 1; j <= q; j++) {         w[n + j] = (query){py[j] - (double)px[j] * v[i].y / v[i].x, px[j],                            px[j] + v[i].x * t[j], -j},               px[j] += v[i].x * t[j];         py[j] += v[i].y * t[j];       }       sort(w + 1, w + n + q + 1, compw);       memset(s, 0, sizeof(s));       for (int j = 1; j <= n + q; j++) {         if (w[j].z) {           ans[-w[j].z] -=               sum((upper_bound(c + 1, c + cn + 1, w[j].y) - c - 1)) -               sum((upper_bound(c + 1, c + cn + 1, w[j].x - (i < 2)) - c - 1));         } else {           add((upper_bound(c + 1, c + cn + 1, w[j].x) - c - 1), w[j].y);         }       }     }     for (int i = 1; i <= k; i++) {       if (!v[i].x) {         break;       }       for (int j = 1; j <= n; j++) {         w[j] = (query){y[j] - (double)x[j] * v[i].y / v[i].x, x[j], a[j], 0};       }       for (int j = 1; j <= q; j++) {         w[n + j] = (query){py[j] - (double)px[j] * v[i].y / v[i].x,                            px[j] - v[i].x * t[j], px[j], j},               px[j] -= v[i].x * t[j], py[j] -= v[i].y * t[j];       }       sort(w + 1, w + n + q + 1, compw);       memset(s, 0, sizeof(s));       for (int j = 1; j <= n + q; j++) {         if (w[j].z) {           ans[w[j].z] +=               sum((upper_bound(c + 1, c + cn + 1, w[j].y - (i > 1)) - c - 1)) -               sum((upper_bound(c + 1, c + cn + 1, w[j].x - 1) - c - 1));         } else {           add((upper_bound(c + 1, c + cn + 1, w[j].x) - c - 1), w[j].y);         }       }     }     for (int i = 1; i <= q; i++) {       writeInt(ans[i],   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int number_of_ones = 0;     string binary_string;     cin >> n >> binary_string;     for (int i = 0; i < n; i++) {       if (binary_string[i] ==  1 ) number_of_ones++;       if (binary_string[i] ==  0 ) {         cout << number_of_ones;         number_of_ones = 0;       }     }     cout << number_of_ones << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 1e17;   const long long mod = 1e9 + 7;   long long modInverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long powm(long long a, long long b) {     a = a % mod;     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (res % mod);   }   const long long N = 3e5 + 6;   struct st {     long long a, b, c, d;   };   bool comp(st x, st y) { return x.a < y.a; }   long long arr[N][2];   long long n, m;   vector<pair<long long, long long> > graph[N];   bool vis[N];   long long ans = 0;   void dijk(long long pos, long long par, long long f) {     for (pair<long long, long long> i : graph[pos])       if (i.first != par) {         arr[i.first][f] = arr[pos][f] + i.second;         dijk(i.first, pos, f);       }   }   void sol() {     vector<st> v;     multiset<long long> s;     for (long long i = 0; i < n; i++) {       v.push_back({arr[i][0] - arr[i][1], arr[i][0], arr[i][1], i});       s.insert(arr[i][1]);     }     sort(v.begin(), v.end(), comp);     for (long long i = 0; i < n - 1; i++) {       s.erase(s.find(v[i].c));       vector<long long> va;       for (pair<long long, long long> j : graph[v[i].d]) {         if (s.find(arr[j.first][1]) != s.end()) {           s.erase(s.find(arr[j.first][1]));           va.push_back(arr[j.first][1]);         }       }       if (s.size() != 0) ans = max(v[i].b + (*s.rbegin()), ans);       for (long long j : va) s.insert(j);     }   }   void solve() {     cin >> n >> m;     for (long long i = 0; i < n; i++) {       arr[i][0] = inf;       arr[i][1] = inf;     }     for (long long i = 0; i < n - 1; i++) {       long long aa, bb, cc;       cin >> aa >> bb >> cc;       aa--;       bb--;       graph[aa].push_back(make_pair(bb, cc));       graph[bb].push_back(make_pair(aa, cc));     }     memset(vis, 0, sizeof(vis));     arr[0][0] = 0;     arr[n - 1][1] = 0;     dijk(0, -1, 0);     dijk(n - 1, -1, 1);     sol();     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       cout << (min(arr[0][1], ans + x)) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   double ans, T, sumb, sumc;   int n, nb, nc;   struct node {     double x, y;     bool operator<(const node &a) const { return y < a.y; }   } a[N], b[N], c[N];   int main() {     scanf( %d%lf , &n, &T);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i].x);     for (int i = 1; i <= n; i++) scanf( %lf , &a[i].y);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++)       if (a[i].y < T)         b[++nb] = (node){a[i].x, T - a[i].y}, sumb = sumb + b[nb].x * b[nb].y;       else if (a[i].y == T)         ans = ans + a[i].x;       else if (a[i].y > T)         c[++nc] = (node){a[i].x, a[i].y - T}, sumc = sumc + c[nc].x * c[nc].y;     for (int i = 1; i < nb / 2; i++) swap(b[i], b[nb - i + 1]);     double x = min(sumb, sumc);     for (int i = 1; i <= nb; i++)       if (x > 1e-12) {         double y = min(b[i].x, x / b[i].y);         ans += y;         x -= y * b[i].y;       }     x = min(sumb, sumc);     for (int i = 1; i <= nc; i++)       if (x > 1e-12) {         double y = min(c[i].x, x / c[i].y);         ans += y;         x -= y * c[i].y;       }     printf( %.12lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, d, e, k[30];   string s;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> a >> s;     for (b = 1; b < a; b++) {       if (s[b] < s[b - 1]) {         cout <<  YES  << endl;         cout << b <<     << b + 1;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 3, M = 3e4 + 4, inf = 2e9 + 1;   int m, n, s, t, cur, tim, mn;   int low[N], dfn[N], vis[N], cst[M];   vector<pair<int, int> > vt[N];   vector<int> pat, rut, ans;   bool dfs(int u) {     vis[u] = 1;     if (u == t) return 1;     for (int i = 0; i < vt[u].size(); i++) {       int v = vt[u][i].first;       int id = vt[u][i].second;       if (!vis[v] && dfs(v)) {         pat.push_back(id);         return 1;       }     }     return 0;   }   bool tarjan(int u, int p = -1) {     vis[u] = 1;     bool cap = u == t;     low[u] = dfn[u] = ++tim;     for (int i = 0; i < vt[u].size(); i++) {       int v = vt[u][i].first;       int id = vt[u][i].second;       if (id == cur || id == p) continue;       if (vis[v])         low[u] = min(low[u], dfn[v]);       else {         bool flag = tarjan(v, id);         cap = flag || cap;         low[u] = min(low[u], low[v]);         if (flag && low[v] == dfn[v]) rut.push_back(id);       }     }     return cap;   }   int main() {     scanf( %d%d%d%d , &n, &m, &s, &t);     for (int i = 1; i < m + 1; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       vt[u].push_back(make_pair(v, i));       vt[v].push_back(make_pair(u, i));       cst[i] = w;     }     if (!dfs(s)) {       puts( 0 n0 n );       return 0;     }     mn = inf;     for (int i = 0; i < pat.size(); i++) {       cur = pat[i];       tim = 0;       memset(vis, 0, sizeof(vis));       rut.clear();       if (!tarjan(s))         if (mn > cst[cur]) {           mn = cst[cur];           ans.clear();           ans.push_back(cur);         }       for (int j = 0; j < rut.size(); j++) {         int sec = rut[j];         if (mn > cst[sec] + cst[cur]) {           mn = cst[sec] + cst[cur];           ans.clear();           ans.push_back(cur);           ans.push_back(sec);         }       }     }     if (mn == inf) {       puts( -1 );       return 0;     }     int len = ans.size();     printf( %d n%d n%d , mn, len, ans[0]);     if (len > 1)       printf(  %d n , ans[1]);     else       puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, c, d, p, nl, nd, np, min = 0, totl, totp, res;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     nd = d * c;     totl = (k * l) / nl;     totp = p / np;     if (totl <= nd && totl <= totp)       min = totl;     else if (nd <= totl && nd <= totp)       min = nd;     else if (totp <= totl && totp <= nd)       min = totp;     res = min / n;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr << x; }   void __print(const char *x) { cerr << x; }   void __print(const string &x) { cerr << x; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  ,  ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) {       cerr << (f++ ?  ,   :   );       __print(i);     }     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) {       cerr <<  ,  ;     }     _print(v...);   }   string go(long long i, long long n, long long dist, string nw, long long k,             string ori) {     ;     if (dist > k) {       return   ;     }     if (nw.substr(0, i) < ori.substr(0, i)) {       return   ;     }     if (i >= n) {       return nw;     }     for (char val =  0 ; val <=  9 ; ++val) {       nw[i] = val;       bool found = false;       for (long long j = 0; j < i; ++j) {         if (nw[j] == val) {           found = true;           break;         }       }       string chk = go(i + 1, n, dist + (found == false), nw, k, ori);       if ((long long)chk.size()) {         return chk;       }     }     return   ;   }   void solve() {     long long n, k;     cin >> n >> k;     string s = to_string(n);     long long dist = 0;     map<char, long long> g;     for (auto ch : s) {       g[ch]++;     }     string ans =         go(0, (long long)s.size(), 0, string((long long)s.size(),  0 ), k, s);     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int64_t func(int64_t c) {     int64_t cost = 0, pc = 1;     for (int ai : a) {       long long diff = ai - pc;       cost += abs(diff);       if (pc > LLONG_MAX / c) return LLONG_MAX;       pc *= c;     }     return cost;   }   int main(void) {     int n;     cin >> n;     int64_t ans = 0;     a.resize(n);     for (int& ai : a) {       cin >> ai;       ans += abs(ai - 1);     }     sort(a.begin(), a.end());     int64_t l = 2, r = 1e5;     while (r - l > 3) {       int64_t m1 = l + (r - l) / 3;       int64_t m2 = r - (r - l) / 3;       int64_t c1 = func(m1);       int64_t c2 = func(m2);       ans = min(ans, c1);       ans = min(ans, c2);       if (c1 > c2)         l = m1;       else         r = m2;     }     for (int64_t i = l; i <= r; i++) ans = min(ans, func(i));     cout << ans <<   n ;   }


#include <iostream>      using namespace std;      const int N = 210;       int a[N];    int main()   {    int t,i,j,k,n,s1=0,s0=0;     cin >> t;     while(t--)    {        cin>>n;        s1=0;s0=0;        for(i=0;i<2*n;i++)            cin>>a[i];        for(i=0;i<2*n;i++)            {                if(a[i]%2==1)s1++;                else s0++;            }            if(s1==s0)puts( Yes n );            else puts( No n );                }    return 0;    }


#include <bits/stdc++.h>   using namespace std;   const long long mxn = 1e5 + 7;   int main() {     int n, a[mxn], q, l[mxn], r[mxn], x;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (i == 1) {         l[i] = 1;         r[i] = a[i];       } else {         l[i] = r[i - 1] + 1;         r[i] = a[i] + r[i - 1];       }     }     cin >> q;     for (int i = 1; i <= q; i++) {       int l1 = 0, r1 = n, x;       cin >> x;       while (r1 - l1 > 1) {         int m = (l1 + r1) >> 1;         if (r[m] >= x)           r1 = m;         else           l1 = m;       }       cout << r1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int xs[2123], ys[2123], bs[2123];   long long fat[2123], prefix[2123][2123];   long long fatinv[2123];   long long sum(int row1, int row2, int col1, int col2) {     if (row1 > row2 || col1 > col2) return 0ll;     row2 = min(row2, 2000);     col2 = min(col2, 2000);     --row1, --col1;     if (row1 < 0) row1 = 0;     if (col1 < 0) col1 = 0;     if (row2 <= row1 or col2 <= col1) return 0ll;     return prefix[row2][col2] - prefix[row2][col1] - prefix[row1][col2] +            prefix[row1][col1];   }   long long sumR(int i, int r) {     return sum(xs[i] - r, xs[i] + r, ys[i] - r, ys[i] + r);   }   long long fastexp(long long a, long long b, long long m) {     long long r = 1;     for (a %= m; b; b >>= 1, a = (a * a) % m)       if (b & 1) r = (r * a) % m;     return r;   }   long long comb(int n, int k) {     if (n < k) return 0ll;     return (((fat[n] * fatinv[k]) % 1000000007) * fatinv[n - k]) % 1000000007;   }   int main() {     fat[0] = 1;     for (int i = 1; i < 2123; ++i) fat[i] = (fat[i - 1] * i) % 1000000007;     int n, m, r;     cin >> n >> m >> r;     for (int i = 0; i < 2123; ++i)       fatinv[i] = fastexp(fat[i], 1000000007 - 2, 1000000007);     for (int i = 0; i < n; ++i) {       cin >> xs[i] >> ys[i] >> bs[i];       prefix[xs[i]][ys[i]] = 1;     }     for (int i = 1; i < 2123; ++i) {       for (int j = 1; j < 2123; ++j) {         prefix[i][j] +=             prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1];       }     }     long long resp = 0ll;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         int row1 = xs[i] - r;         int row2 = xs[i] + r;         int col1 = ys[i] - r;         int col2 = ys[i] + r;         row1 = max(row1, xs[j] - r);         row2 = min(row2, xs[j] + r);         col1 = max(col1, ys[j] - r);         col2 = min(col2, ys[j] + r);         long long s = sum(row1, row2, col1, col2);         long long si = sumR(i, r);         long long sj = sumR(j, r);         long long diff = si + sj - s;         long long count = (((comb(n, m) - comb(n - si, m) - comb(n - sj, m) +                              comb(n - diff, m)) %                             1000000007) *                            bs[i]) %                           1000000007;         resp = (resp + (count * bs[j]) % 1000000007) % 1000000007;       }     }     if (resp < 0) resp += 1000000007;     cout << resp <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[10], flag[200];   int main() {     int sum = 0;     for (int i = 1; i <= 5; i++) {       cin >> a[i];       sum += a[i];       flag[a[i]]++;     }     int ans = sum;     for (int i = 1; i <= 5; i++) {       if (flag[a[i]] > 1 && flag[a[i]] < 4)         ans = min(ans, sum - flag[a[i]] * a[i]);       else if (flag[a[i]] > 3) {         ans = min(ans, sum - 3 * a[i]);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace p316GGoodSubstrings {   template <size_t MAXLEN, size_t ALPHABET>   struct SuffixAutomaton {     struct Node {       Node *child[ALPHABET], *suff, *next;       int len, cnt;     };     Node pool[2 * MAXLEN], *root, *nextnode, *last, *first[MAXLEN + 1];     Node* makenode(int length) {       memset(nextnode, 0, sizeof(Node));       nextnode->len = length;       return nextnode++;     }     void init() {       nextnode = pool;       last = root = makenode(0);       memset(first, 0, sizeof(first));     }     void extend(int ch) {       Node *p = last, *cur = makenode(p->len + 1);       cur->cnt = 1;       for (; p != NULL && p->child[ch] == NULL; p = p->suff) p->child[ch] = cur;       if (p == NULL)         cur->suff = root;       else {         Node* q = p->child[ch];         if (p->len + 1 == q->len)           cur->suff = q;         else {           Node* copy = makenode(p->len + 1);           memcpy(copy->child, q->child, sizeof(q->child));           copy->suff = q->suff;           q->suff = cur->suff = copy;           for (; p != NULL && p->child[ch] == q; p = p->suff) p->child[ch] = copy;         }       }       last = cur;     }     void go() {       for (Node* i = pool; i < nextnode; i++) {         i->next = first[i->len];         first[i->len] = i;       }       for (int len = MAXLEN; len > 0; len--)         for (Node* i = first[len]; i != NULL; i = i->next) i->suff->cnt += i->cnt;     }   };   struct TNode {     TNode* ch[26];     bool bad;     TNode() : bad(false) { memset(ch, 0, sizeof(ch)); }   };   SuffixAutomaton<55555, 26> sam;   TNode* root;   char str[55555];   int l, r, res = 0;   void go(TNode* at, SuffixAutomaton<55555, 26>::Node* cur) {     int cnt = cur ? cur->cnt : 0;     if (cnt < l || cnt > r) at->bad = true;     for (int c = 0; c < 26; c++)       if (at->ch[c] != NULL)         go(at->ch[c], cur && cur->child[c] ? cur->child[c] : NULL);   }   void dfs(TNode* at) {     if (!at->bad) res++;     for (int c = 0; c < 26; c++)       if (at->ch[c]) dfs(at->ch[c]);   }   void solve(int test_num) {     root = new TNode();     scanf( %s , str);     int len = strlen(str);     for (int i = 0; i < len; i++) {       TNode* at = root;       for (int j = i, c; j < len; j++) {         c = str[j] -  a ;         if (at->ch[c] == NULL) at->ch[c] = new TNode();         at = at->ch[c];       }     }     int cnt;     scanf( %d , &cnt);     for (int q = 0; q < cnt; q++) {       scanf( %s %d %d , str, &l, &r);       sam.init();       for (int i = 0; str[i] >    ; i++) sam.extend(str[i] -  a );       sam.go();       go(root, sam.root);     }     dfs(root);     if (!root->bad) res--;     cout << res << endl;   }   void solve() { solve(1); }   }  // namespace p316GGoodSubstrings   int main() {     p316GGoodSubstrings::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const double eps = 1e-10;   const int N = 3e5 + 5;   int n, m, d[N];   vector<pair<int, int> > g[N];   vector<int> vec;   bool vis[N];   void dfs(int u) {     vis[u] = true;     for (auto &e : g[u]) {       int &v = e.first;       if (vis[v]) continue;       dfs(v);       if (d[v] == 1) {         if (~d[u]) d[u] ^= 1;         d[v] = 0, vec.push_back(e.second);       }     }   }   int main() {     scanf( %d %d , &n, &m);     int s = 1;     for (int i = 1; i <= n; i++) {       scanf( %d , d + i);       if (d[i] == -1) s = i;     }     for (int i = 1, u, v; i <= m; i++) {       scanf( %d %d , &u, &v);       g[u].push_back(pair<int, int>(v, i));       g[v].push_back(pair<int, int>(u, i));     }     dfs(s);     if (~d[s] && d[s]) {       puts( -1 );       return 0;     }     printf( %d n , vec.size());     for (int id : vec) printf( %d n , id);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     int fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= fh;   }   struct Onfo {     int nu, ne;   } a[200010 * 2];   struct Info {     int x, t, we, an;   } v[200010];   struct seg {     int l, r, ma, ta, de;   } t[200010 * 4];   int b[200010], num, m, n, x, so[200010], si[200010], d[200010], f[200010],       tp[200010], bi[200010], fb[200010];   vector<int> no;   bool co(const Info &a, const Info &b) {     if (a.t + d[a.x] != b.t + d[b.x]) return a.t + d[a.x] < b.t + d[b.x];     return a.x < b.x;   }   bool c1(const Info &a, const Info &b) { return a.we < b.we; }   void jb(int x, int y) {     a[++num].nu = y;     a[num].ne = b[x];     b[x] = num;   }   void dfs(int x, int fa, int dep) {     si[x] = 1;     so[x] = 0;     f[x] = fa;     d[x] = dep;     for (int y = b[x]; y; y = a[y].ne) {       if (a[y].nu != fa) {         dfs(a[y].nu, x, dep + 1);         si[x] += si[a[y].nu];         if (si[a[y].nu] > si[so[x]]) so[x] = a[y].nu;       }     }   }   void dfs1(int x) {     bi[x] = ++num;     fb[num] = x;     if (so[x] != 0) {       tp[so[x]] = tp[x];       dfs1(so[x]);     }     for (int y = b[x]; y; y = a[y].ne) {       if (a[y].nu != f[x] && a[y].nu != so[x]) {         tp[a[y].nu] = a[y].nu;         dfs1(a[y].nu);       }     }   }   void build(int nu, int l, int r) {     t[nu].ma = -2e9;     t[nu].l = l;     t[nu].r = r;     t[nu].ta = -2e9;     if (l != r) {       build(nu * 2, l, (l + r) / 2);       build(nu * 2 + 1, (l + r) / 2 + 1, r);       t[nu].de = t[nu * 2 + 1].de;     } else {       t[nu].de = d[fb[l]];     }   }   void ya(int nu) {     if (t[nu].ta != -2e9) {       if (t[nu].l != t[nu].r) {         t[nu * 2].ta = t[nu].ta;         t[nu * 2 + 1].ta = t[nu].ta;       }       t[nu].ma = t[nu].ta + t[nu].de * 2;       t[nu].ta = -2e9;     }   }   int que(int nu, int l, int r) {     ya(nu);     if (t[nu].l == l && t[nu].r == r) return t[nu].ma;     int mid = (t[nu].l + t[nu].r) / 2;     if (l > mid) return que(nu * 2 + 1, l, r);     if (r <= mid) return que(nu * 2, l, r);     return max(que(nu * 2, l, mid), que(nu * 2 + 1, mid + 1, r));   }   void get(int nu, int l, int r) {     ya(nu);     if (t[nu].l == l && t[nu].r == r) {       no.push_back(nu);       return;     }     int mid = (t[nu].l + t[nu].r) / 2;     if (l <= mid) get(nu * 2, l, min(mid, r));     if (r > mid) get(nu * 2 + 1, max(mid + 1, l), r);   }   int getans(int nu, int y) {     if (t[nu].l == t[nu].r) return fb[t[nu].l];     ya(nu * 2 + 1);     if (t[nu * 2 + 1].ma <= y) return getans(nu * 2, y);     return getans(nu * 2 + 1, y);   }   int get(int x, int y) {     while (x != 0) {       if (que(1, bi[tp[x]], bi[x]) > y) {         no.clear();         get(1, bi[tp[x]], bi[x]);         for (int i = no.size() - 1; i >= 0; i--) {           if (t[no[i]].ma > y) return getans(no[i], y);         }       }       x = f[tp[x]];     }     return x;   }   void add(int nu, int l, int r, int x) {     ya(nu);     if (t[nu].l == l && t[nu].r == r) {       t[nu].ta = x;       return;     }     int mid = (t[nu].l + t[nu].r) / 2;     if (l <= mid) add(nu * 2, l, min(mid, r), x);     if (r > mid) add(nu * 2 + 1, max(mid + 1, l), r, x);     ya(nu * 2);     ya(nu * 2 + 1);     t[nu].ma = max(t[nu * 2].ma, t[nu * 2 + 1].ma);   }   void fu(int x, int y, int z) {     while (tp[x] != tp[y]) {       add(1, bi[tp[x]], bi[x], z);       x = f[tp[x]];     }     if (x != y) add(1, bi[y] + 1, bi[x], z);   }   int main() {     read(n);     read(m);     for (int i = 1; i <= n; i++) {       read(x);       jb(x + 1, i + 1);       jb(i + 1, x + 1);     }     n++;     dfs(1, 0, 1);     num = 0;     tp[1] = 1;     dfs1(1);     build(1, 1, n);     add(1, 1, 1, 2e9);     for (int i = 1; i <= m; i++) {       read(v[i].x);       read(v[i].t);       v[i].x++;       v[i].we = i;     }     sort(v + 1, v + m + 1, co);     for (int i = 1; i <= m; i++) {       v[i].an = get(v[i].x, v[i].t + d[v[i].x]);       fu(v[i].x, v[i].an, v[i].t + d[v[i].x] - d[v[i].an] * 2);     }     sort(v + 1, v + m + 1, c1);     for (int i = 1; i <= m; i++)       printf( %d  , v[i].t + d[v[i].x] * 2 - d[v[i].an] * 2);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   long double pi = 3.1415926535897932384626433832795;   const int N = 5e5 + 10, lg = 20;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     long long a, b, c;     cin >> a >> b >> c;     if (c == 0) {       if (a != b)         cout <<  NO ;       else         cout <<  YES ;       return 0;     }     if (a == b || ((a > b && c < 0) && (a - b) % (-c) == 0) ||         ((a < b && c > 0) && (b - a) % c == 0))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int check(vector<long long> &a, long long q) {     multiset<long long> s;     for (int j = 0; j < n; ++j) {       if (q + a[j] >= 0) {         q += a[j];         s.insert(a[j]);       } else if (a[j] > (*s.begin())) {         q += (a[j] - (*s.begin()));         s.erase(s.begin());         s.insert(a[j]);       }     }     return s.size();   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     vector<pair<long long, int> > b(m);     vector<int> out(m);     vector<long long> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < m; ++i) {       cin >> b[i].first;       b[i].second = i;     }     sort(b.begin(), b.end());     int pre = -1, li = 0;     for (int i = 0; i <= n && pre != m - 1; ++i) {       int l = pre + 1, h = m - 1;       while (l < h) {         int md = (h + l) >> 1;         if (check(a, b[md].first) >= i) {           h = md;         } else {           l = md + 1;         }       }       if (check(a, b[l].first) != i) {         continue;       }       for (int j = pre + 1; j < l; ++j) {         out[b[j].second] = n - li;       }       li = i;       out[b[l].second] = n - i;       pre = l;     }     while (pre != m) {       out[b[pre++].second] = n - li;     }     for (int i = 0; i < m; ++i) {       cout << out[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool life[1000005];   int main() {     long long a, b;     int l, r, mid;     int ans, cnt = 0;     scanf( %lld%lld , &a, &b);     l = 0;     r = 1000000007;     while (l != r) {       mid = (r + l + 1) / 2;       if (((mid + 1LL) * mid) / 2 > a + b)         r = mid - 1;       else         l = mid;     }     ans = l;     for (int i = l; i > 0; i--) {       if (a >= i) {         a -= i;         life[i] = 1;         cnt++;       }     }     printf( %d n , cnt);     if (cnt) {       for (int i = 1; i <= l; i++) {         if (life[i]) printf( %d  , i);       }       printf(  n );     }     printf( %d n , ans - cnt);     if (ans - cnt) {       for (int i = 1; i <= l; i++) {         if (!life[i]) printf( %d  , i);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int addingval[100];   long long int lastOcc[100];   long long int wt[100];   long long int cum[100005];   map<long long int, long long int> mp[100];   int main() {     for (int i = 0; i < 26; ++i) cin >> wt[i];     string s;     cin >> s;     int sz = s.size();     s =  $  + s;     long long int cnt = 0;     for (int i = 1; i <= sz; ++i) {       char c = s[i] -  a ;       cum[i] = cum[i - 1] + wt[c];       cnt += mp[c][cum[i - 1]];       mp[c][cum[i]]++;     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int a[26][26];   int main() {     int n;     cin >> n;     memset(a, 0, sizeof(a));     char ch[20];     int len;     for (int i = 1; i <= n; i++) {       scanf(  %s , ch);       for (len = 0; ch[len]; len++)         ;       for (int j = 0; j < 26; j++)         if (a[j][ch[0] -  a ]) {           a[j][ch[len - 1] -  a ] =               max(a[j][ch[len - 1] -  a ], a[j][ch[0] -  a ] + len);         }       a[ch[0] -  a ][ch[len - 1] -  a ] =           max(a[ch[0] -  a ][ch[len - 1] -  a ], len);     }     int ans = 0;     for (int i = 0; i < 26; i++) ans = max(ans, a[i][i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1 << 20;   int bio[MAX];   vector<int> V[MAX];   int a[MAX], b[MAX];   int deg[MAX];   void dfs(int x) {     if (bio[x]++) return;     for (auto it : V[x]) dfs(it);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int usebe = 0;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a[i], &b[i]);       a[i]--;       b[i]--;       V[a[i]].push_back(b[i]);       V[b[i]].push_back(a[i]);       if (a[i] == b[i])         usebe++;       else {         deg[a[i]]++;         deg[b[i]]++;       }     }     for (int i = 0; i < n; i++) {       if (V[i].size()) {         dfs(i);         break;       }     }     for (int i = 0; i < n; i++)       if (!bio[i] && V[i].size()) {         printf( 0 n );         return 0;       }     long long rje = 0;     rje += (long long)usebe * (usebe - 1) / 2;     rje += (long long)usebe * (m - usebe);     for (int i = 0; i < n; i++) rje += (long long)deg[i] * (deg[i] - 1) / 2;     printf( %lld n , rje);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int n, m;   int fir[N + 10][2], nex[N + 10][2], tot[2], en[N + 10][2];   int tag[N + 10][2], vis[N + 10];   void addEdge(int x, int y, int p) {     tot[p]++;     nex[tot[p]][p] = fir[x][p];     fir[x][p] = tot[p];     en[tot[p]][p] = y;   }   void dfs1(int x) {     vis[x] = 1;     for (int tmp = fir[x][0]; tmp > 0; tmp = nex[tmp][0]) {       int y = en[tmp][0];       if (vis[y] == 0) {         dfs1(y);       } else if (vis[y] == 1) {         puts( -1 );         exit(0);       }     }     vis[x] = 2;   }   void dfs2(int x, int p) {     if (tag[x][p] == 1) {       return;     }     tag[x][p] = 1;     for (int tmp = fir[x][p]; tmp > 0; tmp = nex[tmp][p]) {       int y = en[tmp][p];       if (tag[y][p] == 0) {         dfs2(y, p);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       addEdge(x, y, 0);       addEdge(y, x, 1);     }     for (int i = 1; i <= n; i++)       if (vis[i] == 0) {         dfs1(i);       }     string ans =   ;     int cnta = 0;     for (int i = 1; i <= n; i++) {       if (tag[i][0] == 0 && tag[i][1] == 0) {         ans +=  A ;         cnta++;       } else {         ans +=  E ;       }       dfs2(i, 0);       dfs2(i, 1);     }     printf( %d n , cnta);     printf( %s n , ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, arr[100001];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> s;     bool gotwater = false;     long long curt = 0, energy = 0, totwalk = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  L ) {         curt += arr[i];         if (energy < arr[i]) {           long long diff = arr[i] - energy;           if (gotwater)             curt += diff * 3;           else             curt += diff * 5;           energy += diff;         }         energy -= arr[i];       } else {         energy += arr[i];         if (s[i] ==  W ) {           gotwater = true;           curt += arr[i] * 3;         } else {           curt += arr[i] * 5;           totwalk += arr[i] * 2;         }       }       totwalk = min(totwalk, energy);     }     if (energy > 0) {       curt -= totwalk * 2;       curt -= (energy - totwalk);     }     cout << curt;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000000 + 7;   int main() {     long long a, b;     cin >> a >> b;     long long ans = 0;     for (long long r = 1; r < b; ++r) {       long long tmp = (a * (a + 1) / 2) % mod;       tmp = (tmp * r) % mod;       tmp = (tmp * b) % mod;       tmp = (tmp + (a * r) % mod) % mod;       ans = (ans + tmp) % mod;     }     if (ans < 0) ans += mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[101010];   long long l, r, pref[101010];   long long ans, cnt, sum, max1, min1, ali;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     string s;     cin >> n;     while (n--) {       cin >> l >> r;       if (l >= r)         cout << r << endl;       else {         min1 = r / l;         max1 = r % l;         ans = ((min1 + 1) * (min1 + 1)) * max1;         ans += (min1 * min1) * (l - max1);         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   const int mod = 998244353;   const int maxn = 2e5 + 10;   struct edge {     int st, ed;     int w;     bool operator<(const edge &b) const { return w < b.w; }     edge() {}     edge(int st, int ed, int w) : st(st), ed(ed), w(w) {}   };   edge e[maxn];   int vet[805];   ll dis[805][805];   int temp[805], cnt;   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < m; ++i) {       int x, y, w;       scanf( %d %d %d , &x, &y, &w);       e[i] = edge(x, y, w);     }     sort(e, e + m);     for (int i = 0; i < min(m, k); ++i) {       temp[cnt++] = e[i].st;       temp[cnt++] = e[i].ed;     }     sort(temp, temp + cnt);     cnt = unique(temp, temp + cnt) - temp;     memset(dis, 0x3f, sizeof(dis));     for (int i = 0; i < min(m, k); ++i) {       int x, y;       x = lower_bound(temp, temp + cnt, e[i].st) - temp;       y = lower_bound(temp, temp + cnt, e[i].ed) - temp;       dis[x][y] = min(dis[x][y], (ll)e[i].w);       dis[y][x] = dis[x][y];     }     for (int a = 0; a < cnt; ++a) {       for (int i = 0; i < cnt; ++i) {         for (int j = i + 1; j < cnt; ++j) {           dis[i][j] = min(dis[i][j], dis[i][a] + dis[a][j]);           dis[j][i] = dis[i][j];         }       }     }     vector<ll> ans;     for (int i = 0; i < cnt; ++i) {       for (int j = i + 1; j < cnt; ++j) ans.push_back(dis[i][j]);     }     sort(ans.begin(), ans.end());     printf( %lld n , ans[k - 1]);   }


#include <bits/stdc++.h>   using namespace std;   long long int check(long long int a) {     if (a >= 1000000000 + 7) a %= 1000000000 + 7;     return a;   }   long long int check2(long long int a) {     if (a > 0) return a;     long long int b = a / 1000000000 + 7;     a -= b * 1000000000 + 7;     if (a < 0) a += 1000000000 + 7;     return a;   }   long long int exp(long long int a, long long int n) {     if (n == 0) return 1;     if (n == 1) return check(a);     long long int b = exp(a, n / 2);     if (n % 2 == 0) return check(b * b);     return check(b * check(b * a));   }   int arr[4][4];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int i = 0; i < 4; i++)       for (int j = 0; j < 4; j++) cin >> arr[i][j];     for (int i = 0; i < 4; i++) {       if (arr[i][3] == 1)         for (int j = 0; j < 3; j++)           if (arr[i][j] == 1) {             cout <<  YES ;             return 0;           }     }     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 3; j++) {         int k = (i + 1 + j) % 4;         if (arr[i][3] == 1 && arr[i][3] == arr[k][j]) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }