#include <bits/stdc++.h>   int n, k;   bool visited[101][101][1010];   double ar[101], dp[101][101][1010];   double F(int i, int j, int k) {     if (i > j) return 1.0 - F(j, i, k);     if (k == 0) return 1.0;     if (visited[i][j][k]) return dp[i][j][k];     int a, b, c, d, l;     double x, y, p = 1.0 / ((n * (n + 1)) >> 1), res = 0.0;     for (a = 0; a < n; a++) {       for (b = a; b < n; b++) {         c = i, d = j;         if (c >= a && c <= b) c = b - (c - a);         if (d >= a && d <= b) d = b - (d - a);         res += (p * F(c, d, k - 1));       }     }     visited[i][j][k] = true;     return (dp[i][j][k] = res);   }   int main() {     int i, j, l;     while (scanf( %d %d , &n, &k) != EOF) {       if (k > 1000) k = 1000;       for (i = 0; i < n; i++) scanf( %d , &ar[i]);       memset(visited, 0, sizeof(visited));       double res = 0.0;       for (i = 0; i < n; i++) {         for (j = i + 1; j < n; j++) {           if (ar[i] < ar[j])             res += (1.0 - F(i, j, k));           else             res += F(i, j, k);         }       }       printf( %0.12f n , res + 1e-15);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const double EPS = 1e-9;   const double PI = acos(-1.);   const long long LL_INF = 1e17 + 16;   const int INF = 1e9 + 10;   const long long MOD = 1e9 + 7;   const int MAXN = 20;   set<long long> goods;   long long f[MAXN];   void gen() {     for (int i = (1); i <= (int)(10); i++) {       for (int j = (0); j < (int)(1 << i); j++) {         long long v = 0;         long long st10 = 1;         for (int k = (0); k < (int)(i); k++) {           if (j & (1 << k)) {             v += 7 * st10;           } else {             v += 4 * st10;           }           st10 *= 10;         }         goods.insert(v);       }     }   }   int per[MAXN];   int used[MAXN];   void solve() {     gen();     long long n, k;     cin >> n >> k;     f[0] = 1;     int m;     for (m = 1;; m++) {       f[m] = f[m - 1] * m;       if (f[m] >= k) {         break;       }     }     if (m > n) {       printf( -1 n );       return;     }     int ans = 0;     int offset = n - m;     for (__typeof((goods).begin()) it = (goods).begin(); it != (goods).end();          it++) {       if ((*it) <= offset) {         ans++;       }     }     k--;     int top = 1;     for (int i = m; i >= 1; i--) {       int v = k / f[i - 1] + 1;       int cnt = 0;       for (int j = (1); j <= (int)(m); j++) {         if (!used[j]) {           cnt++;           if (cnt == v) {             per[top++] = j;             used[j] = 1;             break;           }         }       }       k %= f[i - 1];     }     for (int i = (1); i <= (int)(m); i++) {       if (goods.count(i + offset) && goods.count(per[i] + offset)) {         ans++;       }     }     cout << ans << endl;   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void dfs(set<int> &temp, list<int> adj[], vector<bool> &v, int s, int &t1,            int &t2, vector<int> b, vector<int> w) {     v[s] = true;     list<int>::iterator it;     for (it = adj[s].begin(); it != adj[s].end(); it++) {       if (!v[*it]) {         temp.insert(*it);         t1 += b[*it];         t2 += w[*it];         dfs(temp, adj, v, *it, t1, t2, b, w);       }     }   }   list<int> adj[1001];   int main() {     int n, m, weight;     cin >> n >> m >> weight;     vector<int> b(n + 1);     vector<int> w(n + 1);     for (int i = 1; i <= n; i++) cin >> w[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     vector<bool> v(n + 1, false);     vector<set<int> > arr;     vector<int> tw;     vector<int> tb;     for (int i = 1; i <= n; i++) {       if (!v[i]) {         set<int> temp;         temp.insert(i);         int t1 = b[i], t2 = w[i];         dfs(temp, adj, v, i, t1, t2, b, w);         arr.push_back(temp);         tb.push_back(t1);         tw.push_back(t2);       }     }     vector<vector<int> > dp(arr.size() + 1, vector<int>(weight + 1, 0));     for (int i = 1; i <= arr.size(); i++) {       for (int j = 1; j <= weight; j++) {         int max = 0;         if (dp[i - 1][j] > max) max = dp[i - 1][j];         if (j - tw[i - 1] >= 0)           if (dp[i - 1][j - tw[i - 1]] + tb[i - 1] > max)             max = dp[i - 1][j - tw[i - 1]] + tb[i - 1];         set<int>::iterator it;         for (it = arr[i - 1].begin(); it != arr[i - 1].end(); it++) {           if (j - w[*it] >= 0)             if (dp[i - 1][j - w[*it]] + b[*it] > max)               max = dp[i - 1][j - w[*it]] + b[*it];         }         dp[i][j] = max;       }     }     int max = 0;     for (int i = 0; i <= weight; i++)       if (dp[arr.size()][i] > max) max = dp[arr.size()][i];     cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, ans, x, i, j, s;   double a[100], b[100];   map<double, pair<long long, long long> > mp;   map<double, pair<long long, long long> >::iterator it, it2;   long long num(long long x) {     s = 0;     while (x) {       s++;       x -= x & -x;     }     return s;   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) cin >> b[i];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         mp[(a[i] + b[j]) / 2.0].first |= (1LL << i);         mp[(a[i] + b[j]) / 2.0].second |= (1LL << j);       }     for (it = mp.begin(); it != mp.end(); it++)       for (it2 = it; it2 != mp.end(); it2++) {         x = num((*it).second.first | (*it2).second.first) +             num((*it).second.second | (*it2).second.second);         if (x > ans) ans = x;       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     long long n, k;     scanf( %I64d , &n);     while (n % 3 == 0) n /= 3;     printf( %I64d , 1 + n / 3);     getchar();     getchar();   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = numeric_limits<long long>::max() / 4;   constexpr long long n_max = 2e5 + 10;   template <typename A, typename B>   string to_string(pair<A, B> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char c) { return to_string((string)&c); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) res += static_cast<char>( 0  + v[i]);     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) res +=  ,  ;       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <class T>   bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   signed main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     long long t;     cin >> t;     for (long long _ = 0; _ < (long long)(t); _++) {       long long n;       cin >> n;       vector<long long> a(n);       for (long long i = 0; i < (long long)(n); i++) cin >> a[i];       vector<long long> dp(n + 1);       for (long long i = 1; i < (long long)(n) + 1; i++) {         dp[i]++;         for (long long j = i * 2; j <= n; j += i) {           if (a[j - 1] > a[i - 1]) chmax(dp[j], dp[i]);         }       }       long long ans = 0;       for (long long i = 0; i < (long long)(n + 1); i++) chmax(ans, dp[i]);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int test = 1;     cin >> test;     while (test--) {       long long int n, m;       cin >> n >> m;       long long int sum1 = 0, sum2 = 0;       long long int a[n], b[n], mina[n], mi = 0;       for (int i = 0; i < n; i++) {         cin >> a[i] >> b[i];         sum1 += a[i];         sum2 += b[i];         mina[i] = max(0LL, m - b[i]);         mi += mina[i];         a[i] = min(a[i], m);       }       long long int ans = sum1 - sum2 + (n * m);       long long int x = ans - 2LL * mi;       for (int i = 0; i < n; i++) {         if (x <= 0) break;         long long int temp = min(2LL * (a[i] - mina[i]), x);         temp /= 2;         mina[i] += temp;         x -= 2LL * temp;       }       cout << abs(x) <<   n ;       for (int i = 0; i < n; i++) cout << mina[i] <<     << m - mina[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   bool compare(int a, int b) { return a > b; }   int main() {     int t, p, f, cnts, cntw, s, w;     scanf( %d , &t);     while (t--) {       scanf( %d%d , &p, &f);       scanf( %d%d , &cnts, &cntw);       scanf( %d%d , &s, &w);       if (s > w) {         int temp = s;         s = w;         w = temp;         temp = cnts;         cnts = cntw;         cntw = temp;       }       int mx = min(cnts, p / s);       int ans = 0;       for (int s1 = 0; s1 <= mx; s1++) {         int w1 = min(cntw, (p - s1 * s) / w);         int s2 = min(cnts - s1, f / s);         int w2 = min(cntw - w1, (f - s2 * s) / w);         ans = max(ans, s1 + s2 + w1 + w2);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 10;   long long n, k;   int main() {     scanf( %I64d%I64d , &n, &k);     long long x;     x = sqrt(9 + 8 * (n + k)) - 3;     x /= 2;     printf( %I64d n , n - x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   const int N = 3e3;   long long dmod(long long x) { return x % MOD; }   int n, k;   int h[N + 5];   long long memo[N + 5][2 * N + 5];   long long dp(int idx, int gap) {     if (idx > n) {       if (gap > 0) return 1;       return 0;     }     long long &ret = memo[idx][gap + N];     if (ret != -1) return ret;     ret = 0ll;     if (h[idx] == h[idx % n + 1]) {       ret = dmod((long long)k * dp(idx + 1, gap));     } else {       ret = dp(idx + 1, gap + 1);       ret = dmod(ret + dp(idx + 1, gap - 1));       ret = dmod(ret + dmod((long long)(k - 2) * dp(idx + 1, gap)));     }     return ret;   }   int main() {     memset(memo, -1, sizeof(memo));     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);     }     printf( %lld n , dp(1, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, m = 0, sum = 0;     cin >> n >> x;     int *arr = new int[n];     for (long long i = 0; i < n; i++) cin >> arr[i], sum += arr[i];     if (sum > 0)       while (sum > 0) {         sum -= x;         m++;       }     else       while (sum < 0) {         sum += x;         m++;       }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int brute(int s, int x) {     int ans = 0;     for (int i = 1; i <= s; ++i)       for (int j = 1; j <= s; ++j)         if (i + j == s && (i ^ j) == x) ++ans;     return ans;   }   long long ways0(long long s, long long x) {     if (s == x) return 2;     return 0;   }   long long solve(long long s, long long x) {     long long dp[60][2] = {};     if (s % 2 != x % 2) {       return 0;     }     if (x & (1LL << 0)) {       dp[0][0] = 2;     } else {       dp[0][0] = 1;       dp[0][1] = 1;     }     for (int i = 1; i < 60; ++i) {       if (x & (1LL << i)) {         if (s & (1LL << i)) {           dp[i][0] += 2 * dp[i - 1][0];         } else {           dp[i][1] += 2 * dp[i - 1][1];         }       } else {         if (s & (1LL << i)) {           dp[i][0] += dp[i - 1][1];           dp[i][1] += dp[i - 1][1];         } else {           dp[i][0] += dp[i - 1][0];           dp[i][1] += dp[i - 1][0];         }       }     }     return dp[59][0] - ways0(s, x);   }   int main() {     long long s, x;     cin >> s >> x;     cout << solve(s, x) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void dmin(T& x, T y) {     y < x ? x = y : 0;   }   template <class T>   inline void dmax(T& x, T y) {     y > x ? x = y : 0;   }   template <class T>   inline void dmin(T& x, vector<T> y) {     for (auto t : y) t < x ? x = t : 0;   }   template <class T>   inline void dmax(T& x, vector<T> y) {     for (auto t : y) t > x ? x = t : 0;   }   const int N = 5 + 1e6;   const long long INF = -2e18;   int n, k;   long long gk(int x, long long a[], int i, long long f) {     return a[x] + (i - x) / 3 * f;   }   bool cmp(int x, int y, long long a[], int i, long long f) {     return gk(x, a, i, f) > gk(y, a, i, f);   }   void opera(long long a[], int n, long long f, int k) {     static long long b[N];     static long long q[3][N], left[3], right[3];     for (int i = 0; i < 3; ++i) left[i] = 1, right[i] = 0;     for (int i = 0; i < n; ++i) b[i] = INF;     for (int i = 0; i < n; ++i) {       int t = i % 3;       while (left[t] <= right[t] && q[t][left[t]] < i - 3 * k) ++left[t];       while (left[t] <= right[t] && cmp(i, q[t][right[t]], a, i, f)) --right[t];       q[t][++right[t]] = i;       b[i] = gk(q[t][left[t]], a, i, f);     }     for (int i = 0; i < n; ++i) a[i] = b[i];   }   void opera2(long long a[], int n, long long f, int k) {     static long long f1[N], f2[N];     for (int i = 0; i < n; ++i) {       f1[i] = f2[i] = a[i];       for (int j = 1; j < 10 && i - j >= 0; ++j) f2[i] = max(f2[i], a[i - j]);     }     opera(f1, n, f, 3 * k);     opera(f2, n, f, 3 * (k - 1));     for (int i = 0; i < n; ++i) a[i] = max(f1[i], f2[i]);   }   long long a[N], b[N];   int main() {     int k;     scanf( %d , &k);     long long f[6];     for (int i = 0; i < 6; ++i) scanf( %lld , &f[i]);     a[0] = 0;     n = 1;     for (int i = 5; i >= 0; --i) {       for (int j = 0; j < 10 * n; ++j) b[j] = INF;       for (int j = 0; j < n; ++j) b[j * 10] = a[j];       n *= 10;       opera2(b, n, f[i], k);       for (int j = 0; j < n; ++j) a[j] = b[j];     }     int q;     scanf( %d , &q);     while (q--) {       int x;       scanf( %d , &x);       printf( %lld n , a[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       sort(arr, arr + n);       bool f = true;       for (int j = 1; j < n; j++) {         int diff = abs(arr[j] - arr[j - 1]);         if (diff > 1) {           f = false;         }       }       if (f) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int modulo = 1000000007;   const int limite = 1000001;   long long int elev[limite];   int ocupado[limite];   int main() {     ios_base::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     elev[0] = 1;     for (int i = 1; i < limite; i++) elev[i] = (elev[i - 1] * 2) % modulo;     int ini = 0;     int fin = n + 1;     int inf = k + 2;     int sup = n;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       if (v == u + 1)         ;       else if (v == u + k + 1) {         ocupado[v] = 1;         ini = max(ini, u);         fin = min(fin, v);         inf = max(inf, u + 1);         sup = min(sup, v + k);       } else {         cout << 0 << endl;         exit(0);       }     }     if (fin <= ini) {       cout << 0 << endl;       exit(0);     }     int libres = 0;     long long int maneras = 1;     for (int i = inf; i <= sup; i++) {       if (not ocupado[i]) {         maneras = (maneras + elev[libres]) % modulo;         libres++;       }       if (i - k >= inf and not ocupado[i - k]) libres--;     }     cout << maneras << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool v[6];   int a[100009][6], maxx = -1, t;   long long m = 1e9 + 7;   struct pi {     long long ah[60][60];   };   pi multi(pi x, pi y) {     pi z;     for (int i = 1; i <= t; i++) {       for (int j = 1; j <= t; j++) {         z.ah[i][j] = 0;         for (int k = 1; k <= t; k++)           z.ah[i][j] = (z.ah[i][j] % m + x.ah[i][k] % m * y.ah[k][j] % m) % m;         z.ah[i][j] %= m;       }     }     return z;   }   pi quimul(pi x, long long int n) {     pi an;     for (int i = 1; i <= t; i++) an.ah[i][i] = 1;     for (; n; n >>= 1) {       if (n & 1) an = multi(an, x);       x = multi(x, x);     }     return an;   }   int main() {     long long n;     int x, v, p[600], zh[90][90];     char c =  a , u;     for (int i = 1; i <= 52; i++)       for (int j = 1; j <= 52; j++) zh[i][j] = 1;     for (int i = 1; i <= 26; i++) p[(int)c + i - 1] = i;     c =  A ;     for (int i = 27; i <= 52; i++) p[(int)c + i - 27] = i;     cin >> n >> t >> v;     for (int i = 0; i < v; i++) {       scanf(  %c %c , &c, &u);       zh[p[(int)c]][p[(int)u]] = 0;     }     pi ans;     for (int i = 1; i <= t; i++)       for (int j = 1; j <= t; j++) ans.ah[i][j] = zh[i][j];     ans = quimul(ans, n - 1);     long long int pp = 0;     for (int i = 1; i <= t; i++)       for (int j = 1; j <= t; j++) pp = (pp + ans.ah[i][j]) % m;     cout << (pp + m) % m << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n, i, j, money;     cin >> a >> b >> c;     cin >> n;     int m[n];     money = 0;     for (i = 0; i < n; i++) {       cin >> m[i];       if (m[i] > b && m[i] < c) money = money + 1;     }     if (a > b && a < c)       cout << money;     else       cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void display(T a[], int size) {     for (int i = 0; i < size; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void display(vector<pair<int, int> > a) {     for (int i = 0; i < a.size(); i++) {       cout <<  (  << a[i].first <<  ,  << a[i].second <<  )             <<    ;     }     cout << endl;   }   void display(const vector<int>& a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i];       if (i == a.size() - 1)         cout << endl;       else         cout <<    ;     }   }   template <typename T>   void initialise(T a[], T value, int length) {     for (int i = 0; i < length; i++) a[i] = value;   }   template <typename T>   void initialise(vector<T>& a, T value) {     for (int i = 0; i < a.size(); i++) a[i] = value;   }   bool compare(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second < b.second;   }   int max(int a[], int n) {     int max = -1000000000;     for (int i = 0; i < n; i++) {       if (a[i] > max) max = a[i];     }     return max;   }   bool find(string a[], string s, int n) {     int left = 0;     int right = n - 1;     while (left < right) {       int mid = (left + right) / 2;       if (s.compare(a[mid]) == 0)         return true;       else if (s.compare(a[mid]) < 0) {         right = mid;       } else {         left = mid + 1;       }     }     return false;   }   void factor(int a[], int base, int num, int n) {     for (int i = n - 1; i >= 0; i--) {       a[i] = num % base;       num = num / base;     }   }   int findLength(int n, int base) {     int i = 0;     while (n > 0) {       i++;       n = n / base;     }     return i;   }   int gcd(int a, int b) {     while (a % b != 0 && b % a != 0) {       if (b > a) {         b = b % a;       } else if (a > b) {         a = a % b;       }     }     if (a <= b)       return a;     else       return b;   }   int main() {     int n;     cin >> n;     int dir[n];     int step[n];     for (int i = 0; i < n; i++) {       char now;       cin >> now;       if (now ==  > )         dir[i] = 1;       else         dir[i] = -1;     }     for (int i = 0; i < n; i++) {       cin >> step[i];     }     int trace[n];     initialise(trace, 0, n);     int curr = 0;     while (true) {       if (trace[curr] == 1) {         cout <<  INFINITE  << endl;         break;       } else {         trace[curr] = 1;         curr = curr + dir[curr] * step[curr];         if (curr >= n || curr < 0) {           cout <<  FINITE  << endl;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, c = 0, d = 0, k;     string str;     cin >> n >> str;     for (int i = 0; i < n; i++) {       if (str[i] ==  - ) c++;     }     if (c == n) {       cout << 0 << endl;       return 0;     } else if (str[0] ==  - ) {       for (int i = 0; i < n; i++) {         if (str[i] ==  - ) {           continue;         } else {           k = i;           break;         }       }       for (int i = k; i < n; i++) {         if (str[i] ==  + )           d += 1;         else {           d -= 1;           if (d < 0) d = 0;         }       }     } else {       for (int i = 0; i < n; i++) {         if (str[i] ==  + )           d += 1;         else {           d -= 1;           if (d < 0) d = 0;         }       }     }     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M;   const int MAX = 100001;   vector<int> _size, marked, _pow, _ipow;   vector<pair<int, int> > adjList[MAX + 1];   int getSize(int u, int p = -1) {     _size[u] = 1;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v]) _size[u] += getSize(v, u);     return _size[u];   }   int getCentroid(int u, int p, int n) {     for (auto [v, w] : adjList[u])       if (v != p && !marked[v] && _size[v] * 2 > n) return getCentroid(v, u, n);     return u;   }   void add(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     aux[rem]++;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         add(aux, v, u, lvl + 1, (int(1LL * w * _pow[lvl] % M) + rem) % M);   }   void remove(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     aux[rem]--;     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         remove(aux, v, u, lvl + 1, (int(1LL * w * _pow[lvl] % M) + rem) % M);   }   long long count(unordered_map<int, int> &aux, int u, int p, int lvl, int rem) {     int nxt = int(1LL * _ipow[lvl] * (M - rem) % M);     long long ans = aux[nxt];     for (auto [v, w] : adjList[u])       if (v != p && !marked[v])         ans += count(aux, v, u, lvl + 1, (rem * 10LL + w) % M);     return ans;   }   long long solve(int u) {     int N = getSize(u);     u = getCentroid(u, -1, N);     marked[u] = 1;     unordered_map<int, int> aux;     aux[0] = 1;     for (auto [v, w] : adjList[u])       if (!marked[v]) add(aux, v, u, 1, w % M);     long long ans = aux[0] - 1;     for (auto [v, w] : adjList[u])       if (!marked[v]) {         remove(aux, v, u, 1, w % M);         ans += count(aux, v, u, 1, w % M);         add(aux, v, u, 1, w % M);       }     aux.clear();     for (auto [v, w] : adjList[u])       if (!marked[v]) ans += solve(v);     return ans;   }   int gcd(int a, int b, int &x, int &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     int x1, y1;     int d = gcd(b, a % b, x1, y1);     x = y1;     y = x1 - y1 * (a / b);     return d;   }   int getInv() {     int x, y;     int g = gcd(10, M, x, y);     assert(g == 1);     return (x % M + M) % M;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n >> M;     _size = vector<int>(n), _pow = vector<int>(n + 1, 1),     _ipow = vector<int>(n + 1, 1), marked = vector<int>(n + 1);     _ipow[1] = getInv();     _pow[1] = 10;     for (int i = 2; i <= n; i++) {       _pow[i] = int(1LL * _pow[i - 1] * 10 % M);       _ipow[i] = int(1LL * _ipow[i - 1] * _ipow[1] % M);     }     for (int i = 0; i < n - 1; i++) {       int u, v, w;       cin >> u >> v >> w;       adjList[u].push_back({v, w});       adjList[v].push_back({u, w});     }     cout << solve(0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 100, M = 1e6 + 100;   int n, up[N], down[M], nei[M][2];   int lim;   bool mark[M], bad[M];   vector<int> vec;   int f(int a) { return lower_bound(vec.begin(), vec.end(), a) - vec.begin(); }   bool dfs(int v) {     mark[v] = true;     for (int i = 0; i < 2 && nei[v][i] <= lim; i++) {       int u = nei[v][i];       if (up[u] == -1 || (mark[up[u]] == false && dfs(up[u]))) {         up[u] = v;         down[v] = u;         return true;       }     }     return false;   }   bool ok(int X) {     lim = X;     fill(up, up + N, -1);     fill(down, down + M, -1);     memset(bad, false, sizeof bad);     int matching = 0;     bool done = false;     for (int v = 0; v < n; v++)       if (nei[v][0] > lim)         return false;       else if (nei[v][1] > lim) {         if (up[nei[v][0]] != -1) return false;         down[v] = nei[v][0];         up[nei[v][0]] = v;         bad[v] = true;         matching++;       }     while (done == false) {       done = true;       copy(bad, bad + n, mark);       for (int v = 0; v < n; v++)         if (mark[v] == false && down[v] == -1 && dfs(v)) {           matching++;           done = false;         }     }     return matching == n;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> nei[i][0] >> nei[i][1];       vec.push_back(nei[i][0]);       vec.push_back(nei[i][1]);     }     sort(vec.begin(), vec.end());     vec.resize(unique(vec.begin(), vec.end()) - vec.begin());     for (int i = 0; i < n; i++)       nei[i][0] = f(nei[i][0]), nei[i][1] = f(nei[i][1]);     if (ok(vec.size() - 1) == false) {       cout << -1;       return 0;     }     if (ok(vec.size() - 2) == false) {       cout << vec.back();       return 0;     }     int l = -1, r = vec.size() - 1;     while (r - l > 1) {       if (ok((l + r) >> 1))         r = lim;       else         l = lim;     }     cout << vec[r];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int val[200007], add[200007];   int main() {     int n, t, a, x, k, l = 1;     long long sum = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &t);       if (t == 1) {         scanf( %d%d , &a, &x);         add[a] += x;         sum += a * x;       } else if (t == 2) {         scanf( %d , &k);         val[++l] = k;         sum += val[l];       } else if (l > 1) {         sum -= val[l];         sum -= add[l];         add[l - 1] += add[l];         add[l] = 0;         --l;       }       printf( %.6lf n , (double)sum / l);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 2e5 + 10;   long long n, w, k, happy[N], nice, t[N], mytime, ans;   bool in[N];   pair<int, int> lowest;   set<pair<int, int>> st;   queue<int> q;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> w >> k;     for (int i = 0; i < n; i++) cin >> happy[i];     for (int i = 0; i < n; i++) cin >> t[i];     for (int i = n - 1; ~i; i--) {       st.insert({t[i], -i});       if ((int)st.size() == w) {         lowest = *st.begin();         mytime += (t[i] + 1) / 2;         in[i] = true;       } else if ((int)st.size() > w) {         if (t[i] >= lowest.first) {           in[-lowest.second] = false;           mytime += (t[i] + 1) / 2;           mytime -= (lowest.first + 1) / 2;           mytime += lowest.first;           lowest = *st.upper_bound(lowest);           in[i] = true;         } else           mytime += t[i];       } else {         in[i] = true;         mytime += (t[i] + 1) / 2;       }       nice += happy[i];       q.push(i);       while (mytime > k) {         nice -= happy[q.front()];         if (in[q.front()]) {           mytime -= (t[q.front()] + 1) / 2;           in[q.front()] = false;           st.erase({t[q.front()], -q.front()});           if ((int)st.size() >= w) {             lowest = *(--st.lower_bound(lowest));             in[-lowest.second] = true;             mytime -= lowest.first;             mytime += (lowest.first + 1) / 2;           }         } else {           mytime -= t[q.front()];           st.erase({t[q.front()], -q.front()});         }         q.pop();       }       ans = max(ans, nice);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void speedUp() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long int t, n, m, p[100005], q[100005], Podd, Peven, Qodd, Qeven, tot;   int main() {     speedUp();     int t, n;     cin >> t;     while (t--) {       tot = Podd = Peven = Qodd = Qeven = 0;       cin >> n;       for (int i = 1; i <= n; i++) {         cin >> p[i];         if (p[i] % 2 == 0)           Peven++;         else           Podd++;       }       cin >> m;       for (int i = 1; i <= m; i++) {         cin >> q[i];         if (q[i] % 2 == 0)           Qeven++;         else           Qodd++;       }       for (int i = 1; i <= n; i++) {         if (p[i] % 2 == 0)           tot += Qeven;         else           tot += Qodd;       }       cout << tot << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     scanf( %d , &n);     int v[n];     for (int i = 0; i < n; i++) scanf( %d , v + i);     if (n > 2) {       for (int i = 0; i + 3 <= n; i++) {         int a = v[i], b = v[i + 1], c = v[i + 2];         int ans1 = -1, ans2 = -1;         set<int> ms;         ms.insert(a);         ms.insert(b);         ms.insert(c);         if (ms.size() == 1)           continue;         else if (ms.size() == 3) {           if (a == *ms.begin())             ans1 = i, ans2 = i + 1;           else if (a == *(++ms.begin()))             ans1 = i, ans2 = i + 2;           else if (a == *ms.rbegin())             ans1 = i, ans2 = i + 1;         } else if (ms.size() == 2) {           if (a == c) {             int d = -1;             if (i > 0) {               d = v[i - 1];               if (d != a)                 ans1 = i - 1, ans2 = i;               else                 ans1 = i, ans2 = i + 1;             } else if (i + 3 < n) {               d = v[i + 3];               if (d != a)                 ans1 = i + 2, ans2 = i + 3;               else                 ans1 = i + 1, ans2 = i + 2;             } else               continue;           } else if (a == b)             ans1 = i + 1, ans2 = i + 2;           else if (b == c)             ans1 = i, ans2 = i + 1;         }         printf( %d %d n , ans1 + 1, ans2 + 1);         return 0;       }     }     printf( -1 n );     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-2;   struct cplx {     double x, y;     cplx(double x1 = 0, double x2 = 0) { x = x1, y = x2; }   } g[2000001], f[2000001];   cplx operator+(cplx a, cplx b) { return cplx(a.x + b.x, a.y + b.y); }   cplx operator-(cplx a, cplx b) { return cplx(a.x - b.x, a.y - b.y); }   cplx operator*(cplx a, cplx b) {     return cplx(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);   }   void swap(cplx &a, cplx &b) { swap(a.x, b.x), swap(a.y, b.y); }   int a[2000001], b[2000001];   int r[2000001];   const double Pi = acos(-1);   void fft(cplx f[], int op, int n) {     for (int i = 0; i < n; i++)       if (i < r[i]) swap(f[i], f[r[i]]);     for (int w = 2; w <= n; w <<= 1) {       int len = w / 2;       cplx tmp(cos(Pi / len), op * sin(Pi / len));       for (int k = 0; k < n; k += w) {         cplx buf(1, 0);         for (int l = k; l < k + len; l++) {           cplx tt = f[len + l] * buf;           f[len + l] = f[l] - tt;           f[l] = f[l] + tt;           buf = buf * tmp;         }       }     }     if (op == -1) {       for (int i = 0; i < n; i++) f[i].x /= n, f[i].y /= n;     }   }   char p[2000001];   char q[2000001];   int res[2000001];   int l1, l2, k, n, m;   void solve(char c) {     for (int i = 0; i <= n; i++) f[i].x = f[i].y = g[i].x = g[i].y = 0;     int far = -1;     for (int i = 0; i < l1; i++) {       if (p[i] == c) far = i + k;       if (i <= far) f[i].x = 1;     }     far = l1;     for (int i = l1 - 1; i >= 0; i--) {       if (p[i] == c) far = i - k;       if (i >= far) f[i].x = 1;     }     for (int i = 0; i < l2; i++)       if (q[i] == c) g[i].x = 1;     fft(f, 1, n);     fft(g, 1, n);     for (int i = 0; i < n; i++) f[i] = f[i] * g[i];     fft(f, -1, n);     for (int i = 0; i < n; i++) res[i] += (int)(f[i].x + eps);   }   signed main() {     int ans = 0;     scanf( %d%d%d , &l1, &l2, &k);     cin >> p;     cin >> q;     reverse(p, p + l1);     n = l1, m = l2;     for (m += n, n = 1; n <= m; n <<= 1)       ;     for (int i = 0; i < n; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) ? n >> 1 : 0);     solve( A );     solve( T );     solve( G );     solve( C );     for (int i = 0; i <= l1 - l2; i++)       if (res[l1 - i - 1] >= l2) ans++;     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   struct edge {     int to, nxt;   } e[100005], e2[100005];   int h[100005], n, cnt, hei[100005], gson[100005], node[100005], N, fa[100005];   void ins(int x, int y) {     e[++cnt].nxt = h[x];     e[cnt].to = y;     h[x] = cnt;   }   void dfs1(int x) {     hei[x] = 1;     for (int i = h[x]; i; i = e[i].nxt) {       dfs1(e[i].to);       hei[x] = std::max(hei[x], hei[e[i].to] + 1);       if (hei[gson[x]] < hei[e[i].to]) gson[x] = e[i].to;     }   }   void dfs2(int x) {     node[++N] = x;     for (int i = h[x]; i; i = e[i].nxt)       if (e[i].to != gson[x]) dfs2(e[i].to);     if (gson[x]) dfs2(gson[x]);   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++) scanf( %d , &fa[i]), ins((++fa[i]), i);     dfs1(1);     dfs2(1);     for (int i = 1; i <= n; i++) printf( %d  , node[i] - 1);     printf(  n%d n , n - hei[1]);     for (int i = 1, j = 1, k = 0; i <= n - hei[1]; i++) {       while (j <= n && fa[node[j]] == k) k = node[j++];       if (j > n) break;       printf( %d  , node[j] - 1);       k = fa[k];     }   }


#include <bits/stdc++.h>   using namespace std;   char a[1005], b[1005];   int main() {     int s1 = 0, s2 = 0;     scanf( %s %s , &a, &b);     int len1 = strlen(a);     int len2 = strlen(b);     for (int i = 0; i < len1; i++)       if (a[i] ==  1 ) s1++;     for (int i = 0; i < len2; i++)       if (b[i] ==  1 ) s2++;     if (s1 & 1) s1++;     if (s1 >= s2)       puts( YES );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   int n, Q, x, y, z, kk;   int dis[500005], head[500005], father[500005], top[500005], q[500005];   bool vis[500005];   int far[500005], heavyson[500005], rak[500005], sum[500005], leaf[500005], ans,       d[500005];   struct Tree {     int nxt, to, step;   } e[500005];   inline bool cmp(int u, int v) {     return dis[u] - dis[father[top[u]]] > dis[v] - dis[father[top[v]]];   }   inline void link(int x, int y, int z) {     e[++kk].nxt = head[x];     e[kk].to = y;     e[kk].step = z;     head[x] = kk;   }   inline int bfs(int S) {     int left1 = 1;     int right1 = 1;     q[left1] = S;     memset(d, 0, sizeof(d));     memset(vis, false, sizeof(vis));     vis[S] = true;     while (left1 <= right1) {       int u = q[left1++];       for (int i = head[u]; i; i = e[i].nxt) {         int v = e[i].to;         if (vis[v]) continue;         vis[v] = true;         q[++right1] = v;         d[v] = d[u] + e[i].step;       }     }     int kkk = 0;     for (int i = 1; i <= n; i++) {       if (d[i] > d[kkk]) kkk = i;     }     return kkk;   }   void dfs1(int u, int fa) {     far[u] = dis[u];     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == fa) continue;       father[v] = u;       dis[v] = dis[u] + e[i].step;       dfs1(v, u);       if (!heavyson[u] || far[u] < far[v]) heavyson[u] = v, far[u] = far[v];     }   }   void dfs2(int u, int first) {     top[u] = first;     if (!heavyson[u]) {       leaf[++leaf[0]] = u;       return;     }     dfs2(heavyson[u], first);     for (int i = head[u]; i; i = e[i].nxt) {       int v = e[i].to;       if (v == father[u] || v == heavyson[u]) continue;       dfs2(v, v);     }   }   inline int solve(int x, int y) {     if (rak[top[x]] <= 2 * y - 1) return sum[min(y * 2 - 1, leaf[0])];     int u = x;     while (rak[top[u]] > y * 2 - 1) u = father[top[u]];     return sum[y * 2 - 1] -            min(min(sum[y * 2 - 1] - sum[y * 2 - 2], far[u] - dis[u]), dis[u]) +            far[x] - dis[u];   }   int main() {     scanf( %d%d , &n, &Q);     for (int i = 1; i < n; i++) {       scanf( %d%d%d , &x, &y, &z);       link(x, y, z);       link(y, x, z);     }     int first = bfs(1);     int root = bfs(first);     dfs1(root, -1);     dfs2(root, root);     sort(leaf + 1, leaf + leaf[0] + 1, cmp);     for (int i = 1; i <= leaf[0]; i++) {       rak[top[leaf[i]]] = i;       sum[i] = sum[i - 1] + dis[leaf[i]] - dis[father[top[leaf[i]]]];     }     while (Q--) {       scanf( %d%d , &x, &y);       x = ((x + ans - 1) % n) + 1;       y = ((y + ans - 1) % n) + 1;       printf( %d n , ans = solve(x, y));     }     return 0;   }


#include<bits/stdc++.h>      #define For(i, x, n) for(int i = x; i < n; i++)   #define ROF(i,x,n) for(int i = n - 1; i >= x; i--)      #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define F first   #define S second   #define pb push_back   #define po pop_back   #define mp make_pair   #define En endl   ///#define endl   n       #define ALL(x) x.begin(), x.end()      using namespace std;      typedef double db;   typedef long long LL;   typedef string str;   typedef pair<int, int> PII;   typedef pair<LL, LL> PLL;      typedef vector<int> VI;   typedef vector<LL> VLL;   typedef vector<bool> VB;   typedef vector<char> VC;   typedef vector<PII> VPII;   typedef vector<string> VSTR;   typedef set<int> SI;   typedef set<LL> SLL;   typedef set<PII> SPII;      typedef const int CI;   typedef const long long CLL;      /// CI MAX_N = ;   CI MOD = 1e9 + 7;      int t, n, a;      int main () {       IOS;       cin >> t;       while (t--) {           cin >> n;           int sumz = 0;           int sumf = 0;           For (i, 0, 2 * n) {               cin >> a;               if (a % 2 == 0) sumz++;               else sumf++;           }           if (sumz == sumf) cout <<  YES  << En;           else cout <<  NO  << En;       }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200010;   int n, m, X, a[maxn], b[maxn], c[maxn], d[maxn], tr[maxn];   long long ans;   vector<int> M[maxn];   vector<pair<int, int>> Q[maxn];   void add(int p) {     for (; p <= X; p += p & -p) tr[p]++;   }   int sum(int p) {     int s = 0;     for (; p; p -= p & -p) s += tr[p];     return s;   }   int main() {     scanf( %d %d %d , &n, &m, &X);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]), a[i] = min(a[i], X);     }     for (int i = 1; i <= m; i++) {       scanf( %d , &b[i]), b[i] = min(b[i], X);     }     auto init = [&](int n, int *a, int *c) {       static int mx[20][maxn], lb[maxn], rb[maxn];       for (int i = 1; i <= n; i++) {         mx[0][i] = a[i], lb[i] = rb[i] = 0;       }       for (int i = 1; i < 20; i++) {         for (int j = 1; j + (1 << i) - 1 <= n; j++) {           mx[i][j] = max(mx[i - 1][j], mx[i - 1][j + (1 << (i - 1))]);         }       }       auto query = [&](int l, int r) {         int k = log2(r - l + 1);         return max(mx[k][l], mx[k][r - (1 << k) + 1]);       };       stack<int> st;       for (int i = 1; i <= n; i++) {         while (!st.empty() && a[st.top()] > a[i]) rb[st.top()] = i, st.pop();         if (!st.empty()) lb[i] = st.top();         st.push(i);       }       for (int i = 1; i <= n; i++) {         c[i] = min(!lb[i] ? X : query(lb[i], i), !rb[i] ? X : query(i, rb[i]));       }     };     init(n, a, c), init(m, b, d);     for (int i = 1; i <= n; i++) {       Q[X - c[i]].emplace_back(a[i], -1);       Q[X - a[i]].emplace_back(a[i], 1);     }     for (int i = 1; i <= m; i++) {       M[b[i]].push_back(X - d[i] + 1);     }     for (int i = 0; i < X; i++) {       for (int d : M[i]) add(d);       for (auto p : Q[i]) ans += p.second * sum(p.first);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[n], b[n];     long int s = 0;     for (int i = 0; i < n; i++) scanf( %d%d , &a[i], &b[i]);     for (int i = 1; i < n; i++) {       if (b[i] >= b[i - 1]) b[i] = b[i - 1];       s += (a[i] * b[i]);     }     printf( %ld n , s + (a[0] * b[0]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a = 1023, b = 0, n, e;     char op;     cin >> n;     while (n--) {       cin >> op >> e;       if (op ==  | ) {         a |= e;         b |= e;       } else if (op ==  & ) {         a &= e;         b &= e;       } else if (op ==  ^ ) {         a ^= e;         b ^= e;       }     }     int ouxor = 0;     int ou = 0;     int exor = 0;     e = 0;     for (int i = 0; i < 10; i++) {       int num = 1 << i;       if ((a & num) && (b & num))         ou |= num;       else if ((b & num))         exor |= num;       else if (!(a & num) && !(b & num))         ouxor |= num;     }     int count = 0;     count += ouxor ? 2 : 0;     count += ou ? 1 : 0;     count += exor ? 1 : 0;     cout << count << endl;     if (ou) cout <<  |   << ou << endl;     if (ouxor) {       cout <<  |   << ouxor << endl;       cout <<  ^   << ouxor << endl;     }     if (exor) cout <<  ^   << exor << endl;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     int a, b, c, d, k, x, y;     while (t--) {       scanf( %d %d %d %d %d , &a, &b, &c, &d, &k);       if (a % c == 0) {         x = a / c;       } else {         x = a / c + 1;       }       if (b % d == 0) {         y = b / d;       } else {         y = b / d + 1;       }       if (x + y > k) {         printf( -1 n );       } else         printf( %d %d n , k - y, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)1e15 + 696969;   long long n, k;   long long a[1LL << 20], b[1LL << 20];   long long opt[20][1LL << 20];   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     memset(opt, -1, sizeof opt);     cin >> n;     for (long long i = 1; i < n; i <<= 1) k++;     long long ok = false;     for (long long i = 0; i < n; i++) {       long long x;       cin >> x;       if (x == -1)         ok = true;       else if (!ok)         a[i] = 0;       else         a[i - 1] = x;     }     n--;     reverse(a, a + n);     for (long long i = k - 1, j = 0; i > 0; i--) {       j += 1 << i;       b[i] = j;     }     for (long long i = 0; i < n; i++) {       opt[0][i] = a[i];     }     for (long long i = 1; i < k; i++) {       long long mn = INF;       for (long long j = n - 1; j >= 0; j--) {         if (j > b[i])           opt[i][j] = INF;         else {           opt[i][j] = mn + a[j];           mn = min(mn, opt[i - 1][j]);         }       }     }     cout << opt[k - 1][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long x1, y1, z1;       long long x2, y2, z2;       cin >> x1 >> y1 >> z1;       cin >> x2 >> y2 >> z2;       long long sum = 0;       if (z2 > x1) {         z2 -= x1;         if (z2 > z1) {           z2 -= z1;           sum -= (2 * z2);         } else {           z1 -= z2;           sum += 2 * min(z1, y2);         }       } else {         sum += 2 * min(z1, y2);       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int N = 1510;   int DP[27][N][N];   int ans[27][N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     memset(DP, 0, sizeof(DP));     memset(ans, 0, sizeof(ans));     DP[s[0] -  a ][0][0] = 1;     for (int i = (int)1; i < (int)N; i++) DP[s[0] -  a ][0][i] = 1;     for (char ch =  a ; ch <=  z ; ch++) {       if (s[0] == ch) continue;       for (int i = (int)1; i < (int)N; i++) DP[ch -  a ][0][i] = 1;     }     for (int i = (int)1; i < (int)(int)(s.size()); i++) {       for (char ch =  a ; ch <=  z ; ch++) {         if (s[i] == ch) {           int len = 0;           for (int k = i; k >= 0; k--) {             if (s[k] != ch) break;             len++;           }           DP[ch -  a ][i][0] = len;         }         for (int j = (int)1; j < (int)N; j++) {           if (ch == s[i])             DP[ch -  a ][i][j] = 1 + DP[ch -  a ][i - 1][j];           else             DP[ch -  a ][i][j] = 1 + DP[ch -  a ][i - 1][j - 1];         }       }     }     for (char ch =  a ; ch <=  z ; ch++) {       for (int j = 0; j < N; j++) {         for (int i = (int)0; i < (int)(int)(s.size()); i++)           ans[ch -  a ][j] = max(ans[ch -  a ][j], DP[ch -  a ][i][j]);       }     }     int q;     cin >> q;     for (int i = (int)0; i < (int)q; i++) {       int m;       char ch;       cin >> m >> ch;       cout << ans[ch -  a ][m] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   int N, ans, P[100100], ord[100100];   int comp(int a, int b) { return P[a] > P[b]; }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cin >> N;     for (int(i) = 1; (i) <= (N); (i)++) {       cin >> P[i];       ord[i] = i;     }     sort(ord + 1, ord + 1 + N, comp);     cout << ord[1] <<     << P[ord[2]] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int inv = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) {         if (a[i] < a[j]) {           inv++;         }       }     }     inv %= 2;     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       int len = r - l + 1;       int di = (len * (len - 1)) / 2;       inv += di;       inv %= 2;       if (inv == 1) {         cout <<  odd  << endl;       } else {         cout <<  even  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 23;   int parseInt() {     int d;     scanf( %d , &d);     ;     return d;   }   int n;   int a[MAXN], b[MAXN];   vector<pair<int, int> > v;   map<int, int> rang;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       a[i] = parseInt();       v.push_back(make_pair(a[i], i));     }     sort(v.begin(), v.end());     for (int i = 0; i < n; ++i) {       rang[v[i].first] = i;       b[i] = v[i].first;     }     int rng;     for (int i = 0; i < n; ++i) {       rng = rang[a[i]];       rng = (rng + 1) % n;       cout << b[rng] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 10;   int n, a, b;   struct _ {     long long a, b, c;     void pr() { printf( a=%lld,b=%lld n , a, b); }     bool operator<(const _& rhs) const { return c > rhs.c; }   } e[N];   long long ans;   int vis[N];   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 1; i <= n; ++i) {       scanf( %lld%lld , &e[i].a, &e[i].b);       e[i].c = e[i].a - e[i].b;     }     for (int i = 1; i <= n; ++i) ans += e[i].b;     if (!b) return printf( %lld n , ans), 0;     if (b == 1) {       long long t = 0;       for (int i = 1; i <= n; ++i) t = max(t, (e[i].a << a) - e[i].b);       return printf( %lld n , ans + t), 0;     }     sort(e + 1, e + 1 + n);     for (int i = 1; i <= n; ++i)       if (e[i].a > e[i].b) vis[i] = 1;     int cnt = 0;     for (int i = 1; i <= b; ++i)       if (vis[i]) ans += e[i].a - e[i].b, ++cnt;     long long t = 0;     for (int i = 1; i <= b; ++i) {       if (vis[i])         t = max(t, (e[i].a << a) - e[i].a);       else         t = max(t, (e[i].a << a) - e[i].b);     }     long long ret = ans + t;     t = 0;     for (int i = b + 1; i <= n; ++i) t = max(t, (e[i].a << a) - e[i].b);     if (cnt < b)       ret = max(ret, ans + t);     else       ret = max(ret, ans + t - e[b].a + e[b].b);     printf( %lld n , ret);   }


#include <bits/stdc++.h>   using namespace std;   int Length[1001], n, x, a[1001], Concern, Pos, Ppl;   vector<int> Queues, adj[1001], Ans;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> x;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (a[i]) adj[a[i]].push_back(i);     }     for (int i = 1; i <= n; ++i) {       if (a[i] == 0) {         Ppl = i;         int len = 0;         while (Ppl) {           ++len;           if (Ppl == x) Concern = i, Pos = len;           if (adj[Ppl].size())             Ppl = adj[Ppl][0];           else             Ppl = 0;         }         if (Concern != i) Queues.push_back(len);       }     }     for (int i = Queues.size() - 1; i >= 0; --i) {       vector<int> Add;       for (int j = 0; j < Ans.size(); ++j) {         if (!Length[Ans[j] + Queues[i]])           Add.push_back(Ans[j] + Queues[i]), Length[Ans[j] + Queues[i]] = 1;       }       for (int j = 0; j < Add.size(); ++j) Ans.push_back(Add[j]);       if (!Length[Queues[i]]) Ans.push_back(Queues[i]), Length[Queues[i]] = 1;     }     cout << Pos <<   n ;     sort(Ans.begin(), Ans.end());     for (int i = 0; i < Ans.size(); ++i) cout << Pos + Ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Min = -10000000;   int Max = -Min;   int A[8] = {1, 1, 0, 0, 1, 1, 1, 1};   int B[8] = {0, 0, 1, 1, 1, 1, -1, -1};   int C[8];   struct Nodes {     int x, y;   } p[100010];   bool operator<(Nodes &p1, Nodes p2) {     if (p1.x == p2.x) return p1.y < p2.y;     return p1.x < p2.x;   }   long long cross(long long x1, long long y1, long long x2, long long y2) {     return x1 * y2 - y1 * x2;   }   int main() {     int i, j, k;     int n;     long long a, b, c, res;     while (scanf( %d , &n) != EOF) {       for (i = 0; i < 8; i++) {         if (i & 1) {           C[i] = Max;         } else           C[i] = Min;       }       for (i = 1; i <= n; i++) {         scanf( %d%d , &p[i].x, &p[i].y);         C[0] = max(C[0], p[i].x);         C[1] = min(C[1], p[i].x);         C[2] = max(C[2], p[i].y);         C[3] = min(C[3], p[i].y);         C[4] = max(C[4], p[i].x + p[i].y);         C[5] = min(C[5], p[i].x + p[i].y);         C[6] = max(C[6], p[i].x - p[i].y);         C[7] = min(C[7], p[i].x - p[i].y);       }       res = 0;       for (i = 0; i < 8; i++) {         Nodes p1, p2;         p1.x = p1.y = Min;         p2.x = p2.y = Max;         for (j = 0; j < 8; j += 2) {           Nodes tmp[2];           for (k = j; k < j + 2; k++) {             c = cross(A[i], B[i], A[k], B[k]);             a = cross(A[i], C[i], A[k], C[k]);             b = cross(C[i], B[i], C[k], B[k]);             if (c == 0) break;             if (b % c || a % c) break;             tmp[k - j].x = b / c;             tmp[k - j].y = a / c;           }           if (k < j + 2) continue;           if (tmp[1] < tmp[0]) swap(tmp[0], tmp[1]);           if (p1 < tmp[0]) p1 = tmp[0];           if (tmp[1] < p2) p2 = tmp[1];         }         res += max(abs(p2.x - p1.x), abs(p2.y - p1.y));       }       cout << res + 4 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5e4 + 2;   int head[N], grp_edge[N][30], max1[N][30], grp[N], level[N], okfine = 0, sum[N],                                                                dem = 0;   char edge[N];   bool cac = true;   vector<pair<int, char> > adj[N];   vector<int> adj_grp[N];   stack<pair<int, char> > lis;   void dfs(int x) {     int i = 0, j;     if (adj[x].size() == 0) {       if (!okfine) {         okfine = level[x];       }       if (okfine != level[x]) {         cac = false;       }       while (lis.size()) {         i = lis.top().first;         if (lis.top().second !=  ? ) {           grp_edge[x][(int)(lis.top().second -  a  + 1)]++;         }         grp[i] = x;         lis.pop();       }       if (i) {         adj_grp[head[i]].push_back(x);         head[x] = head[i];       }     }     if (adj[x].size() == 1) {       level[adj[x][0].first] = level[x] + 1;       lis.push({adj[x][0].first, edge[adj[x][0].first]});       dfs(adj[x][0].first);     }     if (adj[x].size() == 2) {       while (lis.size()) {         i = lis.top().first;         if (lis.top().second !=  ? ) {           grp_edge[x][(int)(lis.top().second -  a  + 1)]++;         }         grp[i] = x;         lis.pop();       }       if (i) {         adj_grp[head[i]].push_back(x);         head[x] = head[i];       }       level[adj[x][0].first] = level[x] + 1;       lis.push({adj[x][0].first, edge[adj[x][0].first]});       dfs(adj[x][0].first);       level[adj[x][1].first] = level[x] + 1;       lis.push({adj[x][1].first, edge[adj[x][1].first]});       dfs(adj[x][1].first);     }   }   void dfs1(int x) {     int i, j;     for (i = 0; i < adj_grp[x].size(); i++) {       dfs1(adj_grp[x][i]);       for (j = 1; j <= 26; j++) {         max1[x][j] =             max(max1[x][j], max1[adj_grp[x][i]][j] + grp_edge[adj_grp[x][i]][j]);       }     }     for (j = 1; j <= 26; j++) {       sum[x] += max1[x][j];     }     if (sum[x] > okfine - level[x]) {       dem++;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, i, j, k, l, q, ans, ans1;     char x, x1;     cin >> n >> q;     for (i = 2; i <= n; i++) {       cin >> head[i] >> edge[i];       adj[head[i]].push_back({i, edge[i]});     }     dfs(1);     dfs1(1);     head[1] = 0;     for (i = 1; i <= q; i++) {       if (!cac) {         cout <<  Fou n ;         continue;       }       cin >> j >> x;       x1 = edge[j];       if (edge[j] !=  ? ) {         grp_edge[grp[j]][(int)(edge[j] -  a  + 1)]--;       }       edge[j] = x;       if (edge[j] !=  ? ) {         grp_edge[grp[j]][(int)(edge[j] -  a  + 1)]++;       }       k = grp[j];       while (k != 1) {         if (adj_grp[head[k]].size() == 2) {           if (sum[head[k]] > okfine - level[head[k]]) {             if (x1 !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x1 -  a  + 1)];               max1[head[k]][(int)(x1 -  a  + 1)] =                   max(max1[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)] +                           grp_edge[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)],                       max1[adj_grp[head[k]][1]][(int)(x1 -  a  + 1)] +                           grp_edge[adj_grp[head[k]][1]][(int)(x1 -  a  + 1)]);               sum[head[k]] += max1[head[k]][(int)(x1 -  a  + 1)];             }             if (x !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x -  a  + 1)];               max1[head[k]][(int)(x -  a  + 1)] =                   max(max1[adj_grp[head[k]][0]][(int)(x -  a  + 1)] +                           grp_edge[adj_grp[head[k]][0]][(int)(x -  a  + 1)],                       max1[adj_grp[head[k]][1]][(int)(x -  a  + 1)] +                           grp_edge[adj_grp[head[k]][1]][(int)(x -  a  + 1)]);               sum[head[k]] += max1[head[k]][(int)(x -  a  + 1)];             }             if (sum[head[k]] <= okfine - level[head[k]]) {               dem--;             }           } else {             if (x1 !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x1 -  a  + 1)];               max1[head[k]][(int)(x1 -  a  + 1)] =                   max(max1[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)] +                           grp_edge[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)],                       max1[adj_grp[head[k]][1]][(int)(x1 -  a  + 1)] +                           grp_edge[adj_grp[head[k]][1]][(int)(x1 -  a  + 1)]);               sum[head[k]] += max1[head[k]][(int)(x1 -  a  + 1)];             }             if (x !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x -  a  + 1)];               max1[head[k]][(int)(x -  a  + 1)] =                   max(max1[adj_grp[head[k]][0]][(int)(x -  a  + 1)] +                           grp_edge[adj_grp[head[k]][0]][(int)(x -  a  + 1)],                       max1[adj_grp[head[k]][1]][(int)(x -  a  + 1)] +                           grp_edge[adj_grp[head[k]][1]][(int)(x -  a  + 1)]);               sum[head[k]] += max1[head[k]][(int)(x -  a  + 1)];             }             if (sum[head[k]] > okfine - level[head[k]]) {               dem++;             }           }         } else {           if (sum[head[k]] > okfine - level[head[k]]) {             if (x1 !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x1 -  a  + 1)];               max1[head[k]][(int)(x1 -  a  + 1)] =                   max1[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)] +                   grp_edge[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)];               sum[head[k]] += max1[head[k]][(int)(x1 -  a  + 1)];             }             if (x !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x -  a  + 1)];               max1[head[k]][(int)(x -  a  + 1)] =                   max1[adj_grp[head[k]][0]][(int)(x -  a  + 1)] +                   grp_edge[adj_grp[head[k]][0]][(int)(x -  a  + 1)];               sum[head[k]] += max1[head[k]][(int)(x -  a  + 1)];             }             if (sum[head[k]] <= okfine - level[head[k]]) {               dem--;             }           } else {             if (x1 !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x1 -  a  + 1)];               max1[head[k]][(int)(x1 -  a  + 1)] =                   max1[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)] +                   grp_edge[adj_grp[head[k]][0]][(int)(x1 -  a  + 1)];               sum[head[k]] += max1[head[k]][(int)(x1 -  a  + 1)];             }             if (x !=  ? ) {               sum[head[k]] -= max1[head[k]][(int)(x -  a  + 1)];               max1[head[k]][(int)(x -  a  + 1)] =                   max1[adj_grp[head[k]][0]][(int)(x -  a  + 1)] +                   grp_edge[adj_grp[head[k]][0]][(int)(x -  a  + 1)];               sum[head[k]] += max1[head[k]][(int)(x -  a  + 1)];             }             if (sum[head[k]] > okfine - level[head[k]]) {               dem++;             }           }         }         k = head[k];       }       if (dem) {         cout <<  Fou n ;       } else {         ans = 0;         ans1 = 0;         for (j = 1; j <= 26; j++) {           ans += max1[1][j] * j;           ans1 += max1[1][j];         }         cout <<  Shi   << ans + (okfine - ans1) * 27 * 13 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (scanf( %d , &n) == 1) {       string s;       cin >> s;       s =  #  + s;       bool used[n + 1];       memset(used, 0, sizeof used);       int d[n + 1];       for (int i = 1; i <= n; i++) {         scanf( %d , d + i);       }       int pos = 1;       bool ok = false;       while (!used[pos]) {         used[pos] = true;         if (s[pos] ==  < ) {           pos -= d[pos];         } else {           pos += d[pos];         }         if (pos <= 0 || pos > n) {           ok = true;           break;         }       }       if (ok) {         puts( FINITE );       } else {         puts( INFINITE );       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {     _out << _p.first <<     << _p.second;     return _out;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.first >> _p.second;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) {       return _out;     }     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) {       _out <<     << *_it;     }     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) {       _in >> _i;     }     return _in;   }   const long long MAXN = 3604;   const long long MAXM = MAXN / 2;   const long long INF = 1e9;   const long long MOD = 998244353;   long long sum(long long a, long long b) {     if (a + b >= MOD) {       return a + b - MOD;     }     return a + b;   }   long long mul(long long a, long long b) {     if (a * b >= MOD) {       return (a * b) % MOD;     }     return a * b;   }   long long sqr(long long a) { return (a * a) % MOD; }   long long bin_pow(long long a, long long b) {     if (b == 0) {       return 1;     }     if (b % 2) {       return mul(a, bin_pow(a, b - 1));     }     return sqr(bin_pow(a, b / 2));   }   long long fact[MAXN];   long long rfact[MAXN];   long long dp[2][MAXM][MAXN];   bool connected[MAXN];   long long dp1[MAXM];   long long dp2[MAXN][MAXM];   inline long long c(long long n, long long k) {     return mul(fact[n], mul(rfact[k], rfact[n - k]));   }   class FSbalansirovannieRaspolozheniyaDomino {    public:     void solve(std::istream &in, std::ostream &out) {       fact[0] = 1;       for (long long i = 1; i < MAXN; i++) {         fact[i] = mul(i, fact[i - 1]);       }       rfact[MAXN - 1] = bin_pow(fact[MAXN - 1], MOD - 2);       for (long long j = MAXN - 1; j >= 1; j--) {         rfact[j - 1] = mul(rfact[j], j);       }       long long h, w;       in >> h >> w;       long long n;       in >> n;       vector<pair<pair<long long, long long>, pair<long long, long long>>> a(n);       in >> a;       {         for (long long i = 0; i <= h; i++) {           for (long long j = 0; j < MAXM; j++) {             dp2[i][j] = 0;             dp[0][j][i] = 0;           }           connected[i] = 0;         }         for (long long j = 0; j < MAXM; j++) {           dp1[j] = 0;         }         for (auto v : a) {           connected[v.first.first - 1] = 1;           connected[v.second.first - 1] = 1;         }         long long counts = 0;         for (long long j = 0; j < h; j++) {           counts += !connected[j];         }         dp1[0] = 1;         for (long long i = 0; i <= h; i++) {           for (long long j = 0; j < MAXM; j++) {             dp1[j] = sum(dp1[j], dp2[i][j]);           }           if (i + 1 < h && connected[i] == 0 && connected[i + 1] == 0) {             for (long long j = 0; j + 1 < MAXM; j++) {               dp2[i + 2][j + 1] = dp1[j];             }           }         }         for (long long i = 0; i < MAXM; i++) {           for (long long j = 0; j <= counts - 2 * i; j++) {             dp[0][i][j] =                 mul(dp1[i], mul(fact[counts - 2 * i],                                 mul(fact[i], rfact[counts - 2 * i - j])));           }         }       }       {         for (long long i = 0; i <= w; i++) {           for (long long j = 0; j < MAXM; j++) {             dp2[i][j] = 0;             dp[1][j][i] = 0;           }           connected[i] = 0;         }         for (long long j = 0; j < MAXM; j++) {           dp1[j] = 0;         }         for (auto v : a) {           connected[v.first.second - 1] = 1;           connected[v.second.second - 1] = 1;         }         long long counts = 0;         for (long long j = 0; j < w; j++) {           counts += !connected[j];         }         dp1[0] = 1;         for (long long i = 0; i <= w; i++) {           for (long long j = 0; j < MAXM; j++) {             dp1[j] = sum(dp1[j], dp2[i][j]);           }           if (i + 1 < w && connected[i] == 0 && connected[i + 1] == 0) {             for (long long j = 0; j + 1 < MAXM; j++) {               dp2[i + 2][j + 1] = dp1[j];             }           }         }         for (long long i = 0; i < MAXM; i++) {           for (long long j = 0; j <= counts - 2 * i; j++) {             dp[1][i][j] = mul(dp1[i], c(counts - 2 * i, j));           }         }       }       long long ans = 0;       for (long long i = 0; 2 * i <= h; i++) {         for (long long j = 0; 2 * j <= w; j++) {           ans += dp[0][i][j] * dp[1][j][i];           if (ans >= MOD * MOD) {             ans -= MOD * MOD;           }         }       }       ans %= MOD;       out << ans;     }   };   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     FSbalansirovannieRaspolozheniyaDomino solver;     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char _;   int num_rectangles;   pair<pair<int, int>, pair<int, int> > rectangles[135000], pre[135000],       suff[135000];   pair<pair<int, int>, pair<int, int> > intersection(       pair<pair<int, int>, pair<int, int> > first,       pair<pair<int, int>, pair<int, int> > second) {     if (first.first.first == INT_MIN || second.first.first == INT_MIN)       return {{INT_MIN, INT_MIN}, {INT_MIN, INT_MIN}};     int tx = max(first.first.first, second.first.first),         bx = min(first.second.first, second.second.first);     int ty = max(first.first.second, second.first.second),         by = min(first.second.second, second.second.second);     if (bx < tx || by < ty) return {{INT_MIN, INT_MIN}, {INT_MIN, INT_MIN}};     return {{tx, ty}, {bx, by}};   }   int main() {     scanf( %d , &num_rectangles);     for (int i = 0; i < num_rectangles; i++)       scanf(  %d %d %d %d , &rectangles[i].first.first,             &rectangles[i].first.second, &rectangles[i].second.first,             &rectangles[i].second.second);     sort(rectangles, rectangles + num_rectangles);     pre[0] = rectangles[0];     suff[num_rectangles - 1] = rectangles[num_rectangles - 1];     for (int i = 1; i < num_rectangles; i++) {       pre[i] = intersection(pre[i - 1], rectangles[i]);       suff[num_rectangles - i - 1] = intersection(           suff[num_rectangles - i], rectangles[num_rectangles - i - 1]);     }     for (int i = 0; i < num_rectangles; i++) {       if (i == 0) {         if (suff[1].first.first != INT_MIN) {           printf( %d %d n , suff[1].first.first, suff[1].first.second);           return 0;         }       } else if (i == num_rectangles - 1) {         if (pre[num_rectangles - 2].first.first != INT_MIN) {           printf( %d %d n , pre[num_rectangles - 2].first.first,                  pre[num_rectangles - 2].first.second);           return 0;         }       } else {         pair<pair<int, int>, pair<int, int> > first = pre[i - 1],                                               second = suff[i + 1],                                               intersect =                                                   intersection(first, second);         if (intersect.first.first != INT_MIN) {           printf( %d %d n , intersect.first.first, intersect.first.second);           return 0;         }       }     }     if (pre[num_rectangles - 1].first.first != INT_MIN) {       printf( %d %d n , pre[num_rectangles - 1].first.first,              pre[num_rectangles - 1].first.second);       return 0;     }     printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6, maxm = 1e6;   unsigned int degree[maxn + 10], blk[maxn + 10];   namespace find {   unsigned int fa[maxn + 10], siz[maxn + 10];   inline void Init(const unsigned int n) {     iota(fa, fa + n + 1, 0);     fill(siz, siz + n + 1, 1);   }   unsigned int GetFather(const unsigned int x) {     return fa[x] == x ? x : fa[x] = GetFather(fa[x]);   }   inline void Merge(const unsigned int x, const unsigned int y) {     unsigned int fx = GetFather(x), fy = GetFather(y);     if (fx == fy) return;     if (siz[fx] < siz[fy]) swap(fx, fy);     fa[fy] = fx;     siz[fx] += siz[fy];   }   }  // namespace find   int main() {     ios_base::sync_with_stdio(false);     unsigned int n, m;     cin >> n >> m;     find::Init(n);     for (unsigned int i = 0; i < m; ++i) {       unsigned int a, b;       cin >> a >> b;       find::Merge(a, b);       ++degree[a];       ++degree[b];     }     unsigned long long ans = 0;     const unsigned int r = find::GetFather(1);     bool fl = true;     for (unsigned int i = 1; i <= n; ++i) {       if (degree[i] & 0x01) ++blk[find::GetFather(i)];       if (degree[i] && find::GetFather(i) != r) fl = false;     }     if (fl && !blk[r]) {       cout <<  0  << endl;       return 0;     }     for (unsigned int i = 1; i <= n; ++i)       if (find::GetFather(i) == i) {         ans += blk[i] / 2;         if (degree[i] && !blk[i]) ++ans;       }     if (!degree[1] && find::siz[1] == 1 && find::GetFather(1) == 1) ++ans;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int count = 0, count1 = 0;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] >= 97 && s[i] <= 122)         count++;       else         count1++;     }     if (count >= count1) {       for (int i = 0; i < s.size(); i++) {         if (isupper(s[i])) s[i] = s[i] + 32;       }     } else {       for (int i = 0; i < s.size(); i++) {         if (islower(s[i])) s[i] = s[i] - 32;       }     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) int idx,                  __attribute__((unused)) int LINE_NUM) {     cerr << endl;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   int const lmt = 2e5 + 5;   int a[lmt];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       for (long long i = 0; i < n; i++) cin >> a[i];       if (a[0] + a[1] <= a[n - 1]) {         cout << 1 <<    ;         cout << 2 <<    ;         cout << n <<   n ;       } else {         cout << -1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[300005], p[300005], out[300005];   long long f[300005];   bool v[300005];   int n, m, cnt;   void work(int p) {     int t = min(a[p], a[p + 1]);     if (t) out[++m] = p;     a[p] -= t;     a[p + 1] -= t;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       long long O = f[max(i - 2, 0)] + a[i];       long long E = f[max(i - 3, 0)] + max(a[i], a[i - 1]);       f[i] = min(O, E);       v[i] = (f[i] != O);     }     long long ans = min(f[n - 1], f[n]);     for (int i = n - (ans == f[n - 1]); i > 0; i -= 2 + v[i]) p[++cnt] = i;     reverse(p + 1, p + cnt + 1);     for (int i = 1; i <= cnt; i++) {       int pre = p[i - 1], now = p[i];       if (v) work(now - 1);       work(pre + 1);       work(now);     }     printf( %d n , m);     for (int i = 1; i <= m; i++) printf( %d n , out[i]);   }


#include <bits/stdc++.h>   int main() {     int n, mxpos = 0, mx = 0, temp, i;     scanf( %d , &n);     int p[n];     for (i = 0; i < n; i++) {       scanf( %d , &p[i]);       if (mx < p[i]) {         mx = p[i];         mxpos = i;       }     }     int loopno = 0, j;     int notsorted = 1;     while (notsorted) {       notsorted = 0;       for (j = 0; j < n - loopno - 1; j++) {         if (p[j] > p[j + 1]) {           temp = p[j];           p[j] = p[j + 1];           p[j + 1] = temp;           notsorted = 1;         }       }       loopno++;     }     printf( %d %d , mxpos + 1, p[n - 2]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 32000;   const int mod = 1000000007;   const int inf = 2 * mod;   int dp[5001][5001];   pair<long long, long long> hashVal[5001];   pair<long long, long long> powVal[5001];   const long long base1 = 37;   const long long base2 = 2017;   const long long mod1 = 1e9 + 7;   const long long mod2 = 1e9 + 297;   int ans[50001];   string s;   inline int ceil(int p, int q) { return (p + q - 1) / q; }   int call(int l, int r) {     if (l > r) return 0;     if (l == r) return 1;     if (l == r - 1) return (s[l] == s[r] ? 2 : 0);     if (dp[l][r] != -1) return dp[l][r];     int ret;     if (s[l] != s[r] || call(l + 1, r - 1) == 0)       ret = 0;     else       ret = 1 + call(l, ceil(l + r, 2) - 1);     return dp[l][r] = ret;   }   int main() {     cin >> s;     int len = s.length();     memset(dp, -1, sizeof(dp));     for (int i = 0; i < len; i++) {       for (int j = 0; j < len; j++) {         ans[call(i, j)]++;       }     }     for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1];     for (int i = 1; i <= len; i++) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX;   const long long mod = 1e9 + 7;   inline long long power(long long n, long long k, long long mod = INF) {     long long ans = 1;     while (k > 0) {       if (k & 1) ans = (ans * n) % mod;       n = (n * n) % mod;       k >>= 1;     }     return ans;   }   void sum() {     string s;     cin >> s;     long long n = (long long)s.size();     long long pre[n + 1];     long long suf[n + 2];     pre[1] = s[0] -  0 ;     suf[n] = s[n - 1] -  0 ;     suf[n + 1] = 0;     suf[0] = 0;     pre[0] = 0;     long long st = pre[1];     long long en = suf[n];     long long t = 1;     long long ans = 0;     for (long long i = 1; i < n; ++i) {       t = (t * 10) % mod;       st = (st * 10 + s[i] -  0 ) % mod;       pre[i + 1] = (pre[i] % mod + st) % mod;       en = (en + t * (s[n - i - 1] -  0 )) % mod;       suf[n - i] = en;     }     for (long long i = 2; i <= n + 1; ++i) {       long long temp = i - 1;       temp %= mod;       ans += (((pre[i - 2] * t) % mod) + (((temp)*suf[i]) % mod)) % mod;       ans %= mod;       t = ((t % mod) * power(10, mod - 2, mod)) % mod;     }     cout << (ans) % mod <<   n ;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     sum();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000] = {0};   int main() {     int n, m, i, j, k;     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     if (n % 2 == 0) {       cout <<  No  << endl;       return 0;     } else {       if (arr[0] % 2 == 1 && arr[n - 1] % 2 == 1) {         cout <<  Yes  << endl;       } else         cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int pages, readPages[7];     scanf( %d , &pages);     for (int i = 0; i < 7; i++) scanf( %d , &readPages[i]);     int day = 1, i = 0;     while (pages > 0) {       if (day == 8) day = 1;       if (i == 7) i = 0;       pages -= readPages[i];       day++, i++;     }     printf( %d n , day - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 3000 + 50;   const int MAX_D = 15;   struct DP {     int d1;     int d2;     int d3;     int v1;     int v2;     int v3;   };   bool operator<(const DP& l, const DP& r) {     return l.v1 < r.v1 || (l.v1 == r.v1 && l.v2 < r.v2) ||            (l.v1 == r.v1 && l.v2 == r.v2 && l.v3 < r.v3);   }   class SparseTable {    public:     SparseTable(vector<pair<int, int> >& vals) {       N = vals.size();       depths.assign(MAX_N, -1);       table.assign(N, vector<pair<int, int> >(MAX_D));       init();       build(vals);     }     void init() {       for (int i = 1; i < MAX_N; ++i) {         depths[i] = depths[i - 1];         if ((i & (i - 1)) == 0) {           ++depths[i];         }       }     }     void build(vector<pair<int, int> >& vals) {       for (int i = 0; i < N; ++i) {         table[i][0] = vals[i];       }       for (int d = 1; d <= depths[N] + 1; ++d) {         for (int i = 0; i < N; ++i) {           int left = i;           int right = min(N - 1, left + (1 << (d - 1)));           table[i][d] = max(table[left][d - 1], table[right][d - 1]);         }       }     }     pair<int, int> getMax(int left, int right) {       int len = right - left + 1;       int d = depths[len];       return max(table[left][d], table[left + len - (1 << d)][d]);     }       private:     vector<vector<pair<int, int> > > table;     vector<int> depths;     int N = 0;   };   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> vec(n);     vector<pair<int, int> > vec_with_index(n);     for (int i = 0; i < n; ++i) {       cin >> vec[i];       vec_with_index[i].first = vec[i];       vec_with_index[i].second = i;     }     sort(vec_with_index.begin(), vec_with_index.end());     vector<pair<int, int> > vals;     vals.push_back({vec_with_index[0].first, 0});     for (int i = 1; i < vec_with_index.size(); ++i) {       vals.push_back({vec_with_index[i].first - vec_with_index[i - 1].first, i});     }     SparseTable st(vals);     DP ret;     ret.v1 = -1;     ret.v2 = -1;     ret.v3 = -1;     for (int d1 = n - 1; d1 >= 0; --d1) {       for (int d2 = d1 - 1; d2 >= 0; --d2) {         int len1 = n - 1 - d1 + 1;         int len2 = d1 - 1 - d2 + 1;         if (len1 > 2 * len2 || len2 > 2 * len1) {           continue;         }         int min_len3 = max({1, (len1 + 1) / 2, (len2 + 1) / 2});         int max_len3 = min({d2, 2 * len1, 2 * len2});         if (min_len3 > max_len3) {           continue;         }         int min_d3 = d2 - max_len3;         int max_d3 = d2 - min_len3;         pair<int, int> max_val = st.getMax(min_d3, max_d3);         DP temp;         temp.d1 = d1;         temp.d2 = d2;         temp.d3 = max_val.second;         temp.v1 = vec_with_index[d1].first - vec_with_index[d1 - 1].first;         temp.v2 = vec_with_index[d2].first - vec_with_index[d2 - 1].first;         temp.v3 = max_val.first;         if (ret < temp) {           ret = temp;         }       }     }     vector<int> ret_vec(n);     for (int i = 0; i < ret.d3; ++i) {       ret_vec[vec_with_index[i].second] = -1;     }     for (int i = ret.d3; i < ret.d2; ++i) {       ret_vec[vec_with_index[i].second] = 3;     }     for (int i = ret.d2; i < ret.d1; ++i) {       ret_vec[vec_with_index[i].second] = 2;     }     for (int i = ret.d1; i < n; ++i) {       ret_vec[vec_with_index[i].second] = 1;     }     for (auto item : ret_vec) {       cout << item <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     long long l, r;     mutable long long val;     Node(long long l = 0, long long r = 0, long long v = 0)         : l(l), r(r), val(v) {}     bool operator<(const Node& rv) const { return l < rv.l; }   };   long long n, m;   set<Node> t;   long long a[100005];   long long seed;   long long vmax;   long long qpow(long long x, long long p, long long m) {     long long ans = 1;     long long base = x;     while (p) {       if (p & 1) ans = (ans * base) % m;       base = (base * base) % m;       p >>= 1;     }     return ans;   }   long long rnd() {     long long ans = seed;     seed = (seed * 7 + 13) % 1000000007;     return ans;   }   set<Node>::iterator split(long long p) {     set<Node>::iterator it = t.lower_bound(Node(p));     if (it != t.end() && it->l == p) {       return it;     }     --it;     long long l = it->l, r = it->r, val = it->val;     t.erase(it);     t.insert(Node(l, p - 1, val));     return t.insert(Node(p, r, val)).first;   }   void assign(long long l, long long r, long long v) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     t.erase(begin, end);     t.insert(Node(l, r, v));   }   void add(long long l, long long r, long long k) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     for (set<Node>::iterator it = begin; it != end; ++it) {       it->val += k;     }   }   long long kth(long long l, long long r, long long k) {     vector<pair<long long, long long> > v;     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     for (set<Node>::iterator it = begin; it != end; ++it) {       v.push_back(make_pair(it->val, it->r - it->l + 1));     }     sort(v.begin(), v.end());     for (long long i = 0; i < v.size(); ++i) {       k -= v[i].second;       if (k <= 0) return v[i].first;     }     return -1;   }   long long power(long long l, long long r, long long k, long long mod) {     set<Node>::iterator end = split(r + 1);     set<Node>::iterator begin = split(l);     long long ans = 0;     for (set<Node>::iterator it = begin; it != end; ++it) {       ans = (ans +              (((qpow(it->val % mod, k, mod) % mod) * (it->r - it->l + 1 % mod)) %               mod)) %             mod;     }     return ans % mod;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> m >> seed >> vmax;     for (long long i = 1; i <= n; ++i) {       a[i] = (rnd() % vmax) + 1;       t.insert(Node(i, i, a[i]));     }     for (long long i = 1; i <= m; ++i) {       long long opt = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1,                 x, y;       if (l > r) swap(l, r);       if (opt == 3)         x = (rnd() % (r - l + 1)) + 1;       else         x = (rnd() % vmax) + 1;       if (opt == 4) y = (rnd() % vmax) + 1;       if (opt == 1) {         add(l, r, x);       } else if (opt == 2) {         assign(l, r, x);       } else if (opt == 3) {         cout << kth(l, r, x) << endl;       } else {         cout << power(l, r, x, y) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxp = 22;   const long double EPS = 1e-18;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   const int N = 2e5 + 1;   void yesno(bool a) {     if (a) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }   }   long long power(long long x, long long n, long long m) {     if (n == 0) return 1;     long long u = power(x, n / 2, m);     u = (u * u) % m;     if (n % 2) u = (u * x) % m;     return u;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     long long i, arr[n];     for (i = 0; i < n; i++) cin >> arr[i];     if (n == 1) {       cout << 1 <<     << 1 <<   n ;       cout << -arr[0] <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;       cout << 0 <<   n ;       return 0;     }     cout << 1 <<     << n - 1 <<   n ;     for (i = 0; i < n - 1; i++) {       long long num = arr[i] % n;       cout << num * (n - 1) <<    ;       arr[i] += num * (n - 1);     }     cout <<   n ;     cout << n <<     << n <<   n ;     long long num = arr[n - 1] % n;     cout << (n - num) <<   n ;     arr[n - 1] += n - num;     cout << 1 <<     << n <<   n ;     for (i = 0; i < n; i++) cout << -arr[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     char c[n][n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         cin >> c[i][j];       }     }     bool re = 1, ce = 1;     for (long long i = 0; i < n; i++) {       re = 1;       for (long long j = 0; j < n; j++) {         if (c[i][j] !=  E ) {           re = 0;         }       }       if (re == 1) {         break;       }     }     for (long long j = 0; j < n; j++) {       ce = 1;       for (long long i = 0; i < n; i++) {         if (c[i][j] !=  E ) {           ce = 0;         }       }       if (ce == 1) {         break;       }     }     if (re == 1 && ce == 1) {       cout <<  -1 ;       return 0;     }     if (re == 1) {       for (long long j = 0; j < n; j++) {         for (long long i = 0; i < n; i++) {           if (c[i][j] !=  E ) {             cout << i + 1 <<     << j + 1 <<   n ;             break;           }         }       }     } else {       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++) {           if (c[i][j] !=  E ) {             cout << i + 1 <<     << j + 1 <<   n ;             break;           }         }       }     }   }


#include <bits/stdc++.h>   int main() {     int n;     std::string s;     std::cin >> n >> s;     int cnt = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 )         cnt++;       else {         std::cout << cnt;         cnt = 0;       }     }     std::cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[105][105][2];   struct seg {     int a;     long long len;     bool operator<(const seg &p) const { return a < p.a; }   } a[105];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%lld , &a[i].a, &a[i].len);     }     sort(a + 1, a + n + 1);     long long ans = 0;     a[0].a = -2e9;     for (int i = 0; i <= n; ++i)       for (int j = 0; j <= i; ++j) {         for (int k = 0; k <= 1; ++k) {           ans = max(ans, f[i][j][k]);           int pr = a[j].a + k * a[j].len;           int R, x;           for (int p = i + 1, mx = -2e9; p <= n; ++p) {             for (int q = 0; q <= 1; ++q) {               int r = a[p].a + q * a[p].len;               if (r > mx) mx = r, R = p, x = q;               f[p][R][x] =                   max(f[p][R][x],                       f[i][j][k] + min(a[p].len, (long long)r - pr) + (mx - r));             }           }         }       }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   const int maxn = 1e5 + 10, lg = 18;   int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg],                           comp[maxn], c1;   bool dp[maxn][lg];   vector<int> G[maxn];   bool mark[maxn];   void dfs1(int a, int p) {     par[a][0] = p;     for (int i = 1; i < lg; i++) {       par[a][i] = par[par[a][i - 1]][i - 1];     }     low[a] = H[a];     mark[a] = 1;     for (int b : G[a]) {       if (!mark[b]) {         H[b] = H[a] + 1;         comp[b] = comp[a];         dfs1(b, a);         low[a] = min(low[a], low[b]);       } else if (b != p) {         low[a] = min(low[a], H[b]);       }     }   }   void dfs2(int a) {     mark[a] = 1;     for (int b : G[a]) {       if (!mark[b]) {         if (low[b] >= H[a]) {           cid[b] = csize++;         } else {           cid[b] = cid[a];         }         dfs2(b);       } else if (H[a] > H[b]) {         int dis = H[a] - H[b];         if ((dis & 1) == 0) {           ok[cid[a]] = 1;         }       }     }   }   void dfs3(int a) {     mark[a] = 1;     dp[a][0] = (ok[cid[a]]);     for (int b : G[a]) {       if (!mark[b]) {         dfs3(b);       }     }   }   bool lca(int a, int b) {     bool ans = 0;     if (H[a] > H[b]) swap(a, b);     for (int i = lg - 1; i >= 0; i--) {       if (H[par[b][i]] >= H[a]) {         ans |= dp[b][i];         b = par[b][i];       }     }     if (a == b) {       return ans;     }     for (int i = lg - 1; i >= 0; i--) {       if (par[b][i] != par[a][i]) {         ans |= dp[a][i];         ans |= dp[b][i];         a = par[a][i];         b = par[b][i];       }     }     ans |= dp[a][0];     ans |= dp[b][0];     return ans;   }   int32_t main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       G[a].push_back(b);       G[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (!mark[i]) {         comp[i] = c1++;         dfs1(i, i);       }     }     fill(mark, mark + n, 0);     for (int i = 0; i < n; i++) {       if (!mark[i]) {         cid[i] = csize++;         dfs2(i);       }     }     fill(mark, mark + n, 0);     for (int i = 0; i < n; i++) {       if (!mark[i]) {         dfs3(i);       }     }     for (int j = 0; j < lg - 1; j++) {       for (int i = 0; i < n; i++) {         dp[i][j + 1] = dp[i][j] | dp[par[i][j]][j];       }     }     scanf( %d , &q);     while (q--) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       if (H[a] > H[b]) swap(a, b);       if (a == b || comp[a] != comp[b]) {         printf( No n );         continue;       }       if ((H[b] - H[a]) & 1) {         printf( Yes n );         continue;       }       bool ans = lca(a, b);       printf(ans ?  Yes n  :  No n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[n];     int count[5005] = {0};     for (int i = 0; i < n; i++) {       cin >> a[i];       count[a[i]]++;     }     int c[n];     int d = 1;     for (int i = 1; i <= 5000; i++) {       if (count[i] > k) {         cout <<  NO               <<   n ;         return 0;       }     }     cout <<  YES           <<   n ;     if (k == 1) {       for (int i = 0; i < n; i++) {         cout <<  1               <<    ;       }     } else {       for (int i = 1; i <= 5000; i++) {         for (int j = 0; j < n; j++) {           if (a[j] == i) {             c[j] = d;             d++;           }           if (d > k) d = d % k;         }       }       for (int i = 0; i < n; i++) {         cout << c[i] <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const long long int LINF = 1LL * INF * INF;   const int MAXN = 2e5 + 10;   const int MAXM = 5e3 + 10;   priority_queue<int> pq;   vector<vector<int> > graph;   queue<int> que;   pair<int, int> A[20];   long long int dp[20][(1 << 20)];   long long int sum[(1 << 20)];   long long int solve(int here, int cur, int n) {     if (dp[here][cur] != -1) return dp[here][cur];     long long int res = 0;     for (int i = 0; i < n; i++) {       if (i == here) continue;       if ((1 << i) & cur) {         if (A[i].second == A[here].second) continue;         res += solve(i, cur ^ (1 << here), n);         res %= 1000000007;       }     }     return dp[here][cur] = res;   }   int main() {     int n, m, k, a, b, x, y;     int cnt = 0;     int mx = 0;     int mn = INF;     int cur = 0, idx = -1;     int T;     cin >> n >> T;     for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second;     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++) dp[i][j] = -1;     for (int i = 0; i < n; i++) dp[i][(1 << i)] = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < (1 << n); j++) solve(i, j, n);     for (int i = 0; i < (1 << n); i++)       for (int j = 0; j < n; j++)         if ((1 << j) & i) sum[i] += (long long int)A[j].first;     long long int res = 0;     for (int i = 0; i < (1 << n); i++) {       if (sum[i] != T) continue;       for (int j = 0; j < n; j++)         if ((1 << j) & i) {           res += (long long int)dp[j][i];           res %= 1000000007;         }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int q[1000005];   long long i, j, t, tot, C, cnt;   long long loc[10005], op[10005];   long long n, m, k, H, x, y, ans, tmp;   long long a[100005], w[100005], e[25], dis[10005], heap[10005];   bool used[100005], f[10005];   map<long long, long long> A;   map<long long, long long>::iterator it;   void Spfa(long long s) {     long long i, head, tail, x, v;     for (i = 1; i <= k; i++) {       dis[i] = 1999999999999999999LL;       f[i] = false;     }     dis[s + 1] = 1;     f[s + 1] = true;     q[1] = s + 1;     head = 1;     tail = 2;     while (head != tail) {       x = q[head];       f[x] = false;       for (i = 1; i <= tot; i++)         if (dis[x] + e[i] < dis[(dis[x] + e[i]) % k + 1]) {           v = (dis[x] + e[i]) % k + 1;           dis[v] = dis[x] + e[i];           if (!f[v]) {             q[tail] = v;             f[v] = true;             tail++;           }         }       head++;     }   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &H, &n, &m, &k);     for (i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i], &w[i]);     tot = 0;     memset(used, false, sizeof used);     x = 1 % k;     for (i = 1; i <= n; i++) {       if (a[i] % k == x) {         used[i] = true;         it = A.find(w[i]);         if (it == A.end())           A.insert(make_pair(w[i], 1));         else           A[w[i]]++;       }     }     for (t = 1; t <= m; t++) {       scanf( %I64d , &C);       if (C == 1) {         scanf( %I64d , &x);         e[++tot] = x;         Spfa(1 % k);         for (i = 1; i <= n; i++)           if (dis[a[i] % k + 1] <= a[i]) {             if (!used[i]) {               used[i] = true;               it = A.find(w[i]);               if (it == A.end())                 A.insert(make_pair(w[i], 1));               else                 A[w[i]]++;             }           }       } else if (C == 2) {         scanf( %I64d%I64d , &x, &y);         if (used[x]) {           it = A.find(w[x]);           tmp = it->second;           if (tmp == 1)             A.erase(w[x]);           else             A[w[x]]--;           w[x] -= y;           it = A.find(w[x]);           if (it != A.end())             A[w[x]]++;           else             A.insert(make_pair(w[x], 1));         } else           w[x] -= y;       } else {         if (A.size() == 0) {           printf( 0 n );           continue;         }         it = A.end();         it--;         ans = it->first;         printf( %I64d n , ans);         tmp = it->second;         if (tmp == 1)           A.erase(ans);         else           A[ans]--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long arr[100000], arr1[100000], n, x, z, co = 0, co1 = 0, k, m,                                                   fin = 1000000;     map<long long, long long> left;     map<long long, long long> right;     cin >> n;     if (n % 2 == 0)       k = n / 2;     else       k = (n / 2) + 1;     for (int i = 0; i < n; i++) {       cin >> x >> z;       if (x == z) {         if (left[x] == 0) {           arr[co++] = x;           left[x]++;         } else           left[x]++;       } else {         if (left[x] == 0) {           arr[co++] = x;           left[x]++;         } else           left[x]++;         if (right[z] == 0) {           arr1[co1++] = z;           right[z]++;         } else           right[z]++;       }     }     for (int i = 0; i < co; i++) {       m = 1000001;       if ((left[arr[i]] + right[arr[i]]) >= k) {         m = k - left[arr[i]];         if (m < 0) {           cout <<  0 ;           exit(0);         }       }       if (m < fin) {         fin = m;       }     }     if (fin == 1000000) {       for (int i = 0; i < co1; i++) {         if (right[arr1[i]] >= k) {           cout << k;           exit(0);         }       }     }     if (fin == 1000000)       cout <<  -1 ;     else       cout << fin;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N6 = 1e6 + 6;   using namespace std;   long long n, m, x, y, sum1, sum2, ans1, ans2;   int main() {     cin >> n >> x >> y;     if (n > y) {       cout << -1;       return 0;     }     sum1 = y - n + 1;     sum1 *= sum1;     sum1 += (n - 1);     if (sum1 >= x) {       for (int i = 1; i < n; ++i) {         cout << 1 <<    ;       }       cout << y - n + 1;     } else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1050;   int dp[maxn][9], nxt[maxn][9][maxn], a[maxn], n, cnt[9];   inline int ask(int k) { return (1 << (k - 1)); }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= 8; ++j) cnt[j] = 0;       for (int j = 1; j <= 8; ++j)         for (int k = 1; k <= n; ++k) nxt[i][j][k] = 1e9;       for (int j = i; j <= n; ++j) nxt[i][a[j]][++cnt[a[j]]] = j;     }     int ans = 0;     for (int num = 0; num * 8 <= n; ++num) {       for (int i = 0; i < 256; ++i)         for (int k = 0; k <= 8; ++k) dp[i][k] = 1e9;       dp[0][0] = 1;       for (int i = 0; i < 256; ++i)         for (int j = 0; j <= 8; ++j)           for (int k = 1; k <= 8; ++k) {             if (dp[i][j] > n || ask(k) & i) continue;             dp[i ^ ask(k)][j] = min(dp[i ^ ask(k)][j], nxt[dp[i][j]][k][num] + 1);             dp[i ^ ask(k)][j + 1] =                 min(dp[i ^ ask(k)][j + 1], nxt[dp[i][j]][k][num + 1] + 1);           }       for (int i = 0; i <= 8; ++i)         if (dp[255][i] <= n + 1) ans = max(ans, 8 * num + i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using lint = long long;   using ldouble = long double;   void solve() {     int n, d;     std::cin >> n >> d;     std::vector<int> vs(n, 1);     int diff = n * (n - 1) / 2 - d;     if (diff < 0) {       std::cout <<  NO  << std::endl;       return;     }     int head = 1;     for (int v = n - 1; v > head; --v) {       int to = std::max(v - diff, head);       --vs[v];       ++vs[to];       diff -= v - to;       if (diff == 0) break;       while (vs[head] == (1 << head)) ++head;     }     if (diff > 0) {       std::cout <<  NO  << std::endl;       return;     }     std::cout <<  YES  << std::endl;     int p = 1;     for (int i = 1; i < n; ++i) {       int v = p, ch = 0;       for (int j = 0; j < vs[i]; ++j) {         std::cout << v <<    ;         if (++ch == 2) {           ++v;           ch = 0;         }       }       p += vs[i - 1];     }     std::cout << std::endl;   }   int main() {     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::ios::sync_with_stdio(false);     int q;     std::cin >> q;     while (q--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 1e18;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       k++;       long long A[n];       for (long long i = 0; i < n; i++) {         cin >> A[i];         long long t = 1;         while (A[i]--) {           t *= 10;         }         A[i] = t;       }       long long ans = 0;       for (long long i = 0; i < n; i++) {         long long cnt = k;         if (i != n - 1) {           cnt = min(cnt, A[i + 1] / A[i] - 1);         }         ans += A[i] * 1LL * cnt;         k -= cnt;         if (k == 0) break;       }       cout << ans <<   n ;     }   }