#include <bits/stdc++.h> n using namespace std; n struct _ { n   _() { ios_base::sync_with_stdio(0); } n } _; n template <class A, class B> n ostream &operator<<(ostream &o, pair<A, B> t) { n   o <<  (  << t.first <<  ,   << t.second <<  ) ; n   return o; n } n template <class T> n string tostring(T first, int len = 0, char c =  0 ) { n   stringstream ss; n   ss << first; n   string r = ss.str(); n   if (r.length() < len) r = string(len - r.length(), c) + r; n   return r; n } n template <class T> n void PV(T a, T b, int n = 0, int w = 0, string s =    ) { n   int c = 0; n   while (a != b) { n     cout << tostring(*a++, w,    ); n     if (a != b && (n == 0 || ++c % n)) n       cout << s; n     else n       cout << endl; n   } n } n template <class T> n inline bool chmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n inline bool chmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n } n const long long linf = 0x3f3f3f3f3f3f3f3fLL; n const int inf = 0x3f3f3f3f; n const int mod = int(1e9) + 7; n const int N = 111111; n vector<int> prime; n bool isp[N]; n vector<int> oddPrime; n void generatePrime(int n = 1000000) { n   memset(isp, 1, sizeof(isp)); n   ; n   isp[0] = isp[1] = 0; n   for (int i = 2; i <= n; i++) { n     if (!isp[i]) continue; n     prime.push_back(i); n     for (int j = i + i; j <= n; j += i) { n       isp[j] = 0; n     } n   } n } n int cnt[10000]; n long long cc; n inline int isPrime(int *a, int n) { n   int r = 0; n   for (int i = 0; i < n; i++) r = 10 * r + a[i]; n   return isp[r]; n } n int D[5][5], n, res; n void dfs(int r, int c) { n   if (n <= 4 && r == n - 1) { n     res++; n     return; n   } n   if (n == 5 && r == n - 2) { n     res += cnt[D[3][0] * 1000 + D[3][1] * 100 + D[3][2] * 10 + D[3][4]]; n     return; n   } n   for (int i = 0; i < 10; i++) { n     D[r][c] = D[c][r] = i; n     if (c == n - 2) { n       if (isPrime(D[r], n)) dfs(r + 1, r + 1); n     } else { n       dfs(r, c + 1); n     } n     if (D[r][n - 1] == 2) break; n   } n } n int main() { n   generatePrime(100000); n   for (int i : prime) { n     int t = i; n     int ok = 1; n     while (t > 0) { n       if (t % 10 != 2 && t % 2 == 0) ok = 0; n       t /= 10; n     } n     if (ok) oddPrime.push_back(i); n     int j = i / 100 * 10 + i % 10; n     cnt[j]++; n   } n   int T; n   cin >> T; n   while (T--) { n     int first; n     cin >> first; n     string s = tostring(first); n     n = s.length(); n     res = 0; n     for (int second : oddPrime) { n       if (tostring(second).size() > n) continue; n       for (int i = 0; i < n; i++) D[0][i] = D[i][0] = s[i] -  0 ; n       string os = tostring(second, n); n       if (os[0] != s[n - 1]) continue; n       int ok = 1; n       for (int i = 0; i < n; i++) { n         int t = os[i] -  0 ; n         D[i][n - 1] = D[n - 1][i] = t; n         if (t % 2 == 0 && D[0][i] != 0) ok = 0; n       } n       if (ok) dfs(1, 1); n     } n     cout << res << endl; n   } n   cerr <<  [  n            0  n             ->   n            clock()  n            :   n        << 1e3 * (clock() - 0) / CLOCKS_PER_SEC <<  ms] n ; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> a; n vector<int> r; n vector<vector<pair<int, int>>> pre, suf; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     a = vector<vector<int>>(n, vector<int>(m)); n     r = vector<int>(n); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cin >> a[i][j]; n       } n       r[i] = i; n     } n     sort(r.begin(), r.end(), [&](int i, int j) { return a[i][0] > a[j][0]; }); n     pre = suf = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>(m)); n     for (int i = 0; i < n; i++) { n       pre[i][0].first = pre[i][0].second = a[i][0]; n       for (int j = 1; j < m; j++) { n         pre[i][j].first = min(pre[i][j - 1].first, a[i][j]); n         pre[i][j].second = max(pre[i][j - 1].second, a[i][j]); n       } n       suf[i][m - 1].first = suf[i][m - 1].second = a[i][m - 1]; n       for (int j = m - 2; j >= 0; j--) { n         suf[i][j].first = min(a[i][j], suf[i][j + 1].first); n         suf[i][j].second = max(a[i][j], suf[i][j + 1].second); n       } n     } n     for (int j = 0; j + 1 < m; j++) { n       vector<pair<int, int>> izq(n), der(n); n       izq[r[0]].first = pre[r[0]][j].first; n       der[r[0]].second = suf[r[0]][j + 1].second; n       for (int i = 1; i + 1 < n; i++) { n         izq[r[i]].first = min(izq[r[i - 1]].first, pre[r[i]][j].first); n         der[r[i]].second = max(der[r[i - 1]].second, suf[r[i]][j + 1].second); n       } n       izq[r[n - 1]].second = pre[r[n - 1]][j].second; n       der[r[n - 1]].first = suf[r[n - 1]][j + 1].first; n       for (int i = n - 2; i > 0; i--) { n         izq[r[i]].second = max(izq[r[i + 1]].second, pre[r[i]][j].second); n         der[r[i]].first = min(der[r[i + 1]].first, suf[r[i]][j + 1].first); n       } n       for (int i = 0; i + 1 < n; i++) { n         if (izq[r[i]].first > izq[r[i + 1]].second && n             der[r[i + 1]].first > der[r[i]].second) { n           cout <<  YES  <<   n ; n           string s(n,  R ); n           for (int j = i + 1; j < n; j++) s[r[j]] =  B ; n           cout << s <<     << j + 1 <<   n ; n           goto out; n         } n       } n     } n     cout <<  NO  <<   n ; n   out:; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   cin.tie(0)->sync_with_stdio(0); n   int n; n   cin >> n; n   int sp = -1, rmv = 0, ans = 0; n   stack<int> st; n   while (n--) { n     int t; n     cin >> t; n     if (t == 1) { n       int x; n       cin >> x; n       sp = x; n     } else if (t == 3) { n       int x; n       cin >> x; n       st.push(x); n     } else if (t == 2) { n       ans += rmv; n       rmv = 0; n     } else if (t == 4) { n       rmv = 0; n     } else if (t == 5) { n       while (st.size()) st.pop(); n     } else if (t == 6) { n       rmv++; n     } n     while (st.size() && st.top() < sp) { n       st.pop(); n       ans++; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, i, a, counter = 0, ar[100000]; n   map<char, int> mp; n   mp[ 6 ] = 1, mp[ 7 ] = 2, mp[ 8 ] = 3, mp[ 9 ] = 4, mp[ T ] = 5; n   mp[ J ] = 6, mp[ Q ] = 7, mp[ K ] = 8, mp[ A ] = 9; n   string str1, str2; n   char trump; n   cin >> trump; n   cin >> str1 >> str2; n   if (str1[1] == trump && str1[1] != str2[1]) n     cout <<  YES  << endl; n   else if (str1[1] == str2[1] && mp[str1[0]] > mp[str2[0]]) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef long double ld; n typedef string str; n  n #define pb push_back n #define ppp pop_back n #define pii pair<int,int> n #define fi first n #define se second n #define stie std::tie n #define vec vector n #define forn(i, l, r) for (int i=l; i<=r; i++) n #define forb(i, r, l) for (int i=r; i>=l; i--) n #define emp empty n #define beg begin n #define ins insert n #define cle clear n #define era erase n #define que queue n #define pque priority_queue n #define mset multiset n #define deq deque n #define sta stack n #define con const n #define rsz resize n #define ass assign n #define lowb lower_bound n #define uppb upper_bound n  n template<class T> void mini(T& a, T b) { a = min(a, b); } n template<class T> void maxi(T& a, T b) { a = max(a, b); } n template<class T1, class T2> ostream& operator<<(ostream &out, pair<T1, T2> a) { return out << a.first <<     << a.second; } n template<class T> ostream& operator<<(ostream& out, vector<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T> ostream& operator<<(ostream& out, set<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T> ostream& operator<<(ostream& out, multiset<T> a) { for (auto& i : a) out << i <<    ; return out; } n template<class T1, class T2> ostream& operator<<(ostream& out, map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; } n template<class T1, class T2> ostream& operator<<(ostream& out, unordered_map<T1, T2> a) { for (auto& i : a) out << i <<   n ; return out; } n template<class T> ostream& operator<<(ostream& out, queue<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop(); } return out; } n template<class T> ostream& operator<<(ostream& out, deque<T> a) { while (!a.empty()) { out << a.front() <<    ; a.pop_front(); } return out; } n template<class T> ostream& operator<<(ostream& out, priority_queue<T> a) { while (!a.empty()) { out << a.top() <<   n ; a.pop(); } return out; } n template<class T> void out(T a) { cout << a << endl; } n template<class T1, class T2> void out(T1 a, T2 b) { cout << a <<     << b << endl; } n template<class T1, class T2, class T3> void out(T1 a, T2 b, T3 c) { cout << a <<     << b <<     << c << endl; } n template<class T1, class T2, class T3, class T4> void out(T1 a, T2 b, T3 c, T4 d) { cout << a <<     << b <<     << c <<     << d << endl; } n template<class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); } n template<class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] <<    ; cout << endl; } n void out() { cout <<  OK  << endl; } n template<class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); } n template<class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); } n template<class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; } n clock_t start_time; void start_timer() { start_time = clock(); } n double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; } n #if __SIZEOF_INT128__ >= 16 n typedef __int128 LL; n istream& operator>>(istream& in, __int128& a) { int64_t b; cin >> b; a = b; return in; } n ostream& operator<<(ostream& out, const __int128 a) { n  unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c =  0123456789 [b % 10]; b /= 10; } while (b); n  if (a < 0) { --c; *c =  - ; } int len = end(buf) - c; out.rdbuf()->sputn(c, len); return out; n } n #endif n  n vec<str> lets = { .      ,  . .    ,  ..     ,  .. .   ,  .  .   ,  ...    ,  ....   ,  . ..   ,   ..    ,   ...   ,  .   .  ,  . . .  ,  ..  .  ,  .. ..  ,  .  ..  ,  ... .  ,  .....  ,  . ...  ,   .. .  ,   ....  ,  .   .. ,  . . .. ,   ... . ,  ..  .. ,  .. ... ,  .  ... }; n  n void Solve() { n     int T; n  cin >> T; n  while (T--) { n   vec<int> a(5); n   forn(i, 0, 4) cin >> a[i]; n   int res = -1; n   forn(i, 0, 25) { n    vec<int> cur(5); n    forn(j, 0, 5) { n     if (lets[i][j] ==  . ) { n      cur[j / 2]++; n      cur[3 + j % 2]++; n     } n    } n    if (cur == a) { n     res = i; n     break; n    } n   } n   cout << char( a  + res); n  } n  cout <<   n ; n } n  n int main() { n  ios_base::sync_with_stdio(0); cin.tie(0); n #ifdef LOCAL n  freopen( input.txt ,  r , stdin); n #endif n  start_timer(); n  Solve(); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool y[200005]; n long long n, m, k, j, i, p[2000005], q[2000005], haj[2000005], s, sum; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   p[1] = 0; n   sum = n * (n + 1) / 2; n   for (i = 1; i < n; i++) { n     haj[i] = i; n     cin >> q[i]; n     p[i + 1] = p[i] + q[i]; n     s += p[i + 1]; n   } n   haj[n] = n; n   sum -= s; n   if (sum % n != 0) { n     cout << -1 << endl; n     return 0; n   } else { n     for (i = 1; i <= n; i++) p[i] += sum / n; n     for (i = 1; i <= n; i++) { n       if (p[i] < 0 || p[i] > n) { n         cout << -1 << endl; n         return 0; n       } else if (y[p[i]]) { n         cout << -1 << endl; n         return 0; n       } else { n         y[p[i]] = true; n       } n     } n     for (i = 1; i <= n; ++i) { n       cout << p[i] << endl; n     } n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ; n const double eps = 1e-8; n const int mod = 1000000007; n const int maxn = 1e5 + 7; n const double pi = acos(-1); n const int inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f; n int n; n long long p; n struct node { n   long long a, b; n } num[maxn]; n bool check(double x) { n   double ans = 0; n   for (int i = 1; i <= n; i++) { n     if (x * num[i].a - num[i].b > eps) { n       ans += x * num[i].a - num[i].b; n     } n   } n   return x * p - ans > eps; n } n int main() { n   scanf( %d%lld , &n, &p); n   long long sum = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %lld%lld , &num[i].a, &num[i].b); n     sum += num[i].a; n   } n   if (sum <= p) { n     printf( -1 n ); n     return 0; n   } n   double ub = INF, lb = 0, mid; n   for (int i = 0; i <= 100; i++) { n     mid = (ub + lb) / 2; n     if (check(mid)) n       lb = mid; n     else n       ub = mid; n   } n   printf( %.7f n , ub); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double eps = 1e-11; n int countbit(int n) { return (n == 0) ? 0 : 1 + countbit(n & (n - 1)); } n int lowbit(int n) { return n & (n ^ (n - 1)); } n string toString(long long v) { n   ostringstream sout; n   sout << v; n   return sout.str(); n } n string toString(int v) { n   ostringstream sout; n   sout << v; n   return sout.str(); n } n int Rand16() { return rand(); } n int Rand32() { return rand() * rand(); } n double DRand() { return (double)rand() / RAND_MAX; } n int RandRange(int f, int r) { return f + (int)(DRand() * (r - f) + 0.5); } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int n; n   cin >> n; n   int i, j; n   int ans = 0; n   for (i = 2; i < n; i++) { n     int tmp = n; n     while (tmp) ans += tmp % i, tmp /= i; n   } n   int d = gcd(ans, n - 2); n   int A = ans / d; n   int B = (n - 2) / d; n   cout << A <<  /  << B << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int N, Q; n   scanf( %d%d , &N, &Q); n   int et[N + 1]; n   memset(et, -1, sizeof(et)); n   while (Q-- > 0) { n     int t, k, d; n     scanf( %d%d%d , &t, &k, &d); n     int ans = -1; n     int as = 0; n     for (int i = 1; i <= N; i++) { n       if (t > et[i]) et[i] = -1; n       if (et[i] == -1) as++; n     } n     if (as >= k) { n       ans = 0; n       for (int i = 1; i <= N && k > 0; i++) { n         if (et[i] == -1) { n           ans += i; n           k--; n           et[i] = t + d - 1; n         } n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 0; n const int N = 100005; n vector<array<int, 2>> v[N]; n vector<set<int>> g(N); n vector<int> depth(N, 0); n vector<vector<int>> p(N, vector<int>(17, 0)); n vector<long long> up(N, 0); n vector<long long> down(N, 0); n vector<int> sz(N, 0); n vector<int> ch[N]; n vector<int> st[N]; n vector<long long> pw(N, 1); n vector<long long> inv(N, 1); n long long res = 0; n int root = 0; n void dfs(int a) { n   depth[a] = depth[p[a][0]] + 1; n   for (int i = 1; i < 17; i++) p[a][i] = p[p[a][i - 1]][i - 1]; n   for (auto [to, k] : v[a]) { n     if (to == p[a][0]) continue; n     p[to][0] = a; n     down[to] = (10 * down[a] + k) % mod; n     up[to] = (pw[depth[a] - 1] * k + up[a]) % mod; n     dfs(to); n   } n } n int lca(int a, int b) { n   if (depth[a] > depth[b]) swap(a, b); n   for (int i = 16; i >= 0; i--) n     if (depth[p[b][i]] >= depth[a]) b = p[b][i]; n   if (a == b) return a; n   for (int i = 16; i >= 0; i--) { n     if (p[a][i] != p[b][i]) { n       a = p[a][i]; n       b = p[b][i]; n     } n   } n   return p[a][0]; n } n int dist(int a, int b) { return depth[a] + depth[b] - 2 * depth[lca(a, b)]; } n long long h(int a, int b) { n   int l = lca(a, b); n   long long x = (((up[a] - up[l] + mod) % mod) * inv[depth[l] - 1]) % mod; n   long long y = n       (((down[b] - pw[depth[b] - depth[l]] * down[l]) % mod) + mod) % mod; n   long long z = (pw[depth[b] - depth[l]] * x + y) % mod; n   return z; n } n void find_sz(int a, int par = 0) { n   sz[a] = 1; n   for (int to : g[a]) { n     if (to == par) continue; n     find_sz(to, a); n     sz[a] += sz[to]; n   } n } n int find_centroid(int a, int par, int n) { n   for (int to : g[a]) { n     if (to == par) continue; n     if (sz[to] > n / 2) return find_centroid(to, a, n); n   } n   return a; n } n void build_cd(int a, int par = 0) { n   find_sz(a); n   int n = sz[a]; n   int centroid = find_centroid(a, 0, n); n   if (par == 0) root = centroid; n   ch[par].push_back(centroid); n   for (int to : g[centroid]) { n     g[to].erase(centroid); n     build_cd(to, centroid); n   } n } n long long fpow(long long b, long long e) { n   long long x = 1; n   while (e) { n     if (e & 1) x = (x * b) % mod; n     b = (b * b) % mod; n     e /= 2; n   } n   return x; n } n long long find_inv() { n   long long x = mod; n   long long tmp = mod; n   for (long long i = 2; i * i <= tmp; i++) { n     if ((tmp % i) == 0) { n       x /= i; n       x *= (i - 1); n     } n     while ((tmp % i) == 0) tmp /= i; n   } n   if (tmp > 1) { n     x /= tmp; n     x *= (tmp - 1); n   } n   return fpow(10, x - 1); n } n void solve(int a) { n   map<int, int> m; n   for (int to : ch[a]) { n     solve(to); n     for (int x : st[to]) { n       m[h(x, a)]++; n       st[a].push_back(x); n     } n   } n   res += m[0]; n   st[a].push_back(a); n   for (int to : ch[a]) { n     for (int x : st[to]) m[h(x, a)]--; n     for (int x : st[to]) { n       long long z = h(a, x); n       if (z == 0) res++; n       long long val = (((-z * inv[dist(a, x)]) % mod) + mod) % mod; n       res += m[val]; n     } n     for (int x : st[to]) m[h(x, a)]++; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n >> mod; n   for (int i = 0; i < n - 1; i++) { n     int a, b, k; n     cin >> a >> b >> k; n     a++; n     b++; n     v[a].push_back({b, k}); n     v[b].push_back({a, k}); n     g[a].insert(b); n     g[b].insert(a); n   } n   for (int i = 1; i <= n; i++) pw[i] = (10 * pw[i - 1]) % mod; n   inv[1] = find_inv(); n   for (int i = 2; i <= n; i++) inv[i] = (inv[i - 1] * inv[1]) % mod; n   dfs(1); n   build_cd(1); n   solve(root); n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int seq[100]; n void display(const int n) { n   for (int i = 0; i < n; ++i) printf( %d  , seq[i]); n   putchar(  n ); n } n int compute_sum(const int n) { n   int sum = 0; n   for (int i = 0; i < n; ++i) { n     int x = seq[i]; n     for (int j = i; j < n; ++j) { n       x = min(x, seq[j]); n       sum += x; n     } n   } n   return sum; n } n bool solve(const int n, int m) { n   for (int i = 0; i < n; ++i) seq[i] = i + 1; n   int best = 0; n   do { n     const int sum = compute_sum(n); n     best = max(best, sum); n   } while (next_permutation(seq, seq + n)); n   for (int i = 0; i < n; ++i) seq[i] = i + 1; n   do { n     const int sum = compute_sum(n); n     if (sum == best) { n       if (--m == 0) { n         display(n); n         return true; n       } n     } n   } while (next_permutation(seq, seq + n)); n   return false; n } n void s(const long long x, const long long y, const int first) { n   printf( visiting with x=%lld, y=%lld, first=%d n , x, y, first); n   if (x <= 0) return; n   assert(y < x); n   long long delta = max(1LL, x >> 1); n   long long index = 0; n   int movements = 0; n   for (;;) { n     printf( index = %lld, delta = %lld, movements = %d n , index, delta, n            movements); n     if (index + delta <= y) { n       movements += 1; n       index += delta; n     } else { n       cout << first + movements <<     << endl; n       s(x >> 1, y - index, first + 1); n       break; n     } n     delta = max(1LL, delta >> 1); n   } n } n vector<int> v; n void compute(const int l, const int r, long long m) { n   if (l > r) return; n   if (l == r) { n     v.push_back(l); n     return; n   } n   const long long x = 1LL << (r - l); n   long long delta = max(1LL, x >> 1); n   int movements = 0; n   for (;;) { n     const long long new_m = m - delta; n     if (new_m >= 0) { n       m = new_m; n       movements += 1; n       delta = max(1LL, delta >> 1); n     } else { n       const int first_digit = l + movements; n       v.push_back(first_digit); n       compute(first_digit + 1, r, m); n       for (int i = l + movements - 1; i >= l; --i) v.push_back(i); n       break; n     } n   } n } n void solve_fast(const int n, long long m) {} n void test() { n   for (int n = 1; n <= 5; ++n) { n     for (int m = 1; m <= 100; ++m) { n       if (m <= 1LL << (n - 1)) { n         if (solve(n, m)) { n           v.clear(); n           compute(1, n, m - 1); n           for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]); n           putchar(  n ); n         } n       } n     } n     putchar(  n ); n   } n } n void run() { n   int n; n   long long m; n   cin >> n >> m; n   v.clear(); n   compute(1, n, m - 1); n   for (int i = 0; i < v.size(); ++i) printf( %d  , v[i]); n   putchar(  n ); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n const int inf = 1039074182; n using namespace std; n int n, r, c; n string word[1000005]; n int len[1000005]; n int nxt[1000005]; n pair<int, int> st[1000005][22]; n int sum[1000005]; n int calc(int start) { n   int res = 0; n   for (int i = 0; i < 22; i++) { n     if ((1 << i) & r) { n       res += st[start][i].second; n       start = st[start][i].first; n     } n   } n   return res; n } n void print(int start) { n   for (int i = 0; i < r; i++) { n     if (start == n) break; n     for (int j = start; j < nxt[start]; j++) { n       cout << word[j]; n       if (j != nxt[start] - 1) cout <<    ; n     } n     cout << endl; n     start = nxt[start]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> r >> c; n   for (int i = 0; i < n; i++) { n     cin >> word[i]; n     len[i] = word[i].size(); n   } n   sum[0] = len[0] + 1; n   for (int i = 1; i < n; i++) { n     sum[i] = sum[i - 1] + len[i] + 1; n   } n   for (int i = 0, j = 0; i < n; i++) { n     while (j < n && sum[j] - (i ? sum[i - 1] : 0) - 1 <= c) j++; n     nxt[i] = j; n   } n   for (int i = 0; i < n; i++) { n     st[i][0] = make_pair(nxt[i], nxt[i] - i); n   } n   for (int i = 0; i < 22; i++) { n     st[n][i] = make_pair(n, 0); n   } n   for (int k = 1; k < 22; k++) { n     for (int i = 0; i < n; i++) { n       st[i][k].first = st[st[i][k - 1].first][k - 1].first; n       st[i][k].second = n           st[i][k - 1].second + st[st[i][k - 1].first][k - 1].second; n     } n   } n   int res = -1, maxk = -1; n   int temp; n   for (int i = 0; i < n; i++) { n     temp = calc(i); n     if (temp > res) { n       res = temp; n       maxk = i; n     } n   } n   print(maxk); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n string a, b, c, d, e; n vector<vector<int> > vals; n vector<vector<int> > forms(1); n map<string, int> getind; n int doop(int left, int right, int op) { n   if (op == 2) return left ^ right; n   if (op == 3) n     return left & right; n   else n     return left | right; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   vals.resize(1, vector<int>(m, 0)); n   getind[ ? ] = 0; n   for (int i = 0; i < n; i++) { n     cin >> a >> b >> c; n     getind[a] = vals.size(); n     vals.resize(vals.size() + 1); n     forms.resize(forms.size() + 1); n     if (c[0] !=  1  && c[0] !=  0 ) { n       cin >> d >> e; n       int first = getind[c]; n       int sec = getind[e]; n       int op = 2; n       if (d ==  AND ) n         op = 3; n       else if (d ==  OR ) n         op = 4; n       forms[forms.size() - 1].push_back(first); n       forms[forms.size() - 1].push_back(op); n       forms[forms.size() - 1].push_back(sec); n       for (int j = 0; j < m; j++) { n         vals[vals.size() - 1].push_back(doop(vals[first][j], vals[sec][j], op)); n       } n     } else { n       for (int j = 0; j < m; j++) { n         if (c[j] ==  1 ) n           vals[vals.size() - 1].push_back(1); n         else n           vals[vals.size() - 1].push_back(0); n       } n     } n   } n   vector<int> best(m, 0); n   vector<int> worst(m, 0); n   for (int i = 0; i < m; i++) { n     int curcnt = 0; n     int rescnt = 0; n     for (int j = 1; j <= n; j++) { n       if (forms[j].size() > 0) { n         curcnt += vals[j][i]; n       } n     } n     vals[0][i] = 1; n     for (int j = 1; j <= n; j++) { n       if (forms[j].size() > 0) { n         int first = forms[j][0]; n         int sec = forms[j][2]; n         int op = forms[j][1]; n         int res = doop(vals[first][i], vals[sec][i], op); n         vals[j][i] = res; n         rescnt += res; n       } n     } n     if (rescnt > curcnt) best[i] = 1; n     if (rescnt < curcnt) worst[i] = 1; n   } n   for (int i = 0; i < m; i++) { n     cout << worst[i]; n   } n   cout <<   n ; n   for (int i = 0; i < m; i++) { n     cout << best[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int r, c; n int main() { n   int n; n   scanf( %d , &n); n   while (n--) { n     scanf( %d %d , &r, &c); n     for (int i = 0; i < r; i++) { n       for (int j = 0; j < c; j++) n         if (i == r - 1 && j == c - 1) n           printf( W ); n         else n           printf( B ); n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2 * (100000) + 5; n int a[MAXN], b[MAXN]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> b[i]; n   int res = 0; n   int j = 0; n   for (int i = 0; i < n && j < n; ++i) { n     while (j < n && a[i] != b[j]) { n       j++; n       res++; n     } n     j++; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long w[400005], sum[400005][21], f[400005][21], mx[400005][21]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(sum, 0x3f, sizeof(sum)); n   int q; n   cin >> q; n   long long last = 0; n   int tot = 1; n   f[1][0] = 1, sum[1][0] = 0; n   while (q--) { n     long long op, p, q; n     cin >> op >> p >> q; n     p ^= last, q ^= last; n     if (op == 1) { n       ++tot; n       w[tot] = q, sum[tot][0] = q, f[tot][0] = tot, mx[tot][0] = q; n       if (q <= w[p]) { n         f[tot][1] = p; n         sum[tot][1] = w[p] + q; n         mx[tot][1] = max(q, w[p]); n         for (int i = 2; i <= 20; ++i) { n           f[tot][i] = f[f[f[tot][i - 1]][1]][i - 1]; n           if (!f[tot][i]) break; n           mx[tot][i] = max(mx[f[f[tot][i - 1]][1]][i - 1], mx[tot][i - 1]); n           sum[tot][i] = sum[f[f[tot][i - 1]][1]][i - 1] + sum[tot][i - 1]; n         } n       } else { n         for (int i = 20; i >= 0; --i) { n           if (!f[p][i]) continue; n           if (mx[p][i] < q) p = f[f[p][i]][1]; n         } n         if (p && q <= w[p]) { n           f[tot][1] = p; n           sum[tot][1] = w[p] + q; n           mx[tot][1] = max(q, w[p]); n           for (int i = 2; i <= 20; ++i) { n             f[tot][i] = f[f[f[tot][i - 1]][1]][i - 1]; n             if (!f[tot][i]) break; n             mx[tot][i] = max(mx[f[f[tot][i - 1]][1]][i - 1], mx[tot][i - 1]); n             sum[tot][i] = sum[f[f[tot][i - 1]][1]][i - 1] + sum[tot][i - 1]; n           } n         } n       } n     } else { n       long long ans = 0, tmp = 0; n       for (int i = 20; i >= 0; --i) { n         if (!f[p][i]) continue; n         if (sum[p][i] + tmp <= q) { n           tmp += sum[p][i]; n           ans += 1 << i; n           p = f[f[p][i]][1]; n         } n         if (!p) break; n       } n       cout << (last = ans) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long n, long long m) { n   long long x, y; n   if (n > m) { n     y = n; n     x = m; n   } else { n     y = m; n     x = n; n   } n   if (y % x == 0) n     return x; n   else { n     return gcd(x, y % x); n   } n } n int main() { n   long long n; n   cin >> n; n   string str; n   cin >> str; n   long long m = n; n   for (long long i = 0; i < n; i += 2) { n     if (m - 2 == 1) { n       cout << str[i] << str[i + 1] << str[i + 2]; n       break; n     } else { n       cout << str[i] << str[i + 1]; n       if (m - 2 != 0) cout <<  - ; n     } n     m -= 2; n   } n } n


#include <bits/stdc++.h> n int q, n; n int main() { n   scanf( %d , &q); n   while (q--) { n     scanf( %d , &n); n     int b = sqrt(2 * n + 4); n     while ((b + 1) * (b + 2) / 2 > n) b--; n     int a = n - (b + 1) * (b + 2) / 2; n     printf( 133 ); n     for (int i = 1; i <= a; i++) printf( 7 ); n     for (int i = 1; i <= b; i++) printf( 3 ); n     printf( 7 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c, d, e; n int ar[200100]; n int ar1[200100]; n int main() { n   vector<int> arr(200100); n   string s, s1; n   cin >> s; n   cin >> s1; n   a = min(s.length(), s1.length()); n   b = a; n   c = 1; n   while ((c <= a) && (s[s.length() - c] == s1[s1.length() - c])) ++c; n   cout << (a - c + 1) + max(s.length(), s1.length()) - c + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   long long t[n + 1], c[n + 1]; n   for (int i = 1; i <= n; i++) { n     cin >> t[i] >> c[i]; n     t[i]++; n     if (t[i] > n) { n       t[i] = n; n     } n   } n   long long dp[n + 1][n + 1]; n   for (int i = 1; i < n + 1; i++) { n     dp[0][i] = 100000000000000; n   } n   dp[0][0] = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = n; j >= 0; --j) { n       dp[i][j] = dp[i - 1][j]; n       if (j >= t[i]) { n         dp[i][j] = min(dp[i][j], dp[i - 1][j - t[i]] + c[i]); n       } n       if (j != n) { n         dp[i][j] = min(dp[i][j], dp[i][j + 1]); n       } n     } n   } n   cout << dp[n][n]; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n const int mod = 998244353; n long long n, k, ans; n long long dp[N][N], dp2[N]; n signed main() { n   cin >> n >> k; n   dp[0][0] = 1; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= i; j++) { n       for (long long l = i - j; l <= i - 1; l++) { n         dp[i][j] = (dp[i][j] + dp[l][min(l, j)]) % mod; n       } n     } n   } n   for (long long i = 1; i <= n; i++) { n     dp2[i] = (dp[n][i] - dp[n][i - 1] + mod) % mod; n   } n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       if (k > i * j) ans = (ans + (dp2[i] * dp2[j] % mod)) % mod; n     } n   } n   cout << (ans * 2) % mod; n   return 0; n } n


#include <cstdio> n #include <iostream> n #include <cstring> n #include <algorithm> n #include <cmath> n #include <bitset> n #include <vector> n #include <unordered_map> n using namespace std; n  n const int N = 100007, M = 500007, INF = 0x3f3f3f3f; n  n typedef long long ll; n typedef int itn; n  n int n, m, t, x; n int fa[N]; n int deep[N]; n int maxx; n int num[N];//每一层结点个数 n int cnt; n int lson[N];//叶子节点 n int head[N], ver[M], edge[M], nex[M], tot; n bitset<N> f[2007];//能否凑齐 x，使用 bitset 优化 n int val[N]; n unordered_map<int, int> vis; n //int vis[N]; n bool ok[N]; n vector<int> v[N]; n  n void add(int x, itn y) n { n  ver[tot] = y; n  nex[tot] = head[x]; n  head[x] = tot ++ ; n } n  n void dfs1(int x) n { n  deep[x] = deep[fa[x]] + 1;//这里根结点 deep[1] = 1 所以不用再 +1 了 n  num[deep[x]] ++ ; n  maxx = max(maxx, deep[x]);//树的直径，实际上也就是最大深度 n  if (head[x] == -1) //没有子节点，说明是叶子结点 n   lson[deep[x]] ++ ;//每层的叶子结点个数 n  for (int i = head[x]; ~i; i = nex[i]) { n   int y = ver[i]; n   dfs1(y); n  } n } n  n void dfs2(itn x, int t) n { n  if(x == 0) n   return; n  for (int i = 0; i < (int)v[x].size(); ++ i) { n   if(val[x] > t || f[x - 1][t]) n    break; n   t -= val[x], ok[v[x][i]] = true; n  } n  dfs2(x - 1, t); n } n  n void init() n { n     memset(head, -1, sizeof head); n     tot = 0; n } n  n void solve() n { n     init(); n  scanf( %d%d , &n, &x); n  for (int i = 2; i <= n; ++ i) { n   scanf( %d , &fa[i]); n   //add(i, fa[i]); n   add(fa[i], i); n  } n  dfs1(1);//预处理每层结点个数 n  //把抽象的树转化为一个个物品，存到 v 里，离散化一下，种类（结点个数）和个数（层数） n  //cout <<  ok  << endl; n  //一共cnt种， n  for (int i = 1; i <= maxx; ++ i) { n   if (vis[num[i]]) { n            v[vis[num[i]]].push_back(i); n   } n   else { n             vis[num[i]] = ++ cnt; n             val[cnt] = num[i]; n             v[cnt].push_back(i);//来找最后选了第几层 n   } n  } n  n  f[0][0] = 1; n  n     for (int i = 1; i <= cnt; ++ i) { n         f[i] = f[i - 1]; n   itn Size = v[i].size(); n   for (int j = 1; j <= Size; j <<= 1) { n    Size -= j; n    f[i] |= (f[i] << (j * val[i])); n   } n   if(Size > 0) n    f[i] |= f[i] << (Size * val[i]); n  } n  n  if(f[cnt][x]) { n   printf( %d n , maxx); n   dfs2(cnt, x);//还原dp的方案 n   for (int i = 1; i <= n; ++ i) { n    putchar(ok[deep[i]] ?  a  :  b ); n   } n  } n  //凑不齐， a  有剩余 n  else { n   int res = INF; n   for (int i = x; i >= 0; -- i) { n    if(f[cnt][i]) { n     res = i;//找到能凑到的最大的数 n     break; n    } n   } n   dfs2(cnt, res); n   int pos = -1; n   for (int i = 1; i <= maxx; ++ i) n   { n    if(!ok[i] && lson[i] >= x - res) { n     pos = i; n     break; n    } n   } n  n   printf( %d n , maxx + 1); n  n   for (int i = 1; i <= n; ++ i) { n    if(deep[i] == pos && head[i] == -1) { n     if(res == x) { n      putchar( b ); n     } n     else n      putchar( a ), ++ res; n    } n    else { n     putchar(ok[deep[i]] ?  a  :  b ); n    } n   } n  } n  return ; n } n  n itn main() n { n     solve(); n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5, inf = 1e9; n int a[maxn]; n struct segtree { n   int lb, rb; n   int mn = 0; n   segtree *l, *r; n   segtree(int _lb, int _rb) { n     lb = _lb, rb = _rb; n     if (lb == rb) n       mn = a[lb]; n     else { n       int t = (lb + rb) / 2; n       l = new segtree(lb, t); n       r = new segtree(t + 1, rb); n       mn = min(l->mn, r->mn); n     } n   } n   int rmq(int lq, int rq) { n     if (lb >= lq && rb <= rq) n       return mn; n     else if (lb > rq || rb < lq) n       return inf; n     return min(l->rmq(lq, rq), r->rmq(lq, rq)); n   } n }; n segtree *p; n vector<pair<int, int> > ans; n void solve(int l, int r, int d) { n   if (l > r) return; n   int mn = p->rmq(l, r); n   while (mn > d) ans.push_back({l + 1, r + 1}), d++; n   int lb = l, rb = r; n   while (lb != rb) { n     int t = (lb + rb) / 2; n     if (p->rmq(l, t) == d) n       rb = t; n     else n       lb = t + 1; n   } n   solve(l, lb - 1, d); n   solve(lb + 1, r, d); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   p = new segtree(0, n - 1); n   solve(0, n - 1, 0); n   cout << ans.size() <<   n ; n   for (auto x : ans) cout << x.first <<     << x.second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<string> v; n   map<char, int> m; n   int k; n   cin >> k; n   string q; n   cin >> q; n   int l = q.size(); n   int flag = 1; n   int cnt = 0; n   string s; n   if (l < k) { n     cout <<  NO ; n     return 0; n   } else { n     cnt = 1; n     s += q[0]; n     m[q[0]] = 1; n     for (int i = 1; i < l; i++) { n       if (m[q[i]] == 0 and cnt < k) { n         m[q[i]] += 1; n         cnt++; n         v.push_back(s); n         s =   ; n         s += q[i]; n       } else { n         s += q[i]; n       } n     } n     v.push_back(s); n   } n   if (v.size() == k) { n     cout <<  YES  << endl; n     for (int i = 0; i < v.size(); i++) cout << v[i] << endl; n   } else { n     cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double h, l; n   scanf( %lf %lf , &h, &l); n   printf( %lf n , (l * l - h * h) / (2 * h * 1.0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX_N = 5000; n const long long MAX_Q = 10000; n struct Node { n   vector<long long> val; n   vector<int> nex; n }; n long long cnt = 1, cur = 0, n           pows[5] = { n               1LL, (MAX_Q + 1LL), (MAX_Q + 1LL) * (MAX_Q + 1LL), n               (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL), n               (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL) * (MAX_Q + 1LL)}; n Node G[MAX_N]; n void dfs(int pos, int dep, long long uplim) { n   if (uplim > MAX_Q) { n     cur += pows[dep] - 1LL; n     return; n   } n   if (dep == 1) { n     for (int i = 1; i <= uplim; i++) { n       cur++; n       G[pos].val.push_back(cur); n       G[pos].nex.push_back(-1); n     } n     return; n   } n   long long cur_uplim = uplim; n   for (int i = 1; i <= uplim + 1; i++) { n     cnt++; n     G[pos].nex.push_back(cnt); n     dfs(cnt, dep - 1, cur_uplim); n     if (i != uplim + 1) { n       cur++; n       G[pos].val.push_back(cur); n       cur_uplim = cur + 1; n     } n   } n } n int main() { n   dfs(1, 5, 1); n   long long cx = 1, range_l = 1, range_r = cur; n   for (int t = 4; t >= 0; t--) { n     vector<long long> D; n     if (cx != -1 && cx <= cnt && G[cx].val.size() >= 1) { n       D = G[cx].val; n     } else { n       for (int i = 1; i <= MAX_Q; i++) n         D.push_back((range_l - 1LL) + 1LL * i * pows[t]); n     } n     cout << D.size(); n     for (int i = 0; i < D.size(); i++) cout <<     << D[i]; n     cout << endl; n     int S; n     cin >> S; n     if (S == -1) break; n     if (cx != -1 && cx <= cnt && G[cx].val.size() >= 1) n       cx = G[cx].nex[S]; n     else n       cx = -1; n     if (S >= 1) range_l = D[S - 1] + 1LL; n     if (S < (int)D.size() - 1) range_r = D[S] - 1LL; n   } n   return 0; n } n


#include <bits/stdc++.h> n void initialize(int *arr, int length) { n   for (int i = 0; i < length; i++) arr[i] = 0; n } n int teams(int *arr, int length) { n   for (int i = 1; i < length; i++) { n     if (arr[i - 1] == 1 && arr[i] == 1) return 2; n   } n   return 1; n } n int main() { n   int queries, len, curr, sieve[100]; n   scanf( %d n , &queries); n   for (int i = 0; i < queries; i++) { n     initialize(sieve, 100); n     scanf( %d n , &len); n     for (int j = 0; j < len; j++) { n       scanf( %d , &curr); n       sieve[curr - 1] = 1; n     } n     scanf(  n ); n     printf( %d n , teams(sieve, 100)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T_container, typename T = typename enable_if< n                                     !is_same<T_container, string>::value, n                                     typename T_container::value_type>::type> n ostream &operator<<(ostream &os, const T_container &v) { n   string sep; n   for (const T &x : v) os << sep << x, sep =    ; n   return os; n } n const int mxN = 12, oo = 1e9; n bool g[12][12], used[13]; n long long ans = 0; n int n = 12, k; n int a[12]; n bool pused[6]; n bool goodr(int i = 0, int d = 0) { n   if (d == n - 2) return g[a[i]][a[i + 1]]; n   for (int to = 0; to < n; to += 2) n     if (!pused[to]) { n       if ((g[a[i]][a[to]] and g[a[i + 1]][a[to + 1]]) or n           (g[a[i]][a[to + 1]] and g[a[i + 1]][a[to]])) { n         pused[to] = true; n         if (goodr(to, d + 2)) { n           pused[to] = false; n           return true; n         } n         pused[to] = false; n       } n     } n   return false; n } n bool good() { n   for (int i = 0; i < n; i += 2) { n     pused[i] = true; n     if (goodr(i)) { n       pused[i] = false; n       return true; n     } n     pused[i] = false; n   } n   return false; n } n set<array<char, 12>> s; n int eq = 0; n array<char, 12> equiv, mp, reale; n void normalize() { n   fill(begin(mp), end(mp), -1); n   int t = 0; n   for (int i = 0; i < n; ++i) { n     if (mp[equiv[i]] == -1) mp[equiv[i]] = t++; n     reale[i] = mp[equiv[i]]; n   } n } n void rec2(int i = 0) { n   if (i == n) { n     normalize(); n     if (eq > k) return; n     if (!s.count(reale)) { n       int cur = 1; n       for (int j = k - eq + 1; j <= k; ++j) { n         cur *= j; n       } n       ans += cur; n       s.insert(reale); n     } n     return; n   } n   equiv[a[i]] = eq; n   equiv[a[i + 1]] = eq; n   eq++; n   rec2(i + 2); n   eq--; n   for (int j = 0; j < eq; ++j) { n     equiv[a[i]] = j; n     equiv[a[i + 1]] = j; n     rec2(i + 2); n   } n } n void rec(int i, int d = 0) { n   while (used[i]) ++i; n   if (i == n) { n     if (good()) { n       rec2(); n     } n     return; n   } n   used[i] = true; n   for (int j = i + 1; j < n; ++j) n     if (!used[j]) { n       used[j] = true; n       a[d] = i; n       a[d + 1] = j; n       rec(i + 1, d + 2); n       used[j] = false; n     } n   used[i] = false; n } n int main() { n   int m; n   cin >> n >> m >> k; n   for (int i = 0; i < m; ++i) { n     int u, v; n     cin >> u >> v, --u, --v; n     g[u][v] = true; n     g[v][u] = true; n   } n   rec(0); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     int n; n     cin >> n; n     vector<int> v(n); n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n     } n     int i; n     bool poss = 1; n     for (i = 0; i < n; i++) n       if (v[i] < i) break; n     i--; n     for (int j = i; j < n - 1; j++) { n       if (v[j + 1] >= v[j]) v[j + 1] = v[j] - 1; n       if (v[j + 1] < 0) { n         poss = 0; n         break; n       } n     } n     if (poss) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 998244353; n int main() { n   ios_base::sync_with_stdio(false); n   long long r, s, p; n   cin >> r >> s >> p; n   double dp[r + 1][s + 1][p + 1]; n   int visited[r + 1][s + 1][p + 1]; n   for (int i = 0; i < r + 1; i++) { n     for (int j = 0; j < s + 1; j++) { n       for (int k = 0; k < p + 1; k++) { n         dp[i][j][k] = 0; n         visited[i][j][k] = 0; n       } n     } n   } n   dp[r][s][p] = 1; n   visited[r][s][p] = 1; n   queue<pair<pair<double, double>, double> > q; n   q.push(make_pair(make_pair(r, s), p)); n   while (!q.empty()) { n     int sz = q.size(); n     for (int i = 0; i < sz; i++) { n       pair<pair<double, double>, double> curp = q.front(); n       q.pop(); n       double rr = curp.first.first; n       double ss = curp.first.second; n       double rp = curp.second; n       if ((int)rr > 0 && (int)ss > 0) { n         dp[(int)rr][(int)ss - 1][(int)rp] += n             dp[(int)rr][(int)ss][(int)rp] * n             (((rr * ss)) / ((rr * ss + rp * rr + ss * rp))); n         if (visited[(int)rr][(int)ss - 1][(int)rp] == 0) { n           q.push(make_pair(make_pair(rr, ss - 1), rp)); n           visited[(int)rr][(int)ss - 1][(int)rp] = 1; n         } n       } n       if ((int)rr > 0 && (int)rp > 0) { n         dp[(int)rr - 1][(int)ss][(int)rp] += n             dp[(int)rr][(int)ss][(int)rp] * n             (((rr * rp)) / ((rr * ss + rp * rr + ss * rp))); n         if (visited[(int)rr - 1][(int)ss][(int)rp] == 0) { n           q.push(make_pair(make_pair(rr - 1, ss), rp)); n           visited[(int)rr - 1][(int)ss][(int)rp] = 1; n         } n       } n       if ((int)rp > 0 && (int)ss > 0) { n         dp[(int)rr][(int)ss][(int)rp - 1] += n             dp[(int)rr][(int)ss][(int)rp] * n             (((rp * ss)) / ((rr * ss + rp * rr + ss * rp))); n         if (visited[(int)rr][(int)ss][(int)rp - 1] == 0) { n           q.push(make_pair(make_pair(rr, ss), rp - 1)); n           visited[(int)rr][(int)ss][(int)rp - 1] = 1; n         } n       } n     } n   } n   double ans1, ans2, ans3; n   ans1 = ans2 = ans3 = 0; n   for (int i = 1; i <= r; i++) { n     ans1 += dp[i][0][0]; n   } n   for (int i = 1; i <= s; i++) { n     ans2 += dp[0][i][0]; n   } n   for (int i = 1; i <= p; i++) { n     ans3 += dp[0][0][i]; n   } n   std::cout << std::setprecision(9) << ans1 <<     << ans2 <<     << ans3; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int a[4]{0}; n     int i, j, k, ans, min1 = 0, min2 = 0; n     for (i = 0; i < s.size(); i++) { n       if (s[i] ==  L ) a[0]++; n       if (s[i] ==  R ) a[1]++; n       if (s[i] ==  U ) a[2]++; n       if (s[i] ==  D ) a[3]++; n     } n     min1 = min(a[0], a[1]); n     min2 = min(a[2], a[3]); n     if (min1 >= 1 && min2 == 0) { n       cout <<  2  << endl; n       cout <<  LR ; n     } else if (min1 == 0 && min2 >= 1) { n       cout <<  2  << endl; n       cout <<  UD ; n     } else { n       string b(2 * (min1 + min2),  1 ); n       for (i = 0; i < 2 * (min1 + min2); i++) { n         if (i < min1) n           b[i] =  R ; n         else if (i >= min1 + min2 && i < (2 * min1 + min2)) n           b[i] =  L ; n         else if (i >= (2 * min1 + min2)) n           b[i] =  U ; n         else n           b[i] =  D ; n       } n       cout << b.size() << endl; n       cout << b; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int e, s, n, m; n vector<int> comp; n vector<pair<int, int> > has; n vector<int> all, butR, onlyS; n int query[200013]; n int id(int x) { n   return lower_bound(comp.begin(), comp.end(), x) - comp.begin(); n } n vector<int> cover(int use) { n   vector<int> res(comp.size()); n   for (auto i : has) n     if (i.second >= use) { n       res[id(i.first)] += 1; n       res[id(i.first + s)] -= 1; n     } n   int prev = 0; n   for (int& i : res) i += prev, prev = i; n   for (int i = 0; i < res.size() - 1; i++) { n     if (res[i]) res[i] = comp[i + 1] - comp[i]; n   } n   prev = 0; n   for (int& i : res) i += prev, prev = i; n   return res; n } n bool test(vector<int>& vec, int ind) { n   return ind != 0 && vec[ind] > vec[ind - 1]; n } n pair<int, int> solve(int f) { n   if (f + s >= e) return make_pair(0, 0); n   f += s; n   int eAt = id(e) - 1, fAt = id(f) - 1; n   if (all[eAt] - all[fAt] != e - f) return make_pair(-1, -1); n   int needR = (e - f) - (butR[eAt] - butR[fAt]); n   int needP = (e - f) - (onlyS[eAt] - onlyS[fAt]) - needR; n   return make_pair(needR, needP); n } n int main() { n   scanf( %d%d%d%d , &e, &s, &n, &m); n   comp.push_back(e); n   comp.push_back(-1.01e9); n   for (int i = 0; i < n; i++) { n     int t, x; n     scanf( %d%d , &t, &x); n     if (x >= e) continue; n     has.push_back(make_pair(x, t)); n     comp.push_back(x); n     comp.push_back(x + s); n   } n   for (int i = 0; i < m; i++) { n     scanf( %d , &query[i]); n     comp.push_back(query[i]); n     comp.push_back(query[i] + s); n   } n   sort(comp.begin(), comp.end()); n   comp.erase(unique(comp.begin(), comp.end()), comp.end()); n   all = cover(1); n   butR = cover(2); n   onlyS = cover(3); n   for (int i = 0; i < m; i++) { n     pair<int, int> ans = solve(query[i]); n     printf( %d %d n , ans.first, ans.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 22; n const int M = (1 << 22); n const int INF = 0x3f3f3f3f; n bool dp[M] = {0}; n int neib[N] = {0}, ex[M] = {0}; n int main() { n   int m, n, u, v; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     neib[i] = (1 << i); n     dp[1 << i] = true; n   } n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &u, &v); n     --u; n     --v; n     dp[(1 << u) | (1 << v)] = true; n     neib[u] |= (1 << v); n     neib[v] |= (1 << u); n   } n   if (n == 1 || m == n * (n - 1) / 2) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 0; i < (1 << n); ++i) n     if (dp[i]) { n       for (int j = 0; j < n; ++j) n         if (i & (1 << j)) { n           ex[i] |= neib[j]; n         } n       for (int j = 0; j < n; ++j) n         if (ex[i] & (1 << j)) { n           dp[i | (1 << j)] = true; n         } n     } n   int best = INF; n   std::vector<int> ans; n   for (int i = 0; i < (1 << n); ++i) n     if (dp[i] && ex[i] == (1 << n) - 1) { n       int cnt = 0; n       for (int j = 0; j < n; ++j) n         if (i & (1 << j)) ++cnt; n       if (cnt >= best) continue; n       best = cnt; n       ans.clear(); n       for (int j = 0; j < n; ++j) n         if (i & (1 << j)) ans.push_back(j); n     } n   printf( %d n , ans.size()); n   for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i] + 1); n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n set<int> s[100001]; n int a[100001]; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     s[x].insert(y); n     s[y].insert(x); n   } n   srand(time(0)); n   for (int op = 1; op <= 200; op++) { n     for (int i = 1; i <= n; i++) a[i] = i; n     random_shuffle(a + 1, a + n + 1); n     a[n + 1] = a[1]; n     int i; n     for (i = 1; i <= m; i++) { n       if (s[a[i]].count(a[i + 1])) break; n     } n     if (i == m + 1) { n       for (i = 1; i <= m; i++) cout << a[i] <<     << a[i + 1] << endl; n       return 0; n     } n   } n   cout << -1; n   return 0; n } n


// BY : VIDIT BHARDWAJ n #include<bits/stdc++.h> n using namespace std; n  n #define int                 long long int n #define ff                  first n #define ss                  second n #define pb                  push_back n #define popb                pop_back n #define lb                  lower_bound n #define ub                  upper_bound n #define all(v)              (v).begin(),(v).end() n #define tc(t)               int t; cin>>t; while(t--) n #define pii                 pair<int,int> n #define max_pq              priority_queue<int> n #define min_pq              priority_queue<int,vector<int>, greater<int> > n #define fast_ios            ios_base::sync_with_stdio(false);cin.tie(NULL); n #define ps(x,y)             fixed<<setprecision(y)<<x  n #define setbits(x)          __builtin_popcountll(x) n #define zerobits(x)         __builtin_ctzll(x) n #define YES                 cout<< YES <<  n  n #define NO                  cout<< NO <<  n  n #define Yes                 cout<< Yes <<  n  n #define No                  cout<< No <<  n  n #define endl                  n  n          n const int N=200010; n const long long mod=1000000007; n // const long long mod=998244353; n const long long inf=1000000000000000000; n const long double pi=3.14159265358979323846264338; n  n /*_______________________________________________________________________*/ n  n signed main(){ n #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n #endif n     fast_ios n     tc(t){ n         string str,s; cin>>str>>s; n         int n=str.size(),m=s.size(); n  n         if(n<m){ n          string temp=str; n          str=s,s=temp; n          n=str.size(),m=s.size(); n         } n  n         if(s!=str.substr(0,s.size())){ n          cout<< -1 <<endl; n          continue; n         } n  n      int it=500,yes=0; n      string temp=s; n      while(it>0){ n       if(s.size()%str.size()==0){ n        yes=1; n        break; n       } n       s+=temp,it--; n      } n      if(yes){ n       temp=str; n       int x=s.size()/str.size(); n       for(int i=1;i<x;i++){ n        str+=temp; n       } n       if(str==s) cout<<s<<endl; n       else cout<< -1 <<endl; n      } n      else cout<< -1 <<endl; n     } n  n     return 0; n } n /* n  n */


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 5; n long long a[N]; n struct t { n   int lval, rval, mval; n } tr[N * 4]; n int sign(long long x) { n   if (x > 0) return 1; n   if (x < 0) return -1; n   return 0; n } n inline void cal(int cur, int l, int r) { n   int m = (l + r) / 2; n   int dcur = cur + cur, u = dcur, v = u + 1; n   tr[cur].mval = max(tr[u].mval, tr[v].mval); n   tr[cur].lval = tr[u].lval; n   tr[cur].rval = tr[v].rval; n   if (!(!a[m] || !a[m + 1] || sign(a[m]) < sign(a[m + 1]))) { n     tr[cur].mval = max(tr[cur].mval, tr[u].rval + tr[v].lval); n     if (tr[dcur].mval == m - l + 1) { n       tr[cur].lval = tr[u].lval + tr[v].lval; n     } n     if (tr[dcur + 1].mval == r - m) { n       tr[cur].rval = tr[v].rval + tr[u].rval; n     } n   } n } n void build(int pos, int l, int r) { n   if (l == r) { n     int x = !!a[l]; n     tr[pos].lval = tr[pos].rval = tr[pos].mval = x; n     return; n   } n   int mid = (l + r) >> 1; n   build(pos * 2, l, mid); n   build(pos * 2 + 1, mid + 1, r); n   cal(pos, l, r); n } n void update(int pos, int l, int r, int k, int d) { n   int mid = (l + r) >> 1; n   if (l == r) { n     a[l] += d; n     int x = !!a[l]; n     tr[pos].lval = tr[pos].rval = tr[pos].mval = x; n     return; n   } else { n     int mid = (l + r) >> 1; n     if (k <= mid) n       update(pos * 2, l, mid, k, d); n     else n       update(pos * 2 + 1, mid + 1, r, k, d); n     cal(pos, l, r); n   } n } n int main() { n   int u, v, n, i, m, l, r, d; n   cin >> n; n   cin >> u; n   for (i = 1; i < n; ++i) scanf( %d , &v), a[i - 1] = v - u, u = v; n   if (n > 1) build(1, 0, n - 2); n   cin >> m; n   while (m--) { n     scanf( %d%d%d , &l, &r, &u); n     if (n == 1) { n       printf( 1 n ); n     } else { n       if (l > 1) update(1, 0, n - 2, l - 2, u); n       if (r < n) update(1, 0, n - 2, r - 1, -u); n       printf( %d n , tr[1].mval + 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long f[5005][5005]; n long long mod = 1000000007, ans = 0; n char s1[5005], s2[5005]; n int main() { n   scanf( %s  n %s , s1 + 1, s2 + 1); n   int len1 = strlen(s1 + 1); n   int len2 = strlen(s2 + 1); n   for (int i = 1; i <= len1; ++i) n     for (int j = 1; j <= len2; ++j) { n       if (s1[i] == s2[j]) f[i][j] = (f[i - 1][j - 1] + 1) % mod; n       f[i][j] = (f[i][j] + f[i][j - 1]) % mod; n     } n   for (int i = 1; i <= len1; ++i) ans = (ans + f[i][len2]) % mod; n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int good = 0; n   int bad = 0; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s.at(i) ==  a ) n       good++; n     else n       bad++; n   } n   if (good > bad) n     cout << s.length(); n   else n     cout << s.length() - (bad - good) - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int x[3]; n   cin >> x[0] >> x[1] >> x[2]; n   sort(x, x + 3); n   cout << (x[1] - x[0]) + (x[2] - x[1]) <<   n ; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long llINF = 9223372036854775807; n const int INF = 2147483647; n const int maxn = 2e5 + 7; n const int maxm = 5e4 + 7; n const long long mod = 1e9 + 7; n const double pi = acos(-1.0); n const double eps = 1e-12; n int n; n int fa[2][maxn]; n int a[maxn], b[maxn]; n int u[maxn], v[maxn], w[maxn]; n long long ans; n void init() { n   for (int j = 0; j < 2; j++) n     for (int i = 0; i < maxn; i++) fa[j][i] = i; n } n int find(int x, int idx) { n   return x == fa[idx][x] ? x : fa[idx][x] = find(fa[idx][x], idx); n } n void merge(int x, int y, int idx) { fa[idx][find(x, idx)] = find(y, idx); } n int main(int argc, char const *argv[]) { n   scanf( %d , &n); n   for (int i = 1; i <= n - 1; i++) scanf( %d%d%d , &u[i], &v[i], &w[i]); n   init(); n   for (int i = 1; i <= n - 1; i++) { n     if (w[i] == 0) n       merge(u[i], v[i], 0); n     else n       merge(u[i], v[i], 1); n   } n   for (int i = 1; i <= n; i++) a[find(i, 0)]++; n   for (int i = 1; i <= n; i++) b[find(i, 1)]++; n   for (int i = 1; i <= n; i++) ans += 1ll * a[find(i, 0)] * b[find(i, 1)]; n   printf( %lld n , ans - n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using point = complex<double>; n const int T = 1 << 16; n point root[T]; n void fft(vector<point>& a) { n   int n = a.size(); n   vector<int> reverse(n); n   for (int i = 0; i < n; ++i) { n     reverse[i] = (reverse[i / 2] + (i % 2) * n) / 2; n     if (i < reverse[i]) { n       swap(a[i], a[reverse[i]]); n     } n   } n   for (int i = 1; i < n; i *= 2) { n     for (int j = 0; j < n; j += 2 * i) { n       for (int k = 0; k < i; ++k) { n         point l = a[j + k]; n         point r = a[i + j + k] * root[i + k]; n         a[j + k] = l + r; n         a[i + j + k] = l - r; n       } n     } n   } n } n vector<point> mul(vector<point> a, vector<point> b) { n   int n = 1, m = a.size() + b.size(); n   while (n < m) { n     n *= 2; n   } n   a.resize(n), b.resize(n); n   fft(a), fft(b); n   for (int i = 0; i < n; ++i) { n     a[i] *= b[i]; n   } n   fft(a); n   for (auto& i : a) { n     i /= n; n   } n   reverse(a.begin() + 1, a.end()); n   a.resize(m - 1); n   return a; n } n const int M = 100; n const int N = 50; n double prob[M][T], expect[M][T], ans[N][T]; n array<int, 3> edges[M]; n long long dist[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout << fixed << setprecision(6); n   for (int i = 1; i < T; i *= 2) { n     for (int j = 0; j < i; ++j) { n       root[i + j] = polar(1.0, j * M_PI / i); n     } n   } n   int n, m, t, x; n   cin >> n >> m >> t >> x; n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     edges[i] = {u - 1, v - 1, w}; n     for (int j = 1; j <= t; ++j) { n       int p; n       cin >> p; n       prob[i][j] = p / 100000.0; n     } n   } n   fill(dist, dist + n - 1, LLONG_MAX); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       auto [u, v, w] = edges[j]; n       if (dist[v] < LLONG_MAX) { n         dist[u] = min(dist[u], dist[v] + w); n       } n     } n   } n   for (int i = 0; i < n - 1; ++i) { n     fill(ans[i], ans[i] + t + 1, HUGE_VAL); n   } n   for (int i = 0; i < m; ++i) { n     auto [u, v, w] = edges[i]; n     double sum = 0.0; n     for (int j = t; j >= 0; --j) { n       expect[i][j] = w + sum * (dist[v] + x); n       sum += prob[i][j]; n     } n     ans[u][0] = min(ans[u][0], expect[i][0]); n   } n   for (int i = 1; i <= t; ++i) { n     for (int j = 0; j < m; ++j) { n       auto [u, v, w] = edges[j]; n       for (int k = 1; i % k == 0; k *= 2) { n         vector<point> poly = n             mul(vector<point>(ans[v] + i - k, ans[v] + i), n                 vector<point>(prob[j] + k, prob[j] + min(2 * k, t + 1))); n         for (int l = 0; l <= t - i && l <= (int)poly.size(); ++l) { n           expect[j][l + i] += poly[l].real(); n         } n       } n       ans[u][i] = min(ans[u][i], expect[j][i]); n     } n   } n   cout << ans[0][t] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool prime[1007]; n int n; n void sieve() { n   for (int i = 4; i <= 1005; i += 2) prime[i] = false, prime[i - 1] = true; n   prime[2] = true; n   for (int i = 3; i <= 1000; i += 2) { n     if (prime[i]) { n       for (int j = i * i; j <= 1005; j += i * 2) prime[j] = false; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   sieve(); n   scanf( %d , &n); n   vector<int> ans; n   for (int i = 1; i <= n; i++) { n     if (prime[i]) { n       int q = 1; n       while (q <= n / i) { n         q *= i; n         ans.push_back(q); n       } n     } n   } n   cout << (ans.size()) << endl; n   for (int i : ans) { n     printf( %d  , i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long q, x; n   cin >> q >> x; n   long long n = q; n   long long a[n]; n   map<long long, long long> m; n   long long min = 0; n   map<long long, long long> f; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     long long mod = a[i] % x; n     f[mod]++; n     m[mod + ((f[mod] - 1) * x)]++; n     while (m[min] == 1) min++; n     cout << min << endl; n   } n   map<long long, long long>::iterator it; n } n


#include <bits/stdc++.h> n int read() { n   static int c, x; n   while ((c = getchar()) < 48) { n   } n   x = c & 15; n   while ((c = getchar()) >= 48) x = x * 10 + (c & 15); n   return x; n } n struct edge { n   int next, to; n } e[100010 << 1]; n int ans = 0; n int head[100010], deg[100010], f0[100010], f1[100010]; n inline void add(const int &x, const int &y) { n   static int ei; n   e[++ei].next = head[x]; n   e[ei].to = y; n   head[x] = ei; n   ++deg[x]; n } n void dfs(const int &x, const int &fa) { n   f1[x] = 1; n   f0[x] = deg[x] - 1; n   for (int i = head[x]; i; i = e[i].next) { n     const int y = e[i].to; n     if (y != fa) { n       dfs(y, x); n       ans = std::max(ans, f0[x] + std::max(f0[y], f1[y])); n       ans = std::max(ans, f1[x] + f0[y]); n       f0[x] = std::max(f0[x], std::max(f0[y], f1[y]) + deg[x] - 2); n       f1[x] = std::max(f1[x], f0[y] + 1); n     } n   } n } n int main() { n   const int n = read(); n   for (int i = n; --i;) { n     const int x = read(), y = read(); n     add(x, y); n     add(y, x); n   } n   dfs(1, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int nroot = floor(sqrt(n)); n     if (nroot * nroot >= n) { n       cout << 2 * nroot - 2 <<   n ; n     } else if ((nroot + 1) * nroot >= n) { n       cout << 2 * nroot - 1 <<   n ; n     } else { n       cout << 2 * nroot <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 100000; n struct point { n   int x, y; n }; n point p[maxn + 10]; n int n, used[maxn + 10]; n inline int one_line(int a, int b, int c) { n   if ((a == 0) || (b == 0) || (c == 0)) { n     return 1; n   } n   return 1ll * (p[c].x - p[a].x) * (p[b].y - p[a].y) == n          1ll * (p[c].y - p[a].y) * (p[b].x - p[a].x); n } n int check(int a, int b) { n   memset(used, 0, sizeof used); n   used[a] = used[b] = 1; n   for (register int i = 1; i <= n; ++i) { n     if ((!used[i]) && (one_line(a, b, i))) { n       used[i] = 1; n     } n   } n   int u = 0, v = 0, w = 0, flag = 1; n   for (register int i = 1; i <= n; ++i) { n     if (!used[i]) { n       u = v; n       v = w; n       w = i; n       if (!one_line(u, v, w)) { n         flag = 0; n         break; n       } n     } n   } n   return flag; n } n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; ++i) { n     scanf( %d%d , &p[i].x, &p[i].y); n   } n   if (check(1, 2) || check(2, 3) || check(1, 3)) { n     puts( YES ); n   } else { n     puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     int x, n, m; n     scanf( %d%d%d , &x, &n, &m); n     while (n-- && x >= 20) x = floor(1.0 * x / 2) + 10; n     while (m--) x -= 10; n     printf(x <= 0 ?  YES n  :  NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200100; n const int INF = 1000 * 1000 * 100; n string s[N]; n char ch[30]; n int d[1000 * 3000 + 10], l[30], r[30]; n int lcps(int x) { n   int sz = s[x].size(); n   for (int i = sz - 1; i >= 0; i--) n     r[i] = r[i + 1] + ((s[x][i] -  0 ) << (sz - i - 1)); n   l[0] = s[x + 1][0] -  0 ; n   for (int i = 1; i < sz; i++) l[i] = l[i - 1] * 2 + (s[x + 1][i] -  0 ); n   for (int i = sz; i > 0; i--) n     if (l[i - 1] == r[sz - i]) return i; n   return 0; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %20s , ch); n     for (int j = 0; j < 20 && (ch[j] ==  0  || ch[j] ==  1 ); j++) n       s[i] += ch[j]; n   } n   int sz = s[0].size(), p = (1 << (sz + 1)), all(0), tmp(0); n   fill(d, d + p, INF); n   d[p - 1] = 0; n   for (int i = 0; i < n; i++) { n     int t = sz, mn = INF, z; n     if (i) { n       t = lcps(i - 1); n       for (int j = 0; j <= sz; j++) { n         if (j == 0) { n           mn = min(all + sz - tmp, mn); n           if (s[i][0] ==  0 ) n             z = p - 2; n           else n             z = 1; n         } else { n           mn = min(d[z] + sz - j, mn); n           z *= 2; n           if (j < sz) z += s[i][j] -  0 ; n           z %= p; n         } n       } n       z = 0; n       mn -= (sz - t); n       d[p - 1] = min(d[p - 1], mn); n       for (int j = sz - 1; j >= 0; j--) { n         int v = (1 << (sz - j - 1)); n         if (s[i - 1][j] -  0  == 1) { n           z &= ((1 << (sz - j)) - 1); n           if ((z & v) == 0) z += v; n         } else { n           z |= ((p - 1) ^ ((1 << (sz - j)) - 1)); n           if ((z & v) != 0) z -= v; n         } n         d[z] = min(d[z], mn); n       } n       tmp += (sz - t); n       all += (sz - t); n       all = min(all, mn + tmp); n     } else n       all += sz, tmp += sz, d[p - 1] = sz; n   } n   cout << all << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n int n, m; n vector<int> liga[200100]; n vector<int> adj[200100]; n int state[200100]; n int id[200100], sz[200100]; n int vis[200200]; n vector<int> top; n int find(int x) { n   if (id[x] == x) return x; n   return id[x] = find(id[x]); n } n void join(int a, int b) { n   a = find(a); n   b = find(b); n   if (a == b) return; n   if (sz[a] < sz[b]) swap(a, b); n   id[b] = a; n   sz[a] += sz[b]; n } n void dfs(int v) { n   vis[v] = 1; n   for (auto x : adj[v]) { n     if (vis[x]) continue; n     dfs(x); n   } n   top.push_back(v); n } n void dfs2(int v, int ori) { n   vis[v] = 1; n   for (auto x : adj[v]) { n     if (vis[x]) continue; n     join(ori, x); n     dfs2(x, ori); n   } n } n void add(int a, int b) { adj[a].push_back(b); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> state[i]; n   for (int i = 1; i <= 2 * m; i++) { n     id[i] = i; n     sz[i] = 1; n   } n   for (int i = 1; i <= m; i++) { n     int amt; n     cin >> amt; n     while (amt--) { n       int x; n       cin >> x; n       liga[x].push_back(i); n     } n   } n   for (int i = 1; i <= n; i++) { n     int x = liga[i][0]; n     int y = liga[i][1]; n     if (state[i]) { n       add(2 * x - 1, 2 * y - 1); n       add(2 * y, 2 * x); n       add(2 * y - 1, 2 * x - 1); n       add(2 * x, 2 * y); n     } else { n       add(2 * x, 2 * y - 1); n       add(2 * y, 2 * x - 1); n       add(2 * x - 1, 2 * y); n       add(2 * y - 1, 2 * x); n     } n   } n   for (int i = 1; i <= 2 * m; i++) n     if (!vis[i]) dfs(i); n   reverse(top.begin(), top.end()); n   memset(vis, 0, sizeof(vis)); n   for (auto x : top) n     if (!vis[x]) dfs2(x, x); n   for (int i = 1; i <= m; i++) { n     if (find(2 * i) == find(2 * i - 1)) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   while (cin >> n >> m) { n     int tmp = 0, mid = (m + 1) / 2, res = mid; n     while (n--) { n       if (tmp % 2 == m % 2) n         res -= tmp; n       else n         res += tmp; n       if (tmp == m) tmp = 0, res = mid; n       cout << res << endl; n       tmp++; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[100010]; n int j[100010]; n string ss; n bool haha; n int m; n void jump(int n) { n   if (n < 0 || n >= m) { n     haha = true; n     return; n   } else if (j[n] == 1) { n     haha = false; n     return; n   } else { n     int p; n     if (ss[n] ==  < ) n       p = -1; n     else if (ss[n] ==  > ) n       p = 1; n     j[n] = 1; n     jump(n + p * v[n]); n     return; n   } n } n int main(int argc, const char* argv[]) { n   memset(j, 0, sizeof(j)); n   memset(v, 0, sizeof(v)); n   int n; n   cin >> n; n   m = n; n   cin >> ss; n   haha = true; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   jump(0); n   if (haha) { n     printf( FINITE n ); n   } else { n     printf( INFINITE n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Search[1001][1001], Target1[1001], Target2[1001], Attack = 0; n int main() { n   int Data1, Data2; n   cin >> Data1 >> Data2; n   for (int i = 0; i < Data1; i++) { n     for (int i2 = 0; i2 < Data2; i2++) { n       char Test; n       cin >> Test; n       if (Test ==  * ) { n         Search[i][i2] = 1, Attack++; n       } n       Target1[i] += Search[i][i2]; n       Target2[i2] += Search[i][i2]; n     } n   } n   for (int i = 0; i < Data1; i++) { n     for (int i2 = 0; i2 < Data2; i2++) { n       if (Search[i][i2] == 0 && Target1[i] + Target2[i2] == Attack) n         return cout <<  YES  << endl << i + 1 <<     << i2 + 1, 0; n       if (Search[i][i2] == 1 && Target1[i] + Target2[i2] == Attack + 1) n         return cout <<  YES  << endl << i + 1 <<     << i2 + 1, 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n long long mulmod(long long a, long long b, long long MOD) { n   if (b == 0) return 0; n   long long res = mulmod(a, b >> 1, MOD); n   res += res; n   res %= MOD; n   return (b & 1) ? (a + res) % MOD : res; n } n int gcd(int a, int b) { n   while (a != 0 && b != 0) { n     if (a > b) { n       a %= b; n     } else { n       b %= a; n     } n   } n   return a + b; n } n long long gcd(long long a, long long b) { n   while (a != 0 && b != 0) { n     if (a > b) { n       a %= b; n     } else { n       b %= a; n     } n   } n   return a + b; n } n long long next(long long i) { n   long long a[13], j = 0; n   memset(a, 0, sizeof(a)); n   while (i != 0) { n     a[j] = i % 10; n     i /= 10; n     j++; n   } n   bool pp = 0; n   for (int k = j - 1; k >= 0; k--) { n     if (pp) { n       a[k] = 4; n       continue; n     } n     if (a[k] < 4) { n       a[k] = 4; n       pp = 1; n       continue; n     } n     if (4 < a[k] && a[k] < 7) { n       a[k] = 7; n       pp = 1; n       continue; n     } n     if (a[k] > 7) { n       while (a[k + 1] == 7) { n         k++; n       } n       if (a[k + 1] == 4) { n         a[k + 1] = 7; n       } else { n         a[k + 1] = 4; n       } n       a[k] = 4; n       pp = 1; n       continue; n     } n   } n   i = 0; n   for (int j = 12; j >= 0; j--) { n     i = i * 10 + a[j]; n   } n   return i; n } n int main() { n   ios::sync_with_stdio(0); n   int n, k; n   string s; n   cin >> n >> k >> s; n   for (int i = 0; i < n - 1; i++) { n     if (i < 0) i = 0; n     if (k <= 0) break; n     if (s[i] ==  4  && s[i + 1] ==  7 ) { n       if (i % 2 == 0) { n         if (i + 2 < n && s[i + 2] ==  7 ) { n           if (k % 2 == 1) { n             s[i + 1] =  4 ; n           } n           k = 0; n           break; n         } else { n           s[i + 1] =  4 ; n           k--; n         } n       } else { n         s[i] =  7 ; n         i -= 2; n         k--; n       } n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n namespace IO { n template <typename Tp> n inline Tp input() { n   Tp x = 0, y = 1; n   char c = getchar(); n   while ((c <  0  ||  9  < c) && c != EOF) { n     if (c ==  - ) y = -1; n     c = getchar(); n   } n   if (c == EOF) return 0; n   while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return x *= y; n } n template <typename Tp> n inline void read(Tp &x) { n   x = input<Tp>(); n } n };  // namespace IO n using namespace IO; n namespace modular { n const int MOD = 1000000007; n inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; } n inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; } n inline int mul(int x, int y) { return 1LL * x * y % MOD; } n inline int qpow(int x, int y) { n   int ans = 1; n   for (; y; y >>= 1, x = mul(x, x)) n     if (y & 1) ans = mul(ans, x); n   return ans; n } n };  // namespace modular n int N, top, tot; n int a[2007], b[2007], c[3]; n std::pair<int, int> ans[2007 * 2007]; n bool cmp(int x, int y) { return a[x] < a[y]; } n int main() { n   srand(0x66ccf); n   read(N); n   for (int i = 1; i <= N; ++i) read(a[i]); n   top = N; n   for (int i = 1; i <= top; ++i) b[i] = i; n   std::sort(b + 1, b + N + 1, cmp); n   std::reverse(b + 1, b + N + 1); n   while (top && !a[b[top]]) top--; n   if (top < 2) return puts( -1 ), 0; n   while (top > 2) { n     for (int i = 0; i <= 2; ++i) { n       c[i] = rand() % (top - i) + i + 1; n       std::swap(b[i + 1], b[c[i]]); n       c[i] = b[i + 1]; n     } n     std::sort(c, c + 3, cmp); n     int k = a[c[1]] / a[c[0]], mx = 0; n     for (int i = 0; i <= 21; ++i) n       if (k >> i & 1) mx = i; n     for (int i = 0; i <= 2; ++i) b[i + 1] = c[i]; n     for (int i = 0; i <= mx; ++i) { n       if (k >> i & 1) { n         ans[++tot] = std::pair<int, int>(c[0], c[1]); n         a[c[1]] -= a[c[0]]; n         a[c[0]] *= 2; n       } else { n         ans[++tot] = std::pair<int, int>(c[0], c[2]); n         a[c[2]] -= a[c[0]]; n         a[c[0]] *= 2; n       } n     } n     if (!a[c[1]]) { n       std::swap(b[top], b[2]); n       top--; n     } n   } n   printf( %d n , tot); n   for (int i = 1; i <= tot; ++i) printf( %d %d n , ans[i].first, ans[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000000 + 9; n long long pow(long long a, int n, long long mod) { n   long long res = 1; n   while (n) { n     if (n % 2) { n       res *= a; n       res %= mod; n       --n; n     } else { n       a *= a; n       a %= mod; n       n /= 2; n     } n   } n   return res; n } n inline long long dec(long long a, long long b) { n   return ((a - b) % mod + mod) % mod; n } n int main() { n   int n, m; n   cin >> n >> m; n   if (m < 26 && n > pow(2, m, mod) - 1) { n     cout << 0; n     return 0; n   } n   long long ans = dec(pow(2, m, mod), 1); n   int i; n   for (i = 1; i < n; ++i) { n     ans *= dec(pow(2, m, mod), i + 1); n     ans %= mod; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n const int oo = 1000000000; n long long n, k; n long long a[N], b[N], c[N]; n long long module = 1000000007; n void print(vector<vector<long long> > mat) { n   for (int j = 0; j < mat.size(); j++) { n     for (int k = 0; k < mat[j].size(); k++) cout << mat[j][k] <<    ; n     cout << endl; n   } n } n vector<vector<long long> > mul(vector<vector<long long> > mat1, n                                vector<vector<long long> > mat2) { n   vector<vector<long long> > res; n   for (int i = 0; i < mat1.size(); i++) { n     vector<long long> row; n     for (int k = 0; k < mat2[0].size(); k++) { n       long long temp = 0; n       for (int j = 0; j < mat1[0].size(); j++) { n         temp = (temp + mat1[i][j] * mat2[j][k] % module) % module; n       } n       row.push_back(temp); n     } n     res.push_back(row); n   } n   return res; n } n vector<vector<long long> > pow(vector<vector<long long> > mat, long long t) { n   vector<vector<long long> > res; n   if (t == 0) { n     for (int i = 0; i < 16; i++) { n       vector<long long> row; n       for (int j = 0; j < 16; j++) { n         if (i == j) n           row.push_back(1); n         else n           row.push_back(0); n       } n       res.push_back(row); n     } n     return res; n   } n   res = pow(mat, t / 2); n   res = mul(res, res); n   if (t % 2 == 0) n     return res; n   else n     return mul(mat, res); n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i]; n   vector<vector<long long> > base; n   vector<long long> row; n   row.push_back(1); n   base.push_back(row); n   for (int i = 1; i < 16; i++) { n     row.resize(0); n     row.push_back(0); n     base.push_back(row); n   } n   base.push_back(row); n   for (int i = 1; i <= n; i++) { n     long long dist = 0; n     if (i == n) n       dist = k - a[i]; n     else n       dist = b[i] - a[i]; n     vector<vector<long long> > mat; n     for (int j = 0; j < 16; j++) { n       vector<long long> row; n       for (int k = 0; k < 16; k++) { n         if (j <= c[i] && k <= c[i] && (k == j || k == j - 1 || k == j + 1)) n           row.push_back(1); n         else n           row.push_back(0); n       } n       mat.push_back(row); n     } n     base = mul(pow(mat, dist), base); n   } n   cout << base[0][0]; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int com(const void* a, const void* b) { return *(int*)a - *(int*)b; } n int main(void) { n   int n, k, i; n   cin >> n >> k; n   if (n / 2 > k) n     cout << -1; n   else if (n == 1 && k != 0) n     cout << -1; n   else { n     i = n / 2 - 1; n     int l = k - i; n     if (n > 1) { n       cout << l <<     << l * 2 <<    ; n       for (l = l * 2 + 1; i > 0; i--, l += 2) printf( %d %d  , l, l + 1); n     } n     if (n % 2) printf( %d , l); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[200001]; n int b[600001]; n int n, L; n bool chk(int d) { n   if (d * 2 >= L) return true; n   int l = 0, r = 3 * n - 1; n   while (b[l] < a[0] - d) l++; n   while (b[r] > a[0] + d) r--; n   for (int i = 1; i < n; i++) { n     l++; n     r++; n     while (b[l] < a[i] - d) l++; n     if (b[r] > a[i] + d) r--; n   } n   return l <= r; n } n void Init() { n   scanf( %d%d , &n, &L); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   for (int i = 0; i < n; i++) scanf( %d , b + n + i); n } n void Solve() { n   for (int i = 0; i < n; i++) { n     b[i] = b[i + n] - L; n     b[i + 2 * n] = b[i + n] + L; n   } n   sort(a, a + n); n   sort(b, b + 3 * n); n   int left = 0, right = L / 2 + 1; n   while (left < right) { n     int m = (left + right) / 2; n     if (chk(m)) n       right = m; n     else n       left = m + 1; n   } n   printf( %d n , left); n } n int main() { n   Init(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[2006]; n int B[2005]; n map<int, int> mp; n int main() { n   int a, b, n, x; n   while (cin >> n) { n     mp.clear(); n     int t = 1, x1, y1; n     for (int i = 0; i < n; i++) { n       scanf( %d , &A[i]); n       if (mp.count(A[i]) == 0) mp[A[i]] = t++; n     } n     for (int i = 0; i < n; i++) { n       scanf( %d , &B[i]); n       if (mp.count(B[i]) == 0) mp[B[i]] = t++; n     } n     int sum = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (i == j) { n           x = A[i] ^ B[j]; n           if (mp.count(x) == 1) sum++; n         } else { n           x = A[i] ^ B[j]; n           if (mp.count(x) == 1) sum++; n         } n       } n     } n     if (sum % 2 == 0) n       cout <<  Karen  << endl; n     else n       cout <<  Koyomi  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int n, a[MAXN * 3], u[MAXN * 3], v[MAXN * 3], front, rear; n int main() { n   int Q; n   long long x; n   scanf( %d%d , &n, &Q); n   front = 1; n   rear = n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= 2 * n - 2; i++) { n     u[i] = a[front], v[i] = a[front + 1]; n     if (u[i] < v[i]) n       a[++front] = v[i], a[++rear] = u[i]; n     else n       a[++front] = u[i], a[++rear] = v[i]; n   } n   while (Q--) { n     cin >> x; n     if (x > n - 1) x = x % (n - 1) + n - 1; n     printf( %d %d n , u[x], v[x]); n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long INF = (long long)1e18 + 123; n const int inf = (int)2e9 + 123; n const int mod = 1e9 + 7; n using namespace std; n int n, m, d[8000011], a[1000011], b[1000011]; n void upd(int id, int x, int v = 1, int tl = 1, int tr = 1000000) { n   if (tl > id || tr < id) return; n   if (tl == tr) { n     d[v] = x; n     return; n   } n   int mid = (tl + tr) / 2; n   upd(id, x, v * 2, tl, mid); n   upd(id, x, v * 2 + 1, mid + 1, tr); n   d[v] = d[v * 2] + d[v * 2 + 1]; n } n int get(int x, int v = 1, int tl = 1, int tr = 1000000) { n   if (tl == tr) return tl; n   int mid = (tl + tr) / 2; n   if (d[v * 2] >= x) { n     return get(x, v * 2, tl, mid); n   } else n     return get(x - d[v * 2], v * 2 + 1, mid + 1, tr); n } n int get_id(int id, int v = 1, int tl = 1, int tr = 1000000) { n   if (tl == tr) return d[v]; n   int mid = (tl + tr) / 2; n   if (id <= mid) n     return get_id(id, v * 2, tl, mid); n   else n     return get_id(id, v * 2 + 1, mid + 1, tr); n } n int size = 0; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> m >> n; n   vector<int> v; n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n   } n   for (int i = 1; i <= m; i++) { n     int type; n     cin >> type; n     if (type == -1) { n       int SZ = d[1]; n       for (int j = 1; j <= n; j++) { n         if (b[j] > SZ) break; n         upd(get(b[j] - j + 1), 0); n       } n     } else { n       a[++size] = type; n       upd(size, 1); n     } n   } n   for (int i = 1; i <= size; i++) { n     if (get_id(i) > 0) v.push_back(a[i]); n   } n   if (!v.size()) { n     cout <<  Poor stack! ; n     return 0; n   } n   for (int i = 0; i < v.size(); i++) { n     cout << v[i]; n   } n   return 0; n } n


#include <bits/stdc++.h> n namespace IO { n template <typename T> n inline void read(T &x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     x = (x << 3) + (x << 1) + ch -  0 , ch = getchar(); n   x *= f; n   return; n } n template <typename T> n inline void write(T x = 0) { n   T wr[51]; n   wr[0] = 0; n   if (x < 0) putchar( - ), x = -x; n   if (!x) putchar(48); n   while (x) wr[++wr[0]] = x % 10, x /= 10; n   while (wr[0]) putchar(48 + wr[wr[0]--]); n   return; n } n }  // namespace IO n using IO::read; n using IO::write; n using namespace std; n const int N = 4e6 + 11; n int n, m, top, now, k; n int op[N], a[N], b[N], fa[N], sz[N], sa[N], sb[N], cur[N], ti[N]; n vector<pair<int, int> > v[N]; n void modify(int x, int y, int a, int b, int k, int l, int r) { n   if (x <= l && r <= y) { n     v[k].push_back(pair<int, int>(a, b)); n     return; n   } n   int mid = (l + r) >> 1; n   if (x <= mid) modify(x, y, a, b, k << 1, l, mid); n   if (mid < y) modify(x, y, a, b, k << 1 | 1, mid + 1, r); n } n int find(int x) { return fa[x] == x ? x : find(fa[x]); } n void merge(int x, int y) { n   x = find(x), y = find(y); n   if (x == y) return; n   if (sz[x] < sz[y]) swap(x, y); n   sa[++top] = x, sb[top] = y; n   sz[x] += sz[y]; n   fa[y] = x; n } n void del(int tim) { n   int x, y; n   while (top > tim) { n     x = sa[top], y = sb[top]; n     fa[y] = y, sz[x] -= sz[y]; n     --top; n   } n } n void dfs(int k, int l, int r) { n   int t = top; n   for (auto s : v[k]) merge(s.first, s.second); n   if (l == r) { n     if (op[l] == 2) printf( %d n , sz[find(a[l])]); n     del(t); n     return; n   } n   int mid = (l + r) >> 1; n   dfs(k << 1, l, mid), dfs(k << 1 | 1, mid + 1, r); n   del(t); n } n int main() { n   read(n); n   read(m); n   read(k); n   for (int i = 1; i <= n; ++i) fa[i] = i, sz[i] = 1; n   for (int i = 1; i <= m; ++i) { n     read(op[i]); n     if (op[i] == 1) n       read(a[i]), read(b[i]), cur[i] = now; n     else if (op[i] == 2) n       read(a[i]), cur[i] = now; n     else n       ti[++now] = i, cur[i] = now; n   } n   for (int i = 1; i <= m; ++i) n     if (op[i] == 1) { n       if (cur[i] + k > now) n         modify(i, m, a[i], b[i], 1, 1, m); n       else n         modify(i, ti[cur[i] + k], a[i], b[i], 1, 1, m); n     } n   dfs(1, 1, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n; n   cin >> n; n   long long a[n]; n   map<long long, long long> m; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     m[a[i]]++; n   } n   long long ctr = 0, mx = 1; n   for (auto i : m) { n     ctr++; n     if (i.second > 1) mx = max(mx, i.second); n   } n   cout << mx <<     << ctr; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 65; n const int M = 5e4 + 10; n int n, m, a[N], b[N], q, trans[M], ans; n vector<int> p[N * N]; n template <class T> n void chkMax(T &x, T y) { n   if (x < y) x = y; n } n int Do(int x, int y) { n   int i = 0, j = 0, ret = 0, szx = p[x].size(), szy = p[y].size(); n   while (i < szx && j < szy) { n     ++ret; n     if (p[x][i] == p[y][j]) n       ++i, ++j; n     else if (p[x][i] < p[y][j]) n       ++i; n     else n       ++j; n   } n   return ret + szx - i + szy - j; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < m; ++i) cin >> b[i]; n   memset(trans, -1, sizeof(trans)); n   q = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       int tmp = a[i] + b[j] + 2e4 + 1; n       if (trans[tmp] == -1) p[trans[tmp] = q++].clear(); n       p[trans[tmp]].push_back(i); n       p[trans[tmp]].push_back(j + n); n     } n   for (int i = 0; i < q; ++i) { n     sort(p[i].begin(), p[i].end()); n     p[i].resize(unique(p[i].begin(), p[i].end()) - p[i].begin()); n   } n   ans = 0; n   if (q == 1) ans = n + m; n   for (int i = 0; i < q; ++i) n     for (int j = i + 1; j < q; ++j) chkMax(ans, Do(i, j)); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int piles = 1, heavy = 0, num; n int a[110], n; n void solve(int x) { n   if (num == 0) { n     return; n   } n   if (heavy <= a[x]) { n     a[x] = -1; n     heavy++; n     num--; n     solve(x + 1); n   } else if (x < n) { n     solve(x + 1); n   } else { n     for (int i = 1; i <= n; i++) { n       if (a[i] != -1) { n         a[i] = -1; n         num--; n         heavy = 1; n         piles++; n         break; n       } n     } n     solve(1); n   } n } n int main() { n   cin >> n; n   num = n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= i; j++) { n       if (a[i] < a[j]) { n         swap(a[i], a[j]); n       } n     } n   } n   solve(1); n   cout << piles; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, nxt[100010], pre[100010]; n pair<int, int> b[100010]; n struct Frog { n   int p, a, id; n } a[100010]; n set<pair<int, int> > s; n inline bool operator<(Frog a, Frog b) { return a.p < b.p; } n inline int cal(int i, int j) { n   if (i == j) return 0x7fffffff; n   int p1 = a[i].p, p2 = a[j].p; n   if (i > j) (p2 += a[j].a) %= m; n   int d = (p2 - p1 + m) % m, step = (a[i].a - a[j].a); n   if (d <= a[i].a) return 1; n   if (a[j].a >= a[i].a) return 0x7fffffff; n   return (d - a[j].a + step - 1) / step; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) n     scanf( %d%d , &a[i].p, &a[i].a), a[i].p--, b[i] = make_pair(a[i].p, i); n   sort(b, b + n); n   for (int i = 0; i < n; i++) { n     nxt[b[i].second] = b[(i + 1) % n].second; n     pre[b[(i + 1) % n].second] = b[i].second; n   } n   for (int i = 0; i < n; i++) s.insert(make_pair(cal(i, nxt[i]), i)); n   while (!s.empty()) { n     set<pair<int, int> >::iterator it = s.begin(); n     int i = it->second; n     if (it->first == 0x7fffffff) break; n     s.erase(it); n     s.erase(make_pair(cal(nxt[i], nxt[nxt[i]]), nxt[i])); n     s.erase(make_pair(cal(pre[i], i), pre[i])); n     a[i].p += cal(i, nxt[i]); n     a[i].a--; n     nxt[i] = nxt[nxt[i]]; n     pre[nxt[i]] = i; n     s.insert(make_pair(cal(pre[i], i), pre[i])); n     s.insert(make_pair(cal(i, nxt[i]), i)); n   } n   printf( %d n , s.size()); n   for (set<pair<int, int> >::iterator it = s.begin(); it != s.end(); it++) n     printf( %d  , it->second + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b, c; n   map<char, char> mp; n   mp.clear(); n   int s = 0; n   cin >> a; n   cin >> b; n   cin >> c; n   s = c.size(); n   for (int i = 0; i < 26; i++) { n     mp[a[i]] = b[i]; n   } n   for (int i = 0; i < s; i++) { n     if (c[i] < 97 && c[i] >= 65) { n       c[i] += 32; n       cout << char(mp[c[i]] - 32); n     } else if (c[i] >= 97) n       cout << mp[c[i]]; n     else n       cout << c[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 5; n const long long mod = 1e9 + 7; n const long double PI = acos(-1); n long long n, k; n pair<long long, long long> a[N]; n long long ans[N]; n int main() { n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     scanf( %lld , &a[i].first); n     a[i].second = i; n   } n   set<int> st; n   for (int i = k + 1; i <= k + n; i++) { n     st.insert(i); n   } n   sort(a, a + n); n   reverse(a, a + n); n   long long out = 0; n   for (int i = 0; i < n; i++) { n     auto it = st.lower_bound(a[i].second + 1); n     out += ((*it - (a[i].second + 1)) * 1ll * a[i].first); n     ans[a[i].second] = *it; n     st.erase(it); n   } n   printf( %lld n , out); n   for (int i = 0; i < n; i++) n     printf( %lld%c , ans[i], (i + 1 == n ?   n  :    )); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int occ[26]; n int main() { n   string s, p; n   cin >> s >> p; n   int err = 0; n   if (s.size() < p.size()) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 0; i < p.size(); i++) { n     occ[p[i] -  a ]++; n   } n   for (int i = 0; i < p.size(); i++) { n     if (s[i] !=  ? ) { n       occ[s[i] -  a ]--; n       if (occ[s[i] -  a ] == -1) err++; n     } n   } n   int sol = 0; n   for (int i = 0; i <= s.size() - p.size(); i++) { n     if (err == 0) sol++; n     if (i + p.size() == s.size()) break; n     if (s[i] !=  ? ) { n       occ[s[i] -  a ]++; n       if (occ[s[i] -  a ] == 0) err--; n     } n     if (s[i + p.size()] !=  ? ) { n       occ[s[i + p.size()] -  a ]--; n       if (occ[s[i + p.size()] -  a ] == -1) err++; n     } n   } n   cout << sol << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n int g[maxn][maxn]; n int vis[maxn][maxn]; n int cnt[maxn][maxn]; n struct node { n   int x, y; n } que[maxn * maxn]; n int dx[10] = {0, 1, 0, -1, 0}; n int dy[10] = {0, 0, 1, 0, -1}; n map<char, int> p; n void init() { n   p[ U ] = 2; n   p[ D ] = 4; n   p[ L ] = 3; n   p[ R ] = 1; n } n void add(int x1, int y1, int x2, int y2) { n   int pp = 0; n   if (x1 == x2) { n     if (y1 < y2) n       pp = 2; n     else n       pp = 4; n   } else { n     if (x1 < x2) n       pp = 1; n     else n       pp = 3; n   } n   g[x2][y2] = pp; n   while (x1 != x2 || y1 != y2) { n     g[x1][y1] = pp; n     x1 += dx[pp]; n     y1 += dy[pp]; n   } n } n int main() { n   init(); n   int n, m; n   scanf( %d%d , &m, &n); n   int x1, y1, x2, y2; n   while (m--) { n     scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n     add(x1, y1, x2, y2); n   } n   long long t; n   char c; n   int Q, x, y, vx, vy; n   scanf( %d , &Q); n   for (int q = 1; q <= Q; q++) { n     scanf( %d %d %c %lld , &x, &y, &c, &t); n     vx = dx[p[c]]; n     vy = dy[p[c]]; n     long long t0 = 0; n     while (x >= 0 && x <= n && y >= 0 && y <= n && t > 0) { n       if (g[x][y]) { n         vx = dx[g[x][y]]; n         vy = dy[g[x][y]]; n       } n       if (g[x][y] && vis[x][y] == q) { n         long long t1 = cnt[x][y]; n         long long mod = t0 - t1; n         t %= mod; n         x = que[t1 + t].x; n         y = que[t1 + t].y; n         break; n       } n       vis[x][y] = q; n       cnt[x][y] = t0; n       que[t0].x = x; n       que[t0++].y = y; n       x += vx; n       y += vy; n       t--; n     } n     if (x < 0) x = 0; n     if (x > n) x = n; n     if (y < 0) y = 0; n     if (y > n) y = n; n     printf( %d %d n , x, y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long, int> mark; n int32_t main() { n   int n; n   scanf( %d , &n); n   set<long long> s; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     mark[x]++; n     s.insert(x); n   } n   int p = 0; n   long long MX = 0; n   while (s.size()) { n     long long u = *s.begin(); n     ((MX) = max((MX), (u))); n     mark[u + 1] += mark[u] / 2; n     if (mark[u + 1]) s.insert(u + 1); n     if (mark[u] % 2) p--; n     s.erase(s.begin()); n   } n   return cout << MX + p + 1 << endl, 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int c[5005]; n int r[5005]; n int p[5005]; n int main() { n   memset(p, -1, sizeof p); n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> c[i]; n     if (p[c[i]] == -1) { n       p[c[i]] = i; n     } n   } n   for (int i = 0; i < n; ++i) { n     int o[5005]; n     memset(o, 0, sizeof o); n     o[c[i]] = 1; n     r[c[i]] += 1; n     int mO = c[i]; n     for (int j = i + 1; j < n; ++j) { n       o[c[j]] += 1; n       if (o[c[j]] > o[mO] || (o[c[j]] == o[mO] && c[j] < mO)) { n         mO = c[j]; n       } n       r[mO] += 1; n     } n   } n   for (int i = 1; i <= n; ++i) cout << r[i] <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int buffer_size = 1e5 + 5; n char buf[buffer_size], *S, *T; n bool flag_EOF; n inline char read_char() { n   if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin); n   return S != T ? *(S++) : EOF; n } n inline int read_int() { n   bool flag = false; n   char c = read_char(); n   while (c <  0  || c >  9 ) { n     if (c == EOF) { n       flag_EOF = true; n       return 0; n     } n     flag = (c ==  -  ? true : flag); n     c = read_char(); n   } n   int x = 0; n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + (c ^ 48); n     c = read_char(); n   } n   return flag ? -x : x; n } n const int max_cnt = 1e3 + 5; n int l[max_cnt], p[max_cnt]; n bool mark[max_cnt]; n vector<int> a[2], b[2]; n const int max_size = 5e5 + 5; n bitset<max_size> f[2]; n bool dp[max_size]; n int val[max_size]; n inline int cmp1(int x, int y) { return abs(x) < abs(y); } n inline int cmp2(int x, int y) { return abs(x) > abs(y); } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int h, v; n     scanf( %d , &h); n     for (int i = 1; i <= h; ++i) scanf( %d , l + i); n     scanf( %d , &v); n     for (int i = 1; i <= v; ++i) scanf( %d , p + i); n     if (h != v) { n       printf( No n ); n       continue; n     } n     int sum1 = 0, sum2 = 0; n     for (int i = 1; i <= h; ++i) sum1 += l[i]; n     for (int i = 1; i <= v; ++i) sum2 += p[i]; n     if ((sum1 & 1) || (sum2 & 1)) { n       printf( No n ); n       continue; n     } n     random_shuffle(l + 1, l + h + 1); n     for (int i = 0; i <= sum1; ++i) f[0][i] = 0; n     f[0][0] = 1; n     int pos1 = -1; n     for (int i = 1; i <= h; ++i) { n       int x = (i & 1) ^ 1, y = i & 1; n       f[y] = f[x] | (f[x] << l[i]); n       if (f[y][sum1 >> 1]) { n         pos1 = i; n         break; n       } n     } n     if (pos1 == -1) { n       printf( No n ); n       continue; n     } n     random_shuffle(p + 1, p + v + 1); n     for (int i = 0; i <= sum2; ++i) f[0][i] = 0; n     f[0][0] = 1; n     int pos2 = -1; n     for (int i = 1; i <= v; ++i) { n       int x = (i & 1) ^ 1, y = i & 1; n       f[y] = f[x] | (f[x] << p[i]); n       if (f[y][sum2 >> 1]) { n         pos2 = i; n         break; n       } n     } n     if (pos2 == -1) { n       printf( No n ); n       continue; n     } n     a[0].clear(), a[1].clear(); n     int tot1 = sum1 >> 1; n     for (int i = 1; i <= h; ++i) mark[i] = false; n     for (int i = pos1 + 1; i <= h; ++i) { n       a[0].push_back(l[i]); n       mark[i] = true; n       tot1 -= l[i]; n     } n     for (int i = 0; i <= tot1; ++i) dp[i] = false; n     dp[0] = true; n     for (int i = 1; i <= pos1; ++i) n       for (int j = tot1 - l[i]; j >= 0; --j) n         if (dp[j] && !dp[j + l[i]]) { n           dp[j + l[i]] = true; n           val[j + l[i]] = i; n         } n     int now = tot1; n     while (now) { n       a[0].push_back(l[val[now]]); n       mark[val[now]] = true; n       now -= l[val[now]]; n     } n     int cnt1 = 0; n     for (int i = 1; i <= h; ++i) n       if (!mark[i]) { n         a[1].push_back(l[i]); n         ++cnt1; n       } n     b[0].clear(), b[1].clear(); n     int tot2 = sum2 >> 1; n     for (int i = 1; i <= v; ++i) mark[i] = false; n     for (int i = pos2 + 1; i <= v; ++i) { n       b[0].push_back(p[i]); n       mark[i] = true; n       tot2 -= p[i]; n     } n     for (int i = 0; i <= tot2; ++i) dp[i] = false; n     dp[0] = true; n     for (int i = 1; i <= pos2; ++i) n       for (int j = tot2 - p[i]; j >= 0; --j) n         if (dp[j] && !dp[j + p[i]]) { n           dp[j + p[i]] = true; n           val[j + p[i]] = i; n         } n     now = tot2; n     while (now) { n       b[0].push_back(p[val[now]]); n       mark[val[now]] = true; n       now -= p[val[now]]; n     } n     int cnt2 = 0; n     for (int i = 1; i <= v; ++i) n       if (!mark[i]) { n         b[1].push_back(p[i]); n         ++cnt2; n       } n     printf( Yes n ); n     int x = 0, y = 0; n     if (a[0].size() < a[1].size()) swap(a[0], a[1]); n     if (b[0].size() > b[1].size()) swap(b[0], b[1]); n     sort(a[1].begin(), a[1].end()); n     sort(b[1].begin(), b[1].end(), greater<int>()); n     while (a[1].size()) { n       x += a[1].back(); n       printf( %d %d n , x, y); n       y += b[1].back(); n       printf( %d %d n , x, y); n       a[1].pop_back(); n       b[1].pop_back(); n     } n     while (b[1].size()) { n       x -= a[0].back(); n       printf( %d %d n , x, y); n       y += b[1].back(); n       printf( %d %d n , x, y); n       a[0].pop_back(); n       b[1].pop_back(); n     } n     sort(a[0].begin(), a[0].end()); n     sort(b[0].begin(), b[0].end(), greater<int>()); n     while (b[0].size()) { n       x -= a[0].back(); n       printf( %d %d n , x, y); n       y -= b[0].back(); n       printf( %d %d n , x, y); n       a[0].pop_back(); n       b[0].pop_back(); n     } n   } n   return 0; n } n