#include <bits/stdc++.h> n using namespace std; n template <class _T> n inline _T sqr(const _T &first) { n   return first * first; n } n template <class _T> n inline string tostr(const _T &a) { n   ostringstream os(  ); n   os << a; n   return os.str(); n } n const long double PI = 3.1415926535897932384626433832795L; n const long double EPS = 5e-12; n char TEMPORARY_CHAR; n const int INF = 1e9; n inline void fft(vector<complex<long double> > &a, bool invert) { n   int n = (int)a.size(); n   for (int i = 1, j = 0; i < n; ++i) { n     int bit = n >> 1; n     for (; j >= bit; bit >>= 1) j -= bit; n     j += bit; n     if (i < j) swap(a[i], a[j]); n   } n   for (int len = 2; len <= n; len <<= 1) { n     long double ang = 2 * PI / len * (invert ? -1 : 1); n     complex<long double> wlen(cos(ang), sin(ang)); n     for (int i = 0; i < n; i += len) { n       complex<long double> w(1); n       for (int j = 0; j < len / 2; ++j) { n         complex<long double> u = a[i + j], v = a[i + j + len / 2] * w; n         a[i + j] = u + v; n         a[i + j + len / 2] = u - v; n         w *= wlen; n       } n     } n   } n   if (invert) n     for (int i = 0; i < n; ++i) a[i] /= n; n } n inline void input(int &a) { n   a = 0; n   while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) && n          (TEMPORARY_CHAR !=  - )) { n   } n   char neg = 0; n   if (TEMPORARY_CHAR ==  - ) { n     neg = 1; n     TEMPORARY_CHAR = getchar(); n   } n   while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) { n     a = (a << 3) + (a << 1) + TEMPORARY_CHAR -  0 ; n     TEMPORARY_CHAR = getchar(); n   } n   if (neg) a = -a; n } n inline void out(long long a) { n   if (!a) putchar( 0 ); n   if (a < 0) { n     putchar( - ); n     a = -a; n   } n   char s[20]; n   int i; n   for (i = 0; a; ++i) { n     s[i] =  0  + a % 10; n     a /= 10; n   } n   for (int j = (i)-1; j >= 0; j--) putchar(s[j]); n } n inline int nxt() { n   int(ret); n   input((ret)); n   ; n   return ret; n } n struct lnum { n   vector<int> a; n   int base; n   lnum(int num = 0, int base = 1000000000) : base(base) { n     if (!num) a.resize(1); n     while (num) { n       a.push_back(num % base); n       num /= base; n     } n   } n   inline int len() const { return a.size(); } n   lnum &operator=(const lnum &l) { n     if (this != &l) { n       a = l.a; n       base = l.base; n     } n     return *this; n   } n   inline friend lnum operator+(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     int ln = l.len(), rn = r.len(); n     int n = max(ln, rn); n     ret.a.resize(n); n     int o = 0; n     for (int i = 0; i < n; ++i) { n       int s = o; n       if (i < ln) s += l.a[i]; n       if (i < rn) s += r.a[i]; n       o = s >= base; n       if (o) s -= base; n       ret.a[i] = s; n     } n     if (o) ret.a.push_back(1); n     return ret; n   } n   inline friend lnum operator-(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     int n = l.len(); n     int rn = r.len(); n     ret.a.resize(n); n     int o = 0; n     for (int i = 0; i < n; ++i) { n       int s = l.a[i] - o; n       if (i < rn) s -= r.a[i]; n       o = s < 0; n       if (o) s += base; n       ret.a[i] = s; n     } n     if (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); n     return ret; n   } n   inline friend lnum operator*(const lnum &l, const lnum &r) { n     lnum ret(0, l.base); n     int base = l.base; n     if (l.len() * r.len() > 1000000) { n       vector<complex<long double> > fa(l.a.begin(), l.a.end()), n           fb(r.a.begin(), r.a.end()); n       int n = 1; n       while (n < max(l.len(), r.len())) n <<= 1; n       n <<= 1; n       fa.resize(n), fb.resize(n); n       fft(fa, false), fft(fb, false); n       for (int i = 0; i < n; ++i) fa[i] *= fb[i]; n       fft(fa, true); n       ret.a.resize(n); n       for (int i = 0; i < n; ++i) ret.a[i] = int(fa[i].real() + 0.5); n       int carry = 0; n       for (int i = 0; i < n; ++i) { n         ret.a[i] += carry; n         carry = ret.a[i] / base; n         ret.a[i] %= base; n       } n     } else { n       ret.a.resize(l.len() + r.len()); n       for (int i = 0; i < l.len(); ++i) n         for (int j = 0, carry = 0; j < r.len() || carry; ++j) { n           long long cur = ret.a[i + j] + n                           (long long)l.a[i] * (j < r.len() ? r.a[j] : 0) + n                           carry; n           ret.a[i + j] = cur % base; n           carry = cur / base; n         } n     } n     while (ret.len() > 1 && !ret.a.back()) ret.a.pop_back(); n     return ret; n   } n   inline friend lnum operator/(const lnum &l, const int &r) { n     lnum ret(0, l.base); n     ret.a.resize(l.len()); n     int carry = 0; n     for (int i = l.len() - 1; i >= 0; --i) { n       long long cur = l.a[i] + (long long)carry * l.base; n       ret.a[i] = cur / r; n       carry = cur % r; n     } n     while (ret.len() > 1 && ret.a.back() == 0) ret.a.pop_back(); n     return ret; n   } n   inline friend bool operator<(const lnum &l, const lnum &r) { n     if (l.len() < r.len()) return true; n     if (l.len() > r.len()) return false; n     int n = l.len(); n     for (int i = n - 1; i >= 0; --i) { n       if (l.a[i] < r.a[i]) return true; n       if (l.a[i] > r.a[i]) return false; n     } n     return false; n   } n   inline friend bool operator>(const lnum &l, const lnum &r) { return r < l; } n   inline friend bool operator==(const lnum &l, const lnum &r) { n     if (l.len() != r.len()) return false; n     int n = l.len(); n     for (int i = n - 1; i; --i) { n       if (l.a[i] != r.a[i]) return false; n     } n     return true; n   } n   inline friend bool operator!=(const lnum &l, const lnum &r) { n     return !(l == r); n   } n   inline void print() { n     if (base == 1000000000) { n       printf( %d , a.back()); n       for (int i = a.size() - 2; i >= 0; --i) printf( %09d , a[i]); n     } else { n       for (int i = a.size() - 1; i >= 0; --i) printf( %d , a[i]); n     } n   } n }; n struct item { n   int key, prior; n   item *l, *r; n   item() {} n   item(int key, int prior) : key(key), prior(prior), l(NULL), r(NULL) {} n }; n typedef item *pitem; n void split(pitem t, int key, pitem &l, pitem &r) { n   if (!t) n     l = r = NULL; n   else if (key < t->key) n     split(t->l, key, l, t->l), r = t; n   else n     split(t->r, key, t->r, r), l = t; n } n void merge(pitem &t, pitem l, pitem r) { n   if (!l || !r) n     t = l ? l : r; n   else if (l->prior > r->prior) n     merge(l->r, l->r, r), t = l; n   else n     merge(r->l, l, r->l), t = r; n } n int ans[300000]; n void dfs(pitem v, int ind) { n   if (!v) return; n   if (v->key != ind) { n     ans[v->key] = ind + 1; n   } n   dfs(v->l, ind); n   dfs(v->r, ind); n } n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   memset((ans), 0, sizeof(ans)); n   pitem root = NULL; n   for (int i = 0; i < (int)(n); i++) { n     merge(root, root, new item(i, rand())); n   } n   int l, r, ind; n   for (int i = 0; i < (int)(m); i++) { n     cin >> l >> r >> ind; n     l--; n     r--; n     ind--; n     pitem q1, otr, q2; n     split(root, l - 1, q1, otr); n     split(otr, r, otr, q2); n     dfs(otr, ind); n     merge(root, q1, new item(ind, rand())); n     merge(root, root, q2); n   } n   for (int i = 0; i < (int)(n); i++) { n     if (i) cout <<    ; n     cout << ans[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[300005]; n int sign(long long x) { return x > 0 ? 1 : -1; } n struct Node { n   int l, r, lx, mx, rx; n   void up(Node L, Node R) { n     lx = L.lx; n     rx = R.rx; n     mx = max(L.mx, R.mx); n     if (a[L.r] && a[R.l] && sign(a[L.r]) >= sign(a[R.l])) { n       mx = max(mx, L.rx + R.lx); n       if (L.mx == L.r - L.l + 1) lx = L.mx + R.lx; n       if (R.mx == R.r - R.l + 1) rx = R.mx + L.rx; n     } n     mx = max({mx, lx, rx}); n   } n } seg[300005 * 4]; n void update(int qx, int c, int l, int r, int i) { n   seg[i] = {l, r}; n   if (l == r) { n     a[qx] += c; n     if (a[qx] != 0) n       seg[i] = {l, r, 1, 1, 1}; n     else n       seg[i] = {l, r, 0, 0, 0}; n     return; n   } n   int mid = (l + r) / 2; n   if (qx <= mid) n     update(qx, c, l, mid, i * 2); n   else n     update(qx, c, mid + 1, r, i * 2 + 1); n   seg[i].up(seg[i * 2], seg[i * 2 + 1]); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]); n   for (int i = 1; i < n; ++i) a[i] = a[i + 1] - a[i]; n   for (int i = 1; i < n; ++i) update(i, 0, 1, n - 1, 1); n   int Q; n   scanf( %d , &Q); n   while (Q--) { n     int l, r, x; n     scanf( %d%d%d , &l, &r, &x); n     if (l > 1) update(l - 1, x, 1, n - 1, 1); n     if (r < n) update(r, -x, 1, n - 1, 1); n     printf( %d n , seg[1].mx + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( O2 ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n const double pi = n     3.141592653589793238462643383279502884197169399375105820974944; n const double e = 2.71828182845904523536028747135266249775724709369995; n const long long mod = 1e9 + 7; n const long long inf = 2e18; n const long long ninf = -2e18; n const long long nax = 1e6; n long long power(long long x, long long y, long long mod) { n   long long ans = 1; n   x %= mod; n   while (y) { n     if (y & 1) ans = (x * ans) % mod; n     x = (x * x) % mod; n     y >>= 1; n   } n   return ans; n } n template <class T> n struct search_buckets { n   int N, BUCKET_SIZE; n   vector<T> arr, buckets; n   search_buckets(const vector<T>& initial = {}) { n     arr = buckets = initial; n     N = arr.size(); n     BUCKET_SIZE = 3 * sqrtl(N * log(N + 1)) + 1; n     cerr <<  Bucket size:   << BUCKET_SIZE <<   n ; n     for (int start = 0; start < N; start += BUCKET_SIZE) { n       sort(buckets.begin() + start, buckets.begin() + get_bucket_end(start)); n     } n   } n   int get_bucket_end(int bucket_start) const { n     return min(bucket_start + BUCKET_SIZE, N); n   } n   int bucket_less_than(int bucket_start, T value) const { n     auto begin = buckets.begin() + bucket_start; n     auto end = buckets.begin() + get_bucket_end(bucket_start); n     return lower_bound(begin, end, value) - begin; n   } n   int less_than(int start, int end, T value) const { n     int count = 0; n     int bucket_start = start - start % BUCKET_SIZE; n     int bucket_end = min(get_bucket_end(bucket_start), end); n     if (start - bucket_start < bucket_end - start) { n       while (start > bucket_start) { n         count -= arr[--start] < value; n       } n     } else { n       while (start < bucket_end) { n         count += arr[start++] < value; n       } n     } n     if (start == end) return count; n     bucket_start = end - end % BUCKET_SIZE; n     bucket_end = get_bucket_end(bucket_start); n     if (end - bucket_start < bucket_end - end) { n       while (end > bucket_start) { n         count += arr[--end] < value; n       } n     } else { n       while (end < bucket_end) { n         count -= arr[end++] < value; n       } n     } n     while (start < end && get_bucket_end(start) <= end) { n       count += bucket_less_than(start, value); n       start = get_bucket_end(start); n     } n     assert(start == end); n     return count; n   } n   int prefix_less_than(int n, T value) const { return less_than(0, n, value); } n   void modify(int index, T value) { n     int bucket_start = index - index % BUCKET_SIZE; n     int old_pos = bucket_start + bucket_less_than(bucket_start, arr[index]); n     int new_pos = bucket_start + bucket_less_than(bucket_start, value); n     if (old_pos < new_pos) { n       copy(buckets.begin() + old_pos + 1, buckets.begin() + new_pos, n            buckets.begin() + old_pos); n       new_pos--; n     } else { n       copy_backward(buckets.begin() + new_pos, buckets.begin() + old_pos, n                     buckets.begin() + old_pos + 1); n     } n     buckets[new_pos] = value; n     arr[index] = value; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   time_t t1, t2; n   t1 = clock(); n   int n; n   cin >> n; n   vector<int> a(n + 1); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     a[i] = min(a[i], n); n   } n   search_buckets<int> st(a); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     int lol = a[i] - st.less_than(1, a[i] + 1, i) - (a[i] >= i); n     ; n     ans += lol; n   } n   cout << ans / 2; n   t2 = clock(); n   cerr <<   n  n        <<  time taken:   << t2 - t1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100010; n const int INF = 1000000; n int n; n stack<int> killers; n int main() { n   cin >> n; n   int values[n + 1], life[n + 1]; n   for (int i = 1; i <= n; ++i) { n     cin >> values[i]; n   } n   life[0] = INF; n   values[0] = 0; n   killers.push(0); n   for (int i = 1; i <= n; ++i) { n     life[i] = 1; n     while (killers.size() && values[i] > values[killers.top()]) { n       life[i] = max(life[i], life[killers.top()] + 1); n       killers.pop(); n     } n     killers.push(i); n   } n   int sol = 0; n   for (int i = 1; i <= n; ++i) { n     if (life[i] < INF) { n       sol = max(sol, life[i]); n     } n   } n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   for (int j = 0; j < n; ++j) { n     if (arr[j] == 0) n       if (j == (n - 1)) n         cout <<  EASY  << endl; n       else n         continue; n     else { n       cout <<  HARD  << endl; n       break; n     } n   } n   return 0; n }; n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, l, m, n; n   int a[1001]; n   char s[1000], c; n   while (scanf( %d%d , &n, &m) != EOF) { n     memset(a, 0, sizeof(a)); n     while (m--) { n       scanf( %s , s); n       scanf( %s , s); n       scanf( %s , s); n       c = s[0]; n       scanf( %s , s); n       scanf( %d , &k); n       if (c ==  r ) { n         for (i = 1; i <= k; i++) a[i] = 1; n       } else { n         for (i = k; i <= n; i++) a[i] = 1; n       } n     } n     k = 0; n     for (i = 1; i <= n; i++) n       if (a[i] == 0) k++; n     if (k == 0) n       printf( -1 n ); n     else n       printf( %d n , k); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char str[100]; n int L; n bool ok(int n) { n   if (n == 0) return true; n   set<string> S; n   for (int i = 0; i + n <= L; i++) { n     string temp(str + i, str + i + n); n     if (!S.insert(temp).second) return true; n   } n   return false; n } n int main() { n   scanf( %s , str); n   L = strlen(str); n   int low = 0, high = L; n   while (high - low > 1) { n     int mid = (low + high) / 2; n     if (ok(mid)) { n       low = mid; n     } else { n       high = mid; n     } n   } n   if (ok(high)) { n     printf( %d n , high); n   } else { n     printf( %d n , low); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long a[100000]; n map<long long, long long> mp; n map<long long, long long> mp1; n int main() { n   cin.sync_with_stdio(false); n   long long i, j, k, l, c, d, e, f, g, h, v, b[10000], aa[1009], bb[1000], n, m, n       r, t; n   long long x1, x2, y1, y2, x3, x4, x5, x6; n   string s, s1, s2 =  fedabc , s3, ss[10000]; n   while (cin >> n) { n     cin >> s[0]; n     c = 0; n     if (n % 4 == 1 || n % 4 == 2) { n       c = c + 16 * (n / 4); n       i = (n / 4) * 4 + 1; n       for (i;; i = i + 3) { n         if (i == n) { n           for (k = 0; k < 6; k++) { n             c++; n             if (s[0] == s2[k]) break; n           } n           cout << (c); n           return 0; n         } else { n           c += 6 + 1; n           for (j = i + 1; j <= (i + 1); j++) { n             if (j == n) { n               for (k = 0; k < 6; k++) { n                 c++; n                 if (s[0] == s2[k]) break; n               } n               cout << (c); n               return 0; n             } n             c += 3; n             i = j; n           } n         } n       } n     } else { n       m = n - 1; n       c = c + 16 * (m / 4); n       i = (m / 4) * 4 + 3; n       { n         for (i;; i = i + 3) { n           if (i == n) { n             for (k = 0; k < 6; k++) { n               c++; n               if (s[0] == s2[k]) break; n             } n             cout << (c); n             return 0; n           } else { n             c += 6 + 1; n             for (j = i + 1; j <= (i + 1); j++) { n               if (j == n) { n                 for (k = 0; k < 6; k++) { n                   c++; n                   if (s[0] == s2[k]) break; n                 } n                 cout << (c); n                 return 0; n               } n               c += 3; n               i = j; n             } n           } n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long hash1 = 201326611; n const int inf = 0x3f3f3f3f; n const int _inf = 0xc0c0c0c0; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const long long _INF = 0xc0c0c0c0c0c0c0c0; n const long long mod = (int)1e9 + 7; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long ksm(long long a, long long b, long long mod) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return ans; n } n long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); } n void exgcd(long long a, long long b, long long &x, long long &y, long long &d) { n   if (!b) { n     d = a; n     x = 1; n     y = 0; n   } else { n     exgcd(b, a % b, y, x, d); n     y -= x * (a / b); n   } n } n inline int read() { n   int date = 0, m = 1; n   char ch = 0; n   while (ch !=  -  && (ch< 0  | ch>  9 )) ch = getchar(); n   if (ch ==  - ) { n     m = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     date = date * 10 + ch -  0 ; n     ch = getchar(); n   } n   return date * m; n } n const int MAX_N = 150025; n int C[MAX_N << 1], arr[MAX_N], b[MAX_N]; n void add(int x, int v) { n   for (; x < MAX_N; x += x & (-x)) C[x] += v; n } n int get(int x) { n   int res = 0; n   for (; x; x -= x & (-x)) res += C[x]; n   return res; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     for (int i = 1; i <= 2 * n + 2; ++i) C[i] = 0; n     for (int i = 1; i <= n; ++i) scanf( %d , &arr[i]), b[i] = arr[i]; n     sort(b + 1, b + 1 + n); n     int sz = unique(b + 1, b + 1 + n) - b - 1; n     int ans = 0; n     for (int i = n; i >= 1; --i) { n       arr[i] = lower_bound(b + 1, b + 1 + sz, arr[i]) - b; n       ans += min(get(arr[i]), 1); n       add(arr[i] + 1, 1); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n stack<int> S; n int a[1005], n; n bool judge() { n   for (int i = 0; i < n; i++) n     if (a[i] != i) return 0; n   return 1; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i <= n; i++) { n     if (judge()) { n       cout <<  Yes  << endl; n       return 0; n     } n     for (int j = 0; j < n; j += 2) a[j] = (a[j] + 1) % n; n     for (int j = 1; j < n; j += 2) a[j] = (a[j] - 1 + n) % n; n   } n   cout <<  No  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string c =  ROYGBIV ; n   vector<char> s; n   for (int i = 0; i < n; i++) { n     if (i <= 6) n       s.push_back(c[i]); n     else { n       s.push_back(s[i - 4]); n     } n   } n   for (int i = 0; i < n; i++) cout << s[i]; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline bool uax(T &x, T y) { n   return (y > x) ? x = y, true : false; n } n template <typename T> n inline bool uin(T &x, T y) { n   return (y < x) ? x = y, true : false; n } n template <typename T> n void kek(T ans) { n   cout << ans << endl; n   exit(0); n } n const int MOD = (int)1e9 + 7; n const long long INF = (long long)1e18 + 42; n int main() { n   cin.tie(nullptr)->sync_with_stdio(false); n   int n; n   cin >> n; n   vector<vector<int>> a(n); n   vector<set<pair<int, int>>> b(3); n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     a[x].push_back(i); n   } n   vector<int> team(3, 0); n   vector<int> ans; n   for (int i = 0; i < n; ++i) { n     for (int j : a[i]) { n       b[i % 3].emplace(i, j); n     } n     if (b[i % 3].empty()) kek( Impossible ); n     auto it = b[i % 3].upper_bound({i - team[i % 3], n}); n     if (it == b[i % 3].begin()) kek( Impossible ); n     --it; n     ans.push_back(it->second); n     uax(team[i % 3], i - it->first); n     b[i % 3].erase(it); n   } n   cout <<  Possible n ; n   for (int i : ans) cout << 1 + i <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b; n long long tinh(long long n) { n   long long l = 0, r = 1000001; n   while (l < r) { n     long long m = (l + r + 1) / 2; n     long long t = m * m * m; n     if (t > n) n       r = m - 1; n     else n       l = m; n   } n   return l; n } n int main() { n   scanf( %d , &n); n   for (int i = (1); i <= (n); i++) { n     scanf( %lld %lld , &a, &b); n     long long res = tinh(a * b); n     if (res * res * res == a * b && a % res == 0 && b % res == 0) { n       printf( YES n ); n     } else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using Point = complex<int>; n using ll = long long; n ll cross(Point a, Point b) { n   return 1LL * a.real() * b.imag() - 1LL * b.real() * a.imag(); n } n ll det(Point a, Point b, Point c) { return cross(b - a, c - a); } n namespace std { n bool operator<(const Point& a, const Point& b) { n   return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag()); n } n }  // namespace std n struct DynHull { n   struct Node { n     int bl, br, l, r, lc, rc; n   }; n   vector<Node> T = {{-1, -1, -1, -1, 0, 0}}; n   vector<Point> P; n   DynHull(vector<Point> P) : P(P) {} n   bool leaf(int x) { return T[x].l == T[x].r; } n   int combine(int lc, int rc, int ret = -1) { n     if (!lc || !rc) return lc + rc; n     if (ret == -1 || ret == lc || ret == rc) ret = T.size(), T.push_back({}); n     T[ret] = {-1, -1, T[lc].l, T[rc].r, lc, rc}; n     while (!leaf(lc) || !leaf(rc)) { n       int a = T[lc].bl, b = T[lc].br, c = T[rc].bl, d = T[rc].br; n       if (a != b && det(P[a], P[b], P[c]) > 0) { n         lc = T[lc].lc; n       } else if (c != d && det(P[b], P[c], P[d]) > 0) { n         rc = T[rc].rc; n       } else if (a == b) { n         rc = T[rc].lc; n       } else if (c == d) { n         lc = T[lc].rc; n       } else { n         auto s1 = det(P[a], P[b], P[c]), s2 = det(P[a], P[b], P[d]); n         assert(s1 >= s2); n         auto xc = P[c].real(), xd = P[d].real(), xm = P[T[rc].l].real(); n         if (s1 == s2 || s1 * xd - s2 * xc < (s1 - s2) * xm) { n           lc = T[lc].rc; n         } else { n           rc = T[rc].lc; n         } n       } n     } n     T[ret].bl = T[lc].l; n     T[ret].br = T[rc].l; n     return ret; n   } n   int Build(int b, int e) { n     if (e - b == 1) { n       T.push_back({b, b, b, b, 0, 0}); n       return T.size() - 1; n     } n     int m = (b + e) / 2; n     return combine(Build(b, m), Build(m, e)); n   } n   int Erase(int x, int pos) { n     if (!x || T[x].r < pos || T[x].l > pos) return x; n     return leaf(x) ? 0 : combine(Erase(T[x].lc, pos), Erase(T[x].rc, pos), x); n   } n   template <typename Callback> n   void Hull(int x, Callback&& cb, int l = 0, int r = 1e9) { n     if (!x || l > r) return; n     if (leaf(x)) { n       cb(T[x].l); n       return; n     } n     Hull(T[x].lc, cb, l, min(r, T[x].bl)); n     Hull(T[x].rc, cb, max(l, T[x].br), r); n   } n }; n inline ll area(Point a, Point b, Point c) { n   return (ll)(b.real() - a.real()) * (c.imag() - a.imag()) - n          (ll)(b.imag() - a.imag()) * (c.real() - a.real()); n } n vector<Point> convexHull(vector<Point> p) { n   int n = p.size(), m = 0; n   if (n < 3) return p; n   vector<Point> hull(n + n); n   sort(p.begin(), p.end()); n   for (int i = 0; i < n; ++i) { n     while (m > 1 and area(hull[m - 2], hull[m - 1], p[i]) <= 0) --m; n     hull[m++] = p[i]; n   } n   for (int i = n - 2, j = m + 1; i >= 0; --i) { n     while (m >= j and area(hull[m - 2], hull[m - 1], p[i]) <= 0) --m; n     hull[m++] = p[i]; n   } n   hull.resize(m - 1); n   return hull; n } n const int LG = 18; n const int N = 100010; n int q, par[LG][N]; n inline int prv(int i, int n) { return (i ? i : n) - 1; } n inline int nxt(int i, int n) { return i + 1 < n ? i + 1 : 0; } n int kthPar(int u, int k) { n   for (int i = LG - 1; i >= 0; --i) { n     assert(u != -1); n     if (k & 1 << i) k ^= 1 << i, u = par[i][u]; n   } n   return u; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<pair<Point, int>> pts(n); n   map<Point, int> id; n   for (int i = 0; i < n; ++i) { n     int x, y; n     cin >> x >> y; n     pts[i] = make_pair(Point{x, y}, i); n     id[Point{x, y}] = i; n   } n   if (n == 1) { n     cin >> q; n     while (q--) cout << 1 <<   n ; n     return 0; n   } n   vector<pair<Point, int>> pts_copy = pts; n   sort(pts.begin(), pts.end()); n   vector<Point> P(n); n   vector<int> remap(n); n   for (int i = 0; i < n; ++i) { n     remap[i] = pts[i].second; n     P[i] = pts[i].first; n   } n   auto LH = DynHull(P); n   int lh = LH.Build(0, n); n   for (int i = 0; i < n; ++i) P[i] = -P[i]; n   reverse(P.begin(), P.end()); n   auto UH = DynHull(P); n   int uh = UH.Build(0, n); n   vector<int> layer(n, -1); n   for (int i = 0;; ++i) { n     vector<int> all; n     LH.Hull(lh, [&](int x) { all.push_back(x); }); n     UH.Hull(uh, [&](int x) { all.push_back(n - x - 1); }); n     if (all.empty()) break; n     for (auto x : all) { n       lh = LH.Erase(lh, x); n       uh = UH.Erase(uh, n - x - 1); n       layer[remap[x]] = i; n     } n   } n   int up = *max_element(layer.begin(), layer.end()) + 1; n   vector<vector<Point>> layers(up); n   for (int i = 0; i < n; ++i) { n     layers[layer[i]].emplace_back(pts_copy[i].first); n   } n   for (int i = 0; i < up; ++i) layers[i] = convexHull(layers[i]); n   vector<int> pf(up); n   for (int i = 0; i < up; ++i) { n     pf[i] = layers[i].size(); n     if (i) pf[i] += pf[i - 1]; n   } n   vector<int> whichLayer(n), whichPos(n); n   for (int i = 0; i < up; ++i) { n     for (int j = 0; j < layers[i].size(); ++j) { n       auto x = layers[i][j]; n       whichLayer[id[x]] = i, whichPos[id[x]] = j; n     } n   } n   memset(par, -1, sizeof par); n   for (int i = 0; i + 1 < up; ++i) { n     if (layers[i + 1].size() == 1) { n       int to = id[layers[i + 1][0]]; n       for (auto x : layers[i]) par[0][id[x]] = to; n       continue; n     } n     int k = 0, sz = layers[i + 1].size(); n     vector<int> to(layers[i].size()); n     for (int j = 0; j < layers[i].size(); ++j) { n       while (area(layers[i][j], layers[i + 1][k], layers[i + 1][nxt(k, sz)]) < n              0) n         k = nxt(k, sz); n       while (area(layers[i][j], layers[i + 1][prv(k, sz)], layers[i + 1][k]) > n              0) n         k = prv(k, sz); n       to[j] = k; n     } n     for (int j = 0; j < layers[i].size(); ++j) { n       int u = id[layers[i][j]], n           v = id[layers[i + 1][to[prv(j, layers[i].size())]]]; n       par[0][u] = v; n     } n   } n   for (auto x : layers[up - 1]) par[0][id[x]] = n; n   for (int j = 1; j < LG; ++j) { n     for (int i = 0; i <= n; ++i) n       if (par[j - 1][i] != -1) { n         par[j][i] = par[j - 1][par[j - 1][i]]; n       } n   } n   int sz = layers[0].size(); n   vector<pair<long double, int>> vec; n   for (int i = 0; i < sz; ++i) { n     Point cur = layers[0][nxt(i, sz)] - layers[0][i]; n     vec.emplace_back(atan2l(cur.imag(), cur.real()), i); n   } n   sort(vec.begin(), vec.end()); n   cin >> q; n   while (q--) { n     int dx, dy, k; n     cin >> dx >> dy >> k; n     long double ang = atan2l(dy, dx); n     int pos = -1; n     auto it = upper_bound(vec.begin(), vec.end(), make_pair(ang, 696969)); n     if (it == vec.end()) n       pos = vec[0].second; n     else n       pos = it->second; n     int where = lower_bound(pf.begin(), pf.end(), k) - pf.begin(); n     int ext = k - (where ? pf[where - 1] : 0); n     int at = kthPar(id[layers[0][pos]], where); n     assert(at != n); n     int final = (whichPos[at] + ext - 1) % (int)layers[where].size(); n     int ans = id[layers[where][final]]; n     printf( %d n , ans + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using vi = vector<int>; n const int LOG = 17; n const int inf = 1e9; n template <typename T> n struct RMQ { n   vector<vector<T>> spr; n   RMQ(const vector<T>& v) : spr(1, v) { n     for (int j = 1; (1 << j) <= (int)v.size(); ++j) { n       spr.push_back(vector<T>((int)v.size() - (1 << j) + 1)); n       for (int i = 0; i < (int)spr[j].size(); ++i) { n         spr[j][i] = min(spr[j - 1][i], spr[j - 1][i + (1 << (j - 1))]); n       } n     } n   } n   T get(int l, int r) { n     int d = 31 - __builtin_clz(r - l + 1); n     return min(spr[d][l], spr[d][r - (1 << d) + 1]); n   } n }; n int main() { n   cin.tie(0)->sync_with_stdio(0); n   int n, m, q; n   cin >> n >> m >> q; n   vi v(n), g(n); n   for (int i = 0; i < n; ++i) cin >> v[i], v[i]--; n   for (int i = 0; i < n; ++i) g[v[i]] = v[(i + 1) % n]; n   vi a(m); n   for (int i = 0; i < m; ++i) cin >> a[i], a[i]--; n   vector<vi> spr(LOG + 1, vi(m)); n   vi nxt(n, -1); n   for (int i = m - 1; i >= 0; --i) { n     nxt[a[i]] = i; n     spr[0][i] = nxt[g[a[i]]]; n   } n   for (int j = 0; j < LOG; ++j) { n     for (int i = 0; i < m; ++i) { n       if (spr[j][i] == -1) n         spr[j + 1][i] = -1; n       else n         spr[j + 1][i] = spr[j][spr[j][i]]; n     } n   } n   vi res(m); n   for (int i = 0; i < m; ++i) { n     int k = i; n     for (int j = LOG; j >= 0; --j) { n       if ((n - 1) & (1 << j)) { n         k = spr[j][k]; n         if (k == -1) break; n       } n     } n     res[i] = k == -1 ? inf : k; n   } n   RMQ<int> rmq(res); n   string ans; n   for (int i = 0; i < q; ++i) { n     int l, r; n     cin >> l >> r; n     --l, --r; n     int a = rmq.get(l, r); n     if (a <= r) n       ans.push_back( 1 ); n     else n       ans.push_back( 0 ); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-15; n const long double PI = 3.14159265358979323846; n inline int lg2(long long n) { n   int h = 0; n   while ((1ll << h) < n) ++h; n   return h; n } n struct configio { n   configio() { n     cin.tie(nullptr); n     ios_base::sync_with_stdio(false); n   } n } cnfio; n int diff(int a, int b, int mod) { return ((a - b) % mod + mod) % mod; } n struct candy { n   int h, m; n }; n int main() { n   int n, x; n   cin >> n >> x; n   vector<candy> v1[2]; n   for (int i = 0; i < n; ++i) { n     int t, h, m; n     cin >> t >> h >> m; n     v1[t].push_back({h, m}); n   } n   long long ans = 0; n   for (int type = 0; type <= 1; ++type) { n     vector<candy> v[2]; n     v[0] = v1[0]; n     v[1] = v1[1]; n     int cur_ans = 0; n     long long cur_x = x; n     int cur_type = type; n     while (true) { n       int id = -1; n       for (int i = 0; i < v[cur_type].size(); ++i) { n         if (v[cur_type][i].h <= cur_x) { n           if (id == -1 || (v[cur_type][id].m < v[cur_type][i].m)) { n             id = i; n           } n         } n       } n       if (id == -1) { n         break; n       } n       cur_ans++; n       cur_x += v[cur_type][id].m; n       v[cur_type].erase(v[cur_type].begin() + id); n       cur_type ^= 1; n     } n     ans = max(ans, (long long)cur_ans); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 4e3 + 5; n long long n, m, a[N], f[N][N]; n long long solve(long long l, long long r) { n   if (l > r) return 0; n   long long p = 0; n   for (long long i = l; i <= r; i++) n     if (a[i] < a[p]) p = i; n   long long ls = solve(l, p - 1), rs = solve(p + 1, r); n   memset(f[p], -0x3f, sizeof(f[p])); n   for (long long i = 0; i <= p - l; i++) n     for (long long j = 0; j <= r - p; j++) { n       f[p][i + j] = max(f[p][i + j], f[ls][i] + f[rs][j] - 2 * i * j * a[p]); n       f[p][i + j + 1] = n           max(f[p][i + j + 1], f[ls][i] + f[rs][j] - 2 * i * j * a[p] - n                                    2 * (i + j) * a[p] + (m - 1) * a[p]); n     } n   return p; n } n signed main() { n   cin >> n >> m; n   a[0] = 1e18; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   long long p = solve(1, n); n   cout << f[p][m] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   vector<long long> f(2000006, -1); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     f[a[i]] = i; n   } n   long long ans = 1e18, res; n   for (int i = 0; i <= 2000005; i++) { n     if (f[i] < 0) continue; n     if (ans > f[i]) { n       res = i; n     } n     ans = min(f[i], ans); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   long long int a[n], b[n], c[n - 1]; n   b[n - 1] = 0, c[n - 2] = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> b[i]; n   } n   for (int i = 0; i < n - 2; i++) { n     cin >> c[i]; n   } n   sort(a, a + n); n   sort(b, b + n - 1); n   sort(c, c + n - 2); n   for (int i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       cout << a[i] << endl; n       break; n     } n   } n   for (int i = 0; i < n - 1; i++) { n     if (b[i] != c[i]) { n       cout << b[i] << endl; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e5 + 5; n int n; n int ans[inf]; n int last[inf]; n struct node { n   int x, h, q; n   bool operator<(const node &s) const { return s.x > x; } n } a[inf << 1]; n inline int read() { n   int a = 0; n   int b = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) b = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     a = a * 10 + c -  0 ; n     c = getchar(); n   } n   return a * b; n } n inline void run() { n   int x, y; n   n = read(); n   for (int i = 1; i <= n; i++) { n     x = read(); n     y = read(); n     a[i].x = x; n     a[i].h = y; n     a[i].q = i; n   } n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= n; i++) { n     ans[i] = 1; n   } n   for (int i = n - 1; i > 0; i--) { n     int now = i + 1; n     while (now && ((a[i].x + a[i].h) > a[now].x)) { n       ans[a[i].q] += ans[a[now].q]; n       now = last[now]; n     } n     last[i] = now; n   } n   for (int i = 1; i <= n; i++) { n     cout << ans[i] <<    ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int sum, limits; n   vector<int> ans; n   cin >> sum >> limits; n   for (int i = limits; i >= 1; i--) { n     if ((i & (-i)) <= sum) { n       sum -= (i & (-i)); n       ans.push_back(i); n     } n   } n   if (!sum) { n     int len = ans.size(); n     cout << len << endl; n     for (int i = 0; i < len; i++) { n       cout << ans[i]; n       if (i == len - 1) n         cout << endl; n       else n         cout <<    ; n     } n   } else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> arr[1000005]; n int par[1000005], sz[1000005]; n int find(int x) { n   if (par[x] != x) par[x] = find(par[x]); n   return par[x]; n } n void Union(int a, int b) { n   a = find(a); n   b = find(b); n   if (a != b) { n     par[a] = b; n     sz[b] += sz[a]; n     sz[a] = 0; n   } n } n int ans[1005][1005], n, m; n bool vis[1005][1005], add[1000005]; n long long k; n void dfs(int x, int y) { n   vis[x][y] = 1; n   if (!k) return; n   ans[x][y] = 1; n   k--; n   for (int dx = -1; dx <= 1; dx++) { n     for (int dy = -1; dy <= 1; dy++) { n       if (abs(dx) + abs(dy) == 1 && x + dx >= 0 && x + dx < n && y + dy >= 0 && n           y + dy < m && !vis[x + dx][y + dy] && add[(x + dx) * m + y + dy]) n         dfs(x + dx, y + dy); n     } n   } n } n int main() { n   scanf( %d%d%I64d , &n, &m, &k); n   for (int i = 0; i < n * m; i++) { n     scanf( %d , &arr[i].first); n     arr[i].second = i; n     par[i] = i; n     sz[i] = 1; n   } n   sort(arr, arr + n * m); n   for (int i = n * m - 1; i >= 0; i--) { n     int idx = arr[i].second; n     if (idx >= m && add[idx - m]) Union(idx, idx - m); n     if (idx < (n - 1) * m && add[idx + m]) Union(idx, idx + m); n     if (idx % m && add[idx - 1]) Union(idx, idx - 1); n     if (idx % m != m - 1 && add[idx + 1]) Union(idx, idx + 1); n     if (k % arr[i].first == 0 && sz[find(idx)] >= k / arr[i].first) { n       k /= arr[i].first; n       dfs(idx / m, idx % m); n       printf( YES n ); n       for (int x = 0; x < n; x++) { n         for (int j = 0; j < m; j++) printf( %d  , ans[x][j] * arr[i].first); n         printf(  n ); n       } n       return 0; n     } n     add[idx] = 1; n   } n   printf( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int m, n, arr[200][200]; n int color(int x, int y) { n   int col = 1; n   while (arr[x - 1][y] == col or arr[x][y - 1] == col or arr[x + 1][y] == col or n          arr[x][y + 1] == col) n     col++; n   return col; n } n int color2(int x, int y) { n   int col = 1; n   while (arr[x - 1][y] == col or arr[x + 1][y] == col or arr[x][y + 1] == col) n     col++; n   return col; n } n int fit(int x, int y, int col) { n   if (arr[x][y - 1] == col or arr[x + 1][y] == col or arr[x][y + 1] == col) n     return 0; n   return 1; n } n int main() { n   cin >> m >> n; n   int x = 1, y = 1; n   while (x <= m) { n     if (y == n + 1) { n       x++; n       y = 1; n       continue; n     } n     if (arr[x][y]) { n       y++; n       continue; n     } n     int xx = x, yy = y, col = color(x, y); n     arr[x][y] = col; n     while (xx + 1 <= m and yy + 1 <= n and !arr[xx + 1][y] and n            !arr[x][yy + 1] and fit(xx + 1, y, col) and color2(x, yy + 1) == col) n       xx++, yy++; n     for (int i = x; i <= xx; i++) n       for (int j = y; j <= yy; j++) arr[i][j] = col; n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) printf( %c , (char)(arr[i][j] +  A  - 1)); n     puts(  ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n double dp[205][35][35]; n vector<int> p; n pair<int, int> rev(int x, int y, int rx, int ry) { n   if (x >= rx && x <= ry) { n     x = rx + (ry - rx) - (x - rx); n   } n   if (y >= rx && y <= ry) { n     y = rx + (ry - rx) - (y - rx); n   } n   return make_pair(x, y); n } n int main() { n   cin >> n >> k; n   p.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> p[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = i; j < n; j++) { n       dp[0][i][j] = 1.0; n     } n   } n   double pp = 2.0 / (n * (n + 1)); n   for (int q = 1; q <= k; q++) { n     for (int i = 0; i < n; i++) { n       for (int j = i; j < n; j++) { n         for (int k = 0; k < n; k++) { n           for (int l = k; l < n; l++) { n             pair<int, int> xy = rev(i, j, k, l); n             if (xy.first < xy.second) { n               dp[q][i][j] += dp[q - 1][xy.first][xy.second] * pp; n             } else { n               dp[q][i][j] += (1.0 - dp[q - 1][xy.second][xy.first]) * pp; n             } n           } n         } n       } n     } n   } n   double ans = 0; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (p[i] < p[j]) { n         ans += 1.0 - dp[k][i][j]; n       } else { n         ans += dp[k][i][j]; n       } n     } n   } n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long modular(long long a, long long b, long long c) { n   if (b == 0) { n     return 1; n   } n   if (b % 2 == 0) { n     return modular(((a * a) % c), b / 2, c); n   } else { n     return ((a % c) * (modular(((a * a) % c), b / 2, c) % c)) % c; n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a[n]; n     string arr[n]; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       arr[i] = bitset<32>(a[i]).to_string(); n     } n     long long turn = 0; n     long long flag = 0; n     for (long long i = 0; i < 32; i++) { n       long long c1 = 0; n       long long c2 = 0; n       for (long long j = 0; j < n; j++) { n         if (arr[j][i] ==  1 ) { n           c1++; n         } else { n           c2++; n         } n       } n       if ((c1 % 4 == 1) || ((c1 % 4 == 3) && (n % 2 == 0))) { n         if (turn == 0) { n           flag = 1; n           break; n         } else { n           flag = 2; n           break; n         } n       } n       if ((c1 % 4 == 3) && (n % 2 != 0)) { n         if (turn == 0) { n           flag = 2; n           break; n         } else { n           flag = 1; n           break; n         } n       } n     } n     if (flag == 0) { n       cout <<  DRAW  n            <<   n ; n     } else { n       if (flag == 1) { n         cout <<  WIN  n              <<   n ; n       } else { n         cout <<  LOSE  n              <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   char grid[n][m]; n   bool flag1 = 0, flag2 = 0; n   int cnt[100] = {}; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     if (s.find( - ) < 0 || s.find( - ) >= s.size()) continue; n     int x = s.find( G ); n     int y = s.find( R ); n     if (y == -1 && x == -1) continue; n     if (y >= s.size() || y < 0) flag1 = 1; n     if (x >= s.size() || x < 0) flag2 = 1; n     if (x < s.size() && x >= 0 && y < s.size() && y >= 0) { n       int tmp = abs(x - y) - 1; n       int cur = 0; n       while (tmp) { n         cnt[cur] += tmp % 2; n         tmp /= 2; n         cur++; n       } n     } n   } n   if (flag1 & flag2) n     puts( Draw ); n   else if (flag1) n     puts( First ); n   else if (flag2) n     puts( Second ); n   else { n     int ans = 0; n     for (int i = 0; i < 100; i++) n       if (cnt[i] % (k + 1)) { n         puts( First ); n         return 0; n       } n     puts( Second ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   while (1 == scanf( %d , &N)) { n     vector<int> A(N); n     for (int i = 0; i < (int)(N); i++) scanf( %d , &A[i]); n     sort((A).begin(), (A).end()); n     int need_to_fill = 0, need_to_move = 0; n     for (int i = 0; i < (int)(N); i++) need_to_fill += max(0, 3 - A[i]); n     int total = accumulate((A).begin(), (A).end(), 0); n     sort((A).begin(), (A).end()); n     int ans = INT_MAX; n     for (int i = 0; i < (int)(N); i++) { n       int num_rooms = N - i; n       if (4 * num_rooms >= total && 3 * num_rooms <= total) { n         int tmp = max(need_to_move, need_to_fill); n         ans = min(ans, tmp); n       } n       need_to_fill -= max(0, 3 - A[i]); n       need_to_move += A[i]; n     } n     if (ans == INT_MAX) n       puts( -1 ); n     else n       printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   if (t % 2 == 0) { n     cout <<  Mahmoud  << endl; n   } else { n     cout <<  Ehab  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   cin >> a >> b; n   n = a + b + 1; n   for (int i = 0; i < a; i++) cout << i + 1 <<    ; n   for (int i = 0; i <= b; i++) cout << a + b + 1 - i <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int x = 0, f = 1; n   register char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c - 48, c = getchar(); n   return x * f; n } n namespace Graph { n int head[1000005], cnt; n struct edge { n   int v, next, w; n } e[1000005 << 1]; n inline void add(int u, int v, int w) { n   e[++cnt] = (edge){v, head[u], w}, head[u] = cnt; n } n }  // namespace Graph n int n, m, k, Ans, fac, sum, g[1000005]; n char c[1000005]; n inline int qpow(int a, int b) { n   int r = 1; n   while (b) { n     if (b & 1) r = 1ll * a * r % 1000000007; n     a = 1ll * a * a % 1000000007, b >>= 1; n   } n   return r; n } n signed main() { n   Ans = n = read(), k = read(), g[0] = fac = 1; n   for (register int i = (1); i <= (n); ++i) { n     sum = (sum + g[i - 1]) % 1000000007; n     if (i > k) sum = (sum - g[i - k - 1] + 1000000007) % 1000000007; n     g[i] = 1ll * sum * qpow(i, 1000000007 - 2) % 1000000007; n     Ans = (Ans - g[i - 1] + 1000000007) % 1000000007; n     if (i != 1) fac = 1ll * fac * (i - 1) % 1000000007; n   } n   cout << 1ll * fac * Ans % 1000000007; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[200000 + 9]; n long long com[200000 + 9]; n double f1(int i, int k) { n   long long sum1 = a[i] + com[n] - com[n - k] + com[i - 1] - com[i - 1 - k]; n   double av1 = (double)sum1 / (2 * k + 1); n   return av1; n } n double f2(int i, int k) { n   long long sum2 = n       a[i] + com[n] - com[n - (k - 1)] + com[i - 1] - com[i - 1 - (k - 1)]; n   double av2 = (double)sum2 / (2 * (k - 1) + 1); n   return av2; n } n long long ValAt(int i, int k) { n   long long sum = a[i] + com[n] - com[n - k] + com[i - 1] - com[i - 1 - k]; n   return sum; n } n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   cin >> n; n   for (int i = (1); i <= (n); i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   if (n <= 2) { n     cout << n <<   n ; n     for (int i = (1); i <= (n); i++) cout << a[i] <<    ; n     cout <<   n ; n     return 0; n   } n   com[0] = 0; n   for (int i = (1); i <= (n); i++) com[i] = com[i - 1] + a[i]; n   double bestVal = 0; n   int besti = 1, bestSize = 1; n   for (int i = 2; i < n; i++) { n     int s = 1, e = min(i - 1, n - i); n     double bestAv = 0; n     int size; n     while (s <= e) { n       int k = (s + e) / 2; n       long long sum1 = ValAt(i, k); n       double av1 = (double)sum1 / (2 * k + 1); n       long long sum2 = ValAt(i, k - 1); n       double av2 = (double)sum2 / (2 * (k - 1) + 1); n       if (av1 > av2) { n         s = k + 1; n         bestAv = av1; n         size = 2 * k + 1; n       } else n         e = k - 1; n     } n     double val = bestAv - a[i]; n     if (val > bestVal) { n       bestVal = val; n       besti = i; n       bestSize = size; n     } n   } n   vector<int> v; n   v.push_back(a[besti]); n   int k = (bestSize - 1) / 2; n   for (int i = besti - 1; i >= besti - k; i--) v.push_back(a[i]); n   for (int i = n; i > n - k; i--) v.push_back(a[i]); n   sort(v.begin(), v.end()); n   cout << bestSize <<   n ; n   for (auto x : v) cout << x <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double n, m, k; n int main() { n   while (scanf( %lf %lf %lf , &n, &m, &k) != EOF) { n     if (m > n + k) { n       printf( %.6lf n , 0.0); n       continue; n     } n     double resp = 1.0; n     for (int i = 0; i <= k; i++) { n       resp *= ((m - i) / (n + k + 1 - i)); n     } n     printf( %.6lf n , 1.0 - resp); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 9, M = 3e5 + 9, OO = 0x3f3f3f3f; n const double EPS = 0.00000000001; n const int mod = 1000003; n int n, m, d[3005]; n bool flage = 1; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     scanf( %d , d + i); n     if (d[i] == 1 || d[i] == n) flage = 0; n   } n   sort(d, d + m); n   int mx = min(1, m); n   for (int i = 0, j = 1; j < m; ++j) n     if (d[j] == d[j - 1] + 1) n       mx = max(mx, j - i + 1); n     else n       i = j; n   if (mx >= 3) flage = 0; n   if (flage) n     puts( YES ); n   else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n bool a[100100]; n void go() { n   long long int n; n   cin >> n; n   memset(a, true, sizeof(a)); n   for (int i = 2; i <= n; i++) { n     for (int j = i + 1; i * j <= n; j++) { n       if (j % i == 0) continue; n       a[j * i] = false; n     } n   } n   vector<int> ans; n   for (int i = 2; i <= n; i++) { n     if (a[i]) ans.push_back(i); n   } n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ; n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long int t = 1; n   while (t--) go(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 10; n const int inf = 0x3f3f3f3f; n int a[maxn]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= k; ++i) scanf( %d , &a[i]); n   int x = 2 * n, y = n; n   for (int i = 1; i <= k; ++i) { n     if (a[i] >= 4 && y > 0) { n       int m = a[i] / 4; n       a[i] -= min(m, y) * 4; n       y -= min(m, y); n     } n   } n   for (int i = 1; i <= k; ++i) { n     if (x > 0) { n       int m = a[i] / 2; n       a[i] -= min(m, x) * 2; n       x -= min(x, m); n     } n   } n   int tmp = y; n   for (int i = 1; i <= k; ++i) { n     if (y > 0) { n       int m = a[i] / 2; n       a[i] -= min(m, y) * 2; n       y -= min(m, y); n     } n   } n   tmp = tmp - y + x; n   for (int i = 1, j = k; i < j;) { n     if (y > 0) { n       int m = min(min(a[i], a[j]), y); n       a[i] -= m, a[j] -= m, y -= m; n     } n     if (a[i] == 0) ++i; n     if (a[j] == 0) --j; n     if (y == 0) break; n   } n   tmp += y; n   for (int i = 1; i <= k; ++i) { n     if (tmp > 0) { n       int m = min(tmp, a[i]); n       a[i] -= m; n       tmp -= m; n     } n   } n   int f = 1; n   for (int i = 1; i <= k; ++i) { n     if (a[i] > 0) f = 0; n   } n   if (f) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a; n   cin >> n >> a; n   vector<int> checkpt; n   for (int i = 0; i < n; i++) { n     int t; n     cin >> t; n     checkpt.push_back(t); n   } n   sort(checkpt.begin(), checkpt.end()); n   long long distance = 0; n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   if (checkpt[n - 1] <= a) { n     distance += a - checkpt[1]; n     cout << distance << endl; n     return 0; n   } else if (a <= checkpt[0]) { n     distance += checkpt[n - 2] - a; n     cout << distance << endl; n     return 0; n   } n   int pointer; n   for (int i = 0; i < n - 1; i++) { n     if (checkpt[i] <= a && checkpt[i + 1] >= a) { n       checkpt.insert(checkpt.begin() + (i + 1), a); n       pointer = i + 1; n       break; n     } n   } n   long long dis1 = 0; n   long long dis2 = 0; n   long long dis3 = 0; n   long long dis4 = 0; n   dis1 += checkpt[pointer] - checkpt[0]; n   if (pointer + 1 != n) { n     dis1 += checkpt[n - 1] - checkpt[0]; n     dis3 += (checkpt[n - 1] - checkpt[pointer]) * 2; n   } n   dis3 += checkpt[pointer] - checkpt[0]; n   dis4 += checkpt[n] - checkpt[pointer]; n   if (pointer - 1 != 0) { n     dis2 += (checkpt[pointer] - checkpt[1]) * 2; n     dis4 += checkpt[n] - checkpt[1]; n   } n   dis2 += checkpt[n] - checkpt[pointer]; n   long long min1 = min(dis1, dis2); n   long long min2 = min(min1, dis3); n   distance = min(min2, dis4); n   cout << distance << endl; n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<int, int>, bool> fuck; n int n, m; n char s[5]; n int x, y; n long long ans; n int dx, dy; n int main() { n   scanf( %d%d , &n, &m); n   scanf( %d%d , &x, &y); n   scanf( %s , s + 1); n   if (s[1] ==  U ) n     dx = -1; n   else n     dx = 1; n   if (s[2] ==  L ) n     dy = -1; n   else n     dy = 1; n   int fis = 0; n   int test = 1000000; n   while (test--) { n     pair<int, int> now = pair<int, int>(x, y); n     if (!fuck[now]) { n       fuck[now] = 1; n       fis++; n     } n     if (fis == n + m - 2) { n       cout << ans + 1; n       return 0; n     } n     int xl, yl, l; n     int ex, ey; n     if (dx == -1) n       xl = x - 1; n     else n       xl = n - x; n     if (dy == -1) n       yl = y - 1; n     else n       yl = m - y; n     if (xl < yl) { n       ex = -dx; n       ey = dy; n       l = xl; n     } else { n       if (xl > yl) { n         ey = -dy; n         ex = dx; n         l = yl; n       } else { n         ex = -dx; n         ey = -dy; n         l = yl; n       } n     } n     x += dx * l; n     y += dy * l; n     ans += 1ll * l; n     dx = ex; n     dy = ey; n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string c; n   cin >> c; n   for (int i = 1; i <= n; i++) n     if (n % i == 0) reverse(c.begin(), c.begin() + i); n   cout << c; n } n


#include <bits/stdc++.h> n using namespace std; n long long int cost(long long int h[], long long int n, long long int a, n                    long long int r, long long int m, long long int x) { n   long long int plus = 0, minus = 0; n   for (int i = 0; i < n; i++) { n     if (h[i] > x) { n       minus += h[i] - x; n     } else if (h[i] < x) { n       plus += x - h[i]; n     } n   } n   if (m > a + r) { n     return (a * plus + r * minus); n   } else { n     return (min(plus, minus) * m + (plus - min(plus, minus)) * a + n             (minus - min(plus, minus)) * r); n   } n } n int main() { n   long long int n, a, r, m; n   cin >> n >> a >> r >> m; n   long long int h[n], start = 0, end = 0; n   for (int i = 0; i < n; i++) { n     cin >> h[i]; n     end = max(end, h[i]); n   } n   long long int ans = 1e18; n   while (start <= end) { n     long long int mid = (start + end) >> 1, mid_1; n     long long int c_mid = cost(h, n, a, r, m, mid); n     if (c_mid < ans) { n       ans = c_mid; n     } n     mid_1 = mid + 1; n     long long int c_mid_1 = cost(h, n, a, r, m, mid_1); n     if (c_mid_1 > c_mid) { n       end = mid - 1; n     } else { n       start = mid + 1; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9, PI = acos(-1.); n const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; n const int N = 2e5 + 5, SQ = 500; n int n, q, a[N], l[N], r[N], p[N]; n long long ans[N], c[1000005], s; n void add(int x) { n   int v = a[x]; n   s -= c[v] * c[v] * v; n   c[v]++; n   s += c[v] * c[v] * v; n } n void rem(int x) { n   int v = a[x]; n   s -= c[v] * c[v] * v; n   c[v]--; n   s += c[v] * c[v] * v; n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < q; ++i) scanf( %d%d , &l[i], &r[i]), p[i] = i; n   sort(p, p + q, [](int a, int b) { n     return l[a] / SQ == l[b] / SQ ? r[a] < r[b] : l[a] < l[b]; n   }); n   int cl = 0, cr = 0; n   for (int i = 0; i < q; ++i) { n     int cur = p[i]; n     while (cl < l[cur]) rem(cl++); n     while (cl > l[cur]) add(--cl); n     while (cr < r[cur]) add(++cr); n     while (cr > r[cur]) rem(cr--); n     ans[cur] = s; n   } n   for (int i = 0; i < q; ++i) printf( %lld n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void check_max(T& a, T b) { n   if (a < b) a = b; n } n template <class T> n void check_min(T& a, T b) { n   if (a > b) a = b; n } n const int MAXN = 10100; n int n, k; n double per; n double a[MAXN]; n int main() { n   cin >> n >> k; n   per = (double)k / 100; n   for (int _t = n, i = 0; i < _t; i++) cin >> a[i]; n   sort(a, a + n); n   double l = 0, r = 1000; n   while (r - l > 1e-8) { n     double m = (r + l) / 2; n     double more = 0, less = 0; n     for (int _t = n, i = 0; i < _t; i++) n       if (a[i] > m) n         more += a[i] - m; n       else n         less += m - a[i]; n     if (more * (1 - per) >= less) n       l = m; n     else n       r = m; n   } n   double ans = (l + r) / 2; n   printf( %.7lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long i, j, k, x, y, z, n, mi = 1e16, sum = 0; n   cin >> n; n   long long a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   if (n == 1 || n == 2) { n     cout << a[0] - 1; n     return; n   } n   z = (long long)pow(1e18, 1.0 / n); n   for (i = 1; i <= z; i++) { n     sum = 0; n     for (j = 0; j < n; j++) { n       y = (long long)pow(i, j); n       sum += abs(a[j] - y); n     } n     mi = min(mi, sum); n   } n   cout << mi; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t-- > 0) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[2005], b[2005]; n int main() { n   std::ios::sync_with_stdio(false); n   int n, k, p; n   long long minn = (1000 * 1000 * 1000 + 5); n   minn *= (1000 * 1000 * 1000 + 7); n   long long ans; n   int j, val, i; n   cin >> n >> k >> p; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (i = 0; i < k; i++) { n     cin >> b[i]; n   } n   sort(a, a + n); n   sort(b, b + k); n   for (i = 0; i < k - n + 1; i++) { n     val = 0; n     ans = 0; n     for (j = i; j < i + n; j++) { n       if ((b[j] >= a[val] && b[j] <= p) || (a[val] >= b[j] && b[j] >= p)) { n         ans = max(ans, (long long)abs(a[val] - p)); n       } else { n         ans = max(ans, (long long)abs(b[j] - a[val]) + abs(p - b[j])); n       } n       val++; n     } n     minn = min(minn, ans); n   } n   cout << minn << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main() { n   map<string, bool> vis; n   int n; n   scanf( %d , &n); n   while (n--) { n     string s; n     cin >> s; n     if (vis[s]) n       puts( YES ); n     else n       puts( NO ); n     vis[s] = 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double n, r; n signed main() { n   scanf( %lf%lf , &n, &r); n   printf( %.10f n , 2.0 * n * 0.5 * r * r * sin(acos(-1.0) / (2.0 * n)) / n                         sin(acos(-1.0) - (acos(-1.0) / (2.0 * n)) * 3) * n                         sin(2 * acos(-1.0) / (2.0 * n))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double p[1000]; n const int cc = 2; n double a[201][cc * 101][cc * 101]; n double get(int IT) { n   for (int it = 0; it <= IT; it++) n     for (int i = 0; i <= cc * n; i++) n       for (int j = 0; j <= cc * n; j++) a[it][i][j] = -100; n   for (int i = 0; i <= cc * n; i++) n     for (int j = 0; j <= min(n, i); j++) n       a[0][i][min(cc * n, i - j + n - j)] = n           max(a[0][i][min(cc * n, i - j + n - j)], p[j]); n   for (int it = 1; it <= IT; it++) { n     for (int i = 0; i <= cc * n; i++) n       for (int j = 0; j <= cc * n; j++) n         for (int k = 0; k <= cc * n; k++) n           a[it][i][k] = n               max(a[it][i][k], (a[it - 1][i][j] + a[it - 1][j][k]) / 2); n   } n   double ans = 0; n   for (int i = 0; i <= cc * n; i++) ans = max(ans, a[IT][0][i]); n   return ans; n } n int main() { n   cin >> n; n   for (int i = 0; i <= n; i++) { n     cin >> p[i]; n   } n   printf( %.18lf n , (double)get(30)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pwr(long long base, long long p, long long mod = (1000000007LL)) { n   long long ans = 1; n   while (p) { n     if (p & 1) ans = (ans * base) % mod; n     base = (base * base) % mod; n     p /= 2; n   } n   return ans; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long nCr(long long n, long long r) { n   long long C[r + 1]; n   memset(C, 0, sizeof(C)); n   C[0] = 1; n   for (long long i = 1; i <= n; i++) n     for (long long j = min(i, r); j > 0; j--) C[j] = C[j] + C[j - 1]; n   return C[r]; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n == 2) return true; n   if (n % 2 == 0) return false; n   long long m = sqrt(n); n   for (long long i = 3; i <= m; i += 2) n     if (n % i == 0) return false; n   return true; n } n long long M(long long a) { return (a % (1000000007LL)); } n bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> v(n); n   for (long long i = 0; i < (long long)(n); ++i) cin >> v[i]; n   vector<int> ans(n + 1); n   for (long long i = 0; i < (long long)(n); ++i) { n     vector<int> color_total(n + 1); n     int best = 0; n     for (int j = i; j < n; j++) { n       color_total[v[j]]++; n       if (color_total[v[j]] > color_total[best]) { n         best = v[j]; n       } else if (color_total[v[j]] == color_total[best]) { n         if (v[j] < best) { n           best = v[j]; n         } n       } n       ans[best]++; n     } n   } n   for (long long i = 1; i <= (long long)(n); ++i) { n     cout << ans[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, q, a; n   cin >> n >> k >> q; n   int t[150005] = {0}; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     t[i] = a; n   } n   set<pair<int, int> > s; n   set<pair<int, int> >::iterator it; n   for (int i = 1; i <= q; i++) { n     int flag, id; n     cin >> flag >> id; n     if (flag == 1) { n       if (s.size() == k) { n         it = s.begin(); n         if (t[id] > (it->first)) { n           s.erase(it); n           s.insert(make_pair(t[id], id)); n         } n       } else { n         s.insert(make_pair(t[id], id)); n       } n     } else { n       if (s.find(make_pair(t[id], id)) != s.end()) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4e3 + 10, mod = 1e9 + 7; n char a[N]; n int n, k; n long long dp[N][N], dp2[N][N]; n int main() { n   cin >> n >> k; n   cin >> (a + 1); n   dp[0][0] = dp2[0][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = 0; j <= k; j++) { n       dp[i][j] = dp[i - 1][j] * (a[i] -  a  + 1) % mod; n       for (int t = 0; t < j / (n - i + 1) && i - t > 0; t++) n         dp[i][j] = (dp[i][j] + n                     ( z  - a[i]) * dp2[i - t - 1][j - (t + 1) * (n - i + 1)]) % n                    mod; n       dp2[i][j] = (dp[i][j] - dp[i - 1][j] + mod) % mod; n     } n   cout << dp[n][k]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pll = pair<ll, ll>; n using vll = vector<ll>; n using vpll = vector<pll>; n struct d_ { n   template <typename T> n   d_& operator,(const T& x) { n     cerr <<     << x; n     return *this; n   } n } d_t; n int mix[1024]; n int main(void) { n   ios_base::sync_with_stdio(false); n   ll n; n   cin >> n; n   ; n   fill(begin(mix), end(mix), (int)1e9 + 7); n   int st = 2; n   for (ll i(0); i < 10; i++) { n     for (ll k(0); k < 2; k++) { n       set<int> vals; n       for (ll j(0); j < n; j++) { n         if (j % st < st / 2 and k == 0) { n           vals.insert(j); n         } else if (j % st >= st / 2 and k == 1) { n           vals.insert(j); n         } n       } n       if (vals.empty()) continue; n       char* sp =   ; n       cout << vals.size() <<   n ; n       for (auto e : vals) { n         cout << sp << e + 1; n         sp =    ; n       } n       cout << endl; n       for (ll j(0); j < n; j++) { n         ll vl; n         cin >> vl; n         ; n         if (!vals.count(j)) { n           mix[j] = min(mix[j], (int)vl); n         } n       } n       cout << endl; n     } n     st *= 2; n   } n   cout <<  -1  << endl; n   char* sp =   ; n   for (ll i(0); i < n; i++) { n     cout << sp << mix[i]; n     sp =    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char v[2100][2100]; n int n, m; n int sumx[2100][2100]; n int sumy[2100][2100]; n long long ans1, ans2, ans3, cima, baixo; n int main() { n   bool ok; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; ++i) scanf( %s , v[i]); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (j > 0) sumx[i][j] = sumx[i][j - 1]; n       sumx[i][j] += (v[i][j] ==  . ); n     } n   } n   for (int j = 0; j < m; ++j) { n     for (int i = 0; i < n; ++i) { n       if (i > 0) sumy[i][j] = sumy[i - 1][j]; n       sumy[i][j] += (v[i][j] ==  . ); n     } n   } n   for (int i = 1; i < m - 1; ++i) n     if (sumy[n - 1][i] == n) ans1++; n   for (int i = 1; i < n - 1; ++i) n     if (sumx[i][m - 1] == m) ans1++; n   for (int i = 1; i < n - 1; ++i) { n     ok = true; n     if (v[i][0] ==  # ) ok = false; n     if (ok) n       for (int j = 1; j < m - 1; ++j) { n         if (v[i][j] !=  . ) { n           ok = false; n           break; n         } n         if (sumy[i - 1][j] == i) ans2++; n         if (sumy[n - 1][j] - sumy[i][j] == n - i - 1) ans2++; n       } n     if (v[i][m - 1] ==  # ) continue; n     for (int j = m - 2; j >= 1 && v[i][j] ==  . ; --j) { n       if (sumy[i - 1][j] == i) ans2++; n       if (sumy[n - 1][j] - sumy[i][j] == n - i - 1) ans2++; n     } n   } n   for (int i = 1; i < n - 1; ++i) { n     cima = baixo = 0; n     for (int j = 1; j < m - 1; ++j) { n       if (v[i][j] ==  # ) { n         cima = baixo = 0; n         continue; n       } n       if (sumy[i][j] == i + 1) { n         ans3 += baixo + cima; n         if (j > 1 && v[i][j - 1] ==  .  && sumy[i][j - 1] == i + 1) ans3--; n       } n       if (sumy[n - 1][j] - sumy[i][j] == n - i - 1) { n         ans3 += baixo + cima; n         if (j > 1 && v[i][j - 1] ==  .  && n             sumy[n - 1][j - 1] - sumy[i][j - 1] == n - i - 1) n           ans3--; n       } n       if (sumy[i][j] == i + 1) cima++; n       if (sumy[n - 1][j] - sumy[i][j] == n - i - 1) baixo++; n     } n   } n   for (int j = 1; j < m - 1; ++j) { n     cima = baixo = 0; n     for (int i = 1; i < n - 1; ++i) { n       if (v[i][j] ==  # ) { n         cima = baixo = 0; n         continue; n       } n       if (sumx[i][j] == j + 1) { n         ans3 += baixo + cima; n         if (i > 1 && v[i - 1][j] ==  .  && sumx[i - 1][j] == j + 1) ans3--; n       } n       if (sumx[i][m - 1] - sumx[i][j] == m - j - 1) { n         ans3 += baixo + cima; n         if (i > 1 && v[i - 1][j] ==  .  && n             sumx[i - 1][m - 1] - sumx[i - 1][j] == m - j - 1) n           ans3--; n       } n       if (sumx[i][j] == j + 1) cima++; n       if (sumx[i][m - 1] - sumx[i][j] == m - j - 1) baixo++; n     } n   } n   printf( %lld n , ans1 + ans2 + ans3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n const int dy[] = {0, -1, 0, 1, -1, 1, 1, -1}; n template <class T> n inline bool get(T& n) { n   char c, mul = 1; n   n = 0; n   while (!isdigit(c = getchar_unlocked()) && (c != EOF) && (c !=  - )) n     ; n   if (c == EOF) return false; n   if (c ==  - ) { n     c = getchar_unlocked(); n     mul = -1; n   } n   for (; isdigit(c); c = getchar_unlocked()) n = n * 10 + c -  0 ; n   n *= mul; n   return true; n } n inline void get(char& c) { n   while (isspace(c = getchar_unlocked())) n     ; n } n struct Point { n   long long x, y; n } p[101010]; n long long cross(Point o, Point a, Point b) { n   return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x); n } n int n; n int l[101010][20], par[101010], level[101010]; n vector<int> child[101010]; n void dfs(int u, int l) { n   level[u] = l; n   for (int(i) = 0, _ = (child[u].size()); (i) < _; ++i) dfs(child[u][i], l + 1); n } n void preprocess() { n   vector<int> v; n   int k = 0; n   for (int(i) = (n - 1), _ = (0); (i) >= _; --(i)) { n     par[i] = -1; n     while (k > 1 && cross(p[v[k - 2]], p[v[k - 1]], p[i]) < 0) { n       --k; n       v.pop_back(); n     } n     if (k > 0) { n       par[i] = v.back(); n       child[v.back()].push_back(i); n     } n     v.push_back(i); n     ++k; n   } n   int root = 0; n   while (par[root] != -1) root = par[root]; n   dfs(root, 0); n   for (int(i) = 0, _ = (n); (i) < _; ++i) n     for (int j = 0; (1 << j) < n; ++j) l[i][j] = -1; n   for (int(i) = 0, _ = (n); (i) < _; ++i) l[i][0] = par[i]; n   for (int j = 1; 1 << j < n; ++j) n     for (int(i) = 0, _ = (n); (i) < _; ++i) n       if (l[i][j - 1] != -1) l[i][j] = l[l[i][j - 1]][j - 1]; n } n int lca(int p, int q) { n   int log, i; n   if (level[p] < level[q]) swap(p, q); n   for (log = 1; 1 << log <= level[p]; ++log) n     ; n   --log; n   for (i = log; i >= 0; --i) n     if (level[p] - (1 << i) >= level[q]) p = l[p][i]; n   if (p == q) return p; n   for (i = log; i >= 0; --i) n     if (l[p][i] != -1 && l[p][i] != l[q][i]) p = l[p][i], q = l[q][i]; n   return par[p]; n } n int main() { n   get(n); n   for (int(i) = 0, _ = (n); (i) < _; ++i) get(p[i].x), get(p[i].y); n   preprocess(); n   int m, a, b; n   get(m); n   while (m--) { n     get(a); n     get(b); n     --a; n     --b; n     printf( %d  , lca(a, b) + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 50 + 5; n const int maxm = 2500 + 5; n const int inf = 1 << 29; n const long long mod = 1e9 + 7; n const double eps = 1e-8; n long long read() { n   long long s = 0, w = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) { n     if (c ==  - ) w = -1; n   } n   for (; isdigit(c); c = getchar()) { n     s = (s << 3) + (s << 1) + (c ^ 48); n   } n   return w == 1 ? s : -s; n } n int main() { n   int t = read(); n   while (t--) { n     int a = read(), b = read(); n     if (a > b) swap(a, b); n     if ((a + b) & 1) { n       int mn = b - (a + b + 1) / 2; n       int mx = min((a + b + 1) / 2, b) + min((a + b) / 2, a); n       printf( %d n , mx - mn + 1); n       for (int i = mn; i <= mx; i++) { n         printf( %d  , i); n       } n       puts(  ); n     } else { n       int mn = b - (a + b) / 2; n       int mx = min((a + b) / 2, b) + min((a + b) / 2, a); n       printf( %d n , (mx / 2 - mn / 2 + 1)); n       for (int i = mn; i <= mx; i += 2) { n         printf( %d  , i); n       } n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int temp; n   map<int, vector<int>> mpp; n   for (int i = 2; i <= n; i++) { n     cin >> temp; n     mpp[temp].push_back(i); n   } n   for (auto itr = mpp.begin(); itr != mpp.end(); ++itr) { n     vector<int> v = (*itr).second; n     int cnt = 0; n     if (v.size() >= 1) { n       for (int j = 0; j < v.size(); j++) { n         if (mpp[v[j]].size() == 0) { n           cnt++; n         } n       } n       if (cnt < 3) { n         cout <<  No  << endl; n         return 0; n       } n     } n   } n   cout <<  Yes  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   pair<int, int> c = make_pair(1, 0); n   int dx = 1, cover = 0, inc = 0; n   while (k != 1) { n     if (inc == 0) cout << 2 <<    ; n     if (dx == 1 && c.second + dx <= m) { n       c.second += dx; n     } else if (dx == 1) { n       c.first++; n       dx = -1; n     } else if (dx == -1 && c.second + dx >= 1) { n       c.second += dx; n     } else if (dx == -1) { n       c.first++; n       dx = 1; n     } n     cout << c.first <<     << c.second <<    ; n     inc++; n     if (inc == 2) { n       cout << endl; n       k--; n       inc = 0; n     } n     cover++; n   } n   cout << n * m - cover <<    ; n   while (cover < n * m) { n     if (dx == 1 && c.second + dx <= m) { n       c.second += dx; n     } else if (dx == 1) { n       c.first++; n       dx = -1; n     } else if (dx == -1 && c.second + dx >= 1) { n       c.second += dx; n     } else if (dx == -1) { n       c.first++; n       dx = 1; n     } n     cout << c.first <<     << c.second <<    ; n     cover++; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long li, ri; n } sum[400000]; n long long pmx[400000], nmx[400000]; n long long pmi[400000], nmi[400000]; n int main() { n   long long n; n   memset(pmi, 0x7f7f7f7f, sizeof(pmi)); n   memset(nmi, 0x7f7f7f7f, sizeof(nmi)); n   memset(pmx, -0x7f7f7f7f, sizeof(pmx)); n   memset(nmx, -0x7f7f7f7f, sizeof(nmx)); n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     scanf( %lld %lld , &sum[i].li, &sum[i].ri); n   } n   for (long long i = 1; i <= n; i++) { n     pmx[i] = max(sum[i].li, pmx[i - 1]); n     pmi[i] = min(sum[i].ri, pmi[i - 1]); n   } n   for (long long i = n; i >= 1; i--) { n     nmx[i] = max(sum[i].li, nmx[i + 1]); n     nmi[i] = min(sum[i].ri, nmi[i + 1]); n   } n   long long ans = -0x7f7f7f7f, sum1 = 0, sum2 = 0; n   for (long long i = 1; i <= n; i++) { n     sum1 = max(pmx[i - 1], nmx[i + 1]); n     sum2 = min(pmi[i - 1], nmi[i + 1]); n     ans = max(ans, sum2 - sum1); n   } n   if (ans < 0) { n     printf( 0 n ); n   } else n     printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int V = 0; n struct Node { n   int id; n   long long num, sum; n   Node *l, *r; n   Node() { n     num = -1; n     sum = 0; n     l = r = nullptr; n     id = V++; n   } n }; n int N; n string s; n Node* build(int& n) { n   Node* node = new Node(); n   if (s[n] ==  ( ) { n     n++; n     node->l = build(n); n     n++; n     node->r = build(n); n     n++; n     node->sum += node->l->sum + node->r->sum + 1; n   } else { n     node->num = s[n] -  0 ; n     n++; n   } n   return node; n } n const long long INF = 1 << 25; n int P, M; n bool remplus; n long long mi[10000][210]; n long long ma[10000][210]; n pair<long long, long long> f(Node* node, int rem) { n   if (node->num != -1) { n     if (rem) return {INF, INF}; n     return {node->num, node->num}; n   } n   int id = node->id; n   if (mi[id][rem] != INF) return {mi[id][rem], ma[id][rem]}; n   if (rem > node->sum) return {INF, INF}; n   pair<long long, long long> ret = {INF, -INF}; n   for (int i = 0; i < 2; i++) { n     int nrem = rem - (remplus && !i || !remplus && i); n     if (nrem < 0) continue; n     for (int j = 0; j <= nrem; j++) { n       auto res1 = f(node->l, j); n       auto res2 = f(node->r, nrem - j); n       if (res1.first == INF || res2.first == INF) continue; n       if (i == 0) { n         ret.first = min(ret.first, res1.first + res2.first); n         ret.second = max(ret.second, res1.second + res2.second); n       } else { n         ret.first = min(ret.first, res1.first - res2.second); n         ret.second = max(ret.second, res1.second - res2.first); n       } n     } n   } n   mi[id][rem] = ret.first; n   ma[id][rem] = ret.second; n   return ret; n } n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   cin >> s >> P >> M; n   N = s.size(); n   int n = 0; n   Node* root = build(n); n   fill((long long*)begin(mi), (long long*)end(mi), INF); n   fill((long long*)begin(ma), (long long*)end(ma), INF); n   remplus = P <= M; n   int rem = remplus ? P : M; n   cout << f(root, rem).second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int x, y, n; n     cin >> x >> y >> n; n     int a, b; n     a = n % x; n     b = n - a; n     if (b + y <= n) { n       cout << b + y << endl; n     } else { n       cout << b + y - x << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int c[5555], ans[5555]; n int main() { n   int n; n   cin >> n; n   int a[n + 1]; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     memset(c, 0, sizeof(c)); n     int bc = 0, bt = -1; n     for (int j = i; j <= n; j++) { n       int s = ++c[a[j]]; n       if (s > bc || (s == bc && a[j] < bt)) bc = s, bt = a[j]; n       ++ans[bt]; n     } n   } n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int power(int a, int b) { n   if (b == 0) n     return 1; n   else if (b % 2 == 0) n     return power((a * a) % 1000000007, b / 2); n   else n     return (a * power((a * a) % 1000000007, b / 2) % 1000000007); n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   cin >> t; n   while (t--) { n     int n, x, i, m, res, a; n     cin >> n >> x; n     set<int> s; n     m = INT_MIN; n     bool flag = false; n     for (i = 0; i < n; i++) { n       cin >> a; n       s.insert(a); n       m = max(m, a); n       if (x == a) flag = true; n     } n     if (flag) { n       cout <<  1 n ; n       continue; n     } n     res = x / m; n     if (x % m) n       cout << max(2, res + 1) <<   n ; n     else n       cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, rem; n   cin >> a >> b; n   long long int count = 0; n   a = max(a, b); n   b = min(a, b); n   while (a != b && b != 0) { n     count += a / b; n     a = a % b; n     a = a + b; n     b = a - b; n     a = a - b; n   } n   cout << count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, r, x, y, k; n   scanf( %d%d%d%d%d , &x, &y, &l, &r, &k); n   int L = (int)ceil(1.0 * x / k), R = (int)floor(1.0 * y / k); n   if (R < L || R < l || r < L) n     puts( NO ); n   else n     puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct pt { n   long long x; n   long long y; n }; n pt u; n bool cmp(pt a, pt b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } n bool cw(pt a, pt b, pt c) { n   return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0; n } n bool ccw(pt a, pt b, pt c) { n   return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0; n } n long long operator%(const pt &a, const pt &b) { return a.x * b.y - a.y * b.x; } n long long operator*(const pt &a, const pt &b) { return a.x * b.x + a.y * b.y; } n bool A(const pt &p) { return u % p > 0 || (u % p == 0 && u * p > 0); } n bool operator<(const pt &a, const pt &b) { n   return (A(a) == A(b) && a % b > 0) || (A(a) && !A(b)); n } n void convex_hull(vector<pt> &a) { n   if (a.size() == 1) return; n   sort(a.begin(), a.end(), &cmp); n   pt p1 = a[0], p2 = a.back(); n   vector<pt> up, down; n   up.push_back(p1); n   down.push_back(p1); n   for (int i = 1; i < (int)a.size(); i++) { n     if (i == a.size() - 1 || cw(p1, a[i], p2)) { n       while (up.size() >= 2 && !cw(up[up.size() - 2], up[up.size() - 1], a[i])) n         up.pop_back(); n       up.push_back(a[i]); n     } n     if (i == a.size() - 1 || ccw(p1, a[i], p2)) { n       while (down.size() >= 2 && n              !ccw(down[down.size() - 2], down[down.size() - 1], a[i])) n         down.pop_back(); n       down.push_back(a[i]); n     } n   } n   a.clear(); n   for (int i = 0; i < (int)up.size(); i++) a.push_back(up[i]); n   for (int i = down.size() - 2; i > 0; i--) a.push_back(down[i]); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   u.x = 0; n   u.y = 0; n   long long n; n   cin >> n; n   map<pair<long long, long long>, long long> cont; n   vector<pt> points, points2; n   points.push_back({0, 0}); n   for (int i = 0; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     pt a; n     a.x = x; n     a.y = y; n     points.push_back(a); n     points2.push_back(a); n   } n   vector<pt> white; n   vector<pt> black; n   convex_hull(points); n   long long vez = 1; n   sort(points.begin(), points.end()); n   for (auto e : points) { n     cont[{e.x, e.y}] = 1; n     if (e.x == 0 && e.y == 0) { n       white.push_back(e); n       black.push_back(e); n       continue; n     } n     vez = 1 - vez; n     vez == 1 ? white.push_back(e) : black.push_back(e); n   } n   for (auto e : points2) { n     if (cont[{e.x, e.y}] == 0) { n       white.push_back(e); n       black.push_back(e); n     } n   } n   convex_hull(white); n   convex_hull(black); n   bool can = false; n   for (auto e : points) { n     if (e.x & 1 || e.y & 1) can = true; n   } n   for (auto e : black) { n     if (e.x & 1 || e.y & 1) can = true; n   } n   for (auto e : white) { n     if (e.x & 1 || e.y & 1) can = true; n   } n   if (can) n     cout <<  Ani  << endl; n   else n     cout <<  Borna  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char s[50001]; n int last[26][50001]; n int best[51][50001]; n bool prv[51][50001]; n void print(int i, int j, int k) { n   int len = 2 * i + (k != -1 ? 1 : 0); n   char ans[101]; n   ans[len] =   0 ; n   if (k != -1) ans[i] = s[k]; n   while (j != 0) { n     if (!prv[i][j]) { n       --j; n       continue; n     } n     --i, --j; n     ans[i] = ans[len - i - 1] = s[j]; n   } n   printf( %s n , ans); n } n void run(int casenr) { n   scanf( %s , s); n   n = strlen(s); n   memset(last, -1, sizeof(last)); n   for (int j = (0); j < (n); ++j) { n     int x = s[j] -  a ; n     for (int xx = (0); xx < (26); ++xx) last[xx][j + 1] = last[xx][j]; n     last[x][j + 1] = j; n   } n   memset(best, -1, sizeof(best)); n   best[0][0] = n; n   prv[0][0] = true; n   for (int i = (0); i < (50); ++i) n     for (int j = (0); j < (n); ++j) n       if (best[i][j] != -1) { n         if (j + 1 <= best[i][j] && best[i][j] > best[i][j + 1]) { n           best[i][j + 1] = best[i][j]; n           prv[i][j + 1] = false; n         } n         int x = s[j] -  a ; n         if (last[x][best[i][j]] != -1 && last[x][best[i][j]] >= j + 1 && n             last[x][best[i][j]] > best[i + 1][j + 1]) { n           best[i + 1][j + 1] = last[x][best[i][j]]; n           prv[i + 1][j + 1] = true; n         } n       } n   for (int i = 50; i >= 0; --i) { n     if (i != 50) n       for (int j = (0); j < (n); ++j) n         if (best[i][j] != -1 && j < best[i][j]) { n           print(i, j, j); n           return; n         } n     for (int j = (0); j < (n); ++j) n       if (best[i][j] != -1) { n         print(i, j, -1); n         return; n       } n   } n   assert(false); n } n int main() { n   run(1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 13 * 16, Mod = 1e9 + 7; n struct Matrix { n   int n, m, A[N][N]; n   inline Matrix(int _n, int _m) : n(_n), m(_m) { memset(A, 0, sizeof(A)); } n   inline Matrix operator*(Matrix &X) { n     Matrix R(n, X.m); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < X.m; j++) n         for (int k = 0; k < m; k++) n           R.A[i][j] = (R.A[i][j] + 1LL * A[i][k] * X.A[k][j]) % Mod; n     return R; n   } n   inline Matrix operator^(long long pw) { n     Matrix R(n, n), T = *this; n     for (int i = 0; i < n; i++) R.A[i][i] = 1; n     for (; pw; pw >>= 1, T = T * T) n       if (pw & 1) R = R * T; n     return R; n   } n   inline int *operator[](int id) { return A[id]; } n }; n int n, k, m; n inline int Getid(int i, int j) { return (i + j * (k + 1)); } n int main() { n   scanf( %d%d%d , &n, &k, &m); n   Matrix A((k + 1) << m, (k + 1) << m); n   for (int i = 0; i <= k; i++) n     for (int j = 0; j < (1 << m); j++) { n       A[Getid(i, j)][Getid(i, j >> 1)] = 1; n       if (i < k) n         A[Getid(i, j)][Getid(i + 1, (j >> 1) | (1 << m - 1))] = n             __builtin_popcount(j) + 1; n     } n   A = A ^ n; n   int tot = 0; n   for (int j = 0; j < (1 << m); j++) n     tot = (tot + A[Getid(0, 0)][Getid(k, j)]) % Mod; n   return !printf( %d , tot); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int s, x1, x2, t1, t2, p, d; n   cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d; n   swap(t1, t2); n   int sol = abs(x1 - x2) * t1; n   int tram = 0; n   int p1 = p; n   int p2 = x1; n   if (d == -1) { n     if (p2 <= p1) { n       tram += t2 * (p1 - p2); n     } else { n       tram += t2 * (p1 + p2); n       d = 1; n     } n   } else { n     if (p1 <= p2) { n       tram += t2 * (p2 - p1); n     } else { n       tram += t2 * (s - p1 + s - p2); n       d = -1; n     } n   } n   p1 = x1; n   p2 = x2; n   if (d == -1) { n     if (p2 <= p1) { n       tram += t2 * (p1 - p2); n     } else { n       tram += t2 * (p1 + p2); n       d = 1; n     } n   } else { n     if (p1 <= p2) { n       tram += t2 * (p2 - p1); n     } else { n       tram += t2 * (s - p1 + s - p2); n       d = -1; n     } n   } n   sol = min(sol, tram); n   cout << sol <<   n ; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const long long inf = 1e18 + 9; n long long ans = inf; n long long ans1 = 0, ans2 = 0; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, a, b; n   cin >> n >> a >> b; n   long long need = n * 6; n   if (a * b >= need) { n     cout << a * b <<   n ; n     cout << a <<     << b; n     return 0; n   } n   for (long long i = 0; i <= 1e7; i++) { n     long long new_x = a + i; n     long long new_y = need / new_x; n     if (need % new_x != 0) new_y++; n     new_y = max(new_y, b); n     new_x = max(new_x, a); n     if (new_x * new_y < ans) ans = new_x * new_y, ans1 = new_x, ans2 = new_y; n   } n   for (long long i = 0; i <= 1e7; i++) { n     long long new_y = b + i; n     long long new_x = need / new_y; n     if (need % new_y != 0) new_x++; n     new_y = max(new_y, b); n     new_x = max(new_x, a); n     if (new_x * new_y < ans) ans = new_x * new_y, ans1 = new_x, ans2 = new_y; n   } n   cout << ans <<   n ; n   cout << ans1 <<     << ans2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int t, f, w; n   bool operator<(const edge& e) const { return w > e.w; } n   edge(int from, int to, int weight) { n     t = to; n     f = from; n     w = weight; n   } n }; n const double EPS = (1e-9); n class UnionFind { n  public: n   vector<int> p, rank, setSize; n   int numSets; n   UnionFind(int N) { n     setSize.assign(N, 1); n     numSets = N; n     rank.assign(N, 0); n     p.assign(N, 0); n     for (int i = 0; i < N; i++) p[i] = i; n   } n   int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); } n   bool isSameSet(int i, int j) { return findSet(i) == findSet(j); } n   void unionSet(int i, int j) { n     if (!isSameSet(i, j)) { n       numSets--; n       int x = findSet(i), y = findSet(j); n       if (rank[x] > rank[y]) { n         p[y] = x; n         setSize[x] += setSize[y]; n       } else { n         p[x] = y; n         setSize[y] += setSize[x]; n         if (rank[x] == rank[y]) rank[y]++; n       } n     } n   } n   int numDisjointSets() { return numSets; } n   int sizeOfSet(int i) { return setSize[findSet(i)]; } n }; n long long root(long long x) { n   long long l = 0, r = 1e9 + 1; n   while (l < r - 1) { n     long long m = (l + r) / 2; n     if (m * m > x) n       r = m; n     else n       l = m; n   } n   return l; n } n struct line { n   double a, b, c; n }; n bool areParallel(line l1, line l2) { n   return (fabs(l1.a - l2.a) < EPS) && (fabs(l1.b - l2.b) < EPS); n } n bool areSame(line l1, line l2) { n   return areParallel(l1, l2) && (fabs(l1.c - l2.c) < EPS); n } n struct point { n   double x, y; n   point() { x = y = 0.0; } n   point(double _x, double _y) : x(_x), y(_y) {} n   bool operator<(point other) const { n     if (fabs(x - other.x) > EPS) return x < other.x; n     return y < other.y; n   } n }; n void pointsToLine(point p1, point p2, line& l) { n   if (fabs(p1.x - p2.x) < EPS) { n     l.a = 1.0; n     l.b = 0.0; n     l.c = -p1.x; n   } else { n     l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x); n     l.b = 1.0; n     l.c = -(double)(l.a * p1.x) - p1.y; n   } n } n bool areIntersect(line l1, line l2, point& p) { n   if (areParallel(l1, l2)) return false; n   p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); n   if (fabs(l1.b) > EPS) n     p.y = -(l1.a * p.x + l1.c); n   else n     p.y = -(l2.a * p.x + l2.c); n   return true; n } n long long binpowmod(long long a, long long b, long long m) { n   a %= m; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n int findXOR(int n) { n   switch (n % 4) { n     case 0: n       return n; n     case 1: n       return 1; n     case 2: n       return n + 1; n     case 3: n       return 0; n   } n } n int rangeXOR(int l, int r) { return (findXOR(l - 1) ^ findXOR(r)); } n int getbit(int mask, int bit) { return (mask & (1 << bit)); } n void setbit(int& mask, int bit, int val) { n   if (val) n     mask |= (1 << bit); n   else n     mask &= ~(1 << bit); n } n const int N = 1e5 + 1; n const long long INF = 1e7 + 100; n const int MOD = 1e9 + 7; n class SegmentTree { n  private: n   vector<pair<int, int>> st; n   vector<int> lp; n   vector<int> A; n   int n; n   int left(int p) { return p << 1; } n   int right(int p) { return (p << 1) + 1; } n   pair<int, int> merge(pair<int, int> p1, pair<int, int> p2) { n     if (p1.first == p2.first) return {p1.first, p1.second + p2.second}; n     if (p1.first < p2.first) return p1; n     return p2; n   } n   void build(int p, int L, int R) { n     if (L == R) { n       st[p] = {A[L], 1}; n     } else { n       build(left(p), L, (L + R) / 2); n       build(right(p), (L + R) / 2 + 1, R); n       pair<int, int> p1 = st[left(p)], p2 = st[right(p)]; n       st[p] = merge(p1, p2); n     } n   } n   pair<int, int> rmq(int p, int L, int R, int i, int j) { n     if (i > R || j < L) return {-1, -1}; n     if (L >= i && R <= j) return st[p]; n     pair<int, int> p1 = rmq(left(p), L, (L + R) / 2, i, j); n     pair<int, int> p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j); n     if (p1.first == -1) return p2; n     if (p2.first == -1) return p1; n     return merge(p1, p2); n   } n   void update_point(int p, int L, int R, int idx, int v) { n     int i = idx, j = idx; n     if (i > R || j < L) return; n     if (L == i && R == j) { n       A[L] = v; n       st[p] = {v, 1}; n       return; n     } n     pair<int, int> p1, p2; n     update_point(left(p), L, (L + R) / 2, idx, v); n     update_point(right(p), (L + R) / 2 + 1, R, idx, v); n     p1 = st[left(p)]; n     p2 = st[right(p)]; n     st[p] = merge(p1, p2); n   } n  n  public: n   SegmentTree(const vector<int>& _A) { n     A = _A; n     n = (int)A.size(); n     st.assign(4 * n, {0, 0}); n     lp.assign(4 * n, 0); n     build(1, 0, n - 1); n   } n   pair<int, int> rmq(int i, int j) { return rmq(1, 0, n - 1, i, j); } n   void update_point(int idx, int new_value) { n     update_point(1, 0, n - 1, idx, new_value); n   } n }; n vector<int> freq; n int n; n bool can(int x) { n   set<pair<int, int>, greater<pair<int, int>>> s; n   vector<int> cnt(n + 1); n   for (int i = 1; i <= n; ++i) { n     if (freq[i]) { n       cnt[i] = freq[i]; n       s.insert({cnt[i], i}); n     } n   } n   vector<int> b; n   for (int i = 0; i < n; ++i) { n     if (i >= x && cnt[b[i - x]] > 0) { n       s.insert({cnt[b[i - x]], b[i - x]}); n     } n     if (s.empty()) return false; n     b.push_back(s.begin()->second); n     s.erase(s.begin()); n     cnt[b.back()]--; n   } n   return true; n } n void solve() { n   cin >> n; n   freq.assign(n + 1, 0); n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     freq[x]++; n   } n   int lo = 0, hi = n; n   while (hi - lo > 1) { n     int mid = (hi + lo) / 2; n     if (can(mid)) { n       lo = mid; n     } else n       hi = mid; n   } n   cout << lo - 1 <<   n ; n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tc = 1; n   cin >> tc; n   while (tc--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int x, y, l, r; n   cin >> x >> y >> l >> r; n   vector<long long int> vec(0); n   long long int xa = 1; n   long long int cap = 0; n   long long int r1 = r; n   while (r1 > 0) { n     r1 /= x; n     ++cap; n   } n   for (long long int i = 0; i < cap; ++i) { n     long long int ya = 1; n     long long int diff = r - xa; n     long long int cap2 = 0; n     while (diff > 0) { n       diff /= y; n       ++cap2; n     } n     for (long long int j = 0; j < cap2; ++j) { n       if (xa + ya >= l && xa + ya <= r) { n         vec.push_back(xa + ya); n       } n       ya *= y; n     } n     xa *= x; n   } n   if (vec.size() == 0) { n     cout << r - l + 1; n     return 0; n   } n   sort(vec.begin(), vec.end()); n   long long int answer = vec[0] - l; n   for (int i = 1; i < vec.size(); ++i) { n     if (vec[i] - vec[i - 1] - 1 > answer) answer = vec[i] - vec[i - 1] - 1; n   } n   if (r - vec[vec.size() - 1] > answer) answer = r - vec[vec.size() - 1]; n   cout << answer; n } n


#include <bits/stdc++.h> n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n using namespace std; n class otr { n  public: n   long long len = 0; n   long long* D = nullptr; n   otr(long long alen) { n     len = alen; n     D = new long long[alen]; n   } n   ~otr() { delete[] D; } n }; n void Flip(long long* left, long long* right, long long flix, bool isleft) { n   while (flix != -1) { n     long long t = left[flix]; n     left[flix] = right[flix]; n     right[flix] = t; n     flix = isleft ? right[flix] : left[flix]; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   std::cout.tie(0); n   std::istream* istr = &cin; n   const long long mdl = 1000000007; n   long long q; n   (*istr) >> q; n   for (long long qi = 0; qi < q; qi++) { n     long long n, m, a, b, c; n     (*istr) >> n; n     otr** data = new otr*[n - 1]; n     for (long long i = 0; i < n - 1; i++) { n       (*istr) >> m; n       data[i] = new otr(m); n       for (long long j = 0; j < m; j++) (*istr) >> data[i]->D[j]; n     } n     for (long long i = 0; i < n - 2; i++) n       for (long long j = i + 1; j < n - 1; j++) n         if (data[i]->len > data[j]->len) { n           otr* t = data[i]; n           data[i] = data[j]; n           data[j] = t; n         } n     long long skippedcnt = 0; n     long long* left = new long long[n]; n     long long* right = new long long[n]; n     long long start = -1; n     long long end = -1; n     long long qend = -1; n     map<long long, bool> mp; n     long long ix = 0; n     bool* skip = new bool[n - 1]; n     while (ix < n - 1 && data[ix]->len == 2) { n       for (long long i = 0; i < n - 1; i++) skip[i] = false; n       skippedcnt = 0; n       for (long long i = 0; i < n; i++) { n         left[i] = -1; n         right[i] = -1; n       } n       mp.clear(); n       right[data[ix]->D[0] - 1] = data[ix]->D[1] - 1; n       left[data[ix]->D[1] - 1] = data[ix]->D[0] - 1; n       long long lastskippedcnt = skippedcnt; n       skip[ix] = true; n       skippedcnt++; n       mp[data[ix]->D[0] - 1] = true; n       mp[data[ix]->D[1] - 1] = true; n       start = data[ix]->D[0] - 1; n       end = data[ix]->D[1] - 1; n       qend = end; n       bool isq = true; n       bool isok = true; n       while (skippedcnt < n - 1) { n         long long iy = 0; n         lastskippedcnt = skippedcnt; n         while (iy < n - 1) { n           if (!skip[iy]) { n             bool startisthere = false; n             bool endisthere = false; n             long long newone = -1; n             long long newonecount = 0; n             for (long long i = 0; i < data[iy]->len; i++) { n               if (data[iy]->D[i] - 1 == start) startisthere = true; n               if (data[iy]->D[i] - 1 == qend) endisthere = true; n               if (mp.find(data[iy]->D[i] - 1) == mp.end()) { n                 newone = data[iy]->D[i] - 1; n                 newonecount++; n               } n             } n             if (newonecount > 1) { n               iy++; n               continue; n             } n             skip[iy] = true; n             skippedcnt++; n             if (startisthere && !endisthere) { n               Flip(left, right, qend, true); n               long long t = start; n               start = qend; n               qend = t; n               if (isq) end = t; n               if (left[start] >= 0) { n                 left[left[start]] = qend; n                 right[qend] = left[start]; n                 left[start] = -1; n               } n             } n             left[newone] = end; n             right[end] = newone; n             end = newone; n             mp[newone] = true; n             if (isq && data[iy]->len == 2) n               qend = end; n             else n               isq = false; n             break; n           } n           iy++; n         } n         if (lastskippedcnt == skippedcnt) { n           isok = false; n           break; n         } n       } n       if (isok) break; n       ix++; n     } n     long long v = start; n     while (v >= 0) { n       cout << v + 1 <<    ; n       v = right[v]; n     } n     cout << endl; n     for (long long i = 0; i < n - 1; i++) delete data[i]; n     delete[] data; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x; n   vector<pair<int, int>> v; n   cin >> n; n   for (int i = 1; i <= n && cin >> x; i++) v.push_back({x, i}); n   sort(v.begin(), v.end()); n   cout << v[n - 1].second <<     << v[n - 2].first; n } n


#include <bits/stdc++.h> n using namespace std; n int z[1005]; n string a[1005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int j = 0; j < m; ++j) { n     for (int i = 1; i < n; ++i) n       for (int i1 = 0; i1 < i; ++i1) { n         bool ok = false; n         for (int k = 0; k < j; ++k) n           if (z[k] == 0 && a[i][k] > a[i1][k]) { n             ok = true; n             break; n           } n         if (!ok && a[i][j] < a[i1][j]) z[j] = 1; n       } n   } n   int ans = 0; n   for (int i = 0; i < m; ++i) n     if (z[i]) ++ans; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int mark[123456]; n int main() { n   int n, t; n   scanf( %d , &n); n   for (int i = 0; i < n - 1; i++) { n     scanf( %d , &t); n     mark[t]++; n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (!mark[i]) { n       ans = i; n       break; n     } n   } n   cout << ans <<   n ; n } n