#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1000000000;   const long long int mod = 1000000000 + 7;   inline void IO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }   template <class T>   inline int CHECK(T MASK, int i) {     return (MASK >> i) & 1;   }   template <class T>   inline T ON(T MASK, int i) {     return MASK | (T(1) << i);   }   template <class T>   inline T OFF(T MASK, int i) {     return MASK & (~(T(1) << i));   }   template <typename T>   inline int CNT(T MASK) {     if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits)       return __builtin_popcount(MASK);     else       return __builtin_popcountll(MASK);   }   template <class T>   inline int RIGHT(T MASK) {     return log2(MASK & -MASK);   }   int dx4[] = {0, 0, -1, +1};   int dy4[] = {+1, -1, 0, 0};   int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};   int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};   inline void I(int& a) { scanf( %d , &a); }   inline void I(long long int& a) { scanf( %I64d , &a); }   inline void I(unsigned long long int& a) { scanf( %I64u , &a); }   inline void I(char* a) { scanf( %s , a); }   char Iarr[2000010];   inline void I(string& a) {     scanf( %s , Iarr);     a = Iarr;   }   template <typename T, typename... Args>   void I(T& a, Args&... args) {     I(a);     I(args...);   }   inline void OUT(int a) { printf( %d , a); }   inline void OUT(long long int a) { printf( %I64d , a); }   inline void OUT(const char* a) { printf( %s , a); }   inline void OUT(char* a) { printf( %s , a); }   inline void OUT(bool a) { printf( %d , a); }   inline void OUT(string a) {     for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end()));          it != (a.end()) - ((a.begin()) > (a.end()));          it += 1 - 2 * ((a.begin()) > (a.end())))       printf( %c , *it);   }   inline void OUT(unsigned long long int a) { printf( %I64u , a); }   template <typename T, typename... Args>   void OUT(T a, Args... args) {     OUT(a);     OUT(   );     OUT(args...);   }   template <typename... Args>   void O(Args... args) {     OUT(args...);     OUT(  n );   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, pair<T1, T2> p) {     os <<  {  << p.first <<  ,   << p.second <<  } ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& os, vector<T>& a) {     os <<  [ ;     for (int i = 0; i < (int)a.size(); i++) {       if (i) os <<  ,  ;       os << a[i];     }     os <<  ] ;     return os;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cout << *it <<   =   << a << endl;     err(++it, args...);   }   const int M = 1000010;   bool dp[500001];   int main() {     int n, d;     I(n, d);     dp[0] = 1;     for (int i = 0; i < n; i++) {       int x;       I(x);       for (int j = 500000; j >= 0; j--) {         if (dp[j]) {           if (j + x <= 500000) dp[j + x] = 1;         }       }     }     vector<int> v;     for (int i = 0; i <= 500000; i++) {       if (dp[i]) v.push_back(i);     }     int in = 0;     int days = 0;     while (1) {       int low = in + 1, high = (int)v.size() - 1;       if (low > high) break;       while (low < high) {         int mid = (low + high + 1) / 2;         if (v[mid] - v[in] <= d) {           low = mid;         } else {           high = mid - 1;         }       }       if (v[low] - v[in] <= d) {         days++;         in = low;       } else {         break;       }     }     O(v[in], days);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream second(s);     second >> sm;     return sm;   }   int n;   double a[19][19];   double dp[19][(1 << 18) + 10];   int vs[19][(1 << 18) + 10];   int lm;   double Solve(int w, int m) {     if (m == lm) {       if (w == 0) return 1.0;       return 0.0;     }     double &res = dp[w][m];     if (vs[w][m]) return res;     vs[w][m] = 1;     res = 0.0;     for (int i = 0; i < n; i++) {       if ((m & (1 << i)) == 0) {         double aa = a[w][i] * Solve(w, (m | (1 << i)));         aa += a[i][w] * Solve(i, (m | (1 << i)));         res = max(res, aa);       }     }     return res;   }   int main() {     cin >> n;     lm = (1 << n) - 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     if (n == 1) {       printf( 1.00 n );       return 0;     } else if (n == 2) {       printf( %.10lf n , a[0][1]);       return 0;     }     double ans = 0.0;     for (int j = 0; j < n; j++) {       for (int i = j + 1; i < n; i++) {         double aa = a[j][i] * Solve(j, (1 << j) | (1 << i));         aa += a[i][j] * Solve(i, (1 << i) | (1 << j));         ans = max(aa, ans);       }     }     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[100005];   int used[100005];   void bfs(int x) {     queue<int> q;     while (!q.empty()) q.pop();     q.push(x);     used[x] = 1;     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < e[p].size(); i++) {         if (e[p][i]) {           if (!used[e[p][i]]) {             if (used[p] == 1)               used[e[p][i]] = 2;             else               used[e[p][i]] = 1;             q.push(e[p][i]);           }         }       }     }   }   int main() {     int n, x, y;     while (~scanf( %d , &n)) {       for (int i = 0; i < n - 1; i++) {         scanf( %d%d , &x, &y);         e[x].push_back(y);         e[y].push_back(x);       }       memset(used, 0, sizeof(used));       bfs(1);       long long ans1 = 0, ans2 = 0;       for (int i = 1; i <= n; i++) {         if (used[i] == 1)           ans1++;         else           ans2++;       }       printf( %I64d n , ans2 * ans1 - (n - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a + b <= max(c, d))       cout <<  Polycarp ;     else if (a <= c && b <= d)       cout <<  Polycarp ;     else       cout <<  Vasiliy ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     int a[105];     scanf( %d , &n);     int B, C;     B = 0;     C = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] < 0)         C += a[i];       else         B += a[i];     }     printf( %d n , B - C);   }


#include <bits/stdc++.h>   using namespace std;   int s[1005];   int main() {     int n, m, h;     scanf( %d%d%d , &n, &m, &h);     int sum = 0;     for (int i = 1; i <= m; i++) {       scanf( %d , &s[i]);       sum += s[i];     }     if (sum < n) {       printf( -1 n );       return 0;     }     long double ans = 1;     long double down = sum - 1;     long double up = sum - s[h];     for (int i = 1; i <= n - 1; i++) {       ans = ans * up / down;       up--, down--;     }     printf( %.20Lf n , 1 - ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> h(n + 5);     vector<long long> deg(n + 5, 0), a(n + 5, 0);     for (long long i = 1; i <= n; i++) cin >> h[i];     for (long long i = 1; i <= n; i++) cin >> a[i], deg[a[i]]++;     long long c = -1;     long long maxi = 0;     for (long long i = 1; i <= n; i++) {       if (h[i] == 1) {         long long x = a[i];         long long cnt = 1;         while (x > 0 && deg[x] == 1) cnt++, x = a[x];         if (cnt > maxi) {           maxi = cnt;           c = i;         }       }     }     vector<long long> temp;     temp.push_back(c);     c = a[c];     while (c > 0 && deg[c] == 1) temp.push_back(c), c = a[c];     long long l = (long long)temp.size();     cout << l <<   n ;     for (long long i = l - 1; i >= 0; i--) cout << temp[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int mxs = 2e5 + 7;   int n;   int a[mxs];   int l[mxs];   int r[mxs];   int ans[mxs];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = n; i; i--) {       l[i] = i;       while (a[i] <= a[l[i] + 1]) l[i] = l[l[i] + 1];     }     for (int i = 1; i <= n; i++) {       r[i] = i;       while (a[i] <= a[r[i] - 1]) r[i] = r[r[i] - 1];     }     for (int i = 1; i <= n; i++) {       int res = l[i] - r[i] + 1;       ans[res] = max(ans[res], a[i]);     }     for (int i = n; i; i--) ans[i] = max(ans[i], ans[i + 1]);     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:64000000 )   const int maxn = 200200;   const int inf = 1000000007;   const int mod = 1000000007;   const int dx[4] = {1, -1, 0, 0};   const int dy[4] = {0, 0, 1, -1};   double pr[maxn];   double pw(double x, int k) {     if (k == 1) return x;     double ans = pw(x, k / 2);     ans = ans * ans;     if (k % 2 == 1) ans = ans * x;     return ans;   }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) == 2) {       pr[n + 1] = 0;       double ans = 0;       for (int i = n; i >= 1; i--) {         pr[i] = 1 - pw((double)(i - 1) / n, m);         ans += i * (pr[i] - pr[i + 1]);       }       printf( %.10lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> nums;   int mod[100];   char in[1000010];   int cnt[100];   int main() {     int i, j, k;     nums.push_back(1);     nums.push_back(6);     nums.push_back(8);     nums.push_back(9);     sort(nums.begin(), nums.end());     do {       int sum = 0;       for (i = 0; i < 4; i++) {         sum *= 10;         sum += nums[i];       }       mod[sum % 7] = sum;     } while (next_permutation(nums.begin(), nums.end()));     int ok = 1;     int n;     scanf( %s , in);     n = strlen(in);     for (i = 0; i < n; i++) {       cnt[in[i] -  0 ]++;     }     for (i = 0; i < 4; i++) {       cnt[nums[i]]--;     }     int now = 0;     for (i = 9; i >= 1; i--) {       while (cnt[i]--) {         now *= 10;         now += i;         now %= 7;         printf( %d , i);       }     }     now *= 10000;     now %= 7;     printf( %d , mod[(7 - now) % 7]);     while (cnt[i]--) {       printf( %d , i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   const long long mod = 998244353;   long long a[N];   long long n, m, k;   long long pw(long long n, long long k) {     if (!k) return 1;     long long res = pw(n, k >> 1);     res = res * res % mod;     if (k & 1) return res * n % mod;     return res;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (long long i = 1; i <= m; i++) {       cin >> a[i];     }     long long ans = 1;     for (long long i = 1; i <= m; i++) {       long long num = a[i] - a[i - 1];       (ans *= pw(k, 2 * num) + pw(k, num)) %= mod;       if (ans < 0) ans += mod;     }     (ans *= pw(k, n - 2 * a[m])) %= mod;     (ans *= pw(pw(2, m), mod - 2)) %= mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       long long c = a ^ b;       a = a & c;       b = b & c;       cout << a + b <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> a;   int n, j;   string s;   map<long long, int> f;   long long h(string s) {     long long res = 0;     for (int i = 0; i < s.length(); i++) res = res * 28 + (s[i] -  a ) + 1;     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       cin >> s;       a.push_back(s);     }     long long j;     for (int i = n - 1; i >= 0; i--) {       j = h(a[i]);       f[j]++;       if (f[j] == 1) cout << a[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.emplace_back(x);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ;     err(++it, args...);   }   template <typename T>   struct number_iterator : std::iterator<random_access_iterator_tag, T> {     T v;     number_iterator(T _v) : v(_v) {}     operator T&() { return v; }     T operator*() const { return v; }   };   template <typename T>   struct number_range {     T b, e;     number_range(T b, T e) : b(b), e(e) {}     number_iterator<T> begin() { return b; }     number_iterator<T> end() { return e; }   };   template <typename T>   number_range<T> range(T e) {     return number_range<T>(1, e + 1);   }   template <typename T>   number_range<T> range(T b, T e) {     return number_range<T>(b, e + 1);   }   long long c(long long len, long long b) {     long long base = 1, tot = 0;     for (int i = (1); i <= (len); i++) {       if (i != b) tot += base;       base *= 2;     }     return tot;   }   long long f(long long d) {     if (d <= 1) return 0;     long long res = 0;     for (int i = (1); i <= (60); i++) {       for (int j = (1); j <= (i - 1); j++) {         if (c(i, j) <= d) res++;       }     }     return res;   }   int main() {     long long a, b;     cin >> a >> b;     long long ff = f(b) - f(a - 1);     cout << ff << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ilter {     int job;     long long ti;     bool operator<(const ilter &a) const { return a.ti > ti; }   } T[100001];   int s, c;   long long TIME;   int main() {     map<int, int> M2;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> T[i].job;       M2[T[i].job]++;     }     for (int i = 0; i < n; i++) {       cin >> T[i].ti;       ;     }     s = k - M2.size();     if (s == 0)       return cout << 0, 0;     else {       sort(T, T + n);       for (int i = 0; i < n; i++) {         if (M2[T[i].job] > 1) {           TIME += T[i].ti;           M2[T[i].job]--;           c++;         }         if (c == s) break;       }       cout << TIME;     }     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-9;   const int MAX_REPS = 2000;   double bx, by, h, r;   void solve(double x, double& y1, double& y2, double& y3) {     double A1, A2, B1, B2, C1, C2, dy1, dy2, dx, dy;     dx = -(x - bx);     dy = ((h - r) - by);     A1 = -dy;     B1 = dx;     C1 = A1 * x + B1 * (h - r);     y1 = C1 / B1;     A2 = -B1;     B2 = A1;     C2 = B2 * y1;     dy1 = ((C1 - A1) / B1) - (C1 / B1);     dy2 = ((C2 - A2) / B2) - (C2 / B2);     assert(dy1 > 0);     assert(dy2 < 0);     A1 = dy1 - dy2;     B1 = sqrt(1 + dy2 * dy2);     y2 = y1 + A1 / B1 * (B1 + r) - A1;     y3 = y1 + A1 / B1 * (B1 - r) - A1;   }   int main(void) {     int i;     double yl, yh, frl, tol, frh, toh, mi, bc, bh, bl;     std::cin >> yl >> yh >> h >> bx >> by >> r;     frh = 0;     toh = bx - r / 2;     for (i = 0; i < MAX_REPS && fabs(frh - toh) >= EPS; ++i) {       mi = (frh + toh) / 2;       solve(mi, bc, bh, bl);       if (bh >= yh) {         frh = mi;       } else {         toh = mi;       }     }     frl = 0;     tol = bx - r / 2;     for (i = 0; i < MAX_REPS && fabs(frl - tol) >= EPS; ++i) {       mi = (frl + tol) / 2;       solve(mi, bc, bh, bl);       if (bc - r <= yl) {         tol = mi;       } else {         frl = mi;       }     }     mi = (frl + frh) / 2;     solve(mi, bc, bh, bl);     if (bc - r < yl || bh > yh) {       std::cout <<  -1  << std::endl;     } else {       std::cout << (frl + frh) / 2 << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 * 2 + 10;   long long int a[MAXN];   long long int b[MAXN];   long long int p[MAXN];   long long int d[MAXN];   long long int mod = 1000 * 1000 * 1000 + 7;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, c;     cin >> n >> c;     for (int i = 0; i < n - 1; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> b[i];     }     cout << 0 <<    ;     for (int i = 0; i < n - 1; i++) {       if (i == 0) {         d[i] = c + b[i];         p[i] = a[i];       } else {         d[i] = min(d[i - 1] + b[i], p[i - 1] + b[i] + c);         p[i] = min(p[i - 1] + a[i], d[i - 1] + a[i]);       }       cout << min(d[i], p[i]) <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[1000005], n, m;   long long f[5005][5005], g[2][5005], fa[5005], fac[5005], p, sum;   inline int read() {     int ret = 0;     char fa = getchar();     while (!isdigit(fa)) fa = getchar();     while (isdigit(fa)) {       ret = (ret << 1) + (ret << 3) + fa -  0 ;       fa = getchar();     }     return ret;   }   inline void Aireen() {     n = read();     m = read();     p = (long long)(read());     for (int i = 1; i <= n; ++i) l[i] = read();     fa[0] = fac[0] = 1ll;     for (int i = 1, j = m; i < 5005 && j; ++i, --j) {       fa[i] = fa[i - 1] * (long long)(i) % p;       fac[i] = fac[i - 1] * (long long)(j) % p;     }     f[0][0] = 1ll;     for (int i = 1; i < 5005; ++i)       for (int j = min(m, i); j; --j)         f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] * (long long)(j - 1) % p) % p;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= l[i + 1]; ++j) g[i & 1][j] = 0ll;       if (i == 1) {         for (int j = min(l[i], m); j; --j) g[i][j] = fac[j] * f[l[i]][j] % p;       } else {         sum = 0ll;         for (int j = min(l[i - 1], m); j; --j) sum = (sum + g[i & 1 ^ 1][j]) % p;         for (int j = min(l[i], m); j; --j) {           g[i & 1][j] = (fac[j] * sum % p - fa[j] * g[i & 1 ^ 1][j] % p + p) % p *                         f[l[i]][j] % p;         }       }     }     sum = 0ll;     for (int j = min(l[n], m); j; --j) sum = (sum + g[n & 1][j]) % p;     cout << sum << endl;   }   int main() {     Aireen();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e % 2)       return ((b * power((b) * (b), (e - 1) / 2)));     else       return power((b) * (b), e / 2);   }   long long modpower(long long b, long long e, long long q) {     long long MOD = q;     if (e == 0) return 1;     if (e % 2)       return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;     else       return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;   }   void dpv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   void dpv(vector<pair<long long, long long> > v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }   }   void dpv(set<long long> v) {     for (auto i : v) {       cout << i <<    ;     }     cout << endl;   }   long long dp[31][31][51];   long long f(long long a, long long b, long long c) {     if (dp[a][b][c] || a * b == c || !c) {       return dp[a][b][c];     }     long long ans = 1e18;     for (long long i = 1; i <= a - i; i++) {       for (long long j = 0; j <= c; j++) {         ans = min(ans, b * b + f(a - i, b, j) + f(i, b, c - j));       }     }     for (long long i = 1; i <= b - i; i++) {       for (long long j = 0; j <= c; j++) {         ans = min(ans, a * a + f(a, i, j) + f(a, b - i, c - j));       }     }     return dp[a][b][c] = ans;   }   void oblivious() {     long long a, b, c;     cin >> a >> b >> c;     cout << f(a, b, c) << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, 0, sizeof(dp));     long long t = 1;     cin >> t;     while (t--) {       oblivious();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     cin >> n >> k;     string s;     cin >> s;     unordered_map<char, int> m;     char last = s[0];     int streak = 1;     int cur_max = 0;     if (k == 1) {       cur_max = 1;       m[last] = 1;       streak = 0;     }     for (int i = 1; i < s.size(); i++) {       if (s[i] == last) {         streak++;       } else {         streak = 1;       }       if (streak == k) {         streak = 0;         if (m.find(s[i]) == m.end()) {           m[s[i]] = 1;         } else {           m[s[i]]++;         }         cur_max = m[s[i]] > cur_max ? m[s[i]] : cur_max;       }       last = s[i];     }     cout << cur_max << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename TT>   ostream &operator<<(ostream &s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &s, vector<T> t) {     s <<  { ;     for (int i = 0; i < t.size(); i++)       s << t[i] << (i == t.size() - 1 ?    :  , );     return s <<  }  << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m, a1, b1, a2, b2;     cin >> n >> m >> a1 >> b1 >> a2 >> b2;     if (abs(a1 - a2) + abs(b1 - b2) <= 4)       cout <<  First ;     else if (abs(a1 - a2) + abs(b1 - b2) == 5 &&              min(abs(a1 - a2), abs(b1 - b2)) >= 1)       cout <<  First ;     else if (abs(a1 - a2) + abs(b1 - b2) == 6 &&              min(abs(a1 - a2), abs(b1 - b2)) >= 2)       cout <<  First ;     else       cout <<  Second ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int maxn = 100010;   static const int INF = 0x3f3f3f3f;   static const int mod = (int)1e9 + 7;   static const double eps = 1e-6;   static const double pi = acos(-1);   void redirect() {}   char s[maxn];   int cnt[26];   int main() {     redirect();     int T;     scanf( %d , &T);     while (T--) {       memset(cnt, 0, sizeof(cnt));       scanf( %s , s);       for (int i = 0; s[i]; i++) cnt[s[i] -  a ]++;       bool flag = true;       for (int i = 0; i < 26; i++)         if (cnt[i] > 1) flag = false;       int i = 0;       while (i < 26 && cnt[i] == 0) i++;       while (i < 26 && cnt[i] == 1) i++;       for (; i < 26; i++)         if (cnt[i]) flag = false;       if (flag)         puts( Yes );       else         puts( No );     }     return 0;   }


/*   Problem :    Algorithm :    Status :    */   #include<bits/stdc++.h>   #include<iostream>   #include<cstring>   #include<cstdio>   #include<algorithm>   #include<cstdlib>   #define DEBUG cerr <<  Passing Line   << __LINE__<<   in Function [  << __FUNCTION__ <<  ]. n ;   using namespace std;   typedef long long ll;   typedef pair<int,int> pii;   template<class T> inline bool checkMax(T &a,const T &b) {return a < b ? a = b,1 : 0;}   template<typename T, typename...Args> inline void checkMax(T &a,const Args...arg) {checkMax(a,max(arg...));}   template<class T> inline bool checkMin(T &a,const T &b) {return a > b ? a = b,1 : 0;}   template<typename T, typename...Args> inline void checkMin(T &a,const Args...arg) {checkMin(a,min(arg...));}      namespace FastIO{       const int SIZE = 1 << 21;       char ch;       char in[SIZE],*inS = in,*inT = in + SIZE;       char out[SIZE],*outS = out,*outT = out + SIZE;          #define flush() fwrite(out,1,outS - out,stdout), outS = out       #define getchar() (inS == inT && (inT = (inS = in) + fread(in,1,SIZE,stdin),inS == inT) ? EOF : *inS++)       void putchar(char c) {*outS++ = c; if(outS == outT) flush();}          struct Flusher {~Flusher() {flush();}} flusher;          template<typename T> inline void read(T &x){           static int f; x = 0; f = 1; ch = getchar();           while(!isdigit(ch)) {if(ch ==  - ) f = -1; ch = getchar();}           while(isdigit(ch)) {x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar();} x *= f;       }          inline void read(char* s){           static int len; len = 0; ch = getchar();           while(ch ==   n  || ch ==     || ch ==   0 ) ch = getchar();           while(ch !=   n  && ch !=     && ch != EOF) s[len++] = ch, ch = getchar(); s[len] =   0 ;       }              template<typename T> inline void write(T x){           if(!x) putchar( 0 );           if(x < 0) {x = -x; putchar( - );}           static int sta[20]; int tot = 0;           while(x) {sta[tot++] = x % 10; x /= 10;}           while(tot) putchar(sta[--tot] + 48);       }          inline void write(char c) {putchar(c);}       template<typename T> inline void writeln(T c) {write(c); putchar(  n );}          template<typename T,typename... Args> inline void read(T &t, Args &...args) {read(t); read(args...);}   }      using FastIO::read;   using FastIO::write;   using FastIO::writeln;      const int INF = 0x3f3f3f3f;   const ll llINF = 1e18;   const int MAXN = 6e4 + 5;   const int MAXC = 5;      int n,C,Q,T;   int cnt[MAXC][MAXN],p[MAXN];   ll comb[MAXN][MAXC],w[MAXC][MAXN * MAXC];      struct Node{       int l,r; ll w;       Node(int _l = 0,int _r = 0,ll _w = 0) : l(_l), r(_r), w(_w) {}   };      struct Deque{       int head,tail;       Node a[MAXN * MAXC * 2 + 100];          Node& operator [] (const int &i) {return a[head + i - 1];}          void push_front(Node u) {a[--head] = u; assert(head >= 1);}       void push_back(Node u) {a[++tail] = u; assert(tail < MAXN * MAXC * 2 + 100);}       void clear() {head = MAXN * MAXC + 5, tail = MAXN * MAXC + 4;}       int size() {return tail - head + 1;}       Deque() {clear();}   } q[MAXC];      void Init(int n){       comb[0][0] = 1;       for(int i = 1;i <= n;i++){           comb[i][0] = 1;           for(int j = 1;j <= min(MAXC - 1,i);j++)               comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];       }       for(int i = 0;i <= n;i++){           for(int j = 1;j < MAXC;j++) comb[i][j] += comb[i][j - 1];       }   }      ll calc(int n,int c){       if(n <= 0) return 1;       assert(n < MAXN);       return comb[n - 1][c];   }      bool cmp(const Node &x,const Node &y){       return p[x.r] < p[y.r];   }      Node GetNxt(int c,int pos,ll rk){       int num = cnt[c][pos];       int l = num + 1, r = q[c].size(), res = 0;       while(l <= r){           int mid = (l + r) >> 1;           if(w[c][mid] - w[c][num] >= rk) res = mid, r = mid - 1;           else l = mid + 1;       }       assert(res >= 1 && res <= q[c].size());       return Node(q[c][res].l,q[c][res].r,w[c][res - 1] - w[c][num]);   }      void Solve(){       read(n,C,Q);       for(int i = 1;i <= n;i++) read(p[i]);       for(int c = 1;c <= C;c++){           q[c].clear(); vector<Node> front,back;            for(int i = 1;i <= n;i++) cnt[c][i] = 0;           q[c].push_back(Node(n,n,1));           for(int i = n - 1;i >= 1;i--){               front.clear(); back.clear();               for(int j = 1;j <= min(c,n - i);j++){                   if(p[i + j] < p[i])                       front.emplace_back(i,i + j,calc(n - i - j,c - j)), cnt[c][i + 1] += 1;                   else back.emplace_back(i,i + j,calc(n - i - j,c - j));               }               sort(front.begin(),front.end(),cmp); reverse(front.begin(),front.end());               sort(back.begin(),back.end(),cmp);               for(auto x : front) q[c].push_front(x);               for(auto x : back) q[c].push_back(x);           }           for(int i = 1;i <= n;i++) cnt[c][i] += cnt[c][i - 1];           assert(q[c].size() <= MAXN * MAXC + 5);           for(int i = 1, sz = q[c].size();i <= sz;i++)               w[c][i] = w[c][i - 1] + q[c][i].w;       }       while(Q--){           int pos; ll rk; read(pos,rk);           if(rk > calc(n,C)) {writeln(-1); continue;}           int x = 1, c = C; vector<pii> vec; vec.clear();           while(c && x <= n){               Node res = GetNxt(c,x,rk);               assert(res.w < rk);               rk -= res.w; c -= (res.r - res.l); x = res.r + 1;               vec.emplace_back(res.l,res.r);           }           int flag = 0;           for(auto pi : vec){               if(pos >= pi.first && pos <= pi.second){                   writeln(p[pi.second - pos + pi.first]);                   flag = 1; break;               }           }           if(!flag) writeln(p[pos]);       }   }      int main(){   //    freopen( data.in , r ,stdin);   //    freopen( data.out , w ,stdout);       Init(MAXN - 1); read(T); while(T--) Solve();       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   struct MCMF {     enum { MAXN = 6500 };     struct Edge {       int x, y;       int cap, cost;     };     vector<Edge> E;     vector<int> adj[MAXN];     int N, prev[MAXN];     int dist[MAXN], phi[MAXN];     MCMF(int NN) : N(NN) {}     void add(int x, int y, int cap, int cost) {       Edge e1 = {x, y, cap, cost}, e2 = {y, x, 0, -cost};       adj[e1.x].push_back(E.size());       E.push_back(e1);       adj[e2.x].push_back(E.size());       E.push_back(e2);     }     vector<queue<int> > Q;     void mcmf(int s, int t, int &flowVal, int &flowCost) {       int x;       flowVal = flowCost = 0;       memset(phi, 0, sizeof(phi));       Q.resize(6500);       while (true) {         for (x = 0; x < N; x++) prev[x] = -1;         for (x = 0; x < N; x++) dist[x] = 1000000000;         dist[s] = prev[s] = 0;         Q[dist[s]].push(s);         for (int i = 0; i < 6400; i++) {           while (!Q[i].empty()) {             x = Q[i].front();             Q[i].pop();             if (dist[x] < i) continue;             vector<int>::iterator it;             for (it = adj[x].begin(); it != adj[x].end(); it++) {               const Edge &e = E[*it];               if (e.cap <= 0) continue;               int cc = e.cost + phi[x] - phi[e.y];               if (dist[x] + cc < dist[e.y]) {                 dist[e.y] = dist[x] + cc;                 prev[e.y] = *it;                 Q[dist[e.y]].push(e.y);               }             }           }         }         if (prev[t] == -1) break;         int z = 1000000000;         for (x = t; x != s; x = E[prev[x]].x) z = min(z, E[prev[x]].cap);         for (x = t; x != s; x = E[prev[x]].x) {           E[prev[x]].cap -= z;           E[prev[x] ^ 1].cap += z;         }         flowVal += z;         flowCost += z * (dist[t] - phi[s] + phi[t]);         for (x = 0; x < N; x++)           if (prev[x] != -1) phi[x] += dist[x];       }     }   } * mc;   int a[90][90];   int main() {     int i, j, k, n, m;     scanf( %d %d , &n, &m);     mc = new MCMF(n * m + 10);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> a[i][j];     int src = n * m + 1;     int dest = n * m + 2;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if ((i + j) % 2 == 0)           mc->add(src, i * m + j, 1, 0);         else {           mc->add(i * m + j, dest, 1, 0);           continue;         }         for (k = 0; k < 4; k++) {           int ni = i + dx[k];           int nj = j + dy[k];           if (ni < n && nj < m && ni >= 0 && nj >= 0) {             mc->add(i * m + j, ni * m + nj, 1, a[i][j] != a[ni][nj]);           }         }       }     }     int fval, fcost;     mc->mcmf(src, dest, fval, fcost);     cout << fcost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   const int mod = 1e9 + 7;   int dp1[N][N], dp2[N][N], a[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       memset(dp1, 0, sizeof(dp1));       memset(dp2, 0, sizeof(dp2));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dp1[i][j] = dp1[i - 1][j];         }         dp1[i][a[i]]++;       }       for (int i = n; i >= 1; i--) {         for (int j = 1; j <= n; j++) {           dp2[i][j] = dp2[i + 1][j];         }         dp2[i][a[i]]++;       }       long long ans = 0;       for (int i = 2; i <= n; i++) {         for (int j = i + 1; j < n; j++) {           ans += dp1[i - 1][a[j]] * dp2[j + 1][a[i]];         }       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::cin.tie(0);     std::ios::sync_with_stdio(false);     long long n;     cin >> n;     if (n <= 5) {       cout << -1 << endl;     } else {       cout << 1 <<     << 2 << endl;       for (int i = 3; i <= n; i++) {         if (i % 2)           cout << 1 <<     << i << endl;         else           cout << 2 <<     << i << endl;       }     }     for (int i = 2; i <= n; i++) cout << 1 <<     << i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 3e3 + 3;   const int second = 200;   struct Node {     static Node mem[maxn + 514], *pmem;     int dep;     Node *fail, *to[2];     int who;     Node() : dep(-1), fail(0), to{NULL, NULL}, who(-1) {}     Node(int _d, int _w) : dep(_d), fail(0), to{NULL, NULL}, who(_w) {}   } Node::mem[maxn + 514], *Node::pmem = Node::mem;   int pos[maxn];   struct AC {     AC() { root = new (Node::pmem++) Node(-1, -1); }     Node *root;     void add(const string &s, int id) {       Node *pt = root;       for (int i = 0; i < int(((int)(s).size())); i++) {         if (!pt->to[s[i] -  a ])           pt->to[s[i] -  a ] = new (Node::pmem++) Node(1 + pt->dep, -1);         pt = pt->to[s[i] -  a ];       }       pt->who = id;       pos[id] = pt - Node::mem;     }     void build() {       queue<Node *> q;       q.push(root);       root->fail = root;       while (((int)(q).size())) {         Node *pt = q.front();         q.pop();         for (int i = 0; i < int(2); i++)           if (pt->to[i]) q.push(pt->to[i]);         if (pt->dep == -1) {           for (int i = 0; i < int(2); i++)             if (pt->to[i]) pt->to[i]->fail = root;           for (int i = 0; i < int(2); i++)             if (!pt->to[i]) pt->to[i] = root;         } else {           for (int i = 0; i < int(2); i++)             if (pt->to[i]) {               Node *&cur = pt->to[i]->fail;               for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail)                 ;               if (cur->to[i]) cur = cur->to[i];             }           for (int i = 0; i < int(2); i++)             if (!pt->to[i]) {               Node *&cur = pt->to[i];               for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail)                 ;               if (cur->to[i]) cur = cur->to[i];             }         }       }     }   } ac;   int n, m;   string s[maxn];   void read() {     RI(n, m);     for (int i = 0; i < int(m); i++) {       static char in[maxn];       RI(in);       s[i] = in;     }   }   const int MOD = 1e9 + 7;   string os[maxn];   int sig;   int f[maxn][maxn];   int _c[2][maxn][maxn / second + 1];   int (*prv)[maxn / second + 1], (*cur)[maxn / second + 1];   int big;   int om;   void build() {     om = m;     for (int i = 0; i < int(m); i++) os[i] = s[i];     sort(s, s + m);     m = unique(s, s + m) - s;     sort(s, s + m, [&](const string &a, const string &b) {       return make_pair(((int)(a).size()), a) > make_pair(((int)(b).size()), b);     });     for (big = 0; big < m && ((int)(s[big]).size()) > second; big++)       ;     for (int i = 0; i < int(m); i++) ac.add(s[i], i);     ac.build();     sig = Node::pmem - Node::mem;   }   int ans[maxn];   void sol_big() {     for (int i = 0; i < int(sig); i++) f[1][i] = Node::mem[i].to[0] - Node::mem;     for (int i = 0; i < int(sig); i++) f[2][i] = Node::mem[i].to[1] - Node::mem;     for (int i = (3); i <= int(n); i++)       for (int j = 0; j < int(sig); j++) f[i][j] = f[i - 2][f[i - 1][j]];     prv = _c[0];     cur = _c[1];     for (int i = 0; i < int(sig); i++)       for (int j = 0; j < int(big); j++) {         Node *pt = Node::mem + i;         for (pt = pt->to[0]; pt->who != j && pt->dep != -1; pt = pt->fail)           ;         prv[i][j] = (pt->who == j);       }     for (int i = 0; i < int(sig); i++)       for (int j = 0; j < int(big); j++) {         Node *pt = Node::mem + i;         for (pt = pt->to[1]; pt->who != j && pt->dep != -1; pt = pt->fail)           ;         cur[i][j] = (pt->who == j);       }     for (int _ = (3); _ <= int(n); _++) {       static int tmp[maxn][maxn / second + 1];       auto &m1 = cur, &m2 = prv;       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++)           tmp[i][j] = m1[i][j] + m2[f[_ - 1][i]][j];       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++)           if (tmp[i][j] >= MOD) tmp[i][j] -= MOD;       swap(prv, cur);       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++) cur[i][j] = tmp[i][j];     }     for (int i = 0; i < int(big); i++) ans[i] = cur[0][i];   }   string h[maxn], t[maxn];   int ap[maxn][maxn];   void merge(const string &p, const string &q, int res[]) {     for (int i = 0; i < int(((int)(p).size())); i++) {       Node *pt = ac.root;       for (int j = (i); j <= int(((int)(p).size()) - 1); j++)         if (!(pt = pt->to[p[j] -  a ]))           while (1)             ;       for (int j = 0; j < int(((int)(q).size())); j++) {         if (!(pt = pt->to[q[j] -  a ]))           while (1)             ;         if (big <= pt->who && pt->who < m &&             pt->dep == (((int)(p).size()) - i) + j)           res[pt->who]++;       }     }     for (int i = (big); i <= int(m - 1); i++)       if (res[i] >= MOD) res[i] -= MOD;   }   void sol_small() {     h[1] =  a ;     h[2] =  b ;     for (int i = (3); i <= int(15); i++) h[i] = h[i - 1] + h[i - 2];     for (int i = (1); i <= int(15); i++) t[i] = h[i];     if (n <= 15) {       for (int j = (big); j <= int(m - 1); j++)         for (size_t o = h[n].find(s[j]); ~o; o = h[n].find(s[j], o + 1)) ans[j]++;     } else {       for (int i = (14); i <= int(15); i++)         for (int j = (big); j <= int(m - 1); j++)           for (size_t o = h[i].find(s[j]); ~o; o = h[i].find(s[j], o + 1))             ap[i][j]++;       for (int i = (14); i <= int(15); i++)         h[i].resize(second), t[i].erase(t[i].begin(), t[i].end() - second);       for (int i = (16); i <= int(n); i++) {         for (int j = (big); j <= int(m - 1); j++)           ap[i][j] = ap[i - 1][j] + ap[i - 2][j];         for (int j = (big); j <= int(m - 1); j++)           if (ap[i][j] >= MOD) ap[i][j] -= MOD;         h[i] = h[i - 1];         t[i] = t[i - 2];         merge(t[i - 1], h[i - 2], ap[i]);       }       for (int i = (big); i <= int(m - 1); i++) ans[i] = ap[n][i];     }   }   void sol() {     sol_big();     sol_small();     for (int i = 0; i < int(om); i++) {       int id = lower_bound(s, s + m, os[i],                            [&](const string &a, const string &b) {                              return make_pair(((int)(a).size()), a) >                                     make_pair(((int)(b).size()), b);                            }) -                s;       PL(ans[id]);     }   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     int mx = -1, my = -1;     while (t--) {       char c;       int t1, t2;       cin >> c >> t1 >> t2;       if (t1 > t2) swap(t1, t2);       if (c ==  + ) {         mx = max(mx, t1);         my = max(my, t2);       } else {         if (mx <= t1 && my <= t2)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-5;   bool board[8][8];   const int dx[8] = {1, 2, 2, 1, -1, -2, -2, -1};   const int dy[8] = {2, 1, -1, -2, -2, -1, 1, 2};   void check(int x, int y, int n) {     board[x][y] = true;     if (n == 1) {       for (int i = (0); i < (int)(8); ++i) {         board[i][y] = true;         board[x][i] = true;       }     }     for (int r = (0); r < (int)(8); ++r) {       if (x + dx[r] < 8 && x + dx[r] >= 0) {         if (y + dy[r] < 8 && y + dy[r] >= 0) {           board[x + dx[r]][y + dy[r]] = true;         }       }     }   }   int main(void) {     int x, y, count = 0;     string line;     cin >> line;     x = line[0] -  a ;     y = line[1] -  1 ;     check(x, y, 1);     cin >> line;     x = line[0] -  a ;     y = line[1] -  1 ;     check(x, y, 2);     for (int x = (0); x < (int)(8); ++x) {       for (int y = (0); y < (int)(8); ++y) {         if (board[x][y]) count++;       }     }     cout << 64 - count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   int SL[MAXN], SR[MAXN];   int A[MAXN][2], n;   int main() {     while (~scanf( %d , &n)) {       SL[0] = SR[0] = 0;       for (int i = 1; i <= n; i++) {         scanf( %d%d , &A[i][0], &A[i][1]);         SL[i] = A[i][0] + SL[i - 1];         SR[i] = A[i][1] + SR[i - 1];       }       int maxn = abs(SL[n] - SR[n]);       int ans = 0;       for (int i = 1; i <= n; i++) {         int _SL = SL[n] - A[i][0] + A[i][1];         int _SR = SR[n] - A[i][1] + A[i][0];         int _ans = abs(_SL - _SR);         if (maxn < _ans) {           maxn = _ans;           ans = i;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[300005], tp, lt, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++) {       tp = min(a[i] / 2, lt);       lt -= tp;       a[i] -= tp * 2;       ans += tp + a[i] / 3;       lt += a[i] % 3;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char my_array[50][50];   bool visited[50][50];   bool dfs(int i, int j, int c_i, int c_j) {     if (visited[i][j]) {       return true;     }     visited[i][j] = true;     char col = my_array[i][j];     bool res = false;     if (i > 0 && col == my_array[i - 1][j] && c_i != i - 1) {       res |= dfs(i - 1, j, i, j);     }     if (j > 0 && col == my_array[i][j - 1] && c_j != j - 1) {       res |= dfs(i, j - 1, i, j);     }     if (i < n - 1 && col == my_array[i + 1][j] && c_i != i + 1) {       res |= dfs(i + 1, j, i, j);     }     if (j < m - 1 && col == my_array[i][j + 1] && c_j != j + 1) {       res |= dfs(i, j + 1, i, j);     }     return res;   }   int main(int argc, const char* argv[]) {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> my_array[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visited[i][j] && dfs(i, j, -1, -1)) {           cout <<  Yes ;           return 0;         }       }     }     cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6, N2 = 5e3, delta = 46639, mod = 1e9 + 7, oo = 1e16;   const long double PI = 3.141592653589793;   int main() {     long long int n, cnt1 = 1, cnt2 = 1, mx = 0;     string s;     cin >> n >> s;     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         string t = s;         long long int cnt = 0, trn = 0, ans = 0;         swap(t[i], t[j]);         for (long long int k = 0; k < n; k++) {           if (t[k] ==  ( )             cnt++;           else {             if (cnt <= 0)               trn++;             else               cnt--;           }         }         for (long long int k = n - 1; k >= 0; k--) {           if (cnt == 0 && trn == 0) ans++;           if (t[k] ==  ( )             cnt--, trn--;           else             cnt++, trn++;         }         mx = max(mx, ans);         if (mx == ans) cnt1 = i + 1, cnt2 = j + 1;       }     }     cout << mx <<   n  << cnt1 <<     << cnt2;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const long double PI = 3.14159265358979323846;   const long double eps = 1e-5;   const int INF = numeric_limits<int>::max();   const long long LINF = numeric_limits<long long>::max();   const long long mod = 1000 * 1000 * 1000 + 7;   struct moves {     int r1, c1, r2, c2;     moves(int _r1, int _c1, int _r2, int _c2)         : r1(_r1), c1(_c1), r2(_r2), c2(_c2) {}   };   vector<moves> solve(int n, int m, vector<vector<int> > b,                       vector<pair<int, int> > p) {     vector<moves> res;     int c = -1;     for (int j = 0; j < n; ++j) {       for (int i = 0; i < n; ++i) {         if (b[i][j] == -1) {           continue;         }         ++c;         int d = c - j;         if (d < 0) {           for (int k = 0; k < -d; ++k) {             swap(b[i][j - k], b[i][j - 1 - k]);             res.push_back(moves(i, j - k, i, j - 1 - k));           }         }         if (d == 0) {           continue;         }         if (d > 0) {           --c;           int l = j + 1;           while (b[i][l] != -1) ++l;           for (int k = l - 1; k >= j; --k) {             swap(b[i][k], b[i][k + 1]);             res.push_back(moves(i, k, i, k + 1));           }         }       }     }     for (int j = 0; j < n; ++j) {       if (b[0][j] != -1) {         swap(b[0][j], b[1][j]);         res.push_back(moves(0, j, 1, j));       }     }     for (int i = 2; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (b[i][j] != -1) {           for (int k = i - 1; k >= 1; --k) {             swap(b[k + 1][j], b[k][j]);             res.push_back(moves(k + 1, j, k, j));           }         }       }     }     for (int t = 0; t < m; ++t) {       int cl = 0;       while (b[1][cl] != t) ++cl;       swap(b[1][cl], b[0][cl]);       res.push_back(moves(1, cl, 0, cl));       for (int j = cl; j > t; --j) {         swap(b[0][j], b[0][j - 1]);         res.push_back(moves(0, j, 0, j - 1));       }       for (int j = cl; j > t; --j) {         swap(b[1][j], b[1][j - 1]);         res.push_back(moves(1, j - 1, 1, j));       }     }     return res;   }   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int> > b1(n, vector<int>(n, -1)), b2(n, vector<int>(n, -1));     vector<pair<int, int> > p1(m), p2(m);     for (int i = 0; i < m; ++i) {       int r, c;       cin >> r >> c;       --r, --c;       p1[i] = pair<int, int>(r, c);       b1[r][c] = i;     }     for (int i = 0; i < m; ++i) {       int r, c;       cin >> r >> c;       --r, --c;       p2[i] = pair<int, int>(r, c);       b2[r][c] = i;     }     if (n == 1) {       cout << 0 << endl;       return;     }     vector<moves> r1 = solve(n, m, b1, p1);     vector<moves> r2 = solve(n, m, b2, p2);     cout << r1.size() + r2.size() <<   n ;     for (int i = 0; i < r1.size(); ++i) {       cout << r1[i].r1 + 1 <<     << r1[i].c1 + 1 <<     << r1[i].r2 + 1 <<                << r1[i].c2 + 1 <<   n ;     }     for (int i = r2.size() - 1; i >= 0; --i) {       cout << r2[i].r2 + 1 <<     << r2[i].c2 + 1 <<     << r2[i].r1 + 1 <<                << r2[i].c1 + 1 <<   n ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool grid[3][10004];   int n;   long long dp[10004][8];   long long calc(int i, int mask) {     int mask2 = 0;     if (grid[0][i]) mask2 |= 1;     if (grid[1][i]) mask2 |= 2;     if (grid[2][i]) mask2 |= 4;     if ((mask & mask2) != 0) {       return 0;     }     mask |= mask2;     long long ret = dp[i][mask];     if (ret != -1) {       return ret;     }     if (i == n - 1) {       if (mask == 1 || mask == 4 || mask == 7) {         return 1;       } else         return 0;     }     switch (mask) {       case 0:         ret = calc(i + 1, 4);         ret += calc(i + 1, 1);         ret += calc(i + 1, 7);         ret %= 1000000007;         break;       case 1:         ret = calc(i + 1, 6);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 2:         ret = calc(i + 1, 5);         break;       case 3:         ret = calc(i + 1, 4);         break;       case 4:         ret = calc(i + 1, 3);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 5:         ret = calc(i + 1, 2);         break;       case 6:         ret = calc(i + 1, 1);         break;       case 7:         ret = calc(i + 1, 0);         break;       default:         break;     }     dp[i][mask] = ret;     return ret;   }   int main() {     cin >> n;     string a, b, c;     cin >> a >> b >> c;     memset(grid, true, sizeof grid);     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       if (a[i] ==  . ) {         grid[0][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (b[i] ==  . ) {         grid[1][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (c[i] ==  . ) {         grid[2][i] = false;       }     }     if (a.find( O ) == string::npos && c.find( O ) == string::npos &&         b.find( O ) != 0 && b.find( O ) != n - 1) {       long long x = calc(0, 0);       int p = b.find( O );       memset(dp, -1, sizeof dp);       grid[1][p - 1] = true;       grid[2][p - 1] = true;       grid[0][p + 1] = true;       grid[1][p + 1] = true;       long long y = calc(0, 0);       grid[0][p - 1] = true;       grid[2][p - 1] = false;       grid[0][p + 1] = false;       grid[2][p + 1] = true;       memset(dp, -1, sizeof(dp));       long long z = calc(0, 0);       cout << (x - y - z + 1000000007 + 1000000007) % 1000000007 << endl;     } else {       cout << calc(0, 0) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > vec;     vector<pair<int, int> > event;     multiset<int> s;     for (int i = 0; i < m; i++) {       int l, r, t;       gn(l, r);       gn(t);       event.push_back(pair<int, int>(l, t));       event.push_back(pair<int, int>(r, -t - 1));     }     sort(event.begin(), event.end());     for (pair<int, int> e : event) {       if (!s.empty()) vec.push_back(pair<int, int>(*s.begin() - e.first, 1));       if (e.second < 0)         s.erase(s.find(-e.second - 1));       else         s.insert(e.second);       if (!s.empty()) vec.push_back(pair<int, int>(*s.begin() - e.first, -1));     }     sort(vec.begin(), vec.end());     long long now = 0, d = 0;     int cur = 0;     int pre = -1e9;     for (int i = 0; i < n; i++) {       int t;       gn(t);       while (cur < vec.size() && vec[cur].first < t) {         now += d * (vec[cur].first - pre);         d += vec[cur].second;         pre = vec[cur].first;         cur++;       }       printf( %I64d n , now + d * (t - pre));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, INF = 0X3F3F3F3F;   int n, tot;   char s[N];   vector<int> ans;   set<int> s1, s2;   int main() {     scanf( %s , s + 1), n = strlen(s + 1);     for (int i = (1); i <= (n); ++i) {       if (s[i] ==  L )         s1.insert(i);       else         s2.insert(i);     }     s1.insert(INF), s2.insert(INF);     if (make_pair(-((int)(s1).size()), *s1.begin()) >         make_pair(-((int)(s2).size()), *s2.begin()))       swap(s1, s2);     int go = *s1.begin();     for (int i = (1); i <= (n); ++i) {       if (i & 1) {         if (go == INF || (*s2.lower_bound(go) == INF && *s1.begin() != go &&                           *s1.begin() < *s2.begin())) {           ++tot;           go = *s1.begin();         }         s1.erase(go);         ans.push_back(go);         go = *s2.lower_bound(go);       } else {         if (go == INF || (*s1.lower_bound(go) == INF && *s2.begin() != go &&                           *s2.begin() < *s1.begin())) {           ++tot;           go = *s2.begin();         }         s2.erase(go);         ans.push_back(go);         go = *s1.lower_bound(go);       }     }     printf( %d n , tot);     for (auto x : ans) printf( %d  , x);     return 0;   }


#include <iostream>   #include <vector>   #include <array>   #define vi vector<int>   #define pii pair<int, int>   #define fst first   #define snd second      using namespace std;      const int SZ = (1 << 19) + 5, INF = (1e9) + 7;      int N, ans[200001];   vi idx[200001];      array<int, 4> seg[2][SZ];   int lz[2][SZ];      array<int, 4> merge(const array<int, 4>& L, const array<int, 4>& R)   {    return {min(L[0], R[0]), max(L[1], R[1]), min(L[2], R[2]), max(L[3], R[3])};   }      inline void prop(int t, int idx, int L, int R)   {    if (lz[t][idx])    {     for (int i = 0; i < 4; i++)      {      if (seg[t][idx][i] > -INF && seg[t][idx][i] < INF) seg[t][idx][i] += lz[t][idx];     }     if (L < R)     {      lz[t][2 * idx] += lz[t][idx];      lz[t][2 * idx + 1] += lz[t][idx];     }     lz[t][idx] = 0;    }   }      void build(int t, int idx, int L, int R)   {    seg[t][idx][0] = seg[t][idx][2] = INF;    seg[t][idx][1] = seg[t][idx][3] = -INF;    if (L == R)     {     seg[t][idx][(L & 1) << 1] = 0;     seg[t][idx][(L & 1) << 1 | 1] = 0;    }    else if (L < R)    {     int M = L + R >> 1;     build(t, 2 * idx, L, M);     build(t, 2 * idx + 1, M + 1, R);     seg[t][idx] = merge(seg[t][2 * idx], seg[t][2 * idx + 1]);    }   }      void upd(int t, int idx, int L, int R, int l, int r, int v)   {    l = max(L, l); r = min(R, r); prop(t, idx, L, R);    if (l <= r)    {     if (L == l && R == r) {lz[t][idx] += v; prop(t, idx, L, R);}     else     {      int M = L + R >> 1;      upd(t, 2 * idx, L, M, l, r, v);      upd(t, 2 * idx + 1, M + 1, R, l, r, v);      seg[t][idx] = merge(seg[t][2 * idx], seg[t][2 * idx + 1]);     }    }   }      array<int, 4> qry(int t, int idx, int L, int R, int l, int r)   {    l = max(L, l); r = min(R, r);    if (l <= r)    {     prop(t, idx, L, R);     if (L == l && R == r) {return seg[t][idx];}     else     {      int M = L + R >> 1;      return merge(qry(t, 2 * idx, L, M, l, r), qry(t, 2 * idx + 1, M + 1, R, l, r));     }    }    return {INF, -INF, INF, -INF};   }      int main()   {    cin >> N;    for (int i = 1; i <= N; i++)    {     int x; cin >> x;     idx[x].push_back(i);    }    build(0, 1, 0, N);    build(1, 1, 0, N);    for (int i = 1; i <= N; i++)    {     upd(i & 1, 1, 0, N, i, N, -1);    }    for (int i = 1; i <= N; i++)    {     for (const auto &x : idx[i])     {      for (int j = 0; j < 2; j++)      {       array<int, 4> A = qry(j, 1, 0, N, 0, x - 1), B = qry(j, 1, 0, N, x, N);       ans[x] = max(ans[x], max(B[1], B[3]) - A[j << 1]);       ans[x] = max(ans[x], A[j << 1 | 1] - min(B[0], B[2]));        }      }     for (const auto &x : idx[i])      {      for (int j = 0; j < 2; j++) upd(j, 1, 0, N, x, N, 1);     }     for (const auto &x : idx[i])     {      for (int j = 0; j < 2; j++)      {       upd(j, 1, 0, N, x, N, -1);       array<int, 4> A = qry(j, 1, 0, N, 0, x - 1), B = qry(j, 1, 0, N, x, N);       ans[x] = max(ans[x], max(B[1], B[3]) - A[j << 1]);       ans[x] = max(ans[x], A[j << 1 | 1] - min(B[0], B[2]));       upd(j, 1, 0, N, x, N, 1);      }     }    }    for (int i = 1; i <= N; i++)    {     cout << ans[i] <<    n [i == N];    }    return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   template <typename T>   inline T Abs(T x) {     return (x >= 0) ? x : -x;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   template <typename T>   string toStr(T x) {     stringstream st;     st << x;     string s;     st >> s;     return s;   }   const int INF = (int)1E9;   const long long INF64 = (long long)1E18;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   map<pair<long long, long long>, long long> d;   long long solve(long long n, long long t) {     if (d.count(make_pair(n, t))) return d[make_pair(n, t)];     if (n == 0) return d[make_pair(n, t)] = 0;     long long l = 1, p = 0;     while (2 * l <= n) {       l *= 2;       p++;     }     if (t == 1) return d[make_pair(n, t)] = p + 1;     if (n <= 2) return d[make_pair(n, t)] = 0;     long long ans = solve(l / 2 - 1, t);     if (t % 2 == 0) ans += solve(l / 2 - 1, t / 2);     if (n != l && t % 2 == 0) ans += solve(n - l, t / 2);     return d[make_pair(n, t)] = ans;   }   int main() {     long long n, t;     cin >> n >> t;     long long ans = solve(n + 1, t);     if (t == 1) ans--;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 710;   const int MOD = 1000000007;   int n;   int mate[MAXN];   long long int dp[MAXN][MAXN][3][3];   char v[MAXN];   stack<int, vector<int> > s;   long long int solve(int l, int r, int bl, int br) {     long long int& ans = dp[l][r][bl][br];     if (ans != -1) return ans;     if (l > r) return ans = 1;     ans = 0;     int mateL = mate[l];     for (int colorL = 1; colorL <= 2; colorL++) {       if (colorL == bl) continue;       long long int left = solve(l + 1, mateL - 1, colorL, 0);       long long int right = solve(mateL + 1, r, 0, br);       ans += left * right;     }     for (int colorL = 1; colorL <= 2; colorL++) {       if (mateL == r && colorL == br) continue;       long long int left = solve(l + 1, mateL - 1, 0, colorL);       long long int right = solve(mateL + 1, r, colorL, br);       ans += left * right;     }     ans %= MOD;     return ans;   }   int main() {     scanf(  %s , v);     n = strlen(v);     for (int i = 0; i < n; i++) {       if (v[i] ==  ( )         s.push(i + 1);       else {         int p = s.top();         s.pop();         mate[p] = i + 1;         mate[i + 1] = p;       }     }     memset(dp, -1, sizeof(dp));     printf( %lld n , solve(1, n, 0, 0));   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, z, cnt, c[100100], d[100100];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       pq;   vector<pair<int, pair<int, int> > > graph[100100];   vector<pair<int, pair<int, int> > > edge, v;   bool mark[100100];   pair<int, int> p[100100];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) d[i] = 1e9;     for (int i = 0; i < m; i++) {       cin >> x >> y >> z;       graph[x].push_back(make_pair(y, make_pair(z, i)));       graph[y].push_back(make_pair(x, make_pair(z, i)));       edge.push_back(make_pair(z, make_pair(x, y)));       if (z) cnt++;     }     d[1] = 0;     pq.push(make_pair(0, 1));     while (!pq.empty()) {       x = pq.top().second;       pq.pop();       for (int i = 0; i < graph[x].size(); i++) {         y = graph[x][i].first;         if (d[x] + 1 <= d[y]) {           if (d[x] + 1 < d[y]) p[y] = make_pair(x, graph[x][i].second.second);           d[y] = d[x] + 1;           if (c[x] + graph[x][i].second.first > c[y]) {             p[y] = make_pair(x, graph[x][i].second.second);             c[y] = c[x] + graph[x][i].second.first;           }           pq.push(make_pair(d[y], y));         }       }     }     x = n;     while (x != 1) {       y = x;       x = p[y].first;       if (edge[p[y].second].first == 0) v.push_back(edge[p[y].second]);       mark[p[y].second] = 1;     }     for (int i = 0; i < edge.size(); i++) {       if (!mark[i] && edge[i].first) v.push_back(edge[i]);     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i].second.first <<     << v[i].second.second <<                << (!v[i].first) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d, ans = 128, x[128], sum[128];   int main() {     cin >> n >> d;     for (int i = 0; i < n; ++i) cin >> x[i];     sort(x, x + n);     for (int l = 0; l < n; ++l)       for (int r = l; r < n; ++r)         if (x[r] - x[l] <= d) ans = min(ans, l + n - 1 - r);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1e9 + 7, oo = 1e9;   const ll loo = 1e18;   ll modpow(ll a, ll b) {     ll ans = 1;     for (; b; b /= 2, a = a * a % mod)       if (b & 1) ans = (ans * a) % mod;     return ans;   }   ll gcd(ll a, ll b) {     while (a) b %= a, swap(a, b);     return b;   }   const bool DEBUG = 1;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int n = s.length();     int pre[n][3];     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) pre[i][j] = i ? pre[i - 1][j] : -oo;       pre[i][s[i] -  a ] = i;     }     stringstream ss;     int i = 0, j = n - 1;     int cnt = 0;     while (i <= j) {       int jj = pre[j][s[i] -  a ];       if (jj - i >= 0 && (jj - i - 1) / 2 + cnt + (1 + (i != jj)) >= n / 2) {         j = jj - 1;         cnt += 1 + (i != jj);         ss << s[i];       }       i++;     }     string t = ss.str();     string r;     if (cnt & 1)       r = t.substr(0, t.length() - 1);     else       r = s.substr(0, t.length());     reverse(r.begin(), r.end());     cout << t << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000;   int n, a, b, da, db;   vector<int> nei[N + 1];   int dep[N + 1], dp[N + 1];   int ans;   void dfs(int x = a, int fa = 0) {     vector<int> v;     v.push_back(dep[x]);     dp[x] = dep[x];     for (int i = 0; i < nei[x].size(); i++) {       int y = nei[x][i];       if (y == fa) continue;       dep[y] = dep[x] + 1;       dfs(y, x);       v.push_back(dp[y]);       dp[x] = max(dp[x], dp[y]);     }     sort(v.begin(), v.end(), greater<int>());     if (v.size() >= 2) ans = max(ans, v[0] + v[1] - 2 * dep[x]);   }   void mian() {     scanf( %d%d%d%d%d , &n, &a, &b, &da, &db);     for (int i = 1; i <= n; i++) nei[i].clear();     for (int i = 1; i <= n; i++) dep[i] = dp[i] = 0;     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       nei[x].push_back(y);       nei[y].push_back(x);     }     if (db < 2 * da + 1) return puts( Alice ), void();     ans = 0;     dfs();     if (ans >= 2 * da + 1 && dep[b] > da)       puts( Bob );     else       puts( Alice );   }   int main() {     int testnum;     cin >> testnum;     while (testnum--) mian();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   struct pt {     long long x, y;     pt(long long x = 0, long long y = 0) : x(x), y(y) {}     pt operator-(const pt &o) const { return pt(x - o.x, y - o.y); }     long long cross(const pt &o) const { return x * o.y - y * o.x; }   };   struct city {     pt p;     bool b;     int id;   };   struct tri {     city a, b, c;     bool ins(const pt &p) {       return (b.p - a.p).cross(p - a.p) > 0 && (c.p - b.p).cross(p - b.p) > 0 &&              (a.p - c.p).cross(p - c.p) > 0;     }   };   const int N = 1e3 + 5;   int n;   vector<city> v;   bool used[N];   vector<city> upperhull(const vector<city> &v, int n) {     vector<city> u;     for (int m, i = 0; i < n; i++) {       while ((m = u.size()) > 1) {         pt p = u[m - 1].p, q = u[m - 2].p;         if ((p - q).cross(v[i].p - p) > 0) break;         u.pop_back();       }       u.push_back(v[i]);     }     return u;   }   vector<city> hull(vector<city> &v, int n) {     vector<city> u = upperhull(v, n);     reverse(v.begin(), v.end());     vector<city> l = upperhull(v, n);     reverse(v.begin(), v.end());     for (int i = 1; i + 1 < l.size(); i++) u.push_back(l[i]);     return u;   }   vector<pair<int, int>> ans;   void solve(tri T, vector<city> v) {     v.erase(remove_if((v).begin(), (v).end(),                       [&](city c) { return used[c.id] || !T.ins(c.p); }),             v.end());     int cnt[2] = {0, 0};     for (city c : {T.a, T.b, T.c}) {       cnt[c.b]++;     }     bool b = (cnt[0] > cnt[1]);     for (city &c : v) {       if (c.b == b) {         for (city d : {T.a, T.b, T.c}) {           if (c.b == d.b) {             ans.emplace_back(c.id, d.id);             break;           }         }         used[c.id] = true;         solve({T.a, T.b, c}, v);         solve({T.b, T.c, c}, v);         solve({T.c, T.a, c}, v);         return;       }     }     city c1 = (T.a.b != b ? T.a : T.b.b != b ? T.b : T.c);     for (city &c : v) {       ans.emplace_back(c.id, c1.id);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = (0); i < (n); i++) {       pt p;       bool b;       cin >> p.x >> p.y >> b;       v.push_back({p, b, i});     }     if (n == 1 || (n == 2 && v[0].b != v[1].b)) {       cout <<  0 n ;       return 0;     } else if (n == 2) {       cout <<  1 n0 1 n ;       return 0;     }     sort((v).begin(), (v).end(), [&](city &a, city &b) {       return make_pair(a.p.x, a.p.y) < make_pair(b.p.x, b.p.y);     });     vector<city> h = hull(v, n);     vector<int> ve;     for (int i = (0); i < (((int)(h).size())); i++) {       if (h[i].b != h[(i + 1) % ((int)(h).size())].b) {         ve.push_back(i);       } else {         ans.emplace_back(h[i].id, h[(i + 1) % ((int)(h).size())].id);       }     }     if (((int)(ve).size()) > 2) {       cout <<  Impossible n ;       return 0;     }     vector<tri> tris;     for (city &c : h) {       used[c.id] = true;     }     if (ve.empty()) {       ans.pop_back();       bool flag = false;       for (city &c : v) {         if (!used[c.id] && c.b != h[0].b) {           used[c.id] = true;           for (int i = (0); i < (((int)(h).size())); i++) {             tris.push_back({h[i], h[(i + 1) % ((int)(h).size())], c});           }           flag = true;           break;         }       }       if (!flag) {         cout << n - 1 <<   n ;         for (int i = (1); i < (n); i++) {           cout << 0 <<     << i <<   n ;         }         return 0;       }     } else {       assert(((int)(ve).size()) == 2);       for (int i = (ve[0] + 1) % ((int)(h).size()); i != ve[1];            i = (i + 1) % ((int)(h).size())) {         tris.push_back({h[ve[0]], h[i], h[(i + 1) % ((int)(h).size())]});       }       for (int i = (ve[1] + 1) % ((int)(h).size()); i != ve[0];            i = (i + 1) % ((int)(h).size())) {         tris.push_back({h[ve[1]], h[i], h[(i + 1) % ((int)(h).size())]});       }     }     for (tri &T : tris) {       solve(T, v);     }     cout << ((int)(ans).size()) <<   n ;     for (pair<int, int> &pa : ans) {       cout << pa.first <<     << pa.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long power(long long a, long long n) {     long long ret = 1;     while (n) {       if (n & 1) {         ret = ret * a % mod;       }       a = a * a % mod;       n >>= 1;     }     return ret;   }   vector<long long> st;   long long C(long long n, long long k) {     long long ret = st[n];     ret = ret * power(st[k], mod - 2) % mod;     ret = ret * power(st[n - k], mod - 2) % mod;     return ret;   }   long long solve(long long n, long long k) {     if (k >= n) return 0;     st.resize(n + 1, 1);     for (long long i = 1; i <= n; i++) st[i] = st[i - 1] * i % mod;     long long ret = 0, c = n - k;     for (long long i = 0; i <= c; i++) {       if ((i & 1) == (c & 1))         ret = (ret + mod + (C(c, i) * power(i, n))) % mod;       else         ret = (ret + mod - (C(c, i) * power(i, n))) % mod;     }     ret = ret * C(n, c) % mod;     return k > 0 ? ret * 2 % mod : ret;   }   int32_t main() {     long long n, k;     cin >> n >> k;     cout << solve(n, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long MAX = 8e18;   const long long MIN = -8e18;   int n;   long long x[N];   long long y[N];   long long z[N];   vector<long long> ansX;   vector<long long> ansY;   vector<long long> ansZ;   inline long long llabs(const long long &a, const long long &b) {     long long res = a - b;     return (res >= 0 ? res : -res);   }   inline long long calDist(long long z0, pair<long long, long long> &xy) {     long long minA, maxA, minB, maxB, h, dist2, a, b;     int i, j, k;     minA = minB = MAX;     maxA = maxB = MIN;     for (i = 0; i < n; i++) {       h = llabs(z0, z[i]);       minA = min(minA, x[i] + y[i] - h);       maxA = max(maxA, x[i] + y[i] + h);       minB = min(minB, x[i] - y[i] - h);       maxB = max(maxB, x[i] - y[i] + h);     }     dist2 = max(maxA - minA, maxB - minB);     a = (maxA + minA) / 2;     b = (maxB + minB) / 2;     xy.first = (a + b) / 2;     xy.second = (a - b) / 2;     return dist2;   }   inline void solve() {     int i;     long long bestZ, bestY, bestX, bestDist, curDist, curY, curX, initX, initY,         curZ, d;     bestDist = MAX;     pair<long long, long long> xy;     bestZ = 0;     bestDist = calDist(bestZ, xy);     d = 1e18;     while (d >= 1) {       curZ = bestZ + d;       curDist = calDist(curZ, xy);       if (curDist < bestDist) {         bestZ = curZ;         bestDist = curDist;         continue;       }       curZ = bestZ - d;       curDist = calDist(curZ, xy);       if (curDist < bestDist) {         bestZ = curZ;         bestDist = curDist;         continue;       }       d /= 2;     }     calDist(bestZ, xy);     initX = xy.first;     initY = xy.second;     bestDist = MAX;     for (curX = initX - 1; curX <= initX + 1; curX++) {       for (curY = initY - 1; curY <= initY + 1; curY++) {         curDist = 0;         for (i = 0; i < n; i++) {           curDist = max(curDist, llabs(x[i] - curX) + llabs(y[i] - curY) +                                      llabs(bestZ - z[i]));         }         if (curDist < bestDist) {           bestDist = curDist;           bestX = curX;           bestY = curY;         }       }     }     ansX.push_back(bestX);     ansY.push_back(bestY);     ansZ.push_back(bestZ);   }   int main() {     int t, i, k;     scanf( %d , &t);     for (k = 0; k < t; k++) {       scanf( %d , &n);       for (i = 0; i < n; i++) {         scanf(              %l               ld               %l               ld               %l               ld ,             &x[i], &y[i], &z[i]);       }       solve();     }     for (i = 0; i < t; i++) {       printf(            %l             ld                           %l             ld                           %l             ld              n ,           ansX[i], ansY[i], ansZ[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const long long inf = 1e16;   const long long ninf = LLONG_MIN;   const double eps = 1e-12;   const long long N = 1000005;   const double PI = 3.14159265358979323846;   const long long LOGN = 19;   long long n, m;   long long s[N], t[N];   char a[N];   long long dp[(1 << 21)];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> s[i];     cin >> m;     sort(s, s + n);     reverse(s, s + n);     for (int i = 0; i < m; i++) cin >> a[i] >> t[i];     for (long long mask = (1 << m) - 1; mask >= 0; mask--) {       long long done = __builtin_popcount(mask);       if (done == m) {         dp[mask] = 0;         continue;       }       if (a[done] ==  p ) {         for (int j = 0; j < m; j++) {           if ((mask & (1 << j)) == 0) {             dp[mask] = (t[done] == 1 ? s[j] : -s[j]) + dp[mask | (1 << j)];             break;           }         }       } else {         if (t[done] == 1) {           dp[mask] = -inf;           for (int j = 0; j < m; j++) {             dp[mask] = max(dp[mask], dp[mask | (1 << j)]);           }         } else {           dp[mask] = inf;           for (int j = 0; j < m; j++) {             dp[mask] = min(dp[mask], dp[mask | (1 << j)]);           }         }       }     }     cout << dp[0] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5, M = 350;   long long dp[5][N], B, a[N], b[N], t[N], n, m, d, minans = 1e9 + 10, dpL[N],                                                     dpR[N];   int last, ldel;   deque<int> stac;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> d;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> t[i];       B += b[i];     }     for (int j = 0; j < n; j++) dp[0][j] = abs(a[0] - (j + 1));     for (int i = 1; i < m; i++) {       last = (i - 1) % 2;       for (int j = 0; j < n; j++) {         ldel = j;         while (!stac.empty() && stac.front() < (j - ((t[i] - t[i - 1]) * d)))           stac.pop_front();         while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])           ldel = stac.back(), stac.pop_back();         if (stac.empty())           dpL[j] = dp[last][ldel];         else           dpL[j] = dp[last][stac.front()];         stac.push_back(j);       }       for (int j = n - 1; j >= 0; j--) {         ldel = j;         while (!stac.empty() && stac.front() > (j + ((t[i] - t[i - 1]) * d)))           stac.pop_front();         while (!stac.empty() && dp[last][stac.back()] >= dp[last][j])           ldel = stac.back(), stac.pop_back();         if (stac.empty())           dpR[j] = dp[last][ldel];         else           dpR[j] = dp[last][stac.front()];         stac.push_back(j);       }       for (int j = 0; j < n; j++)         dp[i % 2][j] =             min(min(dpR[j], dpL[j]), dp[last][j]) + abs(a[i] - (j + 1));       stac.clear();     }     for (int i = 0; i < n; i++) minans = min(minans, dp[(m - 1) % 2][i]);     cout << B - minans;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long st, en;     node() {}     node(long long _st, long long _en) : st(_st), en(_en) {}   };   int main() {     int n, b, t, d;     long long etime[200000];     long long ftime;     int qlen = 0;     cin >> n >> b;     cin >> t >> d;     etime[0] = t + d;     ftime = 1ll * t + d;     int len = 0;     queue<node> ws;     node temp;     cout << etime[0] <<    ;     for (int i = 1; i < n; i++) {       cin >> t >> d;       while (!ws.empty()) {         temp = ws.front();         if (t >= temp.st) {           ws.pop();           len--;         } else           break;       }       if (t < ftime) {         if (len < b) {           ws.push(node(ftime, ftime + d));           len++;           etime[i] = ftime + d;           ftime += d;         } else {           etime[i] = -1;         }       } else {         etime[i] = 1ll * t + d;         ftime = 1ll * t + d;       }       cout << etime[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long, long long>, pair<long long, long long> > Mp;   pair<long long, long long> DFS(pair<long long, long long> u) {     if (u.second < 10)       return pair<long long, long long>(u.first || u.second,                                         u.second - max(u.second, u.first));     if (Mp[u].first) return Mp[u];     long long ans = 0, p = 1;     while (p <= u.second / 10) p *= 10;     pair<long long, long long> res =         DFS(pair<long long, long long>(max(u.first, u.second / p), u.second % p));     ans += res.first;     res = DFS(pair<long long, long long>(u.first, u.second / p * p + res.second));     return Mp[u] = pair<long long, long long>(res.first + ans, res.second);   }   int main() {     long long n;     scanf( %lld , &n);     printf( %lld n , DFS(pair<long long, long long>(0, n)));   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 10;   const int LOG = 18;   int n, m, par[MAX][LOG], h[MAX];   vector<int> graph[MAX];   int par_tree[MAX], mini[MAX];   void lca_dfs(int node, int p) {     if (p + 1) h[node] = h[p] + 1;     par[node][0] = p;     for (int k = 1; k < LOG; k++)       if (par[node][k - 1] + 1) par[node][k] = par[par[node][k - 1]][k - 1];     for (auto& target : (graph[node])) {       if (target != p) lca_dfs(target, node);     }   }   int get_lca(int a, int b) {     if (h[b] > h[a]) swap(a, b);     for (int k = LOG - 1; k >= 0; k--) {       if (par[a][k] + 1 && h[par[a][k]] >= h[b]) a = par[a][k];     }     if (a == b) return a;     for (int k = LOG - 1; k >= 0; k--)       if (par[a][k] != par[b][k]) {         a = par[a][k];         b = par[b][k];       }     return par[a][0];   }   int dist(int a, int b) { return h[a] + h[b] - 2 * h[get_lca(a, b)]; }   int processed[MAX], sizes[MAX];   int get_sizes(int node, int p) {     sizes[node] = 1;     for (auto& target : (graph[node])) {       if (!processed[target] && target != p)         sizes[node] += get_sizes(target, node);     }     return sizes[node];   }   int cent, cent_cost;   void select_cent(int node, int p, int current) {     int node_max = sizes[current] - sizes[node];     for (auto& target : (graph[node])) {       if (!processed[target] && target != p) {         node_max = max(node_max, sizes[target]);         select_cent(target, node, current);       }     }     if (node_max < cent_cost) {       cent = node;       cent_cost = node_max;     }   }   int process(int current) {     get_sizes(current, -1);     if (sizes[current] <= 1) return current;     cent = current;     cent_cost = ((int)1e9 + 10);     select_cent(current, -1, current);     int centroid = cent;     processed[centroid] = 1;     for (auto& target : (graph[centroid])) {       if (!processed[target]) {         int next_cent = process(target);         par_tree[next_cent] = centroid;       }     }     return centroid;   }   void update(int node) {     int cur = node;     while (cur > 0) {       mini[cur] = min(mini[cur], dist(cur, node));       cur = par_tree[cur];     }   }   int query(int node) {     int cur = node, ans = ((int)1e9 + 10);     while (cur > 0) {       ans = min(ans, mini[cur] + dist(node, cur));       cur = par_tree[cur];     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int(i) = (0); (i) < (MAX); (i)++) mini[i] = ((int)1e9 + 10);     memset(par, -1, sizeof(par));     cin >> n >> m;     int a, b;     for (int(i) = (0); (i) < (n - 1); (i)++) {       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     lca_dfs(1, -1);     int root = process(1);     par_tree[root] = -1;     int type, node;     update(1);     for (int(k) = (0); (k) < (m); (k)++) {       cin >> type >> node;       if (type == 1) {         update(node);       } else {         cout << (query(node)) <<   n ;         ;       }     }   }


#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...);   }   vector<int> g[300005];   bool vis[300005];   int child[300005];   int mostchild[300005], par[300005];   int dfs(int u) {     vis[u] = true;     child[u]++;     for (int i = 0; i < g[u].size(); i++) {       if (!vis[g[u][i]]) {         vis[g[u][i]] = true;         int x = dfs(g[u][i]);         child[u] += x;         if (child[mostchild[u]] < x) mostchild[u] = g[u][i];       }     }     return child[u];   }   int res[300005];   void traverse(int u) {     if (u == 0) return;     vis[u] = true;     if (child[u] == 1) {       res[u] = u;       return;     }     traverse(mostchild[u]);     if (2 * child[mostchild[u]] > child[u]) {       int m = res[mostchild[u]];       while (2 * (child[u] - child[m]) > child[u]) m = par[m];       res[u] = m;     } else       res[u] = u;   }   int main() {     int n, q;     cin >> n >> q;     par[1] = 1;     for (int i = 2; i < n + 1; i++) {       scanf( %d , &par[i]);       g[par[i]].push_back(i);     }     memset(vis, false, sizeof(vis));     memset(mostchild, 0, sizeof(mostchild));     child[0] = 0;     dfs(1);     memset(vis, false, sizeof(vis));     for (int i = 1; i < n + 1; i++) {       if (!vis[i]) traverse(i);     }     for (int i = 0; i < q; i++) {       int a;       scanf( %d , &a);       printf( %d n , res[a]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int x, n, m;   int main() {     cin >> t;     while (t--) {       cin >> x >> n >> m;       while (x > 20 && n) {         x = x / 2 + 10;         n--;       }       while (m) x -= 10, m--;       if (x > 0)         printf( NO n );       else         printf( YES n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     cin >> a >> s;     sort(s.begin(), s.end());     int ind = s.length() - 1, n = a.length();     for (int i = 0; i < n; i++) {       if (ind >= 0 && s[ind] > a[i]) {         a[i] = s[ind];         ind--;       }     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using vi = vector<int>;   using vl = vector<ll>;   using pii = pair<int, int>;   using vpii = vector<pair<int, int>>;   template <typename T>   using pque = priority_queue<T, vector<T>, greater<T>>;   constexpr int N = 212345, M = 16;   class Node {    public:     int a = 0;     Node *c[2] = {NULL, NULL};     Node *next(int a) {       if (c[a] == NULL) c[a] = new Node();       return c[a];     }   } *head = new Node();   vpii g[N];   vi v[M][M];   int p[N] = {};   template <class T>   void dfs(int a, int b, T func) {     if (a > b) {       func();       return;     };     for (int i = (0); i < ((a)); i++) {       for (int j : v[a][i]) p[j]++;       dfs(a + 1, b, func);       for (int j : v[a][i]) p[j]--;     }   }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = (0); i < ((m)); i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       g[a].emplace_back(c, b);     }     for (int i = (1); i < (n + 1); i++) {       sort((g[i]).begin(), (g[i]).end());       for (int j = (0); j < (((int)g[i].size())); j++) {         v[g[i].size()][j].emplace_back(g[i][j].second);       }     }     for (int i = (1); i < (k); i++)       for (int j = (0); j < ((i)); j++) {         ;         for (int h : v[i][j])           ;         ;       }     dfs(1, min(6, k), [&]() {       for (int i = (1); i < (n + 1); i++)         ;       ;       Node *node = head;       for (int i = (1); i < (n + 1); i++) {         if (p[i] >= 2) return;         node = node->next(p[i]);       }       node->a++;     });     ;     int ans = 0;     dfs(min(7, k), k <= 6 ? 0 : k, [&]() {       Node *node = head;       for (int i = (1); i < (n + 1); i++) {         if (p[i] >= 2) return;         node = node->next(1 - p[i]);       }       ans += node->a;       ;     });     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int arr[200005] = {0};     long long int ans[200005] = {0};     int x, y, n, k, q;     cin >> n >> k >> q;     while (n--) {       cin >> x >> y;       arr[x]++;       arr[y + 1]--;     }     for (int i = 1; i <= 200000; i++) {       arr[i] += arr[i - 1];     }     for (int i = 1; i <= 200000; i++) {       if (arr[i] >= k)         ans[i] = ans[i - 1] + 1;       else         ans[i] = ans[i - 1];     }     while (q--) {       cin >> x >> y;       cout << ans[y] - ans[x - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:20000007 )   #pragma GCC optimize( unroll-loops )   const int N = (int)1e6 + 100;   const int maxn = (int)1e3 + 100;   const int base = (int)1e9;   const int mod = (int)1e9 + 7;   const int inf = INT_MAX;   const long long ll_inf = LLONG_MAX;   const long double pi = acos((long double)-1.0);   const long double eps = 1e-8;   void yes() { exit(!(printf( YES n ))); }   void no() { exit(!(printf( NO n ))); }   void solve() {     string s;     cin >> s;     int n = s.size();     if (n < 4) no();     set<char> S;     vector<int> Cnt(26);     for (char c : s) Cnt[c -  a ]++, S.insert(c);     int L = S.size();     if (L > 4) no();     if (3 <= L && L <= 4) yes();     if (L == 1) no();     if (L == 2) {       if (!any_of(Cnt.begin(), Cnt.end(),                   [&](int Count) -> bool { return Count >= 2; }))         no();       vector<int> others;       for (int i = 0; i < 26; ++i)         if (Cnt[i] >= 2) others.push_back(i);       if (others.size() >= 2)         yes();       else         no();     }     no();   }   int main() {     int T = 1;     for (; T; --T) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cout << x; }   void __print(long x) { cout << x; }   void __print(long long x) { cout << x; }   void __print(unsigned x) { cout << x; }   void __print(unsigned long x) { cout << x; }   void __print(unsigned long long x) { cout << x; }   void __print(float x) { cout << x; }   void __print(double x) { cout << x; }   void __print(long double x) { cout << x; }   void __print(char x) { cout <<      << x <<     ; }   void __print(const char *x) { cout <<     << x <<    ; }   void __print(const string &x) { cout <<     << x <<    ; }   void __print(bool x) { cout << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cout <<  { ;     __print(x.first);     cout <<  , ;     __print(x.second);     cout <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cout <<  { ;     for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);     cout <<  } ;   }   void _print() { cout <<   n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cout <<  ,  ;     _print(v...);   }   const int mod = 1e9 + 7, mxn = 1e5 + 1;   int solve() {     int n, m, k;     cin >> n >> m >> k;     vector<long long> v(n + 1);     for (long long i = (1); i < (n + 1); ++i) cin >> v[i];     vector<long long> pref(n + 1, 0);     pref[0] = 0;     for (long long i = (1); i < (n + 1); ++i) pref[i] = pref[i - 1] + v[i];     long long dp[n + 1][k + 1];     memset(dp, 0ll, sizeof(dp));     for (long long i = (1); i < (n + 1); ++i) {       for (long long j = (1); j < (k + 1); ++j) {         if (i - m >= 0)           dp[i][j] = max(dp[i - 1][j], dp[i - m][j - 1] + pref[i] - pref[i - m]);         else           dp[i][j] = dp[i - 1][j];       }     }     cout << dp[n][k] <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   constexpr int maxn = 1e5 + 10;   vector<int> topo;   vector<vector<pii>> pilha;   int ans[maxn];   int main() {     int n;     scanf( %d , &n);     vector<int> a(n);     for (auto& it : a) scanf( %d , &it);     for (int i = 0; i < n; i++) {       auto it = lower_bound((topo).begin(), (topo).end(), a[i]);       if (it == topo.end())         topo.push_back(a[i]), pilha.push_back({{a[i], i}});       else {         int pos = (int)(it - topo.begin());         topo[pos] = a[i];         pilha[pos].push_back({a[i], i});       }     }     vector<pii> valid = pilha.back();     if ((int)((valid).size()) > 1)       for (auto it : valid) ans[it.second] = 2;     else       ans[valid[0].second] = 3;     for (int i = (int)((pilha).size()) - 2; i >= 0; i--) {       assert((int)((valid).size()));       sort((valid).begin(), (valid).end());       vector<int> suf((int)((valid).size())), comp((int)((valid).size()));       suf.back() = valid.back().second;       for (int pos = (int)((valid).size()) - 2; pos >= 0; pos--)         suf[pos] = max(suf[pos + 1], valid[pos].second);       for (int j = 0; j < (int)((valid).size()); j++) comp[j] = valid[j].first;       valid.clear();       for (int j = 0; j < (int)((pilha[i]).size()); j++) {         auto it = upper_bound((comp).begin(), (comp).end(), pilha[i][j].first);         if (it == comp.end())           ans[pilha[i][j].second] = 1;         else {           int pos = (int)(it - comp.begin());           if (suf[pos] < pilha[i][j].second)             ans[pilha[i][j].second] = 1;           else             valid.push_back(pilha[i][j]);         }       }       if ((int)((valid).size()) > 1)         for (auto it : valid) ans[it.second] = 2;       else         ans[valid[0].second] = 3;     }     for (int i = 0; i < n; i++) printf( %d , ans[i]);     printf(  n );   }


#include<bits/stdc++.h>   using namespace std;      void solve(){    int n;    cin >> n;    int a[n];    for(int i=0;i<n;i++){     cin >> a[i];    }        vector<int> ans;    ans.push_back(0);        int current = a[0];    for(int i=1;i<n;i++){     int cans = (current|a[i])^a[i];     ans.push_back(cans);     current = current|a[i];    }        for(int i=0;i<n;i++){     cout << ans[i] <<    ;    }        cout << endl;   }      int main(){    int t=1;    cin >> t;    while(t--){     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int len = s.length();     for (int i = 0; i < len;) {       if (s[i] !=  1 ) {         cout <<  NO  << endl;         return 0;       }       if (i + 3 <= len) {         if (s[i + 1] ==  4  and s[i + 2] ==  4 ) {           i += 3;         } else if (s[i + 1] ==  4 ) {           i += 2;         } else           ++i;       } else if (i + 2 <= len) {         if (s[i + 1] ==  4 ) {           i += 2;         } else           ++i;       } else         ++i;     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   class graph {    public:     struct edge {       int from;       int to;       T cost;     };     vector<edge> edges;     vector<vector<int>> g;     int n;     graph(int _n) : n(_n) { g.resize(n); }     virtual int add(int from, int to, T cost) = 0;   };   template <typename T>   class undigraph : public graph<T> {    public:     using graph<T>::edges;     using graph<T>::g;     using graph<T>::n;     undigraph(int _n) : graph<T>(_n) {}     int add(int from, int to, T cost = 1) {       assert(0 <= from && from < n && 0 <= to && to < n);       int id = (int)edges.size();       g[from].push_back(id);       g[to].push_back(id);       edges.push_back({from, to, cost});       return id;     }   };   template <typename T>   vector<vector<int>> find_cycles(const graph<T> &g, int bound_cnt = 1 << 30,                                   int bound_size = 1 << 30) {     vector<int> was(g.n, -1);     vector<int> st;     vector<vector<int>> cycles;     int total_size = 0;     function<void(int, int)> dfs = [&](int v, int pe) {       if ((int)cycles.size() >= bound_cnt || total_size >= bound_size) {         return;       }       was[v] = (int)st.size();       for (int id : g.g[v]) {         if (id == pe) {           continue;         }         auto &e = g.edges[id];         int to = e.from ^ e.to ^ v;         if (was[to] >= 0) {           vector<int> cycle(1, id);           for (int j = was[to]; j < (int)st.size(); j++) {             cycle.push_back(st[j]);           }           cycles.push_back(cycle);           total_size += (int)cycle.size();           if ((int)cycles.size() >= bound_cnt || total_size >= bound_size) {             return;           }           continue;         }         if (was[to] == -1) {           st.push_back(id);           dfs(to, id);           st.pop_back();         }       }       was[v] = -2;     };     for (int i = 0; i < g.n; i++) {       if (was[i] == -1) {         dfs(i, -1);       }     }     return cycles;   }   template <typename T>   vector<int> edges_to_vertices(const graph<T> &g,                                 const vector<int> &edge_cycle) {     int sz = (int)edge_cycle.size();     vector<int> vertex_cycle;     if (sz <= 2) {       vertex_cycle.push_back(g.edges[edge_cycle[0]].from);       if (sz == 2) {         vertex_cycle.push_back(g.edges[edge_cycle[0]].to);       }     } else {       for (int i = 0; i < sz; i++) {         int j = (i + 1) % sz;         auto &e = g.edges[edge_cycle[i]];         auto &other = g.edges[edge_cycle[j]];         if (other.from == e.from || other.to == e.from) {           vertex_cycle.push_back(e.to);         } else {           vertex_cycle.push_back(e.from);         }       }     }     return vertex_cycle;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     undigraph<int> g(n);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       --x;       --y;       g.add(x, y);     }     vector<vector<int>> cycles = find_cycles(g);     vector<vector<int>> events(m);     for (auto &cycle : cycles) {       int sz = (int)cycle.size();       int pos = (int)(min_element(cycle.begin(), cycle.end()) - cycle.begin());       rotate(cycle.begin(), cycle.begin() + pos, cycle.end());       pos = (int)(max_element(cycle.begin(), cycle.end()) - cycle.begin());       bool ok = true;       for (int i = 0; i < pos - 1; i++) {         if (cycle[i] > cycle[i + 1]) {           ok = false;           break;         }       }       for (int i = pos; i < sz - 1; i++) {         if (cycle[i] < cycle[i + 1]) {           ok = false;           break;         }       }       if (ok) {         events[cycle[pos]].push_back(cycle[0]);       }     }     vector<int> sub(m, 0);     vector<int> ans(n, 1);     for (int i = m - 1; i >= 0; i--) {       auto &e = g.edges[i];       int x = e.from;       int y = e.to;       int cur = ans[x] + ans[y] - sub[i];       ans[x] = ans[y] = cur;       for (int j : events[i]) {         sub[j] += cur;       }     }     for (int i = 0; i < n; i++) {       if (i > 0) {         cout <<    ;       }       cout << ans[i] - 1;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cout << 0 <<     << 0 <<     << n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     register int res = 0, c;     while (c = getchar(), c <  0  || c >  9 )       ;     do {       res = (res << 3) + (res << 1) + (c ^ 48);     } while (c = getchar(), c >=  0  && c <=  9 );     return res;   }   const int inf = 0x3f3f3f3f;   const int maxn = 100010;   const int maxd = 8000010;   int T[maxd], s[maxn], lson[maxd], rson[maxd], val[maxd], tot;   int l[maxn], r[maxn], d[maxn];   vector<int> edge[maxn], lay[maxn];   int N, R, last, dep, dfn;   void dfs(int x, int dep) {     l[x] = ++dfn;     d[x] = dep;     ::dep = max(dep, ::dep);     lay[dep].push_back(x);     for (auto i : edge[x])       if (!l[i]) {         dfs(i, dep + 1);       }     r[x] = dfn;   }   void update(int to, int L, int R, int& rt) {     if (L == R) {       val[rt = ++tot] = s[to];       return;     }     int mid = L + R >> 1;     lson[++tot] = lson[rt];     rson[tot] = rson[rt];     rt = tot;     if (l[to] <= mid)       update(to, L, mid, lson[rt]);     else       update(to, mid + 1, R, rson[rt]);     val[rt] = min(val[lson[rt]], val[rson[rt]]);   }   int query(int l, int r, int L, int R, int rt) {     if (L >= l && R <= r) {       return val[rt];     }     int mid = L + R >> 1, res = inf;     if (mid >= l) res = query(l, r, L, mid, lson[rt]);     if (mid < r) res = min(res, query(l, r, mid + 1, R, rson[rt]));     return res;   }   int main() {     N = read(), R = read();     for (int i = 1; i <= N; i++) s[i] = read();     for (int i = 1; i < N; i++) {       int x = read(), y = read();       edge[x].push_back(y);       edge[y].push_back(x);     }     dfs(R, 1);     T[0] = lson[0] = rson[0] = 0;     val[0] = inf;     for (int d = 1; d <= dep; d++) {       T[d] = ++tot;       lson[tot] = lson[T[d - 1]];       rson[tot] = rson[T[d - 1]];       for (auto i : lay[d]) update(i, 1, N, T[d]);     }     int Q = read();     while (Q--) {       int X = (last + read()) % N + 1, K = (read() + last) % N;       printf( %d n , last = query(l[X], r[X], 1, N, T[min(dep, d[X] + K)]));     }   }


#include <bits/stdc++.h>   int main(void) {     int n;     std::cin >> n;     int arr[2 * n];     for (int i = 0; i < 2 * n; i++) std::cin >> arr[i];     int swc = 0;     for (int i = 0; i < 2 * n; i += 2) {       int pos = -1;       for (int j = i + 1; j < 2 * n; j++) {         if (arr[j] == arr[i]) {           pos = j;           break;         }       }       for (int j = pos; j > i + 1; j--) {         swc++;         std::swap(arr[j], arr[j - 1]);       }     }     std::cout << swc <<   n ;     return 0;   }