#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void getar(T a, int n, int m) {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; ++j) {         scanf( %d , &a[i][j]);       }   }   inline void getar(int *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , a + ii);     }   }   inline void getar(pair<int, int> *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( d , &a[ii].first, &a[ii].second);     }   }   inline void getar(long long *a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , a + ii);     }   }   inline void getv(vector<int> &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , &a[ii]);     }   }   inline void getv(vector<long long> &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , &a[ii]);     }   }   inline void getv(vector<pair<int, int> > &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %d , &a[ii].first, &a[ii].second);     }   }   inline void getv(vector<pair<long long, long long> > &a, int n) {     for (int ii = 0; ii < n; ii++) {       scanf( %I64d , &a[ii].first, &a[ii].second);     }   }   inline void getvv(vector<vector<int> > &a, int n, int m) {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; ++j) {         scanf( %d , &a[i][j]);       }   }   inline void printa(int *a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %d  , a[ii]);     }   }   inline void printa(long long *a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %I64d  , a[ii]);     }   }   inline void printv(vector<int> &a, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %d  , a[ii]);     }   }   inline void printv(vector<long long> &a, int n, int i, int j) {     for (int ii = i; ii <= j; ii++) {       printf( %I64d  , a[ii]);     }   }   inline long long max(long long a, long long b) { return (a > b) ? a : b; }   inline int max(int a, int b) { return (a > b) ? a : b; }   inline double max(double a, double b) { return (a > b) ? a : b; }   inline long long max(long long a, long long b, long long c) {     return max(a, max(b, c));   }   inline int max(int a, int b, int c) { return max(a, max(b, c)); }   inline double max(double a, double b, double c) { return max(a, max(b, c)); }   inline long long min(long long a, long long b) { return (a < b) ? a : b; }   inline int min(int a, int b) { return (a < b) ? a : b; }   inline double min(double a, double b) { return (a < b) ? a : b; }   inline long long min(long long a, long long b, long long c) {     return min(a, min(b, c));   }   inline int min(int a, int b, int c) { return min(a, min(b, c)); }   inline double min(double a, double b, double c) { return min(a, min(b, c)); }   inline long long pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res *= x;       x *= x;       n >>= 1;     }     return res;   }   inline long long powmod(long long x, long long n, long long _mod) {     long long res = 1;     while (n) {       if (n & 1) res = (res * x) % _mod;       x = (x * x) % _mod;       n >>= 1;     }     return res;   }   inline long long gcd(long long a, long long b) {     long long t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline int gcd(int a, int b) {     int t;     while (b) {       a = a % b;       t = a;       a = b;       b = t;     }     return a;   }   inline long long lcm(int a, int b) { return a / gcd(a, b) * (long long)b; }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long gcd(long long a, long long b, long long c) {     return gcd(gcd(a, b), c);   }   inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); }   inline long long lcm(long long a, long long b, long long c) {     return lcm(lcm(a, b), c);   }   inline long long lcm(int a, int b, int c) {     return lcm(lcm(a, b), (long long)c);   }   inline int bits_count(int v) {     v = v - ((v >> 1) & 0x55555555);     v = (v & 0x33333333) + ((v >> 2) & 0x33333333);     return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;   }   inline int bits_count(long long v) {     long long t = v >> 32;     long long p = (v & ((1LL << 32) - 1));     return bits_count(t) + bits_count(p);   }   inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }   const char nl =   n ;   void solve() {     int n;     cin >> n;     vector<int> a(n);     getv(a, n);     int last = -1, cnt = 0;     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) {       if (a[i] != 1 && last < a[i] - 1)         last = a[i] - 1, cnt++;       else if (last < a[i])         last = a[i], cnt++;       else if (last < a[i] + 1)         last = a[i] + 1, cnt++;     }     cout << cnt << nl;   }   int main() {     clock_t clk = clock();     cerr <<  Hey P.. n ;     int t;     t = 1;     while (t--) solve();     cerr <<  Look at the sky. n ;     cerr <<  Time (in ms):   << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC          <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   const int N = 1e6 + 5;   struct ele {     int f, g;     ele(int a = 0, int b = 0) : f(a), g(b) {}     bool operator<(const ele A) const {       if (f != A.f) return f < A.f;       return g > A.g;     }   };   ele operator+(const ele a, const ele b) { return ele(a.f + b.f, a.g + b.g); }   ele f[N];   char c[N];   int s[N];   int n, k, l;   ele dp(int mid) {     for (int i = 0; i < l; i++) f[i] = ele(0, 0);     for (int i = l; i <= n; i++)       f[i] = max(f[i - 1], f[i - l] + ele(s[i] - s[i - l] - mid, 1));     return f[n];   }   int solve(int opt) {     for (int i = 1; i <= n; i++)       s[i] = s[i - 1] + ((c[i] >=  a  && c[i] <=  z ) == opt);     int l = 0, r = n - 1, ans = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (dp(mid).g <= k)         ans = mid, r = mid - 1;       else         l = mid + 1;     }     return s[n] - (dp(ans).f + ans * k);   }   int main() {     read(n);     read(k);     read(l);     scanf( %s , c + 1);     if (1ll * k * l > n) {       print(0,   n );       return 0;     }     print(min(solve(0), solve(1)),   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int legs[N];   bool hide[N];   vector<vector<int> > adj;   void dfs(int v, int par = 0) {     if (adj[v].size() <= 2u) {       hide[v] = true;       for (int i : adj[v]) {         if (i != par) {           dfs(i, v);         }       }     }   }   int main() {     int n, a, b;     scanf( %d , &n);     adj.resize(n + 1);     for (int i = 0; i < n - 1; ++i) {       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = 1; i <= n; ++i) {       if (adj[i].size() == 1u) {         dfs(i);       }     }     for (int i = 1; i <= n; ++i) {       for (int j : adj[i]) {         if (hide[j]) {           legs[i] = min(2, legs[i] + 1);         }       }     }     for (int i = 1; i <= n; ++i) {       if (!hide[i]) {         int count = 0;         for (int j : adj[i]) {           if (!hide[j] && (int)adj[j].size() - legs[j] > 1) {             ++count;           }         }         if (count > 2) {           printf( No n );           return 0;         }       }     }     printf( Yes n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int parent[5001][5001];   int dp[5001][5001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, m, t;     cin >> n >> m >> t;     vector<int> u(m + 1), v(m + 1), tm(m + 1);     for (int i = 1; i <= m; i++) {       cin >> u[i] >> v[i] >> tm[i];     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = 1e9 + 5;       }     }     dp[1][1] = 0;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         int p = u[j];         int cur = v[j];         if (dp[p][i - 1] + tm[j] < dp[cur][i]) {           dp[cur][i] = dp[p][i - 1] + tm[j];           parent[cur][i] = p;         }       }     }     int res = 0;     for (int i = n; i > 0; i--) {       if (dp[n][i] <= t) {         res = i;         break;       }     }     cout << res << endl;     int ind = n;     int visit = res;     vector<int> path;     while (ind != 0) {       path.push_back(ind);       ind = parent[ind][visit--];     }     for (int i = path.size() - 1; i >= 0; i--) {       cout << path[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> dp[1100][20];   int bitcnt[1100];   long long p10[21];   string a;   int n, k;   pair<long long, long long> dfs(int bi, int pos, int flag, int leading) {     if (pos == -1) return make_pair(0, 1);     if (dp[bi][pos].second != -1 && !flag && !leading) {       return dp[bi][pos];     }     long long ans = 0;     long long cnt = 0;     int upper = (flag ? a[n - pos - 1] -  0  : 9);     for (int i = 0; i <= upper; i++) {       int nextstate = (bi | (1 << i));       if ((bi & (1 << i)) == 0 && !(leading && i == 0)) {         if (bitcnt[nextstate] > k) continue;         pair<long long, long long> p =             dfs(nextstate, pos - 1, flag && (i == upper), leading && (i == 0));         cnt = (cnt + p.second) % 998244353;         ans = (ans +                ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) %                    998244353) %               998244353;       } else {         pair<long long, long long> p =             dfs(bi, pos - 1, flag && (i == upper), leading && (i == 0));         cnt = (cnt + p.second) % 998244353;         ans = (ans +                ((((p.second * i) % 998244353) * p10[pos]) % 998244353 + p.first) %                    998244353) %               998244353;       }     }     if (!flag && !leading) {       dp[bi][pos] = make_pair(ans % 998244353, cnt % 998244353);     }     return make_pair(ans % 998244353, cnt % 998244353);   }   long long solve(long long num) {     a = to_string(num);     n = (int)a.length();     pair<long long, long long> p = dfs(0, n - 1, 1, 1);     return p.first % 998244353;   }   int main() {     long long l, r;     int i, j;     p10[0] = 1;     for (i = 1; i <= 20; i++) {       p10[i] = (p10[i - 1] * 10) % 998244353;     }     for (i = 0; i < 1100; i++) {       for (j = 0; j < 20; j++) {         dp[i][j] = make_pair(0, -1);       }     }     bitcnt[0] = 0;     bitcnt[1] = 1;     for (i = 2; i < 1100; i++) bitcnt[i] = bitcnt[i - (i & -i)] + 1;     cin >> l >> r >> k;     cout << (solve(r) - solve(l - 1) + 998244353) % 998244353 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   string s;   int main() {     int t, cas = 1;     cin >> s;     int n = ((int)(s).size());     for (int i = 1; i <= n / 2; i++) {       int cnt = 0;       for (int j = 0; j < n - i; j++) {         if (s[j] == s[j + i])           cnt++;         else           cnt = 0;         if (cnt == i) {           s = s.substr(0, j - i + 1) + s.substr(j + 1, n - j - 1);           n -= i;           i = 0;           break;         }       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int b[200005];     vector<int> a;     cin >> n;     a.push_back(31);     a.push_back(28);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(31);     a.push_back(30);     a.push_back(31);     a.push_back(30);     a.push_back(31);     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < 12; i++) {       int count = 0, f = 0;       for (int j = 0; j < n; j++) {         if ((i + j) % 12 == 1) {           if (a[(i + j) % 12] == b[j])             continue;           else {             if (a[(i + j) % 12] == 28 && b[j] == 29 && count == 0) {               count = 1;               continue;             }           }         }         if (a[(i + j) % 12] != b[j]) {           f = 1;           break;         }       }       if (f == 0) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   const double pi = 3.14159265358979323;   struct dpoint {     double x, y;     dpoint() : x(0), y(0) {}     dpoint(double x, double y) : x(x), y(y) {}   };   void run(std::istream& in, std::ostream& out) {     int n;     dpoint p;     in >> n >> p.x >> p.y;     std::vector<dpoint> points(n);     for (int i = 0; i < n; i++) {       in >> points[i].x >> points[i].y;     }     double maxR = 0;     double minR = 1e10;     for (int i = 0; i < n; i++) {       double dist1 = hypot(points[i].x - p.x, points[i].y - p.y);       maxR = std::max(maxR, dist1);       minR = std::min(minR, dist1);       dpoint& p1 = points[i];       dpoint& p2 = points[(i + 1) % n];       if ((p2.x - p1.x) * (p.x - p1.x) + (p2.y - p1.y) * (p.y - p1.y) > 0.5 &&           (p1.x - p2.x) * (p.x - p2.x) + (p1.y - p2.y) * (p.y - p2.y) > 0.5) {         double a = p1.y - p2.y;         double b = p2.x - p1.x;         double dist = a * p.x + b * p.y - a * p1.x - b * p1.y;         dist /= hypot(a, b);         minR = std::min(minR, std::abs(dist));       }     }     out.precision(20);     out << std::fixed;     out << (maxR * maxR - minR * minR) * pi << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastInOut() {     ios_base::sync_with_stdio(0);     cin.tie(NULL), cout.tie(NULL);   }   int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};   int dy[] = {1, -1, 0, 0, -1, 1, -1, 1};   int main() {     double m, n, total = 0.0;     cin >> m >> n;     for (double i = 1; i <= m; i++) {       double temp = pow(i / m, n) - pow((i - 1) / m, n);       temp *= i;       total += temp;     }     cout << fixed << setprecision(12) << total;   }


#include <bits/stdc++.h>   using namespace std;   const int _1e5 = 100000;   const int _1e7 = 10000000;   const int _1e9 = 1000000000;   template <typename A, typename B>   ostream& operator<<(ostream& str, const pair<A, B>& p) {     return str <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& str, const vector<T>& v) {     str <<  [ ;     for (const auto& n : v) str << n <<  ,  ;     str <<  ] ;     return str;   }   template <typename T>   ostream& operator<<(ostream& str, const set<T>& v) {     str <<  { ;     for (const auto& n : v) {       str << n <<  ,  ;     }     str <<  } ;     return str;   }   template <typename K, typename V>   ostream& operator<<(ostream& str, const unordered_map<K, V>& v) {     str <<  { ;     for (const auto& p : v) {       str << p.first <<   =>   << p.second <<  ,  ;     }     str <<  } ;     return str;   }   int main() {     ios_base::sync_with_stdio(false);     cout.setf(std::ios::fixed);     cout.precision(12);     int n;     cin >> n;     string a;     cin >> a;     vector<int> f(10);     f[0] = 0;     for (int i = 1; i <= 9; ++i) {       cin >> f[i];     }     int left_start = -1;     for (int i = 0; i < a.size(); ++i) {       int digit = a[i] -  0 ;       if (f[digit] > digit) {         left_start = i;         break;       }     }     if (left_start == -1) {       cout << a << endl;       return 0;     }     while (true) {       if (left_start >= a.size()) {         break;       }       int digit = a[left_start] -  0 ;       if (f[digit] < digit) {         break;       }       a[left_start++] =  0  + f[digit];     }     cout << a << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<int, int> PII;   long long qpow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % m;       a = a * a % m, b >>= 1;     }     return ans;   }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a;       a = a * a, b >>= 1;     }     return ans;   }   long long qmul(long long a, long long b, long long m) {     long long res = 0;     while (b > 0) {       if (b & 1) res = (res + a) % m;       a = (a + a) % m;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long inv(long long t, long long p) {     return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long r = exgcd(b, a % b, y, x);     y -= (a / b) * x;     return r;   }   long long inv1(long long a, long long p) {     long long d, x, y;     d = exgcd(a, p, x, y);     return d == 1 ? (x % p + p) % p : -1;   }   template <typename T, typename B>   T Add(T a, B b, long long m) {     return a + b >= m ? (a + b) % m : a + b;   }   template <typename T, typename B>   T Sub(T a, B b, long long m) {     return a - b < 0 ? (a - b + m) % m : a - b;   }   template <class T>   void _sf(T &x) {     cin >> x;   }   void _sf(int &x) { scanf( %d , &x); }   void _sf(long long &x) { scanf( %lld , &x); }   void _sf(double &x) { scanf( %lf , &x); }   void _sf(char &x) { scanf(  %c , &x); }   void _sf(char *x) { scanf( %s , x); }   void sf() {}   template <class T, class... U>   void sf(T &head, U &...tail) {     _sf(head);     sf(tail...);   }   template <class T>   void _pf(const T &x) {     cout << x;   }   void _pf(const int &x) { printf( %d , x); }   void _pf(const long long &x) { printf( %lld , x); }   void _pf(const double &x) { printf( %.16f , x); }   void _pf(const char &x) { putchar(x); }   void _pf(const char *x) { printf( %s , x); }   template <class T, class U>   void _pf(const pair<T, U> &x) {     pf(x.first);     putchar(   );     pf(x.second);   }   template <class T>   void _pf(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _pf(*i++))       if (i != x.cbegin()) putchar(   );   }   void pf() {}   template <class T, class... U>   void pf(const T &head, const U &...tail) {     _pf(head);     putchar(sizeof...(tail) ?     :   n );     pf(tail...);   }   template <typename T>   inline void read(T &x) {     x = 0;     static int p;     p = 1;     static char c;     c = getchar();     while (!isdigit(c)) {       if (c ==  - ) p = -1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 1) + (x << 3) + (c - 48);       c = getchar();     }     x *= p;   }   const bool IOS = false;   const double PI = acos(-1);   const double eps = 1e-8;   const long long linf = 0x3f3f3f3f3f3f3f3f;   const long long INV2 = 500000004;   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int maxn = 1e6 + 100;   char s1[maxn], s2[maxn];   long long a[maxn], b[maxn];   void init() {     a[0] = b[0] = 1;     for (int i = 1; i < maxn; ++i) {       a[i] = (a[i - 1] * i) % mod;     }     b[maxn - 1] = qpow(a[maxn - 1], mod - 2, mod);     for (int i = maxn - 1; i > 0; i--) b[i - 1] = b[i] * i % mod;   }   long long C(long long n, long long m) {     if (n < m) return 0;     return a[n] * b[m] % mod * b[n - m] % mod;   }   int cnt[256];   long long calc(char s[], int n) {     memset(cnt, 0, sizeof(cnt));     for (int i = 1; i <= n; ++i) cnt[s1[i]]++;     long long tmp = a[n];     for (int i =  a ; i <=  z ; ++i) tmp = tmp * b[cnt[i]] % mod;     long long ret = 0;     for (int i = 1; i <= n; ++i) {       tmp = tmp * qpow(n - i + 1, mod - 2, mod) % mod;       for (int j =  a ; j < s[i]; ++j)         if (cnt[j]) ret = (ret + tmp * cnt[j] % mod) % mod;       tmp = tmp * cnt[s[i]] % mod;       cnt[s[i]]--;       if (cnt[s[i]] < 0) return ret;     }     return ret;   }   void Main();   int main() {     if (IOS) std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     Main();     0;     return 0;   }   void Main() {     init();     scanf( %s%s , s1 + 1, s2 + 1);     int len = strlen(s1 + 1);     long long res = calc(s2, len) - calc(s1, len);     res--;     res = (res % mod + mod) % mod;     pf(res);   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5 + 10;   int a[MAX_N];   vector<pair<int, int>> scanCuts[2][MAX_N];   pair<int, int> cuts[MAX_N];   int tree[2 * MAX_N], d[2 * MAX_N];   void push(int i) {     d[2 * i + 1] += d[i];     d[2 * i + 2] += d[i];     tree[2 * i + 1] += d[i];     tree[2 * i + 2] += d[i];     d[i] = 0;   }   void pull(int i) {     tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]);     tree[i] += d[i];   }   void build(int i, int l, int r) {     if (r - l == 1) {       tree[i] = a[l];       return;     }     int mid = (l + r) / 2;     build(2 * i + 1, l, mid);     build(2 * i + 2, mid, r);     pull(i);   }   void add(int l, int r, int x, int i, int cl, int cr) {     if (r <= cl || cr <= l) return;     if (l <= cl && cr <= r) {       tree[i] += x;       d[i] += x;       return;     }     int mid = (cl + cr) / 2;     add(l, r, x, 2 * i + 1, cl, mid);     add(l, r, x, 2 * i + 2, mid, cr);     pull(i);   }   int get(int l, int r, int i, int cl, int cr) {     if (r <= cl || cr <= l) return +1e9;     if (l <= cl && cr <= r) return tree[i];     int mid = (cl + cr) / 2;     push(i);     return min(get(l, r, 2 * i + 1, cl, mid), get(l, r, 2 * i + 2, mid, cr));   }   void print(int i, int cl, int cr) {     cout << i <<   (  << cl <<  ;   << cr <<  ) ->   << tree[i] <<     << d[i]          <<   n ;     if (cr - cl == 1) return;     int mid = (cl + cr) / 2;     print(2 * i + 1, cl, mid);     print(2 * i + 2, mid, cr);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; ++i) cin >> a[i];     build(0, 0, n);     set<int> bestAns;     set<int> currAns;     for (int i = 0; i < q; ++i) {       cin >> cuts[i].first >> cuts[i].second;       --cuts[i].first;       currAns.insert(i);       add(cuts[i].first, cuts[i].second, -1, 0, 0, n);       scanCuts[0][cuts[i].first].push_back({cuts[i].second, i});       scanCuts[1][cuts[i].second].push_back({cuts[i].first, i});     }     int ans = 0;     for (int i = 0; i < n; ++i) {       for (auto u : scanCuts[0][i]) {         add(i, u.first, 1, 0, 0, n);         currAns.erase(u.second);       }       for (auto u : scanCuts[1][i]) {         add(u.first, i, -1, 0, 0, n);         currAns.insert(u.second);       }       int lans = get(i, i + 1, 0, 0, n) - get(0, n, 0, 0, n);       if (lans > ans) {         ans = lans;         bestAns = currAns;       }     }     cout << ans <<   n ;     cout << bestAns.size() <<   n ;     for (int u : bestAns) cout << u + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n == 1) return false;     if (n == 2) return true;     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         return false;       }     }     return true;   }   long long poww(long long b, long long e) {     if (e == 0)       return 1;     else if (e % 2 == 0) {       long long a = pow(b, e / 2);       return a * a;     } else {       long long a = pow(b, e / 2);       return b * a * a;     }   }   long long powm(long long x, long long y, long long m = 1000000007) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long modInverse(long long a, long long m = 1000000007) {     return powm(a, m - 2, m);   }   void print(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }   }   void print(long long arr[]) {     long long size = *(&arr + 1) - arr;     for (long long i = 0; i < size; i++) {       cout << arr[i] <<    ;     }   }   string to_bin(long long n) {     string res =   ;     long long i = 0;     while (n > 0) {       if (n % 2 == 1) {         res = res +  1 ;       } else {         res = res +  0 ;       }       n /= 2;       i++;     }     reverse(res.begin(), res.end());     return res;   }   long long to_dec(string second) {     long long n = second.size(), ans = 0, temp = 1;     for (long long i = n - 1; i >= 0; i--) {       long long x = second[i] -  0 ;       ans += x * temp;       temp *= 2;     }     return ans;   }   void result(bool first) {     if (first)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   void solve() {     long long a, b, p;     cin >> a >> b >> p;     string second;     cin >> second;     reverse(second.begin(), second.end());     long long n = second.length();     long long ind = 1;     long long maxi;     for (long long i = 1; i < n; i++) {       char ch = second[i];       if (second[i] ==  B ) {         if (p >= b) {           p -= b;           if (i != n - 1) {             while (second[i + 1] ==  B ) {               i++;             }           }           ind = i + 1;         } else           break;       } else if (second[i] ==  A ) {         if (p >= a) {           p -= a;           if (i != n - 1) {             while (second[i + 1] ==  A ) {               i++;             }           }           ind = i + 1;         } else           break;       }     }     long long ans = n - ind + 1;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio();     cin.tie(0);     cout.tie(0);     long long tests;     cin >> tests;     while (tests--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int C = 10005, N = 1005;   int n, w, b, x, c[N], cost[N];   long long dp[2][C];   template <class T>   void maxz(T &a, T b) {     if (a < b) a = b;   }   int main() {     int i, j, k, ub;     long long mn;     scanf( %d%d%d%d , &n, &w, &b, &x);     for (i = 1; i <= n; i++) scanf( %d , c + i);     for (i = 1; i <= n; i++) scanf( %d , cost + i);     memset(dp[0], -1, sizeof(dp[0]));     ub = 1;     dp[0][0] = w;     for (i = 1; i <= n; i++) {       memset(dp[i & 1], -1, sizeof(dp[0]));       for (j = 0; j < ub; j++)         if (dp[~i & 1][j] >= 0) {           mn = min(dp[~i & 1][j] + x, w + (long long)b * j);           for (k = 0; k <= c[i] && mn >= 0; k++) {             maxz(dp[i & 1][j + k], mn);             mn -= cost[i];           }           maxz(ub, j + k);         }     }     printf( %d , ub - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r = 2, g = 5, b = 8, n, k;   int h, j, p;   int main() {     cin >> n >> k;     h = r * n;     j = g * n;     p = b * n;     h = (h + k - 1) / k;     j = (j + k - 1) / k;     p = (p + k - 1) / k;     cout << p + j + h;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<long long>> dp(10, vector<long long>(1000005, 0));   long long g(long long n) {     if (n < 10) return n;     long long ans = 1;     while (n) {       if (n % 10) ans *= (n % 10);       n /= 10;     }     return g(ans);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (long long i = 1; i <= 1000000; i++) dp[g(i)][i]++;     for (long long i = 0; i < 10; i++) {       for (long long j = 2; j <= 1000000; j++) {         dp[i][j] += dp[i][j - 1];       }     }     long long t;     cin >> t;     while (t--) {       long long l, r, k;       cin >> l >> r >> k;       cout << dp[k][r] - dp[k][l - 1] <<   n ;     }   }


#include <bits/stdc++.h>   const int MOD = 1e9;   const int N = 100003;   using namespace std;   vector<int> ans;   int main() {     int n;     cin >> n;     int p, q;     p = q = 0;     for (int i = 0; i < n; i++) {       char c;       int x, y;       cin >> c;       scanf( %d , &x);       scanf( %d , &y);       if (x > y) swap(x, y);       if (c ==  + )         p = max(p, x), q = max(q, y);       else if (p <= x && q <= y)         cout <<  YES ;       else         cout <<  NO ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 69;   const int inf = 1e9 + 5;   const long long mod = 1e9 + 7;   const long double eps = 1e-10;   vector<int> v[MX];   int par[24][MX];   int depth[MX];   void dfs(int x, int p) {     for (auto g : v[x]) {       if (g == p) {         continue;       }       depth[g] = depth[x] + 1;       dfs(g, x);       par[0][g] = x;     }   }   int lca(int x, int y) {     if (depth[x] > depth[y]) swap(x, y);     int i = 22;     while (depth[x] < depth[y]) {       if (depth[par[i][y]] >= depth[x]) {         y = par[i][y];       }       i--;     }     for (int i = 22; i >= 0; i--) {       if (par[i][x] != par[i][y]) {         x = par[i][x];         y = par[i][y];       }     }     if (x != y) {       x = par[0][x];       y = par[0][y];     }     return x;   }   int dis(int a, int b) { return (depth[a] + depth[b] - 2 * depth[lca(a, b)]); }   int cal(int a, int b, int c) {     int ret = 0;     int q1 = lca(a, b);     int q2 = lca(a, c);     int q3 = lca(b, c);     if (depth[q1] >= max(depth[q2], depth[q3])) {       ret = dis(lca(a, b), c);     } else {       ret = dis((depth[q2] >= depth[q3] ? q2 : q3), c);     }     return ret;   }   int main() {     depth[0] = -1;     int n, q;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int b;       scanf( %d , &b);       v[i].push_back(b);       v[b].push_back(i);     }     dfs(1, -1);     for (int i = 1; i < 23; i++) {       for (int j = 1; j <= n; j++) {         par[i][j] = par[i - 1][par[i - 1][j]];       }     }     while (q--) {       int ans = 0;       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       ans = max(cal(a, b, c), max(cal(a, c, b), cal(b, c, a)));       printf( %d n , ans + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int>> g(n);     vector<pair<int, int>> e(n - 1);     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);       e[i] = make_pair(u, v);     }     vector<int> col(n);     for (int &i : col) {       cin >> i;     }     int diff = 0;     for (auto i : e) {       if (col[i.first] != col[i.second]) {         ++diff;       }     }     for (int i = 0; i < n; ++i) {       int ctr = 0;       for (int j : g[i]) {         if (col[i] != col[j]) {           ++ctr;         }       }       if (ctr == diff) {         cout <<  YES n  << i + 1;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, k;   int a[20];   bitset<2001> d[66000];   multiset<pair<int, int> > s;   void solve(int now, int cs, int r) {     if (!now) return;     while (cs <= 2000) {       for (int i = 1; i <= n; i++) {         if (((now >> (i - 1)) & 1) && cs >= a[i] &&             d[now ^ (1 << (i - 1))][cs - a[i]]) {           s.insert(make_pair(-r, a[i]));           solve(now ^ (1 << (i - 1)), cs - a[i], r);           return;         }       }       cs = cs * k, r++;     }     assert(0);   }   int main() {     n = readint();     k = readint();     for (int i = 1; i <= n; i++) a[i] = readint();     d[0][0] = 1;     for (int i = 1; i < (1 << n); i++) {       for (int j = 1; j <= n; j++)         if ((i >> (j - 1)) & 1) d[i] |= d[i ^ (1 << (j - 1))] << a[j];       for (int j = 2000 / k; j >= 1; j--)         if (d[i][j * k]) d[i][j] = 1;     }     if (!d[(1 << n) - 1][1]) return printf( NO n ), 0;     printf( YES n );     solve((1 << n) - 1, 1, 0);     while (s.size() > 1) {       auto it1 = s.begin(), it2 = it1;       it2++;       assert(it1->first == it2->first);       printf( %d %d n , it1->second, it2->second);       int tmp = it1->second + it2->second, dep = -it1->first;       while (tmp % k == 0) tmp /= k, dep--;       s.erase(it1);       s.erase(it2);       s.insert(make_pair(-dep, tmp));     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int a, b;     scanf( %lld%lld , &a, &b);     if (a > b) {       printf( %lld %lld , b, (a - b) / 2);     } else {       printf( %lld %lld , a, (b - a) / 2);     }   }


#include <bits/stdc++.h>   int main() {     int a, b, c, ab = -1, min;     scanf( %d %d %d , &a, &b, &c);     min = b;     if (a < b) min = a;     for (int i = 0; i <= min; i++) {       if (b + a - 2 * i == c) {         ab = i;         break;       }     }     if (ab == -1)       printf( Impossible );     else       printf( %d %d %d , ab, b - ab, a - ab);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   set<int> fang[400001];   map<int, int> cishu[400001];   int n, m, q, to1[400001], Nxt[400001], first1[400001], dfn[400001], low[400001];   int to[500001], nxt[500001], first[500001], cnt, e1, x2, fa[400001];   int sum, tot = 0, ss[400001], heavy[400001], siz[400001], seg[1000001];   int pos[400001], top[400001], deep[400001], h = 0, Stack[400001 * 10];   char ch;   void Build(int x, int y) {     to1[cnt] = y;     Nxt[cnt] = first1[x];     first1[x] = cnt++;   }   void insert(int x, int y) {     to[e1] = y;     nxt[e1] = first[x];     first[x] = e1++;   }   void tarjan(int x) {     dfn[x] = low[x] = ++tot;     Stack[++h] = x;     for (int i = first1[x]; i != -1; i = Nxt[i])       if (!dfn[to1[i]]) {         tarjan(to1[i]);         low[x] = min(low[x], low[to1[i]]);         if (dfn[x] <= low[to1[i]]) {           int z;           sum++;           do {             z = Stack[h--];             insert(sum, z);             insert(z, sum);           } while (z != to1[i]);           insert(sum, x);           insert(x, sum);         }       } else         low[x] = min(low[x], dfn[to1[i]]);   }   void dfs(int o, int p) {     siz[o] = 1;     deep[o] = deep[p] + 1;     fa[o] = p;     for (int i = first[o]; i != -1; i = nxt[i])       if (to[i] != p) {         dfs(to[i], o);         siz[o] += siz[to[i]];         if (siz[to[i]] > siz[heavy[o]]) heavy[o] = to[i];       }   }   void dfs1(int o, int p) {     pos[o] = ++x2;     if (heavy[o] > 0) {       top[heavy[o]] = top[o];       dfs1(heavy[o], o);       for (int i = first[o]; i != -1; i = nxt[i])         if ((to[i] != p) && (to[i] != heavy[o])) {           top[to[i]] = to[i];           dfs1(to[i], o);         }     }   }   void put(int o, int p, int q, int r, int s) {     if ((o == q) && (p == q)) {       seg[r] = s;       return;     }     int mid = (o + p) / 2;     if (q <= mid) {       put(o, mid, q, r * 2, s);       seg[r] = min(seg[r * 2 + 1], seg[r * 2]);     } else {       put(mid + 1, p, q, r * 2 + 1, s);       seg[r] = min(seg[r * 2], seg[r * 2 + 1]);     }   }   int get(int o, int p, int q, int r, int s) {     if ((o == q) && (p == r)) return seg[s];     int mid = (o + p) / 2;     if (r <= mid)       return get(o, mid, q, r, s * 2);     else if (q > mid)       return get(mid + 1, p, q, r, s * 2 + 1);     else       return min(get(o, mid, q, mid, s * 2),                  get(mid + 1, p, mid + 1, r, s * 2 + 1));   }   int gettree(int o, int p) {     int yu = INF;     while (top[o] != top[p]) {       if (deep[top[o]] < deep[top[p]]) {         int t = o;         o = p;         p = t;       }       yu = min(yu, get(1, sum, pos[top[o]], pos[o], 1));       o = fa[top[o]];     }     if (deep[o] > deep[p]) {       int t = o;       o = p;       p = t;     }     yu = min(yu, get(1, sum, pos[o], pos[p], 1));     if (o > n) yu = min(yu, ss[fa[o]]);     return yu;   }   int main() {     memset(first1, -1, sizeof(first1));     memset(first, -1, sizeof(first));     scanf( %d%d%d , &n, &m, &q);     sum = n;     for (int i = 1; i <= n; i++) scanf( %d , &ss[i]);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       Build(x, y);       Build(y, x);     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) tarjan(i);     deep[0] = 0;     dfs(1, 0);     top[1] = 1;     dfs1(1, 0);     for (int i = 1; i <= n; i++)       if (fa[i] > 0) {         fang[fa[i]].insert(ss[i]);         if (!cishu[fa[i]].count(ss[i])) cishu[fa[i]][ss[i]] = 0;         cishu[fa[i]][ss[i]]++;       }     for (int i = n + 1; i <= sum; i++) ss[i] = *fang[i].begin();     for (int i = 0; i <= 1000000; i++) seg[i] = INF + 1;     for (int i = 1; i <= sum; i++) put(1, sum, pos[i], 1, ss[i]);     for (int i = 1; i <= q; i++) {       int x, y;       getchar();       scanf( %c%d%d , &ch, &x, &y);       if (ch ==  C ) {         if (fa[x] > 0) {           cishu[fa[x]][ss[x]]--;           if (cishu[fa[x]][ss[x]] == 0) fang[fa[x]].erase(ss[x]);           if (!cishu[fa[x]].count(y)) cishu[fa[x]][y] = 0;           cishu[fa[x]][y]++;           fang[fa[x]].insert(y);           put(1, sum, pos[fa[x]], 1, (*fang[fa[x]].begin()));         }         put(1, sum, pos[x], 1, y);         ss[x] = y;       } else         cout << gettree(x, y) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, b, d;     cin >> n >> b >> d;     int cur = 0, cnt = 0;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a > b) continue;       cur += a;       if (cur > d) {         cnt++;         cur = 0;       }     }     if (cur > d) cnt++;     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const int N = (int)1e5 + 10;   struct qq {     int l, r, i, w;   };   int t[4 * N], ans[2 * N];   pair<int, int> p[2 * N];   vector<qq> qx[N], qy[N];   void upd(int pos, int val, int v = 1, int l = 1, int r = N - 10) {     if (l == r) {       t[v] = val;       return;     }     int m = (l + r) >> 1;     if (pos <= m) {       upd(pos, val, v + v, l, m);     } else {       upd(pos, val, v + v + 1, m + 1, r);     }     t[v] = min(t[v + v], t[v + v + 1]);   }   int get(int l, int r, int v = 1, int tl = 1, int tr = N - 10) {     if (l > r || tr < l || tl > r) {       return inf;     }     if (l <= tl && tr <= r) {       return t[v];     }     int tm = (tl + tr) >> 1;     return min(get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr));   }   inline bool cmp(pair<int, int> f, pair<int, int> s) {     return f.second < s.second || (f.second == s.second && f.first < s.first);   }   int main() {     int n, m, k, q;     scanf( %d %d %d %d , &n, &m, &k, &q);     for (int i = 1; i <= k; i++) {       int x, y;       scanf( %d %d , &x, &y);       p[i] = {x, y};     }     for (int i = 1; i <= q; i++) {       int ax, ay, bx, by;       scanf( %d %d %d %d , &ax, &ay, &bx, &by);       qx[bx].emplace_back(qq({ay, by, i, ax}));       qy[by].emplace_back(qq({ax, bx, i, ay}));     }     sort(p + 1, p + k + 1);     int ptr = 1;     for (int i = 1; i < N; i++) {       while (ptr <= k && p[ptr].first == i) {         upd(p[ptr].second, i);         ptr++;       }       for (auto j : qx[i]) {         ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0);       }     }     memset(t, 0, sizeof(t));     ptr = 1;     sort(p + 1, p + k + 1, cmp);     for (int i = 1; i < N; i++) {       while (ptr <= k && p[ptr].second == i) {         upd(p[ptr].first, i);         ptr++;       }       for (auto j : qy[i]) {         ans[j.i] |= ((get(j.l, j.r) >= j.w) ? 1 : 0);       }     }     for (int i = 1; i <= q; i++) {       if (ans[i] == 1)         puts( YES );       else         puts( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 3e5 + 10, N2 = 2e5, delta = 10499, mod = 1e9 + 7,                       oo = 1e18, LOG = 20, SQ = 300;   const long double PI = 3.141592653589793;   pair<pair<long long int, long long int>, long long int> p[N];   int32_t main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       for (long long int i = 0; i < 2 * n - 1; i++) {         long long int x, y;         cin >> x >> y;         p[i] = {{x, y}, i};       }       cout <<  YES n ;       sort(p, p + 2 * n - 1);       for (long long int i = 0; i < 2 * n - 2; i += 2) {         if (p[i].first.second < p[i + 1].first.second)           cout << p[i + 1].second + 1 <<    ;         else           cout << p[i].second + 1 <<    ;       }       cout << p[2 * n - 2].second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     fixed(cout);     cout << setprecision(10);     ;     long long int n, h;     cin >> n >> h;     for (int i = 1; i <= n - 1; i++) {       double x = (h * h * i) / double(n);       x = sqrt(x);       if (i == n) break;       cout << x <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int tipo[100000 + 5];   int main() {     int n, x, y, z, m;     cin >> n >> m;     memset(tipo, -1, sizeof(tipo));     for (int i = 0; i < m; ++i) {       cin >> x >> y >> z;       x--, y--, z--;       bool enc = 0;       if (tipo[x] != -1) {         enc = 1;         tipo[y] = (tipo[x] + 1) % 3;         tipo[z] = (tipo[x] + 2) % 3;       } else if (tipo[y] != -1) {         enc = 1;         tipo[x] = (tipo[y] + 1) % 3;         tipo[z] = (tipo[y] + 2) % 3;       } else if (tipo[z] != -1) {         enc = 1;         tipo[x] = (tipo[z] + 1) % 3;         tipo[y] = (tipo[z] + 2) % 3;       }       if (enc == 0) {         tipo[x] = 0, tipo[y] = 1, tipo[z] = 2;       }     }     for (int i = 0; i < n; ++i) {       if (i == 0)         cout << tipo[i] + 1;       else         cout <<     << tipo[i] + 1;     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int vis[10] = {0};   int main() {     int c = 0, n = 0, i, flag = 0;     long long ans = 1;     string s;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ? ) {         if (i == 0) flag = 1;         c++;       }       if (s[i] >=  A  && s[i] <=  J ) {         if (i == 0) flag = 1;         vis[s[i] -  A ] = 1;       }     }     for (i = 0; i < 10; i++)       if (vis[i]) n++;     for (i = 0; i < n; i++) ans *= 10 - i;     if (flag) {       ans *= 9;       if (ans % 10 == 0) {         ans /= 10;         flag = 0;       }     }     cout << ans;     for (i = flag; i < c; i++) cout << 0;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int32_t main() {     c_p_c();     long long t;     cin >> t;     while (t--) {       long long n, r;       cin >> n >> r;       long long k = r;       r = min(n - 1, r);       long long ans = r * (r + 1) / 2;       if (k > r) ans++;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   const int inf = 0x3f3f3f3f;   vector<int> ve[maxn];   int a[maxn], c[maxn];   struct node {     int pos, val;   } nod[maxn];   bool cmp(node a, node b) { return a.val < b.val; }   bool cmp1(int x, int y) { return nod[a[x]].val > nod[a[y]].val; }   int main() {     int n, q, k, x, y;     scanf( %d , &n);     for (int i = 0; i <= n; i++) {       ve[i].clear();       nod[i].val = 0;       nod[i].pos = 0;     }     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       ve[x].push_back(y);       nod[x].pos = x;       nod[x].val = max(nod[x].val, y);     }     sort(nod + 1, nod + 1 + n, cmp);     for (int i = 1; i <= n; i++) a[nod[i].pos] = i;     scanf( %d , &q);     int ans, res;     while (q--) {       int max1 = nod[n].val, pos1 = nod[n].pos;       int max2 = nod[n - 1].val, pos2 = nod[n - 1].pos, s, j = n - 2;       scanf( %d , &k);       for (int i = 0; i < k; i++) scanf( %d , &c[i]);       sort(c, c + k, cmp1);       for (int i = 0; i < k; i++) {         if (c[i] == pos1) {           max1 = max2;           pos1 = pos2;           max2 = nod[j].val;           pos2 = nod[j--].pos;         } else if (c[i] == pos2) {           max2 = nod[j].val;           pos2 = nod[j--].pos;         }       }       if (max1 == 0)         ans = 0, res = 0;       else {         int l = 0, r = ve[pos1].size(), mid;         while (l < r) {           mid = l + (r - l) / 2;           if (max2 <= ve[pos1][mid])             r = mid;           else             l = mid + 1;         }         ans = pos1;         res = ve[pos1][l];       }       printf( %d %d n , ans, res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod_expo(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int main() {     long long int t;     cin >> t;     while (t--) {       map<long long int, long long int> right;       long long int n;       cin >> n;       long long int ar[2 * n + 4];       long long int dp[2 * n + 3];       for (long long int i = 0; i < 2 * n; i++) {         cin >> ar[i];       }       long long int count = 0;       for (long long int i = 0; i < n; i++) {         if (ar[i] == 1)           count++;         else {           count--;         }         dp[i] = count;       }       count = 0;       for (long long int i = 2 * n - 1; i >= n; i--) {         if (ar[i] == 1)           count--;         else {           count++;         }         dp[i] = count;         right[count] = i;       }       long long int mini = 2 * n;       for (long long int i = 0; i < 2 * n; i++) {         if (dp[i] == 0) {           if (i < n && mini > (2 * n - i - 1))             mini = 2 * n - i - 1;           else if (i >= n && mini > (i))             mini = i;         }       }       for (long long int i = n - 1; i >= 0; i--) {         long long int p = dp[i];         long long int k = right[p];         if (k > 0 && mini > (k - i - 1)) mini = k - i - 1;       }       cout << mini << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long A, B;     cin >> A >> B;     if (A < B) {       puts( -1 );       return 0;     }     if ((A - B) % 2 != 0) {       puts( -1 );       return 0;     }     unsigned long long C = (A - B) / 2;     unsigned long long X = 0, Y = 0;     for (unsigned long long bit = 1ULL << 63; bit >= 1; bit >>= 1) {       bool dif = (B & bit);       bool allHas = (C & bit);       if (allHas && dif) {         puts( -1 );         return 0;       }       if (allHas) {         X |= bit;         Y |= bit;       }       if (dif) {         Y |= bit;       }     }     cout << X <<     << Y << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e4 + 10;   int n, w, b, x;   long long dp[1005][maxN];   int c[maxN];   int cost[maxN];   int main() {     cin >> n >> w >> b >> x;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= n; i++) cin >> cost[i];     memset(dp, -1, sizeof dp);     dp[0][0] = w;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < maxN; j++) {         long long cur_bal = dp[i - 1][j];         if (cur_bal == -1) continue;         for (int k = 0; k <= c[i]; k++) {           if (1LL * k * cost[i] > cur_bal) continue;           dp[i][j + k] = max(min(cur_bal - (1LL * k * cost[i]) + x,                                  1LL * w + (1LL * b * (j + k))),                              dp[i][j + k]);         }       }     }     for (int i = maxN - 1; i >= 0; i--) {       if (dp[n][i] != -1) {         cout << i;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T, n, b[100010], mp[100010], hah[100010];   struct qwq {     int v, id;   } a[100010];   bool cmp(qwq x, qwq y) { return x.v < y.v; }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++)         scanf( %d , &a[i].v), mp[a[i].v] = i, b[i] = a[i].v, hah[i] = 0;       sort(a + 1, a + n + 1, cmp);       bool flag = true;       for (int i = 1; i <= n;) {         int now = mp[i], js = i;         hah[now] = 1;         for (int j = now + 1; j <= n; j++) {           if (hah[j]) {             break;           }           if (b[j] != b[j - 1] + 1) {             flag = false;             break;           } else {             hah[j] = 1;             js++;           }         }         if (!flag) {           break;         }         i = js + 1;       }       if (flag)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   struct SegmentTree {     struct Node {       bool hasCarry = 0;       int b = 0, e = 0;       U carry = U();       T val = T();       Node() {}       void join(const Node &l, const Node &r) {         val = l.val + r.val;         b = l.b;         e = r.e;       }       void update(const U &u) {         carry += u;         u.update(val, b, e);         hasCarry = 1;       }       void pushDown(Node &l, Node &r) {         if (!hasCarry) return;         l.update(carry);         r.update(carry);         carry = U();         hasCarry = 0;       }     };     vector<Node> V;     int N;     SegmentTree(int N) : V(4 * N), N(N) {}     template <class I>     void create(const vector<I> &VEC, int n = 1, int b = 0, int e = -1) {       if (e == -1) e = N - 1;       if (b == e) {         V[n].val = T(VEC[b]), V[n].b = b, V[n].e = e;       } else {         int m = (b + e) / 2;         create(VEC, 2 * n, b, m);         create(VEC, 2 * n + 1, m + 1, e);         V[n].join(V[2 * n], V[2 * n + 1]);       }     }     T query(int i, int j, int n = 1, int b = 0, int e = -1) {       if (e == -1) e = N - 1;       if (i <= b && e <= j)         return V[n].val;       else {         V[n].pushDown(V[2 * n], V[2 * n + 1]);         int m = (b + e) / 2;         if (i > m) return query(i, j, 2 * n + 1, m + 1, e);         if (j <= m) return query(i, j, 2 * n, b, m);         return query(i, j, 2 * n, b, m) + query(i, j, 2 * n + 1, m + 1, e);       }     }     void update(int i, int j, const U &v, int n = 1, int b = 0, int e = -1) {       if (e == -1) e = N - 1;       if (i <= b && e <= j)         V[n].update(v);       else if (i > e || j < b)         return;       else {         V[n].pushDown(V[2 * n], V[2 * n + 1]);         int m = (b + e) / 2;         update(i, j, v, 2 * n, b, m);         update(i, j, v, 2 * n + 1, m + 1, e);         V[n].join(V[2 * n], V[2 * n + 1]);       }     }     int findOkPrefix(int i, const function<bool(T)> &isOk) {       vector<int> stk;       stk.reserve(20);       stk.push_back(1);       T acum;       int sz = 0;       while (stk.size()) {         int t = stk.back();         stk.pop_back();         Node &n = V[t];         if (n.e < i) continue;         T newAcum = sz == 0 ? n.val : (acum + n.val);         if (i <= n.b) {           if (isOk(newAcum)) {             sz += n.e - n.b + 1;             acum = newAcum;           } else {             if (n.b == n.e) return sz;             V[t].pushDown(V[t << 1], V[t << 1 | 1]);             stk.push_back(2 * t + 1);             stk.push_back(2 * t);           }         } else {           V[t].pushDown(V[t << 1], V[t << 1 | 1]);           stk.push_back(2 * t + 1);           stk.push_back(2 * t);         }       }     }   };   struct RRange {     int tL, tR, sz;     RRange(int v = 0) : tR(v), tL(v), sz(1) {}     RRange operator+(const RRange &m) const {       RRange r;       r.sz = sz + m.sz;       r.tL = max(tL, m.tL - sz);       r.tR = max(tR - m.sz, m.tR);       return r;     }     friend ostream &operator<<(ostream &os, const RRange &range) {       os <<  (  << range.tL <<  ,  << range.tR <<  ) ;       return os;     }     void normalize(int N) {       if (tL + tR + 1 >= N) {         tL = 0;         tR = N - 1;       }       sz = 1;     }     int size() { return tL + tR + 1; }   };   struct Void {     void update(RRange &m, int b, int e) const {}     void operator+=(const Void &s) {}   };   int main() {     int N;     cin >> N;     vector<RRange> V(N);     for (int i = 0; i < N; ++i) {       int n;       cin >> n;       V[i] = RRange(n);       V[i].normalize(N);     }     vector<vector<RRange>> T(20, vector<RRange>(N));     vector<SegmentTree<RRange, Void>> STS;     T[0] = V;     auto fn = [](int i, int j, SegmentTree<RRange, Void> &ST, int N) {       RRange r = ST.query(max(i, 0), min(j, N - 1));       if (i < 0) r = ST.query(N + i, N - 1) + r;       if (j >= N) r = r + ST.query(0, j % N);       return r;     };     for (int i = 1; i < 20; ++i) {       STS.push_back(SegmentTree<RRange, Void>(N));       STS.back().create(T[i - 1]);       auto &ST = STS.back();       for (int j = 0; j < N; ++j) {         T[i][j] = fn(j - T[i - 1][j].tL, j + T[i - 1][j].tR, ST, N);         T[i][j].tL += T[i - 1][j].tL;         T[i][j].tR += T[i - 1][j].tR;         T[i][j].normalize(N);       }     }     for (int i = 0; i < N; ++i) {       RRange mx(0);       int ans = 0;       for (int j = STS.size() - 1; j >= 0; --j) {         RRange t = fn(i - mx.tL, i + mx.tR, STS[j], N);         t.tL += mx.tL;         t.tR += mx.tR;         t.normalize(N);         if (t.size() < N) {           mx = t;           ans |= 1 << j;         }       }       if (mx.size() < N) ans++;       cout << ans <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int p = 1000003;   const int n = 10;   int inv[1000005], a[15][15], ans[15];   int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int calc(int x) {     int res = 0;     for (int i = n; i >= 0; i--) res = (1LL * res * x + ans[i]) % p;     return res;   }   int main() {     inv[1] = 1;     for (int i = 2; i < p; i++) inv[i] = 1LL * (p - p / i) * inv[p % i] % p;     printf( ? 0 n );     fflush(stdout);     ans[0] = read();     for (int i = 1; i <= n; i++) {       printf( ? %d n , i);       fflush(stdout);       a[i][0] = 1;       for (int j = 1; j <= n; j++) a[i][j] = a[i][j - 1] * i % p;       a[i][n + 1] = (read() + p - ans[0]) % p;     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         int t = 1LL * a[j][i] * inv[a[i][i]] % p;         for (int k = i + 1; k <= n + 1; k++)           a[j][k] = (a[j][k] + p - 1LL * a[i][k] * t % p) % p;         a[j][i] = 0;       }     }     for (int i = n; i >= 1; i--) {       int res = a[i][n + 1];       for (int j = i + 1; j <= n; j++)         res = (res + p - 1LL * a[i][j] * ans[j] % p) % p;       ans[i] = 1LL * res * inv[a[i][i]] % p;     }     for (int i = 0; i < p; i++) {       if (calc(i) == 0) {         printf( ! %d n , i);         fflush(stdout);         exit(0);       }     }     printf( ! -1 n );     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10;   int n, d[MAXN], id[MAXN];   bool b[MAXN][MAXN];   bool cmp(int a, int b) {     if (d[a] > d[b]) return true;     if (d[a] < d[b]) return false;     return a < b;   }   int main() {     scanf( %d , &n);     if (n == 4) puts( -1 ), exit(0);     b[3][1] = b[1][2] = b[2][3] = 1;     d[1] = d[2] = d[3] = 1;     for (int i = 4; i <= n; ++i) {       for (int j = 1; j < i; ++j) id[j] = j;       sort(id + 1, id + i, cmp);       for (int j = 1; j <= i / 2; ++j) b[id[j]][i] = 1, ++d[i];       for (int j = i / 2 + 1; j < i; ++j) b[i][id[j]] = 1, ++d[id[j]];     }     for (int i = 1; i <= n; ++i, puts(  ))       for (int j = 1; j <= n; ++j) printf( %d  , b[i][j]);     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1LL;     } while (ch <  0  || ch >  9 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f * x;   }   template <class T>   inline void chmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void chmin(T &a, T b) {     if (a > b) a = b;   }   inline void swap(int &a, int &b) {     int c = a;     a = b;     b = c;   }   using namespace std;   const int N = 4e5 + 10;   set<int> seg[N << 2];   int mx[N << 2], mn[N << 2];   struct node {     int x1, y1, x2, y2;   } a[N];   inline void show(node a) { printf( %d %d %d %d n , a.x1, a.y1, a.x2, a.y2); }   vector<int> ins[N], era[N];   int n, px[N << 1], py[N << 1], totx, toty, lenx, leny, ok[N];   inline void upd(int cur) {     int mxp;     if (seg[cur].size()) {       mxp = *(--seg[cur].end());     } else {       mxp = -1;     }     int mxt = max(mx[cur << 1], mx[cur << 1 | 1]);     int mnt = min(mn[cur << 1], mn[cur << 1 | 1]);     if (mxp > mxt) {       if (ok[mxp] || mxp < mnt) {         mx[cur] = -1;       } else {         mx[cur] = mxp;       }     } else {       mx[cur] = mxt;     }     mn[cur] = max(mxp, mnt);   }   inline void cover(int cur, int L, int R, int l, int r, int id, int fl) {     if (l > r) return;     if (l <= L && r >= R) {       if (fl == 1) {         seg[cur].insert(id);       } else if (fl == -1) {         seg[cur].erase(id);       }       upd(cur);       return;     }     int mid = (L + R) >> 1;     if (l <= mid) cover(cur << 1, L, mid, l, r, id, fl);     if (r > mid) cover(cur << 1 | 1, mid + 1, R, l, r, id, fl);     upd(cur);   }   inline void norx(int &x) {     x = (int)(lower_bound(px + 1, px + lenx + 1, x) - px);   }   inline void nory(int &x) {     x = (int)(lower_bound(py + 1, py + leny + 1, x) - py);   }   int main() {     memset(mx, -1, sizeof(mx));     n = read();     for (int i = (1); i <= (n); ++i)       a[i].x1 = read(), a[i].y1 = read(), a[i].x2 = read(), a[i].y2 = read();     for (int i = (1); i <= (n); ++i) {       px[++totx] = a[i].x1;       px[++totx] = a[i].x2;       py[++toty] = a[i].y1;       py[++toty] = a[i].y2;     }     sort(px + 1, px + totx + 1);     sort(py + 1, py + toty + 1);     lenx = (int)(unique(px + 1, px + totx + 1) - px - 1);     leny = (int)(unique(py + 1, py + toty + 1) - py - 1);     for (int i = (1); i <= (n); ++i) {       norx(a[i].x1);       norx(a[i].x2);       nory(a[i].y1);       nory(a[i].y2);     }     for (int i = (1); i <= (n); ++i) {       ins[a[i].x1].push_back(i);       era[a[i].x2].push_back(i);     }     for (int t = (1); t <= (lenx); ++t) {       for (auto cur : ins[t]) {         cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, 1);       }       for (auto cur : era[t]) {         cover(1, 1, leny, a[cur].y1, a[cur].y2 - 1, cur, -1);       }       while (~mx[1]) {         ok[mx[1]] = 1;         cover(1, 1, leny, a[mx[1]].y1, a[mx[1]].y2 - 1, mx[1], 0);       }     }     int ans = 1;     for (int i = (1); i <= (n); ++i)       if (ok[i]) ++ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   int q, t, l, r, x, last;   std::map<int, int> dsu, val;   int root(int x) {     int cur = dsu[x];     if (cur < 0)       return x;     else {       dsu[x] = root(dsu[x]);       val[x] ^= val[cur];       return dsu[x];     }   }   void connect(int x, int y, int v) {     int a = root(x), b = root(y);     if (a != b) {       if (dsu[a] > dsu[b]) std::swap(a, b);       dsu[a] += dsu[b];       dsu[b] = a;       val[b] = v ^ val[x] ^ val[y];     }   }   int main() {     std::cin >> q;     while (q--) {       std::cin >> t >> l >> r;       if ((l ^= last) > (r ^= last)) std::swap(l, r);       if (!dsu.count(l)) dsu[l] = -1;       if (!dsu.count(++r)) dsu[r] = -1;       if (t == 1) {         std::cin >> x;         connect(l, r, x ^= last);       } else if (root(l) == root(r))         std::cout << (last = val[l] ^ val[r]) <<   n ;       else         std::cout << -(last = 1) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long pl, pr, vl, vr;   int k;   long long Inter(long long x1, long long x2, long long y1, long long y2) {     long long a = max(x1, y1);     long long b = min(x2, y2);     if (a > b)       return 0.0;     else       return b - a + 1;   }   long long GetProb(long long x1, long long x2, long long y1, long long y2) {     return Inter(x1, x2, pl, pr) * Inter(y1, y2, vl, vr) +            Inter(x1, x2, vl, vr) * Inter(y1, y2, pl, pr);   }   int main() {     cin >> pl >> pr >> vl >> vr >> k;     vector<long long> numbers;     numbers.push_back(0);     int a = 0;     for (int i = 0; i < 9; i++) {       int b = numbers.size();       for (int j = a; j < b; j++) {         numbers.push_back(numbers[j] * 10 + 4);         numbers.push_back(numbers[j] * 10 + 7);       }       a = b;     }     numbers.push_back(1000000000);     long long P = (pr - pl + 1) * (vr - vl + 1);     long long gP = 0;     int l = 1;     int r = k;     while (1) {       gP +=           GetProb(numbers[l - 1] + 1, numbers[l], numbers[r], numbers[r + 1] - 1);       l++;       r++;       if (r + 1 >= numbers.size()) break;     }     l = 1;     r = k + 1;     while (1) {       l++;       r++;       if (r + 1 >= numbers.size()) break;     }     l = 1;     if (k == 1)       while (1) {         gP -= GetProb(numbers[l], numbers[l], numbers[l], numbers[l]) / 2;         l++;         if (l + 1 >= numbers.size()) break;       }     printf( %.15f , (long double)gP / P);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 205;   int a[maxn];   int main() {     ios::sync_with_stdio(false);     int n, k;     scanf( %d %d , &n, &k);     int m = n + n + 1;     for (int i = 0; i < m; ++i) scanf( %d , &a[i]);     for (int i = 1; k && i < m; i += 2) {       if (a[i] > max(a[i - 1], a[i + 1]) + 1) {         --a[i];         --k;       }     }     for (int i = 0; i < m; ++i) printf( %d  , a[i]);     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[10][300];   int s[10][10];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < int(n); ++i)       for (int j = 0; j < int(m); ++j) cin >> s[i][j];     int *cur = dp[0], *next = dp[1];     for (int i = n - 1; i >= 0; --i) {       for (int j = m - 1; j >= 0; --j) {         for (int used = 0; used < int(1 << m); ++used) {           if (used & (1 << j)) {             next[used] = cur[used & ~(1 << j)];           } else {             int best = 0;             if (j + 1 < m && !(used & (1 << (j + 1))))               best = max(best,                          cur[used | (1 << (j + 1))] + (s[i][j] == s[i][j + 1]));             if (i + 1 < n)               best = max(best, cur[used | (1 << j)] + (s[i][j] == s[i + 1][j]));             next[used] = best;           }         }         swap(cur, next);       }     }     cout << n * m / 2 - cur[0] << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100001], flag[100001];   vector<pair<long long, long long> > ans;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, sum = 0;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     sum /= n / 2;     for (long long i = 0; i < n; i++) {       if (flag[i] == 0)         for (long long j = i + 1; j < n; j++) {           if (flag[j] == 0 && ((a[i] + a[j]) == sum)) {             flag[j] = 1;             flag[i] = 1;             ans.push_back(make_pair(i + 1, j + 1));             break;           }         }     }     for (auto i : ans) {       cout << i.first <<     << i.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long f(const string& s) {     long long res = 0;     for (int i = 0; i + 1 < s.size(); ++i) {       if (s[i] != s[i + 1]) {         res += (m - 1) * (n - i - 1);       }     }     return res;   }   long long g(const string& s) {     long long res = 0;     for (int i = 0; i + 1 < s.size(); ++i)       if (s[i] != s[i + 1]) {         int j = i + 1;         while (j + 1 < s.size() && s[j + 1] == s[j - 1]) ++j;         long long l = j - i + 1;         res += l * (l - 1) / 2;         i = j - 1;       }     return res;   }   int main() {     string s;     cin >> n >> m >> s;     long long res = n * (m - 1) + f(s);     reverse(s.begin(), s.end());     res += f(s) - g(s);     cout << res << endl;     return 0;   }


/*mjytxdy!*/   #include <bits/stdc++.h>   using namespace std;   #define pb push_back   #define fi first   #define se second   #define all(x) x.begin(),x.end()   #define SZ(x) ((int)x.size())   #define pii pair<int,int>   #define pil pair<int,ll>   #define pli pair<ll,int>   #define pll pair<ll,ll>   #define inl inline   #define rep(i,l,r) for(int i=(l);i<=(r);i++)   #define per(i,r,l) for(int i=(r);i>=(l);i--)   #define trv(i,u) for(int i=head[u];i;i=e[i].next)   #define lb(x) ((x)&(-(x)))   #define debug(x) cout<<#x : <<x<<  n    #define myput puts( QaQ )   #define file(x) freopen(#x .in , r ,stdin),freopen(#x .out , w ,stdout);   typedef long long ll;   template<class T>inl bool ylmin(T &a,T b){return a<b?0:(a=b,1);}   template<class T>inl bool ylmax(T &a,T b){return a>b?0:(a=b,1);}   template<class T>inl T abs(T x){return x<0?-x:x;}   inl char read(){    static const int IO_LEN=1024*1024;    static char buf[IO_LEN],*ioh,*iot;    if(ioh==iot){     iot=(ioh=buf)+fread(buf,1,IO_LEN,stdin);     if(ioh==iot) return -1;    }    return *ioh++;   }   template<class T>inl void read(T &x){    static int iosig;static char ioc;    for(iosig=0,ioc=read();!isdigit(ioc);ioc=read()) if(ioc== - ) iosig=1;    for(x=0;isdigit(ioc);ioc=read())x=(x<<1)+(x<<3)+(ioc^ 0 );    if(iosig) x=-x;   }   const int MAXN = 1e5 + 10;   struct Node{    int x,y;   }a[MAXN];   int n,m;   vector<int> S,T,Set;   map<pii,bool> Map;   inl bool cmp(Node a,Node b){    return a.x-a.y>b.x-b.y;   }   struct Segment{    #define ls rt<<1    #define rs rt<<1|1    pii Min[MAXN<<2];    int tag;    inl void pushup(int rt){     Min[rt]=min(Min[ls],Min[rs]);    }    inl pii query(int rt,int l,int r,int L,int R){     if(L>R) return {2e9,-1};     if(l>=L && r<=R) return Min[rt];      int mid=l+r>>1;     if(R<=mid) return query(ls,l,mid,L,R);     else if(L>mid) return query(rs,mid+1,r,L,R);     else return min(query(ls,l,mid,L,R),query(rs,mid+1,r,L,R));    }    inl void update(int rt,int l,int r,int pos) {     if(l==r) return Min[rt]={2e9,-1},void();     int mid=l+r>>1;     if(pos<=mid) update(ls,l,mid,pos);     else update(rs,mid+1,r,pos);     pushup(rt);    }    inl void build(int rt,int l,int r,int opt){     if(l==r) {      Min[rt]={opt?a[l].y:a[l].x,l};      return ;     }     int mid=l+r>>1;     build(ls,l,mid,opt),build(rs,mid+1,r,opt);     pushup(rt);    }    #undef ls    #undef rs   }t[2];   int main(){    //freopen( in.txt , r ,stdin);    read(n),read(m);    rep(i,1,n) read(a[i].x),read(a[i].y),Map[{a[i].x,a[i].y}]=1;    sort(a+1,a+n+1,cmp);    per(i,n,1) Set.push_back(a[i].x-a[i].y);    t[0].build(1,1,n,0),t[1].build(1,1,n,1);    int delta=0;S.push_back(-1),T.push_back(-1);    rep(i,1,n) {     int pos=n-(lower_bound(all(Set),delta)-Set.begin())+1;     pii lans=t[0].query(1,1,n,1,pos-1),rans=t[1].query(1,1,n,pos,n);     lans.fi-=t[0].tag,rans.fi-=t[1].tag;     pii Min=min(lans,rans);     int id=Min.se;     if(a[id].x-a[id].y==delta) {      if(S.back()!=a[id].x && T.back()!=a[id].y) {       t[0].tag++,S.push_back(a[id].x);       t[1].tag++,T.push_back(a[id].y);      }     } else if(a[id].x-a[id].y>delta) {      if(S.back()!=a[id].x) delta++,t[0].tag++,S.push_back(a[id].x);     } else if(a[id].x-a[id].y<delta) {      if(T.back()!=a[id].y) delta--,t[1].tag++,T.push_back(a[id].y);     }     t[0].update(1,1,n,id);t[1].update(1,1,n,id);     }     rep(i,1,m) {      int x,y;      read(x),read(y);      if(Map[{x,y}]) {puts( LOSE );continue;}      if(binary_search(all(S),x) || binary_search(all(T),y)) {puts( WIN );continue;}     x-=lower_bound(all(S),x)-S.begin();      y-=lower_bound(all(T),y)-T.begin();      puts(x==y? LOSE : WIN );    }    return 0;   }


#include <bits/stdc++.h>   using std::bitset;   using std::cerr;   using std::cin;   using std::complex;   using std::cout;   using std::deque;   using std::endl;   using std::ios_base;   using std::iterator;   using std::map;   using std::max;   using std::max_element;   using std::min;   using std::min_element;   using std::multimap;   using std::multiset;   using std::pair;   using std::queue;   using std::reverse;   using std::set;   using std::sort;   using std::stable_sort;   using std::stack;   using std::string;   using std::swap;   using std::unique;   using std::vector;   namespace MySpace {   struct Small_Segment_Tree {     vector<int> a;     int l, r;       private:     int __summ(int L, int R, int l, int r, int v) {       if (L <= l && r <= R) return a[v];       if (R <= l || r <= L) return 0;       int m = (l + r) / 2;       return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);     }     void __set(int P, int l, int r, int v, int V) {       if (l + 1 == r) {         a[v] = V;         return;       }       int m = (l + r) / 2;       if (P < m) {         __set(P, l, m, 2 * v + 1, V);         a[v] = a[2 * v + 1] + a[2 * v + 2];       } else {         __set(P, m, r, 2 * v + 2, V);         a[v] = a[2 * v + 1] + a[2 * v + 2];       }     }       public:     int Summ(int L, int R) {       if (R < L) return 0;       return __summ(L, R + 1, l, r, 0);     }     void Set(int P, int V) { __set(P, l, r, 0, V); }     Small_Segment_Tree(int _n) {       a.resize(4 * _n);       l = 0, r = _n;     }   };   long long inq(long long x, long long q, long long MOD) {     if (q == 0) return 1;     long long l = inq(x, q / 2, MOD);     if (q % 2) return l * l % MOD * x % MOD;     return l * l % MOD;   }   };  // namespace MySpace   using namespace MySpace;   long long n, m;   long long a[500000];   int main() {     ios_base::sync_with_stdio();     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = n; i < 2 * n; i++) cin >> a[i];     sort(a, a + 2 * n);     long long s1 = 0, s2 = 0;     for (int i = 0; i < n; i++) s1 += a[i];     for (int i = n; i < 2 * n; i++) s2 += a[i];     if (s1 == s2) {       cout << -1;       return 0;     }     for (int i = 0; i < 2 * n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   struct event {     int t, time, L, R, idx;     event() {}     event(int t, int time, int L, int R, int idx)         : t(t), time(time), L(L), R(R), idx(idx) {}     bool operator<(const event& a) const {       return (time < a.time || (time == a.time && t < a.t));     }   } e[200005 * 23];   int n, m, i, j, ai, place[200005], L, R, en, idx, ans[200005], fw[200005];   void modify(int j) {     for (; j <= n; j = (j | (j - 1)) + 1) ++fw[j];   }   int query(int j) {     int rt = 0;     for (; j; j &= (j - 1)) rt += fw[j];     return rt;   }   int main(int argc, char* const argv[]) {     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       scanf( %d , &ai);       place[ai] = i;     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &L, &R);       e[++en] = event(2, R, L, R, i);       e[++en] = event(2, L - 1, L, R, -i);     }     for (i = 1; i <= n; i++) {       j = i;       while (j <= n) {         e[++en] = event(1, place[i], place[j], 0, 0);         j += i;       }     }     std::sort(e + 1, e + en + 1);     for (i = 1; i <= en; i++)       if (e[i].t == 1)         modify(e[i].L);       else {         idx = abs(e[i].idx);         ans[idx] += (query(e[i].R) - query(e[i].L - 1)) * (e[i].idx / idx);       }     for (i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int inf = 0x7FFFFFFF;   using namespace std;   int dep[2014], shortcut[20][2014];   struct Edge {     int u, v, w;     bool operator<(const Edge &A) const { return w < A.w; }   } E[4000005];   int mp[2014][2014];   int fa[2014], d[2014];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   vector<int> G[2014], Q;   int get_lca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     for (int i = 20 - 1; i >= 0; i--) {       if (dep[a] - dep[b] >> i & 1) {         a = shortcut[i][a];       }     }     if (a == b) return a;     for (int i = 20 - 1; i >= 0; i--) {       if (shortcut[i][a] != shortcut[i][b]) {         a = shortcut[i][a];         b = shortcut[i][b];       }     }     return shortcut[0][a];   }   int main() {     int N;     scanf( %d , &N);     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) scanf( %d , &mp[i][j]);     int tot = 0;     for (int i = 1; i <= N; i++)       for (int j = i + 1; j <= N; j++) {         E[tot].u = i;         E[tot].v = j;         E[tot].w = mp[i][j];         tot++;       }     sort(E, E + tot);     for (int i = 1; i <= N; i++) fa[i] = i;     for (int i = 0; i < tot; i++) {       int u = E[i].u;       int v = E[i].v;       if (find(u) != find(v)) {         fa[find(u)] = find(v);         G[u].push_back(v);         G[u].push_back(E[i].w);         G[v].push_back(u);         G[v].push_back(E[i].w);       }     }     int *parent = shortcut[0];     d[1] = 0;     parent[1] = -1;     dep[1] = 0;     Q.push_back(1);     for (int head = 0; head < int(Q.size()); head++) {       int u = Q[head];       for (int i = 0; i < int(G[u].size()); i += 2) {         int v = G[u][i];         int w = G[u][i + 1];         if (v != parent[u]) {           parent[v] = u;           dep[v] = dep[u] + 1;           d[v] = d[u] + w;           Q.push_back(v);         }       }     }     for (int i = 1; i < 20; i++) {       for (int j = 1; j <= N; j++) {         int &res = shortcut[i][j];         res = shortcut[i - 1][j];         if (~res) {           res = shortcut[i - 1][res];         }       }     }     bool ok = true;     int num = 0;     for (int i = 1; i <= N; i++)       if (fa[i] == i) num++;     if (num > 1) ok = false;     for (int u = 1; ok && u <= N; u++) {       if (mp[u][u] != 0) ok = false;       for (int v = u + 1; ok && v <= N; v++) {         if (mp[u][v] != mp[v][u]) ok = false;         if (mp[u][v] == 0) ok = false;         int mid = get_lca(u, v);         if (d[u] + d[v] - d[mid] * 2 != mp[u][v]) ok = false;       }     }     puts(ok ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long q;     cin >> q;     ;     for (long long i = (1); i <= (q); i++) {       long long n;       cin >> n;       ;       long long r;       cin >> r;       ;       set<long long, greater<long long>> s;       for (long long i = (1); i <= (n); i++) {         long long x;         cin >> x;         ;         s.insert(x);       }       long long k = 0, st = 0;       for (long long j : s) {         if (j - r * k <= 0) {           cout << k <<   n ;           st = 1;           break;         }         k++;       }       if (!st) cout << k <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 2e5 + 10;   long long x[mx], y[mx];   ifstream fin( input.txt );   ofstream fout( output.txt );   long long sum[5];   int main() {     string b;     cin >> b;     int x = 0, y = 0;     for (int i = 0; i < b.size(); i++) {       if (b[i] ==  x )         x++;       else         y++;     }     if (x > y) {       for (int i = 1; i <= x - y; i++) cout <<  x ;       return 0;     }     for (int i = 1; i <= y - x; i++) cout <<  y ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = 1e9 + 7;   const int MOD = 998244353;   const double PI = 3.141592653589793238460;   const int bs = 1e9 + 7;   unsigned long long power(unsigned long long a, unsigned long long b) {     unsigned long long res = 1;     if (a == 0) return 0;     if (a == 1) return 1;     for (; b > 0; b >>= 1) {       if (b & 1) res = (res * a);       if (res > MOD) res %= MOD;       a = (a * a);       if (a > MOD) a = a % MOD;     }     return res;   }   bool isPrime[1000001];   vector<unsigned long long> prime;   void seive(int limit) {     isPrime[0] = isPrime[1] = 1;     for (int i = 2; i * i <= limit; i++) {       if (!isPrime[i])         for (int j = i * i; j <= limit; j += i) {           isPrime[j] = 1;         }     }     for (int i = 2; i <= limit; i++)       if (!isPrime[i]) prime.push_back(i);   }   map<string, int> m;   unsigned long long parent[100100], sz[100100];   vector<pair<unsigned long long, unsigned long long>> v[100010];   vector<pair<pair<unsigned long long, unsigned long long>,               pair<unsigned long long, unsigned long long>>>       rem;   int visited[100010], valid[100010], cum[100110];   int n, q1, q2;   int finds(int i) {     while (parent[i] != i) i = parent[i];     return i;   }   int unions(int x, int y) {     int xr = finds(x);     int yr = finds(y);     if (xr == yr) return 0;     if (sz[xr] > sz[yr])       parent[yr] = xr;     else if (sz[xr] < sz[yr])       parent[xr] = yr;     else {       sz[yr]++;       parent[xr] = yr;     }     return 1;   }   void dfs(int node, int pnode, int x) {     cum[node] = x;     visited[node] = 1;     for (int i = 0; i < v[node].size(); i++) {       if (!visited[v[node][i].first])         dfs(v[node][i].first, node, x ^ (v[node][i].second));     }   }   void process() {     for (int i = 0; i < n; i++)       if (!visited[i]) dfs(i, i, 0);     for (int i = 0; i < rem.size(); i++) {       int x = rem[i].first.first, y = rem[i].first.second;       int idx = rem[i].second.first, t = rem[i].second.second;       if (cum[x] ^ cum[y] != t)         valid[idx] = 0;       else         valid[idx] = 1;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int tt = 1;     while (tt--) {       cin >> n >> q1 >> q2;       for (int i = 0; i < n; i++) {         string s;         cin >> s;         m[s] = i;         parent[i] = i;         sz[i] = 0;       }       for (int i = 0; i < q1; i++) {         int t;         cin >> t;         string a, b;         cin >> a >> b;         int x = m[a], y = m[b];         if (unions(x, y)) {           v[x].push_back({y, t - 1});           v[y].push_back({x, t - 1});           valid[i] = 1;         } else           rem.push_back({{x, y}, {i, t - 1}});       }       process();       for (int i = 0; i < q1; i++) {         if (valid[i])           cout <<  YES                 <<   n ;         else           cout <<  NO                 <<   n ;       }       for (int i = 0; i < q2; i++) {         string a, b;         cin >> a >> b;         int x = m[a], y = m[b];         if (finds(x) != finds(y))           cout << 3 <<   n ;         else           cout << (cum[x] ^ cum[y]) + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m;     cin >> n >> m;     if (n > 26)       cout << m;     else {       n = pow(2, n);       cout << m % n;     }     return 0;   }


#include <bits/stdc++.h>   const long long INFLL = 1e18;   using namespace std;   const int MAXN = 2 * 100000;   const int INF = 1000 * 1000 * 1000;   int a[MAXN + 1], used[MAXN + 10];   int main() {     int n;     scanf( %d , &n);     int ans = 1;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (used[a[i]]) {         ans++;       }       used[a[i]] = 1;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> segT;   vector<int> lazy;   long long n, m, l, r;   string s;   void buildT(int ss, int se, int si) {     if (ss == se) {       if (s[ss] ==  4 )         segT[si][0] = 1;       else         segT[si][1] = 1;       segT[si][2] = 1;       segT[si][3] = 1;       return;     }     int mid = (ss + se) / 2;     buildT(ss, mid, 2 * si + 1);     buildT(mid + 1, se, 2 * si + 2);     segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0];     segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1];     segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1],                       segT[2 * si + 1][0] + segT[2 * si + 2][2]);     segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0],                       segT[2 * si + 1][1] + segT[2 * si + 2][3]);   }   void upd(int ss, int se, int si) {     if (lazy[si] == 1) {       swap(segT[si][0], segT[si][1]);       swap(segT[si][2], segT[si][3]);       if (ss != se) {         lazy[2 * si + 1] ^= 1;         lazy[2 * si + 2] ^= 1;       }       lazy[si] = 0;     }     if (r < ss || l > se) return;     if (ss >= l && se <= r) {       swap(segT[si][0], segT[si][1]);       swap(segT[si][2], segT[si][3]);       if (ss != se) {         lazy[2 * si + 1] ^= 1;         lazy[2 * si + 2] ^= 1;       }       return;     }     int mid = (ss + se) / 2;     upd(ss, mid, 2 * si + 1);     upd(mid + 1, se, 2 * si + 2);     segT[si][0] = segT[2 * si + 1][0] + segT[2 * si + 2][0];     segT[si][1] = segT[2 * si + 1][1] + segT[2 * si + 2][1];     segT[si][2] = max(segT[2 * si + 1][2] + segT[2 * si + 2][1],                       segT[2 * si + 1][0] + segT[2 * si + 2][2]);     segT[si][3] = max(segT[2 * si + 1][3] + segT[2 * si + 2][0],                       segT[2 * si + 1][1] + segT[2 * si + 2][3]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int i, j;     cin >> n >> m;     cin >> s;     long long lim = 2 * pow(2, ceil(log(n) / log(2.0))) + 2;     vector<int> temp(lim, 0);     vector<vector<int>> temp2(lim, vector<int>(4, 0));     segT = temp2;     lazy = temp;     buildT(0, n - 1, 0);     string typ;     for (i = 0; i < m; i++) {       cin >> typ;       if (typ.compare( switch ) == 0) {         cin >> l >> r;         l -= 1;         r -= 1;         upd(0, n - 1, 0);       } else {         if (lazy[0] == 1)           cout << segT[0][3] << endl;         else           cout << segT[0][2] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace ::std;   int main() {     long long int temp, q, v1, v2, t, d, i, sum = 0;     cin >> v1 >> v2 >> t >> d;     long long int a[t];     sum = d * (t - 1);     i = 0;     temp = 0;     bool ff = false;     while (1) {       if (!ff) {         i += v1;         a[temp] = i;         temp++;         ff = true;         continue;       } else if (i + d - sum + d <= v2) {         i += d;         sum -= d;         a[temp] = i;       } else {         for (long long int k = d - 1; k >= -d; k--) {           if (i + k - sum + d <= v2) {             i += k;             sum -= d;             a[temp] = i;             break;           }         }       }       temp++;       if (temp == t) break;     }     long long int s = 0;     for (long long int j = 0; j < t; j++) s += a[j];     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1e5, inf = 3e18, mod = 1e9 + 7;   long long tc, n, m, q, a, b, c, d, i, j, k;   long long A[N];   vector<long long> vec;   string s;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> tc;     while (tc--) {       cin >> n >> m;       long long flag1 = 0, flag2 = 0;       for (i = 2; i < n + 2; i++) {         cin >> A[i];         if (A[i] == m) flag1 = 1;         if (A[i] >= m && (A[i - 1] >= m || A[i - 2] >= m)) flag2 = 1;       }       if (flag1 && flag2 || (n == 1 && A[2] == m))         cout <<  yes n ;       else         cout <<  no n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 2e5 + 5;   void solve() {     long long int n;     cin >> n;     double ans, pi = 3.14159265358979323846;     double rad = (2.0 * sin(pi / (2.0 * (double)n)));     ans = (cos(pi / (4.0 * n))) / sin(pi / (2.0 * (double)n));     cout << fixed << setprecision(15) << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   template <class T>   inline T read() {     T x = 0, f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     };     while (s >=  0  && s <=  9 ) {       x = (x << 3) + (x << 1) + s - 48;       s = getchar();     };     return x * f;   }   template <typename T>   inline void wri(T x) {     if (x < 0) {       x = -x;       putchar( - );     };     if (x / 10) wri(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void print(T x, char s) {     wri(x);     putchar(s);   }   struct node {     int l, r, val, add;   } e[800010];   int a[200010], ans[200010];   void build_tree(int node, int start, int end) {     e[node].l = start, e[node].r = end;     if (start == end) {       e[node].add = 0;       e[node].val = a[start];       return;     }     int mid = (start + end) >> 1;     build_tree(node << 1, start, mid), build_tree(node << 1 | 1, mid + 1, end);   }   void update(int x, int q, int val) {     if (e[x].l == q && e[x].r == q) {       e[x].val = val, e[x].add = 0;       return;     }     int mid = (e[x].l + e[x].r) >> 1;     e[x << 1].add = max(e[x << 1].add, e[x].add);     e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add);     e[x].add = 0;     if (q <= mid)       update(x << 1, q, val);     else       update(x << 1 | 1, q, val);   }   void query(int x) {     if (e[x].l == e[x].r) {       ans[e[x].l] = max(e[x].val, e[x].add);       return;     }     e[x << 1].add = max(e[x << 1].add, e[x].add);     e[x << 1 | 1].add = max(e[x << 1 | 1].add, e[x].add);     query(x << 1), query(x << 1 | 1);   }   int main() {     int n;     n = read<int>();     for (register int i = (1); i < (n + 1); i++) a[i] = read<int>();     build_tree(1, 1, n);     int q;     q = read<int>();     while (q--) {       int x, y, z;       x = read<int>();       if (x == 1) {         y = read<int>(), z = read<int>();         update(1, y, z);       } else         y = read<int>(), e[1].add = max(e[1].add, y);     }     query(1);     for (register int i = (1); i < (n + 1); i++) print(ans[i],    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     string cnv;     cnv.reserve(62);     for (char i =  a ; i <=  z ; ++i) {       cnv.push_back(i);     }     for (char i =  A ; i <=  Z ; ++i) {       cnv.push_back(i);     }     for (char i =  0 ; i <=  9 ; ++i) {       cnv.push_back(i);     }     for (int i = 0; i < t; ++i) {       int n, m, k;       cin >> n >> m >> k;       vector<string> mas(n);       int cnt = 0;       for (int j = 0; j < n; ++j) {         cin >> mas[j];         for (char c : mas[j]) {           cnt += (c ==  R );         }       }       int cur = 0;       int perc = cnt / k;       int bigger = cnt % k;       int curcnt = 0;       for (int i = 0; i < n; ++i) {         if (i & 1) {           for (int j = 0; j < m; ++j) {             if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) {               ++cur;               curcnt = 0;             }             if (mas[i][j] ==  R ) ++curcnt;             mas[i][j] = cnv[cur];           }         } else {           for (int j = m - 1; j >= 0; --j) {             if (mas[i][j] ==  R  && curcnt == perc + (cur < bigger)) {               ++cur;               curcnt = 0;             }             if (mas[i][j] ==  R ) ++curcnt;             mas[i][j] = cnv[cur];           }         }       }       for (int i = 0; i < n; ++i) {         cout << mas[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, l[50 + 1];   void Answer() {     int j = 1, s = n;     for (int i = 1; i <= k; i++) {       if (i > s) s += n - (++j) + 1;       cout << j <<    ;       for (int u = n - 1; u > n - j; u--) cout << l[u] <<    ;       cout << l[s - i] << endl;     }   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> l[i];     sort(l, l + n);     Answer();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   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;   }   char s[500010];   int l[12], r[12];   int sz, ed;   int cnt[500010], ord[500010 << 1];   struct node {     int deep, fail, cnt, nxt[30], val[12];     void clear() {       memset(nxt, -1, sizeof nxt);       memset(val, 0, sizeof val);       deep = fail = cnt = 0;     }   } mem[500010 << 1];   struct automaton {     void init() {       for (int i = 0; i < 26; i++) mem[0].nxt[i] = 1;       mem[0].deep = -1;       mem[1].clear();       mem[1].cnt = 1;       sz = 2, ed = 1;     }     void insert(int c, int id) {       if (~mem[ed].nxt[c]) {         int p1 = mem[ed].nxt[c];         if (mem[p1].deep == mem[ed].deep + 1) {           mem[p1].val[id]++;           ed = p1;           return;         }         int p2 = sz++;         mem[p2] = mem[p1];         mem[p2].deep = mem[ed].deep + 1;         mem[p2].cnt = 0;         for (int i = 0; i < 12; i++) mem[p2].val[i] = 0;         mem[p2].val[id] = 1;         mem[p1].fail = p2;         while (mem[ed].nxt[c] == p1) {           mem[ed].nxt[c] = p2;           mem[p1].cnt -= mem[ed].cnt;           mem[p2].cnt += mem[ed].cnt;           ed = mem[ed].fail;         }         ed = p2;         return;       }       int p = sz++;       mem[p].clear();       mem[p].deep = mem[ed].deep + 1;       mem[p].val[id] = 1;       while (mem[ed].nxt[c] == -1) {         mem[ed].nxt[c] = p;         mem[p].cnt += mem[ed].cnt;         ed = mem[ed].fail;       }       int p1 = mem[ed].nxt[c];       if (mem[p1].deep == mem[ed].deep + 1)         mem[p].fail = p1;       else {         int p2 = sz++;         mem[p2] = mem[p1];         mem[p2].deep = mem[ed].deep + 1;         mem[p2].cnt = 0;         for (int i = 0; i < 12; i++) mem[p2].val[i] = 0;         mem[p].fail = mem[p1].fail = p2;         while (mem[ed].nxt[c] == p1) {           mem[ed].nxt[c] = p2;           mem[p1].cnt -= mem[ed].cnt;           mem[p2].cnt += mem[ed].cnt;           ed = mem[ed].fail;         }       }       ed = p;     }     void build(int n) {       memset(cnt, 0, sizeof cnt);       for (int i = 1; i < sz; i++) cnt[mem[i].deep]++;       for (int i = 1; i < 500010; i++) cnt[i] += cnt[i - 1];       for (int i = 1; i < sz; i++) ord[--cnt[mem[i].deep]] = i;       for (int i = sz - 2; i >= 0; i--) {         int cur = ord[i], prv = mem[cur].fail;         for (int j = 0; j <= n; j++) mem[prv].val[j] += mem[cur].val[j];       }       long long ans = 0;       for (int i = 2; i < sz; i++)         if (mem[i].val[n]) {           int ok = 1;           for (int j = 0; j < n; j++)             if (mem[i].val[j] < l[j] || mem[i].val[j] > r[j]) {               ok = 0;               break;             }           if (ok) ans += mem[i].cnt;         }       printf( %I64d n , ans);     }   } sam;   int main() {     int n;     scanf( %s %d , s, &n);     sam.init();     int len = strlen(s);     for (int i = 0; i < len; i++) sam.insert(s[i] -  a , n);     for (int i = 0; i < n; i++) {       scanf( %s %d %d , s, l + i, r + i);       ed = 1;       len = strlen(s);       for (int j = 0; j < len; j++) sam.insert(s[j] -  a , i);     }     sam.build(n);   }


#include <bits/stdc++.h>   using namespace std;   double cal(int n, int *a, double x) {     double ret = 0, t1 = 0, t2 = 0;     for (int i = 0; i < n; i++) {       t1 += a[i] - x;       t2 += a[i] - x;       t1 = max(0., t1);       t2 = min(0., t2);       ret = max(ret, t1);       ret = max(ret, -t2);     }     return ret;   }   int main() {     int n;     scanf( %d , &n);     static int a[200000];     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     double l = -10001, r = 10001, ans;     for (int t = 0; t < 100; t++) {       double d1 = (2 * l + r) / 3, d2 = (l + 2 * r) / 3;       double e1 = cal(n, a, d1), e2 = cal(n, a, d2);       if (e1 <= e2) {         r = d2;         ans = e1;       } else {         l = d1;         ans = e2;       }     }     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   char g[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long double h, c, t;       cin >> h >> c >> t;       if (t >= h) {         cout <<  1 n ;         continue;       }       if ((h + c) / 2 >= t) {         cout <<  2 n ;         continue;       }       int x = 0;       x = (h - t) / (2 * t - h - c);       long double curd = 100000000.0;       int res = -1;       for (int i = max(0, x - 50); i <= x + 50; ++i) {         long double xx = (i + 1) * h + i * c;         xx = 1.0 * xx / (2 * i + 1);         xx = abs(xx - t);         if (xx < curd) {           curd = xx;           res = i;         }       }       cout << 2 * res + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   int prime100[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,  41, 43,                     47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103};   template <typename T>   inline bool isLeap(T y) {     return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);   }   template <typename T>   inline T GCD(T a, T b) {     a = abs(a);     b = abs(b);     if (a < b) swap(a, b);     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   template <typename T>   inline T LCM(T x, T y) {     T tp = GCD(x, y);     if ((x / tp) * 1. * y > 9e18) return 9e18;     return (x / tp) * y;   }   template <typename T>   inline T BIGMOD(T A, T B, T M = 1000000007) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   template <typename T>   inline T BigMod(T A, T B, T M) {     T ret = 1;     while (B) {       if (B & 1) ret = (ret * A) % M;       A = (A * A) % M;       B = B >> 1;     }     return ret;   }   long long int MySqrt(long long int n) {     long long int p = sqrt(n);     if ((p + 1) * (p + 1) <= n)       return p + 1;     else if (p * p <= n)       return p;     else       return p - 1;   }   long long int MyPow(long long int x, long long int n) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return MyPow(x * x, n / 2);     else       return x * MyPow(x * x, ((n - 1) / 2));   }   long long int modInverse(long long int n) {     return BIGMOD(n, (long long int)1000000007 - 2) % 1000000007;   }   void solve() {     long long int ans = 1, n;     cin >> n;     if (n % 2 == 1)       printf( 0 n );     else {       n /= 2;       for (int i = 1; i <= n; i++) ans *= 2;       printf( %lld n , ans);     }   }   char arr[505][505];   int Left[505][505];   int Right[505][505];   int Up[505][505];   int Low[505][505];   void Now() {     int n, m, cnt = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  * ) cnt++;       }     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < m; j++) {         if (arr[i - 1][j] ==  * ) Up[i][j] += 1 + Up[i - 1][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 1; j < m; j++) {         if (arr[i][j - 1] ==  * ) Left[i][j] += 1 + Left[i][j - 1];       }     }     for (int i = n - 1; i >= 0; i--) {       for (int j = m - 2; j >= 0; j--) {         if (arr[i][j + 1] ==  * ) Right[i][j] += 1 + Right[i][j + 1];       }     }     for (int i = n - 2; i >= 0; i--) {       for (int j = m - 1; j >= 0; j--) {         if (arr[i + 1][j] ==  * ) Low[i][j] += 1 + Low[i + 1][j];       }     }     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         if (Left[i][j] > 0 && Up[i][j] > 0 && Right[i][j] > 0 && Low[i][j] > 0 &&             arr[i][j] ==  * ) {           if (Left[i][j] + Up[i][j] + Right[i][j] + Low[i][j] + 1 == cnt) {             printf( YES n );             exit(0);           }         }       }     }     printf( NO n );   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     int x, y;     int z = 1;     cin >> n >> m;     cin >> x >> y;     cout << x <<     << y <<   n ;     cout << 1 <<     << y <<   n ;     for (int i = 1; i <= n; i++) {       vector<pair<int, int>> v;       for (int j = 1; j <= m; j++) {         if ((i == x && j == y) || (i == 1 && j == y)) continue;         v.push_back({i, j});       }       if (z) {         reverse(v.begin(), v.end());       }       for (auto it : v) {         cout << it.first <<     << it.second <<   n ;       }       z ^= 1;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     solve();     return 0;   }