#include <bits/stdc++.h>   using namespace std;   #define rep(i, a, b) for(int i=a; i<=b; i++)   #define repd(i, a, b) for(int i=a; i>=b; i--)   #define vi vector<int>   #define vll vector<long long>   #define pii pair<int,int>   #define pll pair<long long,long long>   #define pb push_back   #define fr first   #define sc second   #define vb vector<bool>      typedef long long ll;   typedef unsigned long long ull;      /*struct cmp {       bool operator()(const pair<int, pii> &p1, const pair<int, pii> &p2) {           return p1.fr > p2.fr;       }   };*/      void google(){    static int tc=1;    cout<< Case # <<tc<< :  ;    tc++;   }      int n;      void solve(int tc = 1) {        vi v(n);    for(int i=0;i<n;i++) cin>>v[i];        int cnt=0;    ll h=0;    priority_queue<ll> q;    for(int i=0;i<n;i++){     h+=v[i];     if(v[i]<0){      q.push(-v[i]);     }     cnt++;     if(h<0){      int val=q.top();      q.pop();      cnt--;      h+=val;     }     // cout<<cnt<<   <<h<<endl;    }        cout<<cnt<<endl;   }      int main() {   /*#ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif*/       ios::sync_with_stdio(false);       cin.tie(0);       //cout << setprecision(16) << fixed;       int t = 1;       // cin >> t;       int tc=0;       while (t--) {        cin>>n;           tc++;           solve(tc);       }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long a[1000005], b[1000005];   long long nine[100], t[100];   int main() {     int n, k;     t[0] = 1LL;     for (int i = (1); i <= (10); i++) t[i] = (t[i - 1] * 10LL) % mod;     nine[1] = 9LL;     for (int i = (2); i <= (10); i++) nine[i] = (nine[i - 1] * 10 + 9) % mod;     long long ans = 1;     scanf( %d , &(n));     scanf( %d , &(k));     for (int i = (1); i <= (n / k); i++) scanf( %lld , &(a[i]));     for (int i = (1); i <= (n / k); i++) scanf( %lld , &(b[i]));     t[0] = 0;     nine[0] = 9;     for (int i = (1); i <= (n / k); i++) {       long long f = ((t[k] - 1) / a[i]) + 1;       f %= mod;       long long ss = b[i];       long long temp = 0;       long long st = ss * t[k - 1];       long long e = st + nine[k - 1];       if (k == 1) st = b[i];       if (k == 1) e = st;       temp = ((e / a[i]) - ((st - 1) / a[i]));       if (st == 0) temp = e / a[i] + 1;       f -= temp;       if (f < mod) f += mod;       ans = (ans * f) % mod;     }     cout << ans % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, x1, y1, x2, y2, j, k, sum = 0;     int a[101][101];     memset(a, 0, sizeof(a));     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       for (k = x1; k <= x2; k++)         for (j = y1; j <= y2; j++) a[k][j]++;     }     for (i = 1; i <= 100; i++)       for (j = 1; j <= 100; j++) sum += a[i][j];     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int spend(int x) {     int b, total, cash_back, left;     cash_back = x / 10;     b = cash_back * 10;     left = x - b + cash_back;     if (cash_back < 1) {       return left;     }     return b + spend(left);   }   int main() {     int testcase;     cin >> testcase;     int burles[testcase];     for (int i = 0; i < testcase; ++i) {       cin >> burles[i];       cout << spend(burles[i]);       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q;   string s;   int main() {     cin >> n >> q;     while (q--) {       vector<pair<long long, long long> > v;       long long x, l = 1, r = n, cur = n / 2 + 1;       cin >> x >> s;       while (cur != x) {         v.push_back({l, r});         if (x < cur) {           r = cur - 1;           cur = (l + r) / 2;         } else {           l = cur + 1;           cur = (l + r) / 2;         }       }       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  U ) {           if (!v.empty()) {             l = v.back().first, r = v.back().second;             cur = (l + r) / 2;             v.pop_back();           }         }         if (s[i] ==  L ) {           if (l != r) {             v.push_back({l, r});             r = cur - 1;             cur = (l + r) / 2;           }         }         if (s[i] ==  R ) {           if (l != r) {             v.push_back({l, r});             l = cur + 1;             cur = (l + r) / 2;           }         }       }       cout << cur << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve(void);   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       { solve(); }     }     return 0;   }   void solve() {     long long int n, i;     cin >> n;     vector<long long int> v;     for (i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i != n / i) v.push_back(n / i);       }     }     sort(v.rbegin(), v.rend());     for (auto x : v) {       long long int len = n / x;       long long int a1 = 1;       long long int aend = 1 + (len - 1) * x;       cout << (len * (a1 + aend)) / 2 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2, typename T3>   T2 x_pow_y(T1 x, T3 y, T2 mod) {     T2 ans = 1;     long long a = x % mod;     while (y) {       if (y & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       y >>= 1;     }     return ans;   }   template <typename T1, typename T2>   T2 inv_mod(T1 x, T2 mod) {     return x_pow_y(x, mod - 2, mod);   }   template <typename T>   vector<T> find_factors(T &n) {     vector<T> factors;     int i;     for (i = 1; i * i < n; i++) {       if (n % i == 0) {         factors.push_back(i);         factors.push_back(n / i);       }     }     if (i * i == n) factors.push_back(i);     return factors;   }   void sieve(vector<int> &prime, size_t max) {     vector<int> ar(max + 1, 1);     ar[0] = ar[1] = 0;     for (int i = 2; i * i <= max; i++) {       if (!ar[i]) continue;       for (int j = i * i; j <= max; j++) ar[j] = 0;     }     for (int i = 2; i <= max; i++) {       if (ar[i]) prime.push_back(i);     }   }   template <typename T1, typename T2>   void make_pascal_triangle_mod_p(vector<vector<T1>> &binomial_coefficient,                                   size_t size, T2 &mod) {     for (int i = 0; i <= size; i++) {       vector<T1> temp(i + 1, 1);       for (int j = 1; j <= i / 2; j++) {         temp[i - j] = temp[j] = (binomial_coefficient[i - 1][j] +                                  binomial_coefficient[i - 1][j - 1]) %                                 mod;       }       binomial_coefficient.push_back(temp);     }   }   template <typename T1, typename T2>   void find_factorial_mod_p(vector<T1> &fact, size_t size, T2 mod) {     fact.resize(size + 1, 1);     for (size_t i = 2; i <= size; i++) {       fact[i] = (i * fact[i - 1]) % mod;     }   }   template <typename T1, typename T2>   T2 nCr_mod_p(vector<T1> &fact, size_t n, size_t r, T2 &mod) {     if (fact.empty()) find_factorial(fact, n, mod);     size_t f_n = fact[n];     size_t f_r = inv_mod(fact[r], mod);     size_t f_nr = inv_mod(fact[n - r], mod);     return (f_nr * ((f_n * f_r) % mod)) % mod;   }   size_t nCr(size_t n, size_t r) {     if (n - r < r) r = n - r;     size_t ans = 1;     for (int i = 0; i < n; i++) {       ans *= (n - i);       ans /= (i + 1);     }     return ans;   }   vector<vector<int>> out_;   bool fill_requirements(int s, int n) {     int r_sum[n], c_sum[n];     memset(r_sum, 0, n * sizeof(int));     memset(c_sum, 0, n * sizeof(int));     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         r_sum[i] += out_[i][j];         c_sum[j] += out_[i][j];       }     }     bool flag = true;     for (int i = 0; i < n; i++) {       if (r_sum[i] != s) {         flag = false;         break;       }       if (c_sum[i] != s) {         flag = false;         break;       }     }     int diag_sum = 0;     for (int i = 0; i < n; i++) {       diag_sum += out_[i][i];     }     if (diag_sum != s) flag = false;     int i = n - 1, j = 0;     diag_sum = 0;     while (j != n) {       diag_sum += out_[i][j];       i--;       j++;     }     if (diag_sum != s) flag = false;     return flag;   }   bool flag = false;   void fill_array(int s, vector<int> &ar, int n, int i, int j, vector<int> &vis) {     if (i == n - 1 && j == n) {       flag = fill_requirements(s, n);       return;     }     if (j == n) {       j = 0;       i++;     }     for (int indx = 0; indx < n * n; indx++) {       if (vis[indx]) continue;       vis[indx] = 1;       out_[i][j] = ar[indx];       fill_array(s, ar, n, i, j + 1, vis);       if (flag) {         return;       } else {         vis[indx] = 0;       }     }   }   void solve() {     int n;     cin >> n;     vector<int> ar(n * n);     for (int i = 0; i < n * n; i++) cin >> ar[i];     int sum = 0;     for (int i = 0; i < n * n; i++) sum += ar[i];     out_ = vector<vector<int>>(n, vector<int>(n));     int s = sum / n;     vector<int> vis(n * n);     fill_array(s, ar, n, 0, 0, vis);     cout << s <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) cout << out_[i][j] <<    ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   enum { UP, DOWN, LEFT, RIGHT };   const int MAX = 15500;   struct Node {     int dir;     Node* pt[4];   } node[MAX], *cur, *row[MAX], *col[MAX], *st[MAX];   char s[MAX];   int r, c, top;   int getDir(char c) {     switch (c) {       case  U :         return UP;       case  D :         return DOWN;       case  L :         return LEFT;       case  R :         return RIGHT;     }     return -1;   }   void init() {     cur = node;     top = 0;     for (int i = 0; i < r; i++) {       row[i] = cur++;       row[i]->pt[LEFT] = row[i]->pt[RIGHT] = row[i];       row[i]->pt[UP] = row[i]->pt[DOWN] = NULL;       row[i]->dir = -1;     }     for (int i = 0; i < c; i++) {       col[i] = cur++;       col[i]->pt[UP] = col[i]->pt[DOWN] = col[i];       col[i]->pt[LEFT] = col[i]->pt[RIGHT] = NULL;       col[i]->dir = -1;     }   }   Node* add(int x, int y, int dir) {     cur->pt[RIGHT] = row[x]->pt[RIGHT];     cur->pt[LEFT] = row[x];     cur->pt[DOWN] = col[y]->pt[DOWN];     cur->pt[UP] = col[y];     cur->pt[LEFT]->pt[RIGHT] = cur;     cur->pt[RIGHT]->pt[LEFT] = cur;     cur->pt[UP]->pt[DOWN] = cur;     cur->pt[DOWN]->pt[UP] = cur;     cur->dir = dir;     return cur++;   }   int dfs(Node* t) {     if (t->dir == -1) return 0;     t->pt[LEFT]->pt[RIGHT] = t->pt[RIGHT];     t->pt[RIGHT]->pt[LEFT] = t->pt[LEFT];     t->pt[UP]->pt[DOWN] = t->pt[DOWN];     t->pt[DOWN]->pt[UP] = t->pt[UP];     int ret = dfs(t->pt[t->dir]) + 1;     t->pt[LEFT]->pt[RIGHT] = t;     t->pt[RIGHT]->pt[LEFT] = t;     t->pt[UP]->pt[DOWN] = t;     t->pt[DOWN]->pt[UP] = t;     return ret;   }   int main() {     int ret, cnt;     while (scanf( %d%d , &r, &c) == 2) {       ret = -1;       cnt = 0;       init();       for (int i = 0; i < r; i++) {         scanf( %s , &s[i * c]);       }       for (int i = r - 1; i >= 0; i--) {         for (int j = c - 1; j >= 0; j--) {           if (s[i * c + j] !=  . ) st[top++] = add(i, j, getDir(s[i * c + j]));         }       }       for (int i = 0; i < top; i++) {         int sub = dfs(st[i]);         if (sub > ret) {           ret = sub;           cnt = 1;         } else if (sub == ret) {           cnt++;         }       }       printf( %d %d n , ret, cnt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, j, ans = 1, val[256], v;     string s, p;     cin >> s;     char a;     for (a =  0 ; a <=  9 ; a++) {       p.push_back(a);     }     for (a =  A ; a <=  Z ; a++) {       p.push_back(a);     }     for (a =  a ; a <=  z ; a++) {       p.push_back(a);     }     p.push_back( - );     p.push_back( _ );     for (i = 0; i <= 63; ++i) {       val[p[i]] = i;     }     for (i = 0; i < s.length(); ++i) {       v = val[s[i]];       for (j = 0; j < 6; ++j) {         if ((v & (1 << j)) == 0) {           ans = (ans * 3) % 1000000007;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline long long inc(int &x) { return ++x; }   inline long long inc(long long &x) { return ++x; }   inline long long inc(int &x, long long y) { return x += y; }   inline long long inc(long long &x, long long y) { return x += y; }   inline double inc(double &x, double y) { return x += y; }   inline long long dec(int &x) { return --x; }   inline long long dec(long long &x) { return --x; }   inline long long dec(int &x, long long y) { return x -= y; }   inline long long dec(long long &x, long long y) { return x -= y; }   inline double dec(double &x, double y) { return x -= y; }   inline long long mul(int &x) { return x = ((long long)x) * x; }   inline long long mul(long long &x) { return x = x * x; }   inline long long mul(int &x, long long y) { return x *= y; }   inline long long mul(long long &x, long long y) { return x *= y; }   inline double mul(double &x, double y) { return x *= y; }   inline long long divi(int &x) { return x = sqrt(x); }   inline long long divi(long long &x) { return x = sqrt(x); }   inline long long divi(int &x, long long y) { return x /= y; }   inline long long divi(long long &x, long long y) { return x /= y; }   inline double divi(double &x, double y) { return x /= y; }   inline long long mod(int &x, long long y) { return x %= y; }   inline long long mod(long long &x, long long y) { return x %= y; }   long long n, m, i, j, ans = 0;   string s;   int main() {     cin >> n >> s;     if (n == 1) {       if (s ==  ? ) {         cout <<  Yes ;         return 0;       } else {         cout <<  No ;         return 0;       };     }     s =     + s +    ;     for (i = 1; i + 1 < s.size(); i++) {       if (s[i] !=  ?  && s[i] == s[i - 1]) {         cout <<  No ;         return 0;       };     }     s[0] = s[2];     s[s.size() - 1] = s[s.size() - 3];     for (i = 1; i + 1 < s.size(); i++) {       if (s[i] ==  ? ) {         if (s[i - 1] != s[i + 1] && s[i - 1] !=  ?  && s[i + 1] !=  ? )           ans++;         else {           cout <<  Yes ;           return 0;         };       }     }     {       cout <<  No ;       return 0;     };     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   int z[][2] = {{-1, 0}, {1, 0}};   vector<ii> solve(int x, int y) {     if (x < y) swap(x, y);     vector<ii> a;     x -= y - 1;     for (int k = 0; k < 2 * y - 1; ++k) {       a.push_back({2, 3 + k});       if (~k & 1)         for (int j = 0; j < 2 && x > 0; ++j, --x)           a.push_back({2 + z[j][0], 3 + k + z[j][1]});     }     if (x-- > 0) a.push_back({2, 2});     if (x > 0) a.push_back({2, 4 + 2 * (y - 1)});     return a;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int b, w;       cin >> b >> w;       if (max(w, b) > 3 * min(w, b) + 1) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       auto a = solve(w, b);       if (b > w)         for (auto& [x, y] : a) --y;       for (auto [x, y] : a) cout << x <<     << y <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long N, K;     cin >> N >> K;     vector<long long> A(N), sum(N + 1, 0);     long long ans = 0;     for (long long i = 0; i < N; i++) {       cin >> A[i];       ans += A[i];       sum[i + 1] += sum[i] + A[i];     }     vector<long long> tmp;     for (long long i = (1); i <= (N - 1); ++i) {       tmp.push_back(sum[N] - sum[i]);     }     sort((tmp).rbegin(), (tmp).rend());     for (long long i = 0; i < K - 1; i++) ans += tmp[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int ans = 1, n, mod = 1000003;     scanf( %d , &n);     for (int i = 0; i < n - 1; i++) {       ans *= 3;       ans %= mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) sum += s[i] -  0 ;     for (int i = 2; i <= n; i++) {       if (sum % i == 0) {         int cur = 0;         bool flag = 1;         for (int j = 0; j < n; j++) {           cur += s[j] -  0 ;           if (sum / i < cur) {             flag = 0;             break;           }           if (sum / i == cur) cur = 0;         }         if (flag) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   long long f[200010];   vector<pair<int, long long> > ke[200010];   struct te {     int l, r;     long long s;   } a[200010];   bool cmp(te i, te j) { return ((i.l < j.l) || (i.l == j.l && i.r < j.r)); }   int main() {     if (fopen( a.txt ,  r )) {       freopen( a.txt ,  r , stdin);     } else       ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> x;     for (int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r >> a[i].s;     sort(a + 1, a + n + 1, cmp);     int cur = 0;     for (int i = 0; i <= x; i++) f[i] = (1LL << 61);     long long res = (1LL << 61);     for (int i = 1; i <= n; i++) {       while (cur < a[i].l - 1) {         cur++;         for (auto tmp : ke[cur]) {           f[tmp.first] = min(f[tmp.first], tmp.second);         }       }       if (x > a[i].r - a[i].l + 1)         res = min(res, a[i].s + f[x - a[i].r + a[i].l - 1]);       ke[a[i].r].push_back(make_pair(a[i].r - a[i].l + 1, a[i].s));     }     if (res >= (1LL << 61)) res = -1;     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   constexpr long double m_pi = 3.1415926535897932L;   constexpr long long MOD = 1000000007;   constexpr long long INF = 1LL << 61;   constexpr long double EPS = 1e-10;   template <typename T>   using vector2 = vector<vector<T>>;   template <typename T>   using vector3 = vector<vector2<T>>;   string operator*(const string& s, int k) {     if (k == 0) return   ;     string p = (s + s) * (k / 2);     if (k % 2 == 1) p += s;     return p;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   struct Edge {     int to, rev;     long long cap;     Edge(int _to, long long _cap, int _rev) {       to = _to;       cap = _cap;       rev = _rev;     }   };   void add_edge(vector<vector<Edge>>& G, int from, int to, long long cap,                 bool revFlag, long long revCap) {     G[from].push_back(Edge(to, cap, (long long)G[to].size() + (from == to)));     if (revFlag)       G[to].push_back(Edge(from, revCap, (long long)G[from].size() - 1));   }   long long max_flow_dfs(vector<vector<Edge>>& G, long long v, long long t,                          long long f, vector<bool>& used) {     if (v == t) return f;     used[v] = true;     for (int i = 0; i < G[v].size(); ++i) {       Edge& e = G[v][i];       if (!used[e.to] && e.cap > 0) {         long long d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);         if (d > 0) {           e.cap -= d;           G[e.to][e.rev].cap += d;           return d;         }       }     }     return 0;   }   long long max_flow(vector<vector<Edge>>& G, long long s, long long t) {     long long flow = 0;     for (;;) {       vector<bool> used(G.size());       for (long long(i) = (long long)(0); i < (long long)(used.size()); i++)         used[i] = false;       long long f = max_flow_dfs(G, s, t, INF, used);       if (f == 0) {         return flow;       }       flow += f;     }   }   void BellmanFord(vector<vector<Edge>>& G, long long s, vector<long long>& d,                    vector<long long>& negative) {     d.resize(G.size());     negative.resize(G.size());     for (long long(i) = (long long)(0); i < (long long)(d.size()); i++)       d[i] = INF;     for (long long(i) = (long long)(0); i < (long long)(d.size()); i++)       negative[i] = false;     d[s] = 0;     for (long long(k) = (long long)(0); k < (long long)(G.size() - 1); k++) {       for (long long(i) = (long long)(0); i < (long long)(G.size()); i++) {         for (long long(j) = (long long)(0); j < (long long)(G[i].size()); j++) {           if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {             d[G[i][j].to] = d[i] + G[i][j].cap;           }         }       }     }     for (long long(k) = (long long)(0); k < (long long)(G.size() - 1); k++) {       for (long long(i) = (long long)(0); i < (long long)(G.size()); i++) {         for (long long(j) = (long long)(0); j < (long long)(G[i].size()); j++) {           if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {             d[G[i][j].to] = d[i] + G[i][j].cap;             negative[G[i][j].to] = true;           }           if (negative[i] == true) negative[G[i][j].to] = true;         }       }     }   }   void Dijkstra(vector<vector<Edge>>& G, long long s, vector<long long>& d) {     d.resize(G.size());     for (long long(i) = (long long)(0); i < (long long)(d.size()); i++)       d[i] = INF;     d[s] = 0;     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         q;     q.push(make_pair(0, s));     while (!q.empty()) {       pair<long long, long long> a = q.top();       q.pop();       if (d[a.second] < a.first) continue;       for (long long(i) = (long long)(0); i < (long long)(G[a.second].size());            i++) {         Edge e = G[a.second][i];         if (d[e.to] > d[a.second] + e.cap) {           d[e.to] = d[a.second] + e.cap;           q.push(make_pair(d[e.to], e.to));         }       }     }   }   void WarshallFloyd(vector<vector<Edge>>& G, vector<vector<long long>>& d) {     d.resize(G.size());     for (long long(i) = (long long)(0); i < (long long)(d.size()); i++)       d[i].resize(G.size());     for (long long(i) = (long long)(0); i < (long long)(d.size()); i++) {       for (long long(j) = (long long)(0); j < (long long)(d[i].size()); j++) {         d[i][j] = ((i != j) ? INF : 0);       }     }     for (long long(i) = (long long)(0); i < (long long)(G.size()); i++) {       for (long long(j) = (long long)(0); j < (long long)(G[i].size()); j++) {         chmin(d[i][G[i][j].to], G[i][j].cap);       }     }     for (long long(i) = (long long)(0); i < (long long)(G.size()); i++) {       for (long long(j) = (long long)(0); j < (long long)(G.size()); j++) {         for (long long(k) = (long long)(0); k < (long long)(G.size()); k++) {           if (d[j][i] != INF && d[i][k] != INF) chmin(d[j][k], d[j][i] + d[i][k]);         }       }     }   }   bool tsort(vector<vector<Edge>>& graph, vector<int>& order) {     int n = graph.size(), k = 0;     vector<int> in(n);     for (auto& es : graph)       for (auto& e : es) in[e.to]++;     priority_queue<int, vector<int>, greater<int>> que;     for (long long(i) = (long long)(0); i < (long long)(n); i++)       if (in[i] == 0) que.push(i);     while (que.size()) {       int v = que.top();       que.pop();       order.push_back(v);       for (auto& e : graph[v])         if (--in[e.to] == 0) que.push(e.to);     }     if (order.size() != n)       return false;     else       return true;   }   class Lca {    public:     const int n = 0;     const int log2_n = 0;     std::vector<std::vector<int>> parent;     std::vector<int> depth;     Lca() {}     Lca(const vector<vector<Edge>>& g, int root)         : n(g.size()),           log2_n(log2(n) + 1),           parent(log2_n, std::vector<int>(n)),           depth(n) {       dfs(g, root, -1, 0);       for (int k = 0; k + 1 < log2_n; k++) {         for (int v = 0; v < (int)g.size(); v++) {           if (parent[k][v] < 0)             parent[k + 1][v] = -1;           else             parent[k + 1][v] = parent[k][parent[k][v]];         }       }     }     void dfs(const vector<vector<Edge>>& g, int v, int p, int d) {       parent[0][v] = p;       depth[v] = d;       for (auto& e : g[v]) {         if (e.to != p) dfs(g, e.to, v, d + 1);       }     }     int get(int u, int v) {       if (depth[u] > depth[v]) std::swap(u, v);       for (int k = 0; k < log2_n; k++) {         if ((depth[v] - depth[u]) >> k & 1) {           v = parent[k][v];         }       }       if (u == v) return u;       for (int k = log2_n - 1; k >= 0; k--) {         if (parent[k][u] != parent[k][v]) {           u = parent[k][u];           v = parent[k][v];         }       }       return parent[0][u];     }   };   class UnionFind {     vector<int> data;     int n;       public:     UnionFind(int size) : data(size, -1), n(size) {}     bool merge(int x, int y) {       x = root(x);       y = root(y);       if (x != y) {         if (data[y] < data[x]) swap(x, y);         data[x] += data[y];         data[y] = x;       }       n -= (x != y);       return x != y;     }     bool same(int x, int y) { return root(x) == root(y); }     int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }     int size(int x) { return -data[root(x)]; }     int num() { return n; }   };   template <typename T, typename F>   class SegmentTree {    private:     T identity;     F merge;     long long n;     vector<T> dat;       public:     SegmentTree(F f, T id, vector<T> v) : merge(f), identity(id) {       int _n = v.size();       n = 1;       while (n < _n) n *= 2;       dat.resize(2 * n - 1, identity);       for (long long(i) = (long long)(0); i < (long long)(_n); i++)         dat[n + i - 1] = v[i];       for (int i = n - 2; i >= 0; i--)         dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]);     }     SegmentTree(F f, T id, int _n) : merge(f), identity(id) {       n = 1;       while (n < _n) n *= 2;       dat.resize(2 * n - 1, identity);     }     void set_val(int i, T x) {       i += n - 1;       dat[i] = x;       while (i > 0) {         i = (i - 1) / 2;         dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]);       }     }     T query(int l, int r) {       T left = identity, right = identity;       l += n - 1;       r += n - 1;       while (l < r) {         if ((l & 1) == 0) left = merge(left, dat[l]);         if ((r & 1) == 0) right = merge(dat[r - 1], right);         l = l / 2;         r = (r - 1) / 2;       }       return merge(left, right);     }   };   template <typename T>   class FenwickTree {     vector<T> data;     int n;     int p;       public:     FenwickTree(int n) : n(n) {       data.resize(n + 1LL, 0);       p = 1;       while (p < data.size()) p *= 2;     }     T sum(int k) {       T ret = 0;       for (; k > 0; k -= k & -k) ret += data[k];       return (ret);     }     T sum(int a, int b) { return sum(b) - sum(a); }     void add(int k, T x) {       for (++k; k <= n; k += k & -k) data[k] += x;     }     int lower_bound(long long w) {       if (w <= 0) return -1;       int x = 0;       for (int k = p / 2; k > 0; k /= 2) {         if (x + k <= n && data[x + k] < w) w -= data[x + k], x += k;       }       return x;     }   };   void divisor(long long n, vector<long long>& ret) {     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         ret.push_back(i);         if (i * i != n) ret.push_back(n / i);       }     }     sort(ret.begin(), ret.end());   }   void prime_factorization(long long n, vector<pair<long long, long long>>& ret) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         ret.push_back({i, 0});         while (n % i == 0) {           n /= i;           ret[ret.size() - 1].second++;         }       }     }     if (n != 1) ret.push_back({n, 1});   }   inline long long mod_pow(long long x, long long n, long long mod) {     long long res = 1;     while (n > 0) {       if (n & 1) res = res * x % mod;       x = x * x % mod;       n >>= 1;     }     return res;   }   inline long long mod_inv(long long x, long long mod) {     return mod_pow(x, mod - 2, mod);   }   class Combination {    public:     vector<long long> fact;     vector<long long> fact_inv;     long long mod;     long long nCr(long long n, long long r) {       if (n < r) return 0;       if (n < mod) return ((fact[n] * fact_inv[r] % mod) * fact_inv[n - r]) % mod;       long long ret = 1;       while (n || r) {         long long _n = n % mod, _r = r % mod;         n /= mod;         r /= mod;         (ret *= nCr(_n, _r)) %= mod;       }       return ret;     }     long long nPr(long long n, long long r) {       return (fact[n] * fact_inv[n - r]) % mod;     }     long long nHr(long long n, long long r) { return nCr(r + n - 1, r); }     Combination(long long _n, long long _mod) {       mod = _mod;       long long n = min(_n + 1, mod);       fact.resize(n);       fact[0] = 1;       for (long long(i) = (long long)(0); i < (long long)(n - 1); i++) {         fact[i + 1] = (fact[i] * (i + 1LL)) % mod;       }       fact_inv.resize(n);       fact_inv[n - 1] = mod_inv(fact[n - 1], mod);       for (int i = n - 1; i > 0; i--) {         fact_inv[i - 1] = fact_inv[i] * i % mod;       }     }   };   long long popcount(long long x) {     x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);     x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);     x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F);     x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF);     x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF);     x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF);     return x;   }   int main() {     ios::sync_with_stdio(false);     std::cin.tie(0);     std::cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     for (long long(i) = (long long)(0); i < (long long)(n); i++) cin >> a[i];     vector<array<int, 3>> ans;     for (int i = n; i >= 3; i -= 2) {       ans.push_back({i - 2, i - 1, i});       long long t = a[i - 3] ^ a[i - 2] ^ a[i - 1];       a[i - 3] = a[i - 2] = a[i - 1] = t;     }     for (int i = 3 + (n % 2 == 0 ? 1 : 0); i <= n - 2; i += 2) {       ans.push_back({i, i + 1, i + 2});       long long t = a[i - 1] ^ a[i] ^ a[i + 1];       a[i - 1] = a[i] = a[i + 1] = t;     }     if (*min_element((a).begin(), (a).end()) ==         *max_element((a).begin(), (a).end())) {       cout <<  YES             <<   n ;       cout << ans.size() <<   n ;       for (auto e : ans) cout << e[0] <<     << e[1] <<     << e[2] << endl;     } else       cout <<  NO             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed;   }   int main() {     fastio();     int n;     cin >> n;     long long int a[n];     long long int totsum = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       totsum += a[i];     }     int m = n - 1;     m >>= 1;     long long int cursum = 0;     for (int i = 0; i < m; i++) cursum += a[2 * i];     long long int maxsum = totsum - cursum;     int last = 0;     int first = 2 * m - 2;     for (int i = 0; i < n; i++) {       cursum -= a[last];       last += 2;       last %= n;       first += 2;       first %= n;       cursum += a[first];       maxsum = max(maxsum, totsum - cursum);     }     cout << maxsum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using i3 = pair<int, ii>;   using li = pair<ll, int>;   using lii = pair<ll, ii>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   using vli = vector<li>;   using vpll = vector<pll>;   using vi3 = vector<i3>;   using vlii = vector<lii>;   const int N = 2e5 + 5, L = 20;   const ll INF = 1e17 + 7, mod = 1e9 + 7;   const double eps = 1e-9, PI = acos(-1);   int n, m;   vector<ii> adj[N];   vector<int> tree[N];   int down[N], level[N];   int cycleId[N];   int to[N][L];   int dep[N];   int cact[N];   void dfs(int u, int p) {     cycleId[u] = u;     level[u] = 1 + level[p];     for (ii A : adj[u]) {       int v = A.second;       int e = A.first;       if (cycleId[v] == 0) {         dfs(v, u);       } else if (v != p) {         if (level[v] < level[u])           cycleId[u] = e;         else           down[u]++;       }     }     for (ii A : adj[u]) {       int v = A.second;       if (v == p) continue;       if ((cycleId[v] != v) && (down[v] == 0)) {         cycleId[u] = cycleId[v];       }     }   }   void dfsTree(int u, int p) {     to[u][0] = p;     dep[u] = 1 + dep[p];     for (int i = 1; i < L; i++) {       to[u][i] = to[to[u][i - 1]][i - 1];     }     for (int v : tree[u]) {       if (v != p) {         cact[v] += cact[u];         dfsTree(v, u);       }     }   }   int jump(int u, int k) {     for (int i = 0; i < L; i++)       if (k & (1 << i)) u = to[u][i];     return u;   }   int LCA(int u, int v) {     if (u == v) return u;     if (dep[u] < dep[v]) swap(u, v);     u = jump(u, dep[u] - dep[v]);     if (u == v) return u;     for (int i = L - 1; i >= 0; i--) {       if (to[u][i] != to[v][i]) {         u = to[u][i];         v = to[v][i];       }     }     return to[u][0];   }   ll pow_mod(ll a, ll b) {     ll ret = 1ll;     a %= mod;     for (; b; ret = ret * (b & 1 ? a : 1ll) % mod, a = a * a % mod, b >>= 1ll)       ;     return ret;   }   ll calc(int u, int v) {     ll A = cact[u];     ll B = cact[v];     int lca = LCA(u, v);     ll C = cact[lca];     return pow_mod(2, A + B - 2 * C + (lca > n));   }   void solve(int testCase) {     scanf( %d %d , &n, &m);     vii edges;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u].push_back({i + n + 1, v});       adj[v].push_back({i + n + 1, u});       edges.push_back({u, v});     }     level[1] = 0;     dfs(1, 0);     for (pair<int, int> E : edges) {       int u = cycleId[E.first];       int v = cycleId[E.second];       if (u != v) {         tree[u].push_back(v);         tree[v].push_back(u);       }     }     for (int i = 1; i <= n; i++) {       cact[cycleId[i]] = (cycleId[i] != i);     }     dfsTree(cycleId[1], 0);     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d %d , &u, &v);       printf( %lld n , calc(cycleId[u], cycleId[v]));     }   }   int main() {     int t = 1;     for (int testCase = 1; testCase <= t; testCase++) {       solve(testCase);     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 2e5 + 50;   using namespace std;   int n;   long long a[maxn], dp[maxn], he[maxn];   vector<int> maps[maxn];   void dfs(int u, int fa) {     he[u] = 0;     for (int i = 0, len = maps[u].size(); i < len; i++) {       int v = maps[u][i];       if (v != fa) {         dfs(v, u);         dp[u] += dp[v] + he[v];         he[u] += he[v];       }     }     he[u] += a[u];   }   long long ans;   void dfs1(int u, int fa) {     for (int i = 0, len = maps[u].size(); i < len; i++) {       int v = maps[u][i];       if (v != fa) {         dp[v] = dp[u] - he[v] + he[1] - he[v];         ans = max(ans, dp[v]);         dfs1(v, u);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1, a, b; i < n; i++) {       scanf( %d%d , &a, &b);       maps[a].push_back(b);       maps[b].push_back(a);     }     dfs(1, 1);     ans = dp[1];     dfs1(1, 1);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long maxa = 0;     for (int i = 0; i < k; i++) {       maxa += n - i;     }     vector<int> pos;     for (int i = 0; i < n; i++) {       if (a[i] > n - k) {         pos.emplace_back(i);       }     }     sort(pos.begin(), pos.end());     long long ans = 1;     for (int i = 1; i < pos.size(); i++) {       ans *= pos[i] - pos[i - 1];       ans %= mod;     }     cout << maxa <<     << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.141592653589793238462643383;   int main() {     {       int n, m, k, t;       cin >> n >> m >> k >> t;       set<int> s;       ;       for (long long i = 0; i < k; i++) {         int a, b;         cin >> a >> b;         int id = (a - 1) * m + b;         s.insert(id);       };       for (long long i = 0; i < t; i++) {         int a, b;         cin >> a >> b;         int id = (a - 1) * m + b;         if (s.find(id) != s.end())           cout <<  Waste  << endl;         else {           auto it = lower_bound(s.begin(), s.end(), id);           int d = distance(s.begin(), it);           int val = (id - d) % 3;           if (val == 0)             cout <<  Grapes  << endl;           else if (val == 1)             cout <<  Carrots  << endl;           else             cout <<  Kiwis  << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   array<string, 1510> arr;   unordered_set<string> f;   int n, k, t = int( S  +  E  +  T );   char get(char c1, char c2) {     if (c1 == c2) return c1;     return t - c1 - c2;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       cin >> arr[i];       f.insert(arr[i]);     }     int res = 0;     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) {         string s =   ;         for (int p = 0; p < k; p++) s.push_back(get(arr[i][p], arr[j][p]));         if (f.count(s)) res++;       }     printf( %d n , res / 3);   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int& i : a) cin >> i;     int M = *min_element((a).begin(), (a).end());     int c = 0;     for (int& i : a) c += M == i;     if (c <= n / 2)       cout <<  Alice ;     else       cout <<  Bob ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     int n;     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) cout << 400 <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   int _min(int a, int b) {     if (a < b) return a;     return b;   }   int _max(int a, int b) {     if (a > b) return a;     return b;   }   int main() {     int i, j, k;     int n;     int x1, y1, x2, y2, x3, y3, res;     scanf( %d %d , &x1, &y1);     scanf( %d %d , &x2, &y2);     scanf( %d %d , &x3, &y3);     if ((x1 == x2 && x1 == x3) || (y1 == y2 && y1 == y3)) {       printf( 1 );       return 0;     }     if (x1 == x2) {       int min = _min(y1, y2);       int max = _max(y1, y2);       if (y3 <= min || y3 >= max) {         printf( 2 );         return 0;       }     }     if (y1 == y2) {       int min = _min(x1, x2);       int max = _max(x1, x2);       if (x3 <= min || x3 >= max) {         printf( 2 );         return 0;       }     }     if (x1 == x3) {       int min = _min(y1, y3);       int max = _max(y1, y3);       if (y2 <= min || y2 >= max) {         printf( 2 );         return 0;       }     }     if (y1 == y3) {       int min = _min(x1, x3);       int max = _max(x1, x3);       if (x2 <= min || x2 >= max) {         printf( 2 );         return 0;       }     }     if (x3 == x2) {       int min = _min(y3, y2);       int max = _max(y3, y2);       if (y1 <= min || y1 >= max) {         printf( 2 );         return 0;       }     }     if (y3 == y2) {       int min = _min(x3, x2);       int max = _max(x3, x2);       if (x1 <= min || x1 >= max) {         printf( 2 );         return 0;       }     }     printf( 3 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, m, ax, ay, cx, cy;   int d[100][100], s[100][100];   void take(int ax, int ay, int m) {     for (int y = ay; y < ay + m; ++y) {       for (int i = y; i <= k; ++i) ++s[ax][i];     }   }   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       cx = cy = (k + 1) / 2;       memset(s, 0, sizeof(s));       for (int x = 1; x <= k; ++x)         for (int y = 1; y <= k; ++y)           d[x][y] = d[x][y - 1] + abs(x - cx) + abs(y - cy);       for (int i = 0; i < n; ++i) {         scanf( %d , &m);         int ax = -1, ay = -1, mini = 1000000000;         for (int x = 1; x <= k; ++x) {           for (int y = 1; y + m - 1 <= k; ++y) {             if (s[x][y + m - 1] - s[x][y - 1] == 0) {               if (d[x][y + m - 1] - d[x][y - 1] < mini) {                 ax = x, ay = y;                 mini = d[x][y + m - 1] - d[x][y - 1];               }             }           }         }         if (ax == -1) {           puts( -1 );         } else {           take(ax, ay, m);           printf( %d %d %d n , ax, ay, ay + m - 1);         }       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e4 + 44;   const long long INF = 1e11 + 9;   const double eps = 1e-12;   int main() {     int t;     scanf( %d , &t);     long long x1, y1, x2, y2, n, m;     long long x3, y3, x4, y4;     long long answ = 0, ansb = 0;     while (t--) {       scanf( %lld , &n);       scanf( %lld , &m);       if (n % 2 == 0 || m % 2 == 0) {         answ = ansb = n * m / 2;       } else {         answ = (n * m) / 2 + 1;         ansb = answ - 1;       }       scanf( %lld , &x1);       scanf( %lld , &y1);       scanf( %lld , &x2);       scanf( %lld , &y2);       long long dx = x2 - x1 + 1, dy = y2 - y1 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         answ += (dx * dy) / 2;         ansb -= (dx * dy) / 2;       } else {         if (x1 % 2 && y1 % 2 || x1 % 2 == 0 && y1 % 2 == 0) {           answ += (dx * dy) / 2;           ansb -= (dx * dy) / 2;         } else {           answ += (dx * dy) / 2 + 1;           ansb -= (dx * dy) / 2 + 1;         }       }       scanf( %lld , &x3);       scanf( %lld , &y3);       scanf( %lld , &x4);       scanf( %lld , &y4);       dx = x4 - x3 + 1, dy = y4 - y3 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         answ -= (dx * dy) / 2;         ansb += (dx * dy) / 2;       } else {         if (x3 % 2 && y3 % 2 || x3 % 2 == 0 && y3 % 2 == 0) {           answ -= (dx * dy) / 2 + 1;           ansb += (dx * dy) / 2 + 1;         } else {           answ -= (dx * dy) / 2;           ansb += (dx * dy) / 2;         }       }       long long x5, y5, x6, y6;       if (y3 > y2 || y4 < y1 || x3 > x2 || x4 < x1) {         printf( %lld %lld n , answ, ansb);         continue;       }       x5 = max(x1, x3);       y5 = max(y1, y3);       x6 = min(x2, x4);       y6 = min(y2, y4);       dx = x6 - x5 + 1, dy = y6 - y5 + 1;       if (dx % 2 == 0 || dy % 2 == 0) {         if (x5 % 2 == 0 && y5 % 2 == 0 || x5 % 2 && y5 % 2) {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         } else {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         }       } else {         if (x5 % 2 && y5 % 2 || x5 % 2 == 0 && y5 % 2 == 0) {           answ -= dx * dy / 2;           ansb += dx * dy / 2;         } else {           answ -= dx * dy / 2 + 1;           ansb += dx * dy / 2 + 1;         }       }       printf( %lld %lld n , answ, ansb);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> deg(n), s(n);     for (int i = 0; i < n; i++) cin >> deg[i] >> s[i];     vector<pair<int, int>> edges;     queue<int> q;     for (int i = 0; i < n; i++)       if (deg[i] == 1) q.push(i);     while (!q.empty()) {       int leaf = q.front();       q.pop();       if (deg[leaf] != 1) continue;       int par = s[leaf];       edges.push_back({par, leaf});       deg[par] -= 1;       s[par] ^= leaf;       if (deg[par] == 1) q.push(par);     }     cout << edges.size() << endl;     for (auto p : edges) cout << p.first <<     << p.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     long long k[n];     pair<long long, long long> dt[m];     for (int i = 0; i < n; i++) cin >> k[i];     for (int i = 0; i < m; i++) cin >> dt[i].first >> dt[i].second;     long long total = 0;     for (int i = 0; i < n; i++) total += k[i];     long long start = 1;     long long end = 2 * total;     long long ans = 2 * total;     while (start <= end) {       long long check = start + (end - start) / 2;       pair<long long, long long> last[n];       for (int i = 0; i < n; i++) {         last[i].first = LONG_MAX;         last[i].second = i;       }       for (int i = 0; i < m; i++) {         if (dt[i].first <= check) {           if (last[dt[i].second - 1].first == LONG_MAX)             last[dt[i].second - 1].first = dt[i].first;           else             last[dt[i].second - 1].first =                 max(dt[i].first, last[dt[i].second - 1].first);         }       }       sort(last, last + n);       int point = 0;       long long money = 0;       long long count = 0;       for (int i = 1; i <= check; i++) {         money++;         while (last[point].first == i) {           long long deduce = min(money, k[last[point].second]);           count += deduce;           money -= deduce;           point++;         }       }       money -= 2 * (total - count);       if (money < 0) {         start = check + 1;       } else {         ans = check;         end = check - 1;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 1000;   const int MAXK = 1000;   int n, K;   char s[MAXN + 1];   int act[MAXN + 1][2 * MAXK + 1];   char ret[MAXN + 1];   void run() {     scanf( %d%d%s , &n, &K, s);     memset(act, -1, sizeof(act));     act[0][MAXK] = 1;     for (int i = (0); i < (n); ++i) {       int mxb = min(i, K - 1);       for (int k = (-mxb); k <= (+mxb); ++k)         if (act[i][MAXK + k] != -1) {           for (int a = (-1); a <= (+1); ++a) {             if (s[i] ==  L  && a != -1) continue;             if (s[i] ==  D  && a != 0) continue;             if (s[i] ==  W  && a != +1) continue;             act[i + 1][MAXK + k + a] = a + 1;           }         }     }     for (int k = -K; k <= +K; k += 2 * K)       if (act[n][MAXK + k] != -1) {         for (int i = n - 1; i >= 0; --i) {           ret[i] =  LDW [act[i + 1][MAXK + k]];           k -= act[i + 1][MAXK + k] - 1;         }         ret[n] =   0 ;         printf( %s , ret);         return;       }     printf( NO n );   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string nameOne, nameTwo, tmpOne, tmpTwo;     cin >> nameOne >> nameTwo;     int n;     cin >> n;     cout << nameOne <<     << nameTwo << endl;     for (int i = 0; i < n; i++) {       cin >> tmpOne;       cin >> tmpTwo;       if (tmpOne == nameOne)         nameOne = tmpTwo;       else         nameTwo = tmpTwo;       cout << nameOne <<     << nameTwo << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(long long int arr[], long long int n, long long int l) {     for (int i = 1; i < n; i++) {       arr[i] = min(arr[i], 2 * arr[i - 1]);     }     long long int exp[n];     for (int i = 0; i < n; i++) {       exp[i] = 1LL << i;     }     long long int ans = LLONG_MAX;     long long int val = 0;     for (int i = n - 1; i >= 0; i--) {       long long int currentAns = val + (l + exp[i] - 1) / exp[i] * arr[i];       ans = min(ans, currentAns);       long long int x = l / exp[i];       l -= x * exp[i];       val += x * arr[i];     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, l;       cin >> n >> l;       long long int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       solve(arr, n, l);     }   }


#include <bits/stdc++.h>   using namespace std;   long long fastPrime(long long n) {     if (n == 2) return true;     if (n % 2 == 0) return false;     for (long long i = 3; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, val;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> val;       long long sr = sqrt(val);       if (val != 1 && fastPrime(sr) && sr * sr == val)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 5;   template <typename T>   void chkmax(T& x, T y) {     if (y > x) x = y;   }   template <typename T>   void chkmin(T& x, T y) {     if (y < x) x = y;   }   int N, Q, a[1 << 18];   long long sum;   int main() {     scanf( %d%d , &N, &Q);     for (int i = 0; i < (1 << N); ++i) scanf( %d , &a[i]), sum += a[i];     printf( %.7f n , sum / (double)(1 << N));     while (Q--) {       int p, x;       scanf( %d%d , &p, &x), sum -= a[p], a[p] = x, sum += a[p];       printf( %.7f n , sum / (double)(1 << N));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxm = 1e5 + 80;   const int maxn = 5e3 + 80;   const int up = 20;   template <class T>   void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (;  0  <= c && c <=  9 ; c = getchar()) x = x * 10 + (c ^ 48);     x *= f;   }   unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();   mt19937 rand_num(seed);   uniform_int_distribution<int> dist(0, 10000000);   mt19937 rnd(time(NULL));   int e[maxm][2], cnt[maxm];   int f[maxm], flag, nxt;   int get_rand(int from, int to) {     int x = dist(rand_num) % (to - from + 1);     return x + from;   }   bool solve(int n, int m) {     shuffle(f + 1, f + 1 + n, rnd);     for (int i = 2; i <= m; i++) {       int u = f[i - 1], v = f[i], ti = 0;       bool wa = (e[u][0] == v | e[u][1] == v);       if (wa && i == n) return false;       while (wa && ti < up) {         int t = get_rand(i + 1, n);         ti++;         swap(f[i], f[t]);         v = f[i];         wa = (e[u][0] == v | e[u][1] == v);       }       if (ti == up) return false;     }     nxt = 0;     if (m == 2 || m == 1) nxt = 1;     if (e[f[m]][0] == f[1] || e[f[m]][1] == f[1]) nxt = 1;     if (nxt == 1 && n == m) return false;     if (nxt == 1) {       int u = f[m], v = f[m + 1], ti = 0;       bool wa = (e[u][0] == v | e[u][1] == v);       while (wa && ti < up) {         int t = get_rand(m + 1, n);         ti++;         swap(f[m + 1], f[t]);         v = f[m + 1];         wa = (e[u][0] == v | e[u][1] == v);       }       if (ti == up) return false;     }     flag = 1;     return true;   }   void MC() {     int n, m;     read(n);     read(m);     for (int i = 1; i <= m; i++) {       int u, v;       read(u);       read(v);       e[u][cnt[u]++] = v;       e[v][cnt[v]++] = u;     }     if (n == 2 && m == 2 || m > n) {       printf( -1 n );       return;     }     flag = 0;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= up + up; i++)       if (solve(n, m)) break;     if (!flag) {       printf( -1 n );       return;     }     for (int i = 2; i <= m; i++) printf( %d %d n , f[i - 1], f[i]);     if (!nxt)       printf( %d %d n , f[m], f[1]);     else       printf( %d %d n , f[m], f[m + 1]);   }   int main() {     MC();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 1e7 + 5;   int cnt[2][nmax];   int valu[100005];   vector<int> g[100005];   int liflevel;   int koyta[2];   void dfs(int u, int level = 0) {     cnt[level % 2][valu[u]]++;     koyta[level % 2]++;     for (int v : g[u]) dfs(v, level + 1);     if (g[u].empty()) liflevel = level % 2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> valu[i];     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       g[p].push_back(i);     }     dfs(1);     int jor = 0;     long long ans = 0;     for (int i = 0; i < nmax; i++)       if (cnt[liflevel][i] % 2) jor ^= i;     if (jor) {       for (int i = 0; i < nmax; i++) {         int tmp = jor ^ i;         if (tmp < nmax) ans += 1LL * cnt[liflevel][i] * cnt[liflevel ^ 1][tmp];       }     } else {       ans += 1LL * koyta[0] * (koyta[0] - 1) / 2 +              1LL * koyta[1] * (koyta[1] - 1) / 2;       for (int i = 0; i < nmax; i++) ans += 1LL * cnt[0][i] * cnt[1][i];     }     cout << ans;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const int MX = 1 << 23;   int a, b, c, d, i, j, n, m, k;   int lenl[MX + 1], lenr[MX + 1], cnt[MX + 1], len[MX + 1], num[MX + 1];   pair<int, int> sm[MX + 1];   map<int, int> onwork;   inline int create(int l, int r) {     sm[k] = make_pair(-1, -1);     cnt[k] = 0;     len[k] = lenl[k] = lenr[k] = r - l;     num[k] = l;     return k++;   }   inline int getcnt(int l, int r, int a, int b, int v) {     if (l >= r || a > b) return 0;     if (l == a && b == r - 1) return cnt[v];     int xx = (r + l) / 2;     if (b < xx) {       if (sm[v].first == -1) sm[v].first = create(l, xx);       return getcnt(l, xx, a, b, sm[v].first);     }     if (a >= xx) {       if (sm[v].second == -1) sm[v].second = create(xx, r);       return getcnt(xx, r, a, b, sm[v].second);     }     if (sm[v].first == -1) sm[v].first = create(l, xx);     if (sm[v].second == -1) sm[v].second = create(xx, r);     return getcnt(l, xx, a, xx - 1, sm[v].first) +            getcnt(xx, r, xx, b, sm[v].second);   }   void add(int l, int r, int first, int cc, int v) {     if (l >= r || first >= r || first < l) return;     if (l == r - 1) {       cnt[v] = cc;       num[v] = l;       lenl[v] = lenr[v] = len[v] = cc ^ 1;       return;     }     int xx = (r + l) / 2;     if (sm[v].first == -1) sm[v].first = create(l, xx);     if (sm[v].second == -1) sm[v].second = create(xx, r);     if (first < xx) {       add(l, xx, first, cc, sm[v].first);     } else {       add(xx, r, first, cc, sm[v].second);     }     lenl[v] = lenr[v] = len[v] = 0;     cnt[v] = 0;     {       lenl[v] = lenl[sm[v].first];       len[v] = len[sm[v].first];       num[v] = num[sm[v].first];       cnt[v] = cnt[sm[v].first];     }     {       if (lenl[v] == xx - l) lenl[v] += lenl[sm[v].second];       lenr[v] = lenr[sm[v].second];       if (lenr[v] == r - xx) lenr[v] += lenr[sm[v].first];       if (lenr[sm[v].first] + lenl[sm[v].second] >= len[v]) {         len[v] = lenr[sm[v].first] + lenl[sm[v].second];         num[v] = xx - lenr[sm[v].first];       }       if (len[sm[v].second] >= len[v]) {         len[v] = len[sm[v].second];         num[v] = num[sm[v].second];       }       cnt[v] += cnt[sm[v].second];     }   }   int main() {     scanf( %d%d , &n, &m);     sm[0] = make_pair(-1, -1);     lenl[0] = lenr[0] = len[0] = n;     num[0] = 1;     k = 1;     for (int _n((m)-1), i(0); i <= _n; i++) {       scanf( %d , &a);       if (!a) {         scanf( %d%d , &a, &b);         printf( %d n , getcnt(1, n + 1, a, b, 0));       } else {         if (onwork.count(a)) {           add(1, n + 1, onwork[a], 0, 0);           onwork.erase(onwork.find(a));         } else {           int l = num[0], r = num[0] + len[0];           add(1, n + 1, (r + l) / 2, 1, 0);           onwork[a] = (r + l) / 2;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long Bpow(long long a, long long s) {     if (s == 0) {       return 1;     }     long long u = Bpow(a, s / 2);     if (s & 1)       return u * u % mod * a % mod;     else       return u * u % mod;   }   int32_t main() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     for (long long i = 0; i < n - 2; i++) {       long long now = a[i + 1];       for (long long j = i + 2; j < n; j++) {         if (now > a[i] * 2) break;         if ((a[i] ^ a[j]) == now && a[i] > a[j]) ++ans;         now += a[j];       }     }     for (long long i = n - 1; i > 1; i--) {       long long now = a[i - 1];       for (long long j = i - 2; j >= 0; j--) {         if (now > a[i] * 2) break;         if ((a[i] ^ a[j]) == now && a[i] > a[j]) ++ans;         now += a[j];       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long t[2003];   long long viz[2003];   pair<long long, long long> a[2003];   pair<pair<long long, long long>, long long> b[2003];   vector<long long> v[2003];   vector<pair<pair<long long, long long>, long long> > much;   vector<pair<pair<long long, long long>, long long> > muchsel;   bool cmp_first(pair<pair<long long, long long>, long long> a,                  pair<pair<long long, long long>, long long> b) {     if (a.first.first == b.first.first) return a.first.second < b.first.second;     return a.first.first < b.first.first;   }   bool cmp_second(pair<pair<long long, long long>, long long> a,                   pair<pair<long long, long long>, long long> b) {     if (a.first.second == b.first.second) return a.first.first < b.first.first;     return a.first.second < b.first.second;   }   bool cmp(pair<pair<long long, long long>, long long> a,            pair<pair<long long, long long>, long long> b) {     return a.second < b.second;   }   long long dist(pair<long long, long long> a, pair<long long, long long> b) {     return abs(a.first - b.first) + abs(a.second - b.second);   }   long long root(long long x) {     if (t[x] == 0) return x;     t[x] = root(t[x]);     return t[x];   }   void calc(long long mx) {     muchsel.clear();     long long rx, ry;     int id = 0;     for (auto val : much) {       rx = root(val.first.first);       ry = root(val.first.second);       if (val.second > mx) return;       if (rx != ry) {         t[rx] = ry;         viz[id] = 1;         muchsel.push_back(val);       }       id++;     }     return;   }   long long intercl(pair<long long, long long> a, pair<long long, long long> b,                     pair<long long, long long> c, pair<long long, long long> d) {     long long x = -1, y = -1;     if (a.first == b.first) x = a.first;     if (a.second == b.second) y = a.second;     if (c.first == d.first) x = c.first;     if (c.second == d.second) y = c.second;     if (x != -1 && y != -1) {       long long val1 = max(abs(x - a.first), abs(x - b.first)),                 val2 = max(abs(y - a.second), abs(y - b.second)),                 val3 = max(abs(x - c.first), abs(x - d.first)),                 val4 = max(abs(y - c.second), abs(y - d.second));       long long val = max(val1, max(val2, max(val3, val4)));       return val;     }     return 2000000000000000018;   }   void cleart(long long n) {     for (int i = 1; i <= n; ++i) t[i] = 0;   }   bool solve(long long n, long long t) {     cleart(n);     calc(t);     long long sz = muchsel.size();     long long nrc = n - sz;     long long rx, ry, rk, rq;     if (nrc == 1) return true;     if (nrc == 2) {       for (int i = 1; i <= n; ++i) {         rx = root(i);         for (int j = i + 1; j <= n; ++j) {           ry = root(j);           if (rx == ry) continue;           long long ds =               max(abs(a[i].first - a[j].first), abs(a[i].second - a[j].second));           if (ds <= t) return true;           if (a[i].first == a[j].first || a[i].second == a[j].second)             if ((ds + 1) / 2 <= t) return true;         }       }       return false;     }     if (nrc == 3) {       for (int i = 0; i < much.size(); ++i) {         rx = root(much[i].first.first);         ry = root(much[i].first.second);         if (rx == ry) continue;         for (int j = 1; j <= n; ++j) {           rk = root(j);           if (rx == rk || ry == rk) continue;           pair<long long, long long> e1 = a[much[i].first.first];           pair<long long, long long> e2 = a[much[i].first.second];           pair<long long, long long> e3 = a[j];           pair<long long, long long> pct = {-2000000000000000018,                                             -2000000000000000018};           if (e1.first == e2.first) pct = {e1.first, e3.second};           if (e1.first == e3.first) pct = {e1.first, e2.second};           if (e2.first == e3.first) pct = {e2.first, e1.second};           if (e1.second == e2.second) pct = {e3.first, e1.second};           if (e1.second == e3.second) pct = {e2.first, e1.second};           if (e2.second == e3.second) pct = {e1.first, e2.second};           if (max(dist(e1, pct), max(dist(e2, pct), dist(e3, pct))) <= t)             return true;         }       }       return false;     }     if (nrc == 4) {       for (int i = 0; i < much.size(); ++i) {         rx = root(much[i].first.first);         ry = root(much[i].first.second);         if (rx == ry) continue;         for (int j = i + 1; j < much.size(); ++j) {           rk = root(much[j].first.first);           rq = root(much[j].first.second);           if (rk == rq || rx == rk || rx == rq || ry == rk || ry == rq) continue;           if (intercl(a[much[i].first.first], a[much[i].first.second],                       a[much[j].first.first], a[much[j].first.second]) <= t)             return true;         }       }       return false;     }     return false;   }   int main() {     long long n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first >> a[i].second;       b[i] = {a[i], i};     }     sort(b + 1, b + n + 1, cmp_first);     for (int i = 1; i < n; ++i) {       if (b[i].first.first == b[i + 1].first.first) {         long long dif = b[i + 1].first.second - b[i].first.second,                   id1 = b[i].second, id2 = b[i + 1].second;         if (dif < 0) dif = -dif;         v[id1].push_back(id2);         v[id2].push_back(id1);         much.push_back({{id1, id2}, dif});       }     }     sort(b + 1, b + n + 1, cmp_second);     for (int i = 1; i < n; ++i) {       if (b[i].first.second == b[i + 1].first.second) {         long long dif = b[i + 1].first.first - b[i].first.first,                   id1 = b[i].second, id2 = b[i + 1].second;         if (dif < 0) dif = -dif;         v[id1].push_back(id2);         v[id2].push_back(id1);         much.push_back({{id1, id2}, dif});       }     }     sort(much.begin(), much.end(), cmp);     long long st = 1, dr = 2000000009;     while (st <= dr) {       long long mij = (st + dr) / 2;       if (solve(n, mij))         dr = mij - 1;       else         st = mij + 1;     }     if (solve(n, dr))       cout << dr <<   n ;     else {       if (st == 2000000009 + 1)         cout << -1 <<   n ;       else         cout << st <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   const double pi = acos(-1.0);   const int inf = (int)1e9;   const double eps = 1e-4;   const int ss = (int)1e6 + 3;   const int base = inf;   bool pred(const pair<int, int>& i, const pair<int, int>& j) {     if (i.first == j.first) {       return i.second > j.second;     } else {       return i.first > j.first;     }   }   int a[2000005];   int main() {     int k;     scanf( %d , &k);     long long int res = 0;     for (int i = 0; i < k; ++i) {       scanf( %d , &a[i]);       res += a[i];     }     if (k == 1) {       cout << res;       return 0;     }     sort(a, a + k);     int z = k / 4;     while (z != 0) {       for (int i = k - 1; i >= k - z; --i) {         res += a[i];       }       z /= 4;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long INFLL = 1e18 + 1;   const int MAX = 200001;   const long long MOD = 1000000007;   long long inq(long long k, long long q) {     if (q == 0) return 1;     long long l = inq(k, q / 2);     if (q % 2 == 0)       return l * l % MOD;     else       return (l * l) % MOD * k % MOD;   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   long long cubr(long long a) {     long long l = -1, r = 1e6 + 2;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (mid * mid * mid > a)         r = mid;       else         l = mid;     }     return l;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) { return -1 * max(-a, -b); }   long long possible(long long q) {     if (q == INF) return -1;     return q;   }   bool correct(int x, int xx) {     if (x < 0) return 0;     if (x >= xx) return 0;     return 1;   }   long long dsumm(long long x, long long k) {     long long y = 1;     long long z = 0;     for (int i = 0; y < 1e18; i++) {       z += x / y % k;       y *= k;     }     return z;   }   long long dcount(long long x) {     long long y = 1;     long long z = 0;     int c[100];     for (int i = 0; i < 10; i++) c[i] = 0;     for (int i = 0; x > 0; i++) {       if (c[x / y % 10] == 0) z++;       c[x / y % 10] = 1;       x /= 10;     }     return z;   }   long long lg10(long long x) {     if (x == 0) return 0;     return lg10(x / 10) + 1;   }   long long n, m;   vector<int> graph[4000], graph2[4000];   long long ans;   long long d[5000];   long long f[4000];   long long ff[4000];   int main() {     cin >> n >> m;     for (int(i) = 0; (i) != (m); i++) {       int x, y;       cin >> x >> y;       x--;       y--;       graph[x].push_back(y);       graph2[y].push_back(x);     }     long long it = 2;     for (int b = 0; b < n; b++) {       for (int c = b + 1; c < n; c++) {         long long x = 0;         long long y = 0;         long long z = 0;         for (int i = 0; i < graph[b].size(); i++) {           d[graph[b][i]] = it;         }         for (int i = 0; i < graph[c].size(); i++) {           if (d[graph[c][i]] == it) {             x++;           }         }         it++;         for (int i = 0; i < graph2[b].size(); i++) {           d[graph2[b][i]] = it;         }         for (int i = 0; i < graph2[c].size(); i++) {           if (d[graph2[c][i]] == it) {             y++;           }         }         it++;         for (int i = 0; i < graph[b].size(); i++) {           ff[graph[b][i]] = it * 7;         }         for (int i = 0; i < graph[c].size(); i++) {           if (ff[graph[c][i]] == it * 7)             ff[graph[c][i]]++;           else             ff[graph[c][i]] = 0;         }         for (int i = 0; i < graph2[b].size(); i++) {           if (ff[graph2[b][i]] == it * 7 + 1)             ff[graph2[b][i]]++;           else             ff[graph2[b][i]] = 0;         }         for (int i = 0; i < graph2[c].size(); i++) {           if (ff[graph2[c][i]] == it * 7 + 2) {             z++;             ff[graph2[c][i]] = 0;           }         }         ans += (x - z) * (y - z) + z * (z - 1) + z * (x - z) + z * (y - z);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const long long inf = 1e18;   int bcg[maxn];   struct Edge {     int u, v, nxt;     long long w;   } edge[maxn * 2], edge1[maxn * 2];   vector<Edge> vec[maxn];   struct Node {     long long p;     int v;     friend bool operator<(Node a, Node b) { return a.p > b.p; }     Node() {}     Node(long long x, int y) { p = x, v = y; }   };   int head[maxn], head1[maxn];   long long deep[maxn];   int depth[maxn];   int bian[maxn * 2];   long long dis[50][maxn];   int lca[maxn][25];   int vis[maxn];   int cnt, cnt1, tot;   int n, m;   int findd(int x) { return bcg[x] == x ? bcg[x] : bcg[x] = findd(bcg[x]); }   bool cmp(Edge a, Edge b) { return a.w < b.w; }   void add_e1(int x, int y, long long w) {     ++cnt1;     edge1[cnt1].u = x;     edge1[cnt1].v = y;     edge1[cnt1].w = w;     edge1[cnt1].nxt = head1[x];     head1[x] = cnt1;   }   void add_e(int x, int y, long long w) {     ++cnt;     edge[cnt].u = x;     edge[cnt].v = y;     edge[cnt].w = w;     edge[cnt].nxt = head[x];     head[x] = cnt;   }   int merges(int x, int y) {     int xx = findd(x);     int yy = findd(y);     if (xx != yy) {       bcg[xx] = yy;       return 1;     }     return 0;   }   void init() {     cnt = cnt1 = 0;     tot = 0;     memset(deep, 0, sizeof(deep));     memset(head, 0, sizeof(head));     memset(head1, 0, sizeof(head1));   }   void dfs(int x, int ff) {     lca[x][0] = ff;     for (int i = 1; i <= 20; i++) lca[x][i] = lca[lca[x][i - 1]][i - 1];     for (int i = head[x]; i; i = edge[i].nxt) {       int v = edge[i].v;       if (v == ff) continue;       deep[v] = deep[x] + edge[i].w;       depth[v] = depth[x] + 1;       dfs(v, x);     }   }   int LCA(int x, int y) {     if (depth[x] < depth[y]) swap(x, y);     int ff = depth[x] - depth[y];     for (int i = 20; i >= 0; i--) {       if (ff & (1 << i)) x = lca[x][i];     }     if (x == y) return y;     for (int i = 20; i >= 0; i--) {       if (lca[x][i] != lca[y][i]) x = lca[x][i], y = lca[y][i];     }     return lca[y][0];   }   priority_queue<Node> que;   void dij(int id, int x) {     for (int i = 0; i <= n + 4; i++) {       dis[id][i] = inf;       vis[i] = 0;     }     dis[id][x] = 0;     while (!que.empty()) que.pop();     que.push(Node(0, x));     while (!que.empty()) {       Node vv = que.top();       que.pop();       if (vis[vv.v] || vv.p > dis[id][vv.v]) continue;       vis[vv.v] = 1;       for (int i = 0; i < (int)vec[vv.v].size(); i++) {         Edge k = vec[vv.v][i];         int sw = k.v;         if (vis[sw]) continue;         if (dis[id][sw] > dis[id][vv.v] + k.w) {           dis[id][sw] = dis[id][vv.v] + k.w;           que.push(Node(dis[id][sw], sw));         }       }     }   }   int main() {     scanf( %d%d , &n, &m);     int u, v;     long long w;     init();     for (int i = 1; i <= m; i++) {       scanf( %d%d%lld , &u, &v, &w);       add_e1(u, v, w);       vec[u].push_back((Edge){u, v, 0, w});       vec[v].push_back((Edge){v, u, 0, w});     }     sort(edge1 + 1, edge1 + cnt1 + 1, cmp);     for (int i = 1; i <= n + 4; i++) bcg[i] = i;     for (int i = 1; i <= cnt1; i++) {       int x = edge1[i].u, y = edge1[i].v;       if (merges(x, y)) {         add_e(x, y, edge1[i].w);         add_e(y, x, edge1[i].w);       } else {         bian[++tot] = x;         bian[++tot] = y;       }     }     depth[1] = 0;     deep[1] = 0;     dfs(1, 0);     sort(bian + 1, bian + 1 + tot);     int sz = unique(bian + 1, bian + 1 + tot) - (bian + 1);     for (int i = 1; i <= sz; i++) {       dij(i, bian[i]);     }     int q;     scanf( %d , &q);     int x, y;     while (q--) {       scanf( %d%d , &x, &y);       long long ans = inf;       int pq = LCA(x, y);       ans = deep[x] + deep[y] - 2 * deep[pq];       for (int i = 1; i <= sz; i++) {         ans = min(ans, dis[i][x] + dis[i][y]);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 11;   int n;   int a[MAXN][MAXN];   void read() {     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) cin >> a[i][j];     }   }   const int INF = 1e9 + 7;   const int MAXANS = MAXN * MAXN * 2;   int dp[MAXANS][MAXN * MAXN][MAXN][MAXN][3];   bool ch(int i, int j) { return 0 <= i && i < n && 0 <= j && j < n; }   inline bool check(int i, int j, int ni, int nj, int k) {     if (k == 0) {       return (abs(i - ni) == 1 && abs(j - nj) == 2) ||              (abs(i - ni) == 2 && abs(j - nj) == 1);     } else if (k == 1) {       return abs(i - ni) == abs(j - nj);     } else {       return (i == ni || j == nj);     }   }   pair<int, int> ans = {INF, INF};   pair<int, int> pos[MAXN * MAXN];   vector<pair<int, int> > go[MAXN][MAXN][3];   void solve() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         pos[a[i][j]] = {i, j};       }     }     for (int i = 0; i < MAXANS; ++i) {       for (int j = 0; j < MAXN * MAXN; ++j) {         for (int x = 0; x < MAXN; ++x) {           for (int y = 0; y < MAXN; ++y) {             for (int k = 0; k < 3; ++k) {               dp[i][j][x][y][k] = INF;             }           }         }       }     }     for (int i = 0; i < 3; ++i) {       dp[0][1][pos[1].first][pos[1].second][i] = 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         for (int ni = 0; ni < n; ++ni) {           for (int nj = 0; nj < n; ++nj) {             for (int k = 0; k < 3; ++k) {               if (check(i, j, ni, nj, k)) {                 go[i][j][k].push_back({ni, nj});               }             }           }         }       }     }     for (int op = 0; op < MAXANS - 1; ++op) {       for (int num = 1; num <= n * n; ++num) {         for (int i = 0; i < n; ++i) {           for (int j = 0; j < n; ++j) {             for (int k = 0; k < 3; ++k) {               if (num == n * n && dp[op][num][i][j][k] != INF) {                 ans = min(ans, {op, dp[op][num][i][j][k]});               }               for (auto t : go[i][j][k]) {                 int ni = t.first, nj = t.second;                 if (check(i, j, ni, nj, k)) {                   bool ch =                       (pos[num + 1].first == ni && pos[num + 1].second == nj);                   dp[op + 1][num + ch][ni][nj][k] =                       min(dp[op + 1][num + ch][ni][nj][k], dp[op][num][i][j][k]);                 }               }               for (int nk = 0; nk < 3; ++nk) {                 if (nk != k) {                   dp[op + 1][num][i][j][nk] =                       min(dp[op + 1][num][i][j][nk], dp[op][num][i][j][k] + 1);                 }               }             }           }         }       }     }   }   void print() { cout << ans.first <<     << ans.second <<   n ; }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     solve();     print();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 1000005;   const int mod = 1e9 + 7;   int n, m, k, ans, minp, maxp, a[MAXN], bin[MAXN];   int main() {     n = Read(), m = Read(), k = Read(), minp = n + 1, bin[0] = 1;     for (int i = 1, x, y; i <= m; i++) {       x = Read(), y = Read();       if (y == x + k + 1)         a[x]++, minp = min(minp, x), maxp = max(maxp, x);       else if (y ^ x + 1)         return puts( 0 ), 0;     }     if (maxp - minp > k) return puts( 0 ), 0;     n -= k + 1;     for (int i = 1; i <= n; i++)       a[i] += a[i - 1], bin[i] = (bin[i - 1] << 1) % mod;     if (!maxp) {       ans = 1;       for (int i = 1; i <= n; i++) ans = (ans + bin[min(i + k, n) - i]) % mod;     } else       for (int i = max(maxp - k, 1); i <= minp; i++)         ans = (ans + bin[min(i + k, n) - i - (a[min(i + k, n)] - a[i])]) % mod;     return printf( %d n , ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     {       long long i, j, n, a, b, c, d, mx, mn;       cin >> n >> a >> b >> c >> d;       mx = max(a + b, a + c);       mx = max(mx, b + d);       mx = max(mx, c + d);       mn = min(a + b, a + c);       mn = min(mn, b + d);       mn = min(mn, c + d);       if (mx + 1 <= mn + n) {         i = min(a + b + n, mn + n);         j = max(mx + 1, a + b + 1);         cout << n * (i - j + 1);       } else         cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, ans, x, y, sum, res, day1, day2, moun1, moun2, year1, year2;   bool l;   char a[100];   string s, s1, s2;   vector<int> v;   int main() {     cin >> n;     if (!(n & 1)) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) printf( %d  , i);     cout << endl;     for (int i = 0; i < n; i++) printf( %d  , i);     cout << endl;     for (int i = 0; i < n; i++) printf( %d  , (i + i) % n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> m;   void solve() {     long long n;     cin >> n;     map<long long, long long>::iterator itr;     long long x, maxm = INT_MIN;     for (long long i = 0; i < n; i++) {       cin >> x;       m[x - (i + 1)] += x;     }     for (auto &it : m) {       maxm = max(maxm, it.second);     }     cout << maxm;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isVowel(char c) {     if (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u  or c ==  y )       return true;     return false;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long long n;     cin >> n;     string s;     cin >> s;     string ans =   ;     for (long long i = 0; i < n; i++) {       ans += s[i];       if (!isVowel(s[i])) continue;       long long j = i;       while (j < n && isVowel(s[j])) j++;       i = j - 1;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[11];   string str[11];   int m, n;   int f(int k) {     if (k == n) {       for (int i = 0; i < m; i++)         if (arr[i] != 0) return 0;       return 1;     }     int ans = 0;     bool c = 0;     for (int i = 0; i < m; i++)       if (str[i][k] ==  0 ) {         arr[i]--;         if (arr[i] < 0) c++;       }     if (c == 0) ans += f(k + 1);     for (int i = 0; i < m; i++)       if (str[i][k] ==  0 ) arr[i]++;     c = 0;     for (int i = 0; i < m; i++)       if (str[i][k] ==  1 ) {         arr[i]--;         if (arr[i] < 0) c++;       }     if (!c) ans += f(k + 1);     for (int i = 0; i < m; i++)       if (str[i][k] ==  1 ) arr[i]++;     return ans;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> str[i] >> arr[i];     cout << f(0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       vector<int> val(n);       for (int i = 0; i < n; i++) {         cin >> val[i];       }       if (m == 1) {         cout << max(val[0], val[n - 1]) << endl;         continue;       }       if (k >= m - 1) {         vector<int> vec;         for (int i = 0; i < m; i++) {           vec.push_back(val[i]);           vec.push_back(val[n - i - 1]);         }         cout << *max_element(vec.begin(), vec.end()) << endl;         continue;       }       int res_glob = 0;       for (int i = 0; i <= k; i++) {         int ind_l = i;         int ind_r = n - 1 - (k - i);         int need = m - k - 1;         int cur_res = 2000000000;         for (int j = 0; j <= need; j++) {           int cur_elem = ind_l + j;           int cur_elem_left = ind_r - (need - j);           cur_res = min(cur_res, max(val[cur_elem], val[cur_elem_left]));         }         res_glob = max(res_glob, cur_res);       }       cout << res_glob << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 10;   int n, k, cnt[maxn], a[maxn], L[maxn], R[maxn];   stack<pair<int, int> > stk;   int main() {     scanf( %d , &n);     ;     scanf( %d , &k);     ;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     ;     stk.push({INF, 0});     for (int i = 1; i <= n; i++) {       while (stk.top().first < a[i]) stk.pop();       L[i] = stk.top().second + 1;       stk.push({a[i], i});     }     while (stk.size()) stk.pop();     stk.push({INF, n + 1});     for (int i = n; i >= 1; i--) {       while (stk.top().first <= a[i]) stk.pop();       R[i] = stk.top().second - 1;       stk.push({a[i], i});     }     for (int i = 1; i <= n; i++) {       cnt[i] = (cnt[i - 1] + (i - 1) / (k - 1)) % mod;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = (cnt[R[i] - L[i] + 1] - cnt[i - L[i]] - cnt[R[i] - i]) % mod;       ans += 1LL * t * a[i] % mod;     }     printf( %I64d n , (ans % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[50001], n, l, r;   queue<int> ver[50001];   void go(int pre, int v) {     int t;     p[v] = pre;     if (v != l) {       while (!ver[v].empty()) {         t = ver[v].front();         ver[v].pop();         if (t != pre) go(v, t);       }     }   }   int main() {     scanf( %d%d%d , &n, &l, &r);     l--;     r--;     for (int i = 0; i < n; i++)       if (i == l)         continue;       else {         scanf( %d , &p[i]);         p[i]--;         ver[p[i]].push(i);         ver[i].push(p[i]);       }     go(-1, r);     for (int i = 0; i < n; i++)       if (i == r)         continue;       else         printf( %d  , p[i] + 1);     return 0;   }


#include <bits/stdc++.h>   long long gcd(long long x, long long y) {     if (x > y) std::swap(x, y);     return y % x == 0 ? x : gcd(y % x, x);   }   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[20];     bool flag = true;     for (int i = (1); i <= (n); i++) scanf( %d , a + i);     for (int i = (1); i <= (n - 1); i++)       if (abs(a[i] - a[i + 1]) >= 2) flag = false;     if (flag)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50;   int n, cnt, f[N][18], d[N], fa[N], id[N], s[N];   vector<int> v1[N], v2[N];   void dfs1(int x, int ff) {     for (int i = 0; i < 17; i++) f[x][i + 1] = f[f[x][i]][i];     for (int i = 0, y; i < v1[x].size(); i++)       if ((y = v1[x][i]) != ff)         f[y = v1[x][i]][0] = x, d[y] = d[x] + 1, dfs1(y, x);   }   int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void merge(int x, int y) {     x = find(x);     y = find(y);     if (s[x] > s[y]) swap(x, y);     fa[x] = y;     s[y] += s[x];     id[y] = d[id[y]] < d[id[x]] ? id[y] : id[x];   }   void dfs2(int x, int ff) {     for (int i = 0, y; i < v2[x].size(); i++)       if ((y = v2[x][i]) != ff) dfs2(y, x);     if (!ff) return;     int fx = id[find(x)], p = ff;     for (int i = 17; ~i; i--)       if (d[id[find(f[p][i])]] > d[fx]) p = f[p][i];     if (id[find(f[p][0])] != fx) p = fx;     merge(p, f[p][0]);     printf( %d %d %d %d n , p, f[p][0], x, ff);   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), v1[x].push_back(y), v1[y].push_back(x);     for (int i = 1, x, y; i < n; i++)       scanf( %d%d , &x, &y), v2[x].push_back(y), v2[y].push_back(x);     printf( %d n , n - 1);     for (int i = 1; i <= n; i++) id[i] = fa[i] = i, s[i] = 1;     dfs1(d[1] = 1, 0);     dfs2(1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     int n, m;     cin >> n >> m;     cin >> a >> b;     int pw = 1;     int ans = 0, res = 0;     for (int i = 0; i < m; i++) {       if (i < n && a[n - i - 1] ==  1 ) res = (res + pw) % 998244353;       if (b[m - i - 1] ==  1 ) ans = (ans + res) % 998244353;       pw = (pw + pw) % 998244353;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 100;   int num[N];   bool vis[N];   vector<int> v;   int n, k;   int main() {     scanf( %d %d , &n, &k);     int mn = 1e9 + 1000;     for (int i = 1; i <= n; i++) {       scanf( %d , &num[i]);       if (num[i] < mn) {         mn = num[i];         vis[i] = true;         v.push_back(i);       }     }     v.push_back(n + 1);     num[n + 1] = 0;     int cnt = 0;     int mx = 0;     for (int i = 1; i < v.size(); i++) {       mx = max(mx, v[i] - v[i - 1]);       if (v[i] - v[i - 1] > k) cnt++;     }     if (cnt >= 2) {       puts( NO );     } else if (cnt == 0) {       puts( YES );     } else {       int tmp = -1;       for (int i = 1; i < v.size(); i++) {         if (v[i] - v[i - 1] > k) tmp = i;       }       bool ans = false;       if (tmp != v.size() - 1 && v[tmp + 1] - v[tmp - 1] <= 2 * k) ans = true;       if (tmp == 0 && v[1] <= 2 * k) tmp = true;       for (int i = v[tmp] + 1; i <= n; i++) {         if (vis[i]) continue;         if (num[i] < num[v[tmp - 1]] && num[i] > num[v[tmp]]) ans = true;       }       if (ans)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <iostream>      int main(void) {    int count;    std::cin >> count;    for (int i = 0; i < count; ++i) {     int number;     std::cin >> number;     int64_t sum = 0;     for (int j = 0; j < number; ++j) {      int part;      std::cin >> part;      sum += part;     }     std::cout << (sum % number) * (number - sum % number) <<   n ;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> v(n);     for (auto &i : v) cin >> i;     int q;     cin >> q;     vector<int> idx(n, 0);     vector<int> ops(q, 0);     for (int i = 0; i < q; ++i) {       int op;       cin >> op;       if (op == 1) {         int p, x;         cin >> p >> x;         v[p - 1] = x;         idx[p - 1] = i;       } else {         int x;         cin >> x;         ops[i] = x;       }     }     for (int i = q - 2; i >= 0; --i) ops[i] = max(ops[i], ops[i + 1]);     for (int i = 0; i < n; ++i) {       v[i] = max(ops[idx[i]], v[i]);     }     for (int i = 0; i < n; ++i) cout << v[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define ll long long   #define ld long double   #define lchild 2*node   #define rchild 2*node+1   #define mid (l+r)/2   #define mod 1000000007   #define mx 200007   #define pii pair<int,int>   #define pci pair<int,int>   #define ff first   #define ss second   #define piii pair<int,pii>   using namespace std;      int t1[mx][21], lg2[mx], t2[mx][21];   int arr[mx];      void f( int n )   {       int i, j, k, m, l, r, q;       lg2[1] = 0;       for (i = 2; i <= n; i++) lg2[i] = lg2[i / 2] + 1;       for (i = 1; i <= n; i++) t1[i][0] = arr[i], t2[i][0] = arr[i];       for (j = 1; j <= 20; j++) for (i = 1; i + (1 << (j - 1)) <= n; i++) t1[i][j] = min(t1[i][j - 1], t1[i + (1 << (j - 1))][j - 1]);       for (j = 1; j <= 20; j++) for (i = 1; i + (1 << (j - 1)) <= n; i++) t2[i][j] = max(t2[i][j - 1], t2[i + (1 << (j - 1))][j - 1]);           }      int squery1( int l, int r )   {       // int ans = min(ans, t[l][i]), l += (1 << i);       int k = lg2[r - l + 1];       int ans = min(t1[l][k], t1[r - (1 << k) + 1][k]);          return ans;   }      int squery2( int l, int r )   {       // int ans = min(ans, t[l][i]), l += (1 << i);       int k = lg2[r - l + 1];       int ans = max(t2[l][k], t2[r - (1 << k) + 1][k]);          return ans;   }            int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);          int tc;       cin >> tc;          while (tc--)       {           int n;           cin >> n;              for ( int i = 1; i <= n; i++ )               cin >> arr[i];              f(n);              int pre[n + 5], suff[n + 5];           pre[1] = arr[1];           suff[n] = arr[n];              for ( int i = 2; i <= n; i++ )               pre[i] = max( pre[i - 1], arr[i] );           for ( int i = n - 1; i >= 1; i-- )               suff[i] = max( suff[i + 1], arr[i] );              bool f= 0;           int out, lf, rt;              for ( int i = 2; i < n; i++ )           {               int x = arr[i];                  int baam = i, daan = i;                  int l = 1, r = i;                  if ( i > 1 )               {                   int ans = i;                   while (l <= r)                   {                       int q = squery1( mid, i );                          if (q != x)                           l = mid + 1;                       else                           ans = mid, r = mid - 1;                   }                      baam = ans;               }                  l = i, r = n;                  if ( i < n )               {                   int ans = i;                   while (l <= r)                   {                       int q = squery1( i, mid );                          // cout<<x<<   <<l<<   <<r<<   <<q<<endl;                          if (q != x)                           r = mid - 1;                       else                           ans = mid, l = mid + 1;                   }                      daan = ans;               }                  baam= max( baam, 2 );               daan= min( daan, n-1 );                  if( baam<i and arr[baam]==arr[i] )                   baam++;               if( daan>i and arr[daan]==arr[i] )                   daan--;                  if( pre[baam-1]==suff[daan+1] and pre[baam-1]==arr[i] )               {                   f= 1;                   out= daan-baam+1;                   lf= baam-1;                   rt= n-daan;                   break;               }                  // cout<<i<<   <<baam<<   <<daan<<   <<pre[baam-1]<<    <<suff[daan+1]<<endl;           }              if(f)               cout<< YES n <<lf<<   <<out<<   <<rt<<  n ;           else               cout<< NO n ;          }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int a[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n * 2; i++) scanf( %d , &a[i]);     sort(a, a + n * 2);     long long area = 1ll * (a[n - 1] - a[0]) * (a[n * 2 - 1] - a[n]);     for (int i = 1; i < n; i++) {       area = min(area, 1ll * (a[i + n - 1] - a[i]) * (a[n * 2 - 1] - a[0]));     }     printf( %I64d , area);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     scanf( %d %d , &n, &d);     int data[n + 10];     for (int i = 0; i < n; i++) scanf( %d , &data[i]);     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       int h = upper_bound(data, data + n, data[i] + d) - data;       h--;       int l = i;       int n = (h - l) + 1;       if (n < 3) continue;       n -= 2;       ans += ((long long)(n) * (long long)(n + 1)) / 2;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 123;   int n, t, label[N], times = 0;   vector<int> e[N];   vector<pair<int, int> > res;   void newLabel(int u) {     res.push_back(make_pair(u, times));     label[u] = times;   }   void dfs(int u, int backLabel = -1, int p = 0) {     newLabel(u);     int numchild = (int)e[u].size() - (u > 1);     for (int v : e[u]) {       if (v == p) continue;       if (label[u] >= t) {         times = backLabel - numchild;         newLabel(u);       }       times = label[u] + 1;       dfs(v, label[u], u);       if (label[v] > label[u]) {         times = label[u];         newLabel(v);       }       ++times;       newLabel(u);       --numchild;     }     if (u > 1 && label[u] > backLabel) {       times = backLabel;       newLabel(u);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       e[u].push_back(v);       e[v].push_back(u);     }     t = -1;     for (int i = 1; i <= n; ++i) t = max(t, (int)e[i].size());     dfs(1);     cout << res.size() <<   n ;     for (pair<int, int> x : res) {       cout << x.first <<     << x.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double df, de;     void init(double _df, double _de) {       df = _df;       de = _de;     }   } V[100];   int nf, ne, ns, rf, re, rs, df, de;   int n, top, place[13];   double ans = 0, dp[21][21], lf, le, ls;   bool cmp(const point &a, const point &b) { return a.df > b.df; }   double cross(double l1, double r1, double l2, double r2) {     if (l2 >= r1 || l1 >= r2) return 0;     return min(r1, r2) - max(l1, l2);   }   void init_V() {     top = 0;     for (int i = 0; i < n; i++)       if (place[i] < 2) {         double t1 = lf * df, t2 = le * de;         for (int j = 0; j < n; j++)           if (place[j]) {             t1 += df * place[j] *                   cross(j - ls / 2, j + ls / 2, i - lf / 2, i + lf / 2);             t2 += de * place[j] *                   cross(j - ls / 2, j + ls / 2, i - le / 2, i + le / 2);           }         for (int j = 1; j + place[i] <= 2; j++) V[top++].init(t1, t2);       }     sort(V, V + top, cmp);   }   void init_dp() {     memset(dp, 0, sizeof(dp));     for (int i = 0; i <= nf; i++)       for (int j = 0; j <= ne; j++) {         if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + V[i + j - 1].df);         if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + V[i + j - 1].de);       }     ans = max(ans, dp[nf][ne]);   }   void dfs(int p, int left) {     if ((n - p) * 2 < left) return;     if (p == n) {       init_V();       init_dp();       return;     }     for (int i = 0; i <= 2 && left >= i; i++) {       place[p] = i;       dfs(p + 1, left - i);     }   }   int main() {     cin >> nf >> ne >> ns >> rf >> re >> rs >> df >> de;     n = (nf + ne + ns + 1) / 2;     lf = 2 * sqrt(rf * rf - 1.0);     le = 2 * sqrt(re * re - 1.0);     ls = 2 * sqrt(rs * rs - 1.0);     dfs(0, ns);     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   struct rge {     T b, e;   };   template <class T>   rge<T> range(T i, T j) {     return rge<T>{i, j};   }   struct debug {     template <class T>     debug& operator<<(const T&) {       return *this;     }   };   using ll = long long;   template <typename T>   void min_self(T& a, T b) {     a = min(a, b);   }   template <typename T>   void max_self(T& a, T b) {     a = max(a, b);   }   const int mxN = 2500 * 1000 + 5;   int xs[mxN], N = 0;   const ll inf = 1e18;   class SegTree {    public:     struct Node {       ll mn = inf;       void merge(Node x, Node y) { mn = min(x.mn, y.mn); }     };     SegTree(int _n) : n(_n) {       tree.resize(4 * n);       lazy.resize(4 * n);     }     void build(int i, int L, int R) {       if (L == R) {         tree[i].mn = 0;       } else {         int m = L + (R - L) / 2;         build(2 * i, L, m);         build(2 * i + 1, m + 1, R);         tree[i].merge(tree[2 * i], tree[2 * i + 1]);       }     }     void push(int i) {       ll& v = lazy[i];       tree[2 * i].mn += v;       lazy[2 * i] += v;       tree[2 * i + 1].mn += v;       lazy[2 * i + 1] += v;       v = 0;     }     Node get(int i, int L, int R, int tl, int tr) {       if (tl > tr) return Node();       if (L == tl && tr == R) {         return tree[i];       } else {         push(i);         int m = L + (R - L) / 2;         Node ans;         ans.merge(get(2 * i, L, m, tl, min(tr, m)),                   get(2 * i + 1, m + 1, R, max(m + 1, tl), tr));         return ans;       }     }     ll get(int tl, int tr) {       Node ans = get(1, 1, n, tl, tr);       return ans.mn;     }     void upd(int i, int L, int R, int tl, int tr, int val) {       if (tl > tr) return;       if (L == tl && tr == R) {         tree[i].mn += val;         lazy[i] += val;       } else {         push(i);         int m = L + (R - L) / 2;         upd(2 * i, L, m, tl, min(tr, m), val);         upd(2 * i + 1, m + 1, R, max(m + 1, tl), tr, val);         tree[i].merge(tree[2 * i], tree[2 * i + 1]);       }     }     void upd(int tl, int tr, int val) { upd(1, 1, n, tl, tr, val); }       private:     int n;     vector<Node> tree;     vector<ll> lazy;   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> tv;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       for (int x : {a - 1, a, a + 1, b - 1, b, b + 1}) {         xs[N++] = x;       }       tv.emplace_back(a, b);     }     sort(xs, xs + N);     N = unique(xs, xs + N) - xs;     SegTree st(N);     st.build(1, 1, N);     for (auto pp : tv) {       int L = pp.first, R = pp.second;       L = lower_bound(xs, xs + N, L) - xs;       R = lower_bound(xs, xs + N, R) - xs;       st.upd(L + 1, R + 1, 1);     }     int who = 1;     for (auto pp : tv) {       int L = pp.first, R = pp.second;       L = lower_bound(xs, xs + N, L) - xs;       R = lower_bound(xs, xs + N, R) - xs;       if (st.get(L + 1, R + 1) > 1) {         cout << who <<   n ;         exit(0);       }       who++;     }     cout <<  -1 n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long a, b;     cin >> a >> b;     if (b - a > 5) {       cout << 0 <<   n ;     } else {       long long val = 1;       for (long long j = a + 1; j <= b; j++) {         val *= (j % 10);         val %= 10;       }       cout << val <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     solve();   }