#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class t, class u> n void chmax(t& first, u second) { n   if (first < second) first = second; n } n template <class t, class u> n void chmin(t& first, u second) { n   if (second < first) first = second; n } n template <class t> n using vc = vector<t>; n template <class t> n using vvc = vc<vc<t>>; n using pi = pair<ll, ll>; n using vi = vc<ll>; n template <class t, class u> n ostream& operator<<(ostream& os, const pair<t, u>& p) { n   return os <<  {  << p.first <<  ,  << p.second <<  } ; n } n template <class t> n ostream& operator<<(ostream& os, const vc<t>& v) { n   os <<  { ; n   for (auto e : v) os << e <<  , ; n   return os <<  } ; n } n using uint = unsigned; n using ull = unsigned long long; n template <ll i, class T> n void print_tuple(ostream&, const T&) {} n template <ll i, class T, class H, class... Args> n void print_tuple(ostream& os, const T& t) { n   if (i) os <<  , ; n   os << get<i>(t); n   print_tuple<i + 1, T, Args...>(os, t); n } n template <class... Args> n ostream& operator<<(ostream& os, const tuple<Args...>& t) { n   os <<  { ; n   print_tuple<0, tuple<Args...>, Args...>(os, t); n   return os <<  } ; n } n void print(ll x, ll suc = 1) { n   cout << x; n   if (suc == 1) cout <<   n ; n   if (suc == 2) cout <<    ; n } n ll read() { n   ll i; n   cin >> i; n   return i; n } n vi readvi(ll n, ll off = 0) { n   vi v(n); n   for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off; n   return v; n } n template <class T> n void print(const vector<T>& v, ll suc = 1) { n   for (ll i = ll(0); i < ll(v.size()); i++) n     print(v[i], i == ll(v.size()) - 1 ? suc : 2); n } n string readString() { n   string s; n   cin >> s; n   return s; n } n template <class T> n T sq(const T& t) { n   return t * t; n } n void yes(bool ex = true) { n   cout <<  Yes  << endl; n   if (ex) exit(0); n } n void no(bool ex = true) { n   cout <<  No  << endl; n   if (ex) exit(0); n } n constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; } n const ll infLL = LLONG_MAX / 3; n const ll inf = infLL; n ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } n ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } n ll botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); } n ll botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); } n ll popcount(signed t) { return __builtin_popcount(t); } n ll popcount(ll t) { return __builtin_popcountll(t); } n bool ispow2(ll i) { return i && (i & -i) == i; } n ll mask(ll i) { return (ll(1) << i) - 1; } n bool inc(ll first, ll second, ll c) { return first <= second && second <= c; } n template <class t> n void mkuni(vc<t>& v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n ll rand_int(ll l, ll r) { n   static random_device rd; n   static mt19937_64 gen(rd()); n   return uniform_int_distribution<ll>(l, r)(gen); n } n ll gcd(ll first, ll second) { n   return second ? gcd(second, first % second) : first; n } n ll lcm(ll first, ll second) { return first / gcd(first, second) * second; } n signed main() { n   cin.tie(0); n   ios::sync_with_stdio(0); n   cout << fixed << setprecision(20); n   ll n; n   cin >> n; n   ll g = 0; n   vc<pi> vs; n   for (ll _ = ll(0); _ < ll(n); _++) { n     ll first, second; n     cin >> first >> second; n     g = gcd(g, lcm(first, second)); n     vs.emplace_back(first, second); n   } n   if (g > 1) { n     for (auto z : vs) { n       ll first = gcd(g, z.first); n       ll second = gcd(g, z.second); n       if (first > 1) n         g = first; n       else if (second > 1) n         g = second; n       else n         assert(false); n     } n     cout << g << endl; n   } else n     cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5 * 105000; n int n; n int a[MAXN]; n bool can(int x) { n   if (x == 0) return true; n   if (n - x < x) return false; n   int r = n; n   for (int i = x; i >= 1; i--) { n     if (r <= x) return false; n     while (a[r] < 2 * a[i]) { n       r--; n       if (r <= x) return false; n     } n     r--; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1); n   int l = 0, r = n; n   while (l < r) { n     int m = (l + r + 1) / 2; n     if (can(m)) n       l = m; n     else n       r = m - 1; n   } n   printf( %d , n - l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100020; n const int logn = 18; n const int MOd = 1e9 + 7; n int a, b; n int ar[maxn]; n int main() { n   scanf( %d %d , &a, &b); n   for (int i = 1; i <= a; i++) scanf( %d , &ar[i]); n   double ans = 0.0; n   for (int i = 1, j, k, t; i <= b; i++) { n     scanf( %d %d %d , &j, &k, &t); n     ans = max(ans, ((double)(ar[j] + ar[k]) / t)); n   } n   printf( %.12lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count()); n char mat[105][105]; n void solve() { n   int n, m, horizontal; n   cin >> n >> m >> horizontal; n   int vertical = n * m / 2 - horizontal; n   int oxe = 0, nte = 0; n   char cc =  e ; n   if (n % 2 != m % 2) { n     if (n % 2 == 0) { n       for (int i = 0; i < n; i += 2) { n         mat[i][m - 1] = mat[i + 1][m - 1] = cc++; n         if (cc >  z ) cc =  e ; n       } n       vertical -= n / 2; n       m--; n       nte = 1; n     } else { n       for (int j = 0; j < m; j += 2) { n         mat[n - 1][j] = mat[n - 1][j + 1] = cc++; n         if (cc >  z ) cc =  e ; n       } n       horizontal -= m / 2; n       n--; n       oxe = 1; n     } n   } n   assert(n % 2 == 0 && m % 2 == 0); n   int puth = n * m / 2; n   int putv = 0; n   char mofio[] = { a ,  b }; n   int cur = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j += 2) { n       mat[i][j] = mat[i][j + 1] = mofio[cur]; n       cur ^= 1; n     } n     if (m % 4 == 0) cur ^= 1; n   } n   mofio[0] =  c , mofio[1] =  d ; n   cur = 0; n   for (int i = 0; i < n; i += 2) { n     for (int j = 0; j < m; j += 2) { n       if (puth == horizontal && putv == vertical) { n         cout <<  YES n ; n         for (int ii = 0; ii < n + oxe; ii++) { n           for (int jj = 0; jj < m + nte; jj++) { n             cout << mat[ii][jj]; n           } n           cout <<   n ; n         } n         return; n       } n       mat[i][j] = mat[i + 1][j] = mofio[cur]; n       mat[i][j + 1] = mat[i + 1][j + 1] = mofio[cur ^ 1]; n       puth -= 2; n       putv += 2; n     } n     cur ^= 1; n   } n   if (puth == horizontal && putv == vertical) { n     cout <<  YES n ; n     for (int ii = 0; ii < n + oxe; ii++) { n       for (int jj = 0; jj < m + nte; jj++) { n         cout << mat[ii][jj]; n       } n       cout <<   n ; n     } n     return; n   } n   cout <<  NO n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tt; n   cin >> tt; n   while (tt--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n int main() { n   int N, ele = -1; n   cin >> N; n   vector<int> A(N); n   int i; n   for (i = 0; i < N; ++i) cin >> A[i]; n   sort(A.begin(), A.end()); n   int ans = 0, ctr = 0, x; n   for (i = 0; i < N; i += x) { n     x = upper_bound(A.begin(), A.end(), A[i]) - n         lower_bound(A.begin(), A.end(), A[i]); n     ans = ans + min(ctr, x); n     ctr = max(ctr, x); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int a, b, c; n   cin >> a >> b >> c; n   if (b >= a && c >= a) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n inline int clamp(int v) { n   if (v > n) n     return v - n; n   else if (v < 1) { n     if (v == 0) n       return n; n     else n       return n + v; n   } else n     return v; n } n void validate() { n   n = 6; n   assert(clamp(0) == 6); n   assert(clamp(1) == 1); n   assert(clamp(-1) == 5); n   assert(clamp(6) == 6); n   assert(clamp(7) == 1); n   assert(clamp(3 + 5 % n) == 2); n   assert(clamp(3 + 6 % n) == 3); n   assert(clamp(3 + 7 % n) == 4); n   assert(clamp(3 + 8 % n) == 5); n   assert(clamp(3 + 9 % n) == 6); n   assert(clamp(3 + 10 % n) == 1); n   assert(clamp(3 + 11 % n) == 2); n } n int main() { n   validate(); n   cin >> n >> q; n   int startOdd = 1; n   int startEven = 2; n   for (int i = 0; i < q; i++) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int count; n       scanf( %d , &count); n       startOdd = clamp(startOdd + (count % n)); n       startEven = clamp(startEven + (count % n)); n     } else { n       startOdd = (startOdd % 2 == 0) ? startOdd - 1 : startOdd + 1; n       startEven = (startEven % 2 == 0) ? startEven - 1 : startEven + 1; n     } n   } n   int evenOffset = startEven - 2; n   int oddOffset = startOdd - 1; n   int positions[1000000 + 1]; n   for (int i = 1; i <= n; i++) { n     int pos = (i % 2 == 1) ? clamp(i + oddOffset) : clamp(i + evenOffset); n     positions[pos] = i; n   } n   for (int i = 1; i <= n; i++) { n     cout << positions[i] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j, k, l, mx; n int a[100001]; n int p[100001], miu[100001], len; n vector<int> b[100001]; n vector<int> c[100001]; n bool bz[100001]; n int f[100001]; n long long ans, s; n bool cmp(int a, int b) { return a > b; } n int gcd(int x, int y) { n   int r = x % y; n   while (r) x = y, y = r, r = x % y; n   return y; n } n void init() { n   int i, j, k, l; n   miu[1] = 1; n   for (i = 2; i <= 100000; i++) { n     if (!bz[i]) p[++len] = i, miu[i] = -1; n     for (j = 1; j <= len; j++) n       if (1ll * i * p[j] <= 100000) { n         bz[i * p[j]] = 1; n         if (!(i % p[j])) break; n         miu[i * p[j]] = -miu[i]; n       } else n         break; n   } n } n void add(int t, int s) { n   int i, l = b[t].size(); n   for (i = 0; i <= l - 1; i++) f[b[t][i]] += s; n } n int get(int t) { n   int i, k, l = b[t].size(), ans = 0; n   for (i = 0; i <= l - 1; i++) k = b[t][i], ans += miu[k] * f[k]; n   return ans; n } n void work(int S) { n   static int d[100001]; n   int i, j, k, l, len = c[S].size(), t = 0, A; n   if (!len) return; n   for (i = 0; i <= len - 1; i++) { n     A = c[S][i]; n     while (t && get(A)) { n       while (gcd(d[t], A) > 1) add(d[t], -1), --t; n       s = 1ll * d[t] * A * S; n       ans = (ans > s ? ans : s); n       add(d[t], -1), --t; n     } n     d[++t] = A, add(A, 1); n   } n   while (t) add(d[t], -1), --t; n } n int main() { n   init(); n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]), mx = (mx > a[i] ? mx : a[i]); n   sort(a + 1, a + n + 1, cmp); n   l = 0; n   for (i = 1; i <= n; i++) n     if (a[i] != a[i - 1]) n       a[++l] = a[i]; n     else n       ans = (ans > a[i] ? ans : a[i]); n   n = l; n   for (i = 1; i <= mx; i++) { n     s = floor(sqrt(i)); n     for (j = 1; j <= s; j++) n       if (!(i % j)) { n         b[i].push_back(j); n         if (j * j < i) b[i].push_back(i / j); n       } n   } n   for (i = 1; i <= n; i++) { n     l = b[a[i]].size(); n     for (j = 0; j <= l - 1; j++) k = b[a[i]][j], c[k].push_back(a[i] / k); n   } n   for (i = 1; i <= 100000; i++) work(i); n   printf( %lld n , ans); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n using pr = pair<T, U>; n template <typename T> n using vt = vector<T>; n template <class T> n bool cmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool cmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n inline namespace CP { n inline namespace Output { n template <class T> n void outv(vector<T> v, int add = 0, bool standard = 1) { n   for (T& i : v) (standard ? cout : cerr) << (i + add) <<    ; n   cout <<   n ; n } n template <class T> n void put(T output) { n   cout << output <<   n ; n } n }  // namespace Output n class IO { n  public: n   void setIn(string second) { (void)!freopen(second.c_str(),  r , stdin); } n   void setOut(string second) { (void)!freopen(second.c_str(),  w , stdout); } n   void Input(int __use_input = 0) { n     if (!!__use_input && 0) { n       setIn( in  + to_string(__use_input) +  .txt ); n     } n   } n   IO FastIO() { n     cin.tie(nullptr)->sync_with_stdio(0); n     return *this; n   } n   IO* SetIO(string __s =   , string __t =   ) { n     cin.exceptions(cin.failbit); n     if ((int)(__t).size()) n       setIn(__s), setOut(__t); n     else if ((int)(__s).size()) n       setIn(__s +  .in ), setOut(__s +  .out ); n     return this; n   } n }; n }  // namespace CP n const int MX = (1e5 + 5); n int N, K, P; n int a[MX]; n void test_case() { n   cin >> N >> K >> P; n   for (int i = (0); i < (N); ++i) cin >> a[i]; n   vt<vt<int>> sets(K, vt<int>()); n   vt<pr<int, int>> even_pairs, odd_pairs; n   int ptr = 0, used = 0; n   for (int i = (0); i < (N); ++i) { n     if (a[i] & 1 && ptr < (K - P)) n       sets[ptr++].push_back(a[i]); n     else if (a[i] & 1) { n       if (used) n         odd_pairs.back().second = a[i]; n       else n         odd_pairs.push_back({a[i], -1}); n       used = !used; n     } else n       even_pairs.push_back({a[i], -1}); n   } n   if (ptr != (K - P) || used || n       (int)(even_pairs).size() + (int)(odd_pairs).size() < P) n     return void(put( NO )); n   even_pairs.insert(even_pairs.end(), odd_pairs.begin(), odd_pairs.end()); n   if (P == 0) { n     for (auto pr : even_pairs) { n       if (pr.first & 1) sets[0].push_back(pr.second); n       sets[0].push_back(pr.first); n     } n   } else { n     int have = (int)(even_pairs).size(); n     for (int i = (0); i < (P); ++i) { n       if (i == P - 1) n         for (auto pair : even_pairs) { n           sets[ptr].push_back(pair.first); n           if (pair.first & 1) sets[ptr].push_back(pair.second); n         } n       else { n         if (even_pairs.back().first & 1) n           sets[ptr].push_back(even_pairs.back().second); n         sets[ptr++].push_back(even_pairs.back().first); n         even_pairs.pop_back(); n       } n     } n   } n   put( YES ); n   for (int i = (0); i < (K); ++i) { n     cout << (int)(sets[i]).size() <<    ; n     for (int j = (0); j < ((int)(sets[i]).size()); ++j) n       cout << sets[i][j] <<    n [j == (int)(sets[i]).size() - 1]; n   } n } n int main() { n   CP::IO().SetIO()->FastIO().Input(0); n   int Test_Cases = 1; n   for (int tt = 1; tt <= Test_Cases; ++tt) { n     ; n     ; n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch[1005]; n int dp[1005][3 * 1005]; n int n, k; n int func(int idx, int diff) { n   if (idx == n) { n     return (abs(diff) == k); n   } n   if (abs(diff) == k) { n     return 0; n   } n   int &re = dp[idx][diff + 1005]; n   if (re != -1) return re; n   re = 0; n   if (ch[idx] ==  W ) n     re = func(idx + 1, diff + 1); n   else if (ch[idx] ==  L ) n     re = func(idx + 1, diff - 1); n   else if (ch[idx] ==  D ) n     re = func(idx + 1, diff); n   else { n     re = n         func(idx + 1, diff - 1) | func(idx + 1, diff) | func(idx + 1, diff + 1); n   } n   return re; n } n void path(int idx, int diff) { n   if (idx == n) return; n   if (ch[idx] ==  W ) { n     printf( W ); n     path(idx + 1, diff + 1); n   } else if (ch[idx] ==  L ) { n     printf( L ); n     path(idx + 1, diff - 1); n   } else if (ch[idx] ==  D ) { n     printf( D ); n     path(idx + 1, diff); n   } else { n     if (func(idx + 1, diff + 1)) { n       printf( W ); n       path(idx + 1, diff + 1); n     } else if (func(idx + 1, diff)) { n       printf( D ); n       path(idx + 1, diff); n     } else { n       printf( L ); n       path(idx + 1, diff - 1); n     } n   } n } n int main() { n   scanf( %d%d%s , &n, &k, ch); n   memset(dp, -1, sizeof dp); n   if (func(0, 0)) { n     path(0, 0); n   } else n     printf( NO n ); 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 pos[4] = {0}; n     int n = s.size(), ans = s.size() + 1; n     for (int i = 0; i < n; i++) { n       pos[s[i] -  0 ] = i + 1; n       int x = min(pos[1], min(pos[2], pos[3])); n       if (x == 0) continue; n       ans = min(ans, i - x + 2); n     } n     if (s.size() + 1 == ans) n       cout <<  0  << endl; n     else n       cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long p = 998244353; n const long long maxn = (1 << 16) + 5; n long long cnt[maxn]; n vector<vector<long long> > dp; n long long k; n long long c; n long long c1[20][20]; n long long maxbit(long long x) { n   for (long long i = 16; i >= 0; i--) { n     if (x & (1 << i)) { n       return i; n     } n   } n } n long long po(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   if (b % 2 == 0) { n     long long u = po(a, b / 2); n     return (u * u) % p; n   } else { n     long long u = po(a, b - 1); n     return (a * u) % p; n   } n } n long long inv(long long x) { return po(x, p - 2); } n vector<vector<long long> > build( n     vector<pair<long long, pair<long long, long long> > > g) { n   vector<vector<long long> > answ(k + 1); n   for (long long i = 0; i <= k; ++i) { n     answ[i].resize(1 << c); n     for (long long j = 0; j < (1 << c); ++j) answ[i][j] = 0; n   } n   for (auto h : g) { n     answ[h.second.first][h.second.second] = h.first; n   } n   return answ; n } n vector<pair<long long, pair<long long, long long> > > mul1( n     vector<pair<long long, pair<long long, long long> > > a, n     vector<pair<long long, pair<long long, long long> > > b) { n   map<pair<long long, long long>, long long> m; n   vector<pair<long long, long long> > keys; n   vector<pair<long long, pair<long long, long long> > > ans; n   for (auto h1 : a) { n     for (auto h2 : b) { n       if ((h1.second.first + h2.second.first) <= k) { n         pair<long long, pair<long long, long long> > z = { n             (h1.first * h2.first) % p * n                 c1[h1.second.first + h2.second.first][h1.second.first], n             {h1.second.first + h2.second.first, n              h1.second.second ^ h2.second.second}}; n         if (m.count(z.second)) { n           m[z.second] = (m[z.second] + z.first) % p; n         } else { n           m[z.second] = (z.first % p); n           keys.push_back(z.second); n         } n       } n     } n   } n   for (auto z : keys) { n     ans.push_back({m[z], z}); n   } n   return ans; n } n vector<vector<long long> > answ; n void mul(vector<vector<long long> > &a, vector<vector<long long> > b) { n   vector<pair<long long, long long> > used1; n   vector<pair<long long, long long> > used2; n   for (long long i = 0; i <= k; ++i) { n     for (long long j = 0; j < (1 << c); ++j) { n       if (a[i][j]) used1.push_back({i, j}); n       if (b[i][j]) used2.push_back({i, j}); n     } n   } n   for (long long i = 0; i <= k; ++i) n     for (long long j = 0; j < (1 << c); ++j) answ[i][j] = 0; n   for (auto h1 : used1) { n     for (auto h2 : used2) { n       if ((h1.first + h2.first) <= k) { n         answ[h1.first + h2.first][h1.second ^ h2.second] += n             ((a[h1.first][h1.second] * b[h2.first][h2.second]) % p) * n             c1[h1.first + h2.first][h1.first]; n         answ[h1.first + h2.first][h1.second ^ h2.second] %= p; n       } n     } n   } n   a = answ; n } n vector<pair<long long, pair<long long, long long> > > degree( n     vector<pair<long long, pair<long long, long long> > > h, long long x) { n   if (x == 1) return h; n   if (x % 2 == 0) { n     vector<pair<long long, pair<long long, long long> > > ans1 = n         degree(h, x / 2); n     return mul1(ans1, ans1); n   } else { n     vector<pair<long long, pair<long long, long long> > > ans1 = n         degree(h, x - 1); n     return mul1(ans1, h); n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (long long i = 0; i < 20; ++i) { n     for (long long j = 0; j < 20; ++j) { n       if (i < j) { n         c1[i][j] = 0; n         continue; n       } n       if (i == j || j == 0) { n         c1[i][j] = 1; n         continue; n       } n       c1[i][j] = c1[i - 1][j - 1] + c1[i - 1][j]; n       c1[i][j] %= p; n     } n   } n   long long n; n   cin >> n >> k >> c; n   answ.resize(k + 1); n   for (long long i = 0; i <= k; ++i) answ[i].resize(1 << c); n   long long a[n]; n   long long o1 = 0; n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n     o1 ^= a[i]; n   } n   long long b[n]; n   for (long long i = 0; i < n; ++i) { n     long long x = a[i]; n     while (true) { n       long long u = maxbit(x); n       if ((x - (1 << u)) >= k) { n         x -= (1 << u); n       } else { n         break; n       } n     } n     b[i] = x; n   } n   sort(b, b + n); n   for (long long i = 0; i < n; ++i) { n     cnt[b[i]]++; n   } n   dp.resize(k + 1); n   for (long long i = 0; i <= k; ++i) { n     dp[i].resize(1 << c); n     for (long long j = 0; j < (1 << c); ++j) { n       dp[i][j] = 0; n     } n   } n   dp[0][0] = 1; n   for (long long i = 0; i < (1 << c); ++i) { n     if (!cnt[i]) continue; n     vector<pair<long long, pair<long long, long long> > > h; n     for (long long j = 0; j <= k; ++j) { n       h.push_back({1, {j, i ^ (i - j)}}); n     } n     vector<pair<long long, pair<long long, long long> > > g = degree(h, cnt[i]); n     mul(dp, build(g)); n   } n   vector<long long> ans(1 << c); n   for (long long i = 0; i < (1 << c); ++i) { n     ans[i ^ o1] = dp[k][i]; n   } n   for (long long i = 0; i < (1 << c); ++i) { n     ans[i] *= po(inv(n), k); n     ans[i] %= p; n   } n   for (long long i = 0; i < (1 << c); ++i) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 150; n int ej[M][M]; n const int inf = 1e9; n int n; n int bfs(int src, int sink) { n   vector<int> vis(n, 0); n   vector<int> dis(n, 0); n   queue<int> que; n   vis[src] = 1; n   que.push(src); n   while (que.size() > 0) { n     int u = que.front(); n     que.pop(); n     for (int v = 0; v < n; v++) { n       if (vis[v] == 0 && ej[u][v] == 1) { n         vis[v] = 1; n         dis[v] = dis[u] + 1; n         que.push(v); n         if (v == sink) return dis[v]; n       } n     } n   } n   return -1; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   vector<long long> v; n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     if (x) v.push_back(x); n   } n   n = v.size(); n   for (long long k = 0; k < 62; k++) { n     int cnt = 0; n     for (int i = 0; i < n; i++) { n       if (v[i] & (1LL << k)) { n         cnt++; n       } n     } n     if (cnt >= 3) { n       cout << 3 << endl; n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       if ((v[i] & v[j]) > 0) ej[i][j] = 1; n     } n   } n   int ans = inf; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (ej[i][j] == 0) continue; n       ej[i][j] = 0; n       ej[j][i] = 0; n       int cur = bfs(i, j); n       if (cur != -1) { n         ans = min(ans, cur + 1); n       } n       ej[i][j] = 1; n       ej[j][i] = 1; n     } n   } n   if (ans == inf) ans = -1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   long long arr[n + 5]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   sort(arr, arr + n); n   long long mn = arr[0]; n   long long mx = arr[n - 1]; n   long long cnt1 = 0, cnt2 = 0; n   for (int i = 0; i < n; i++) { n     if (arr[i] == mn) n       cnt1++; n     else if (arr[i] == mx) n       cnt2++; n   } n   cout << mx - mn <<    ; n   if (mn == mx) n     cout << n * 1LL * (n - 1) / 2; n   else n     cout << (long long)(cnt1 * cnt2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int vis[50005]; n long long int dp[50005][505]; n int k; n vector<int> v[50005]; n long long ans; n void dfs(int i) { n   vis[i] = 1; n   dp[i][0] = 1; n   for (auto j : v[i]) { n     if (!vis[j]) { n       vis[j] = 1; n       dfs(j); n       for (int w = 0; w <= k; w++) ans += dp[i][w] * dp[j][k - w - 1]; n       for (int w = 0; w <= k; w++) dp[i][w + 1] += dp[j][w]; n     } n   } n } n int main() { n   int n, a, b; n   cin >> n >> k; n   for (int i = 0; i < n - 1; i++) { n     cin >> a >> b; n     v[a].push_back(b); n     v[b].push_back(a); n   } n   dfs(1); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100100; n int n, a[N], b[N], p[N]; n int main() { n   if (fopen( 180F.in ,  r )) freopen( 180F.in ,  r , stdin); n   scanf( %d n , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , b + i); n   } n   for (int i = 1; i <= n; i++) { n     p[a[i]] = b[i]; n   } n   for (int i = 1; i <= n; i++) { n     printf( %d  , p[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   long long int n, i, k, ans = -1, x, l, sum; n   cin >> n; n   long long int a[n + 2]; n   a[0] = 0; n   long long int ca[n + 2]; n   ca[0] = 0; n   l = (n + 1) / 2; n   for (i = 1; i <= n; i++) { n     if (i <= l) { n       cin >> a[i]; n     } else { n       a[i] = x; n     } n     ca[i] = ca[i - 1] + a[i]; n     if (i == l) cin >> x; n   } n   long long int mn[n + 2]; n   mn[0] = 0; n   for (i = 1; i <= l; i++) { n     sum = i * x - ca[i]; n     mn[i] = min(mn[i - 1], sum); n   } n   for (i = l; i <= n; i++) { n     sum = ca[i]; n     k = n - i; n     sum += mn[k]; n     if (sum > 0) { n       ans = i; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int pkt; n   int start = 0; n   int lr = 0; n   cin >> pkt; n   if (pkt < 0) pkt = pkt / -1; n   for (int a = 1; start != pkt; a++) { n     start = start + a; n     lr++; n     if (start > pkt) { n       if ((start - pkt) % 2 == 1) n         ; n       else n         break; n     } n   } n   cout << lr << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double h = 1e-6; n const int MAX_ = 200005; n inline long long int mul(long long int a, long long int b) { n   return (a * 1ll * b) % 1000000007; n } n inline long long int sub(long long int a, long long int b) { n   long long int c = a - b; n   if (c < 0) c += 1000000007; n   return c; n } n inline long long int add(long long int a, long long int b) { n   long long int c = a + b; n   if (c > 1000000007) c -= 1000000007; n   return c; n } n long long int sqr(long long int x) { return x * x; } n long long int ncr[3050][3050]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   for (int i = 0; i < 3050; i++) { n     for (int j = 0; j <= i; j++) { n       if (i == 0 || j == 0) n         ncr[i][j] = 1; n       else n         ncr[i][j] = add(ncr[i - 1][j - 1], ncr[i - 1][j]); n     } n   } n   int k; n   cin >> k; n   long long int val; n   long long int ans = 1; n   int count = 0; n   for (long long int i = 0; i < k; i++) { n     cin >> val; n     ans = mul(ans, ncr[count + val - 1][val - 1]); n     ans %= 1000000007; n     count += val; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long n, m, dx, dy, qx, qy, ps[1 << 20]; n long t, ans[1 << 20]; n long a, b; n long bst, bp; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m >> dx >> dy; n   qx = qy = 0; n   for (int i = 0; i < n; i++) { n     ps[qx] = qy; n     qy += dy; n     qx += dx; n     qx %= n; n     qy %= n; n   } n   for (int i = 1; i <= m; i++) { n     cin >> a >> b; n     t = b - ps[a] + n; n     t %= n; n     ans[t]++; n   } n   bst = -1; n   for (int i = 0; i < n; i++) n     if (ans[i] > bst) bst = ans[i], bp = i; n   cout << 0 <<     << bp << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long p = 1000000007ll; n int main(void) { n   long long n; n   cin >> n; n   vector<pair<long long, long long> > loops; n   long long tmp = 0; n   for (long long i = (0); i < (n); ++i) { n     string com; n     cin >> com; n     if (com ==  for ) { n       long long x; n       cin >> x; n       loops.emplace_back(x, tmp); n       tmp = 0; n     } else if (com ==  end ) { n       tmp = tmp * loops.back().first + loops.back().second; n       if (tmp >= (1ll << 32)) { n         cout <<  OVERFLOW!!!  << endl; n         return 0; n       } n       loops.pop_back(); n     } else { n       ++tmp; n     } n   } n   if (tmp >= (1ll << 32)) { n     cout <<  OVERFLOW!!!  << endl; n     return 0; n   } n   cout << tmp << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long lar = 1e16; n const long long nlar = -1e16; n const long long INF = LLONG_MAX; n const long long NINF = LLONG_MIN; n const long long mod = 998244353; n const long long N = 1e6 + 100; n struct hash_pair { n   template <class T1, class T2> n   size_t operator()(const pair<T1, T2>& p) const { n     auto hash1 = hash<T1>{}(p.first); n     auto hash2 = hash<T2>{}(p.second); n     return hash1 ^ hash2; n   } n }; n void google(long long t) { cout <<  Case #  << t <<  :  ; } n long double sqrtBinarySearch(long long num, long long p) { n   long long left = 0, right = num; n   long long mid; n   long double res; n   while (left <= right) { n     mid = (left + right) / 2; n     if (mid * mid == num) { n       res = mid; n       break; n     } n     if (mid * mid < num) { n       left = mid + 1; n       res = mid; n     } else { n       right = mid - 1; n     } n   } n   long double incr = 0.1; n   for (long long i = 0; i < p; i++) { n     while (res * res <= num) { n       res += incr; n     } n     res -= incr; n     incr /= 10; n   } n   return res; n } n long long modInverse(long long a, long long m) { n   long long m0 = m; n   long long y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     long long q = a / m; n     long long t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long add(long long x, long long y) { n   x += y; n   while (x >= mod) x -= mod; n   while (x < 0) x += mod; n   return x; n } n long long mul(long long x, long long y) { return (x * 1ll * y) % mod; } n long long binpow(long long x, long long y) { n   long long ans = 1; n   while (y > 0) { n     if (y % 2 == 1) ans = mul(ans, x); n     x = mul(x, x); n     y /= 2; n   } n   return ans; n } n long long divmod(long long i, long long pp) { n   return ((i * (modInverse(pp, mod))) % mod); n } n long long divide(long long x, long long y) { n   return mul(x, binpow(y, mod - 2)); n } n string to_binary(long long num) { n   string res =   ; n   while (num) { n     res += ((num & (1LL)) +  0 ); n     num /= 2; n   } n   reverse(res.begin(), res.end()); n   return res; n } n long long to_decimal(string bi) { n   long long dec = 0; n   long long si = bi.size(); n   long long upd = 1; n   for (long long i = si - 1; i >= 0; i--) { n     dec += (upd * ((long long)(bi[i] -  0 ))); n     upd *= 2; n   } n   return dec; n } n vector<bool> SieveOfEratosthenes(long long n) { n   vector<bool> prime(n + 1, true); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   return prime; n } n long long digitsum(long long x) { n   long long ans = 0; n   while (x) { n     ans += x % 10; n     x /= 10; n   } n   return ans; n } n long long nCr(long long n, long long r) { n   if (n == r) n     return 1; n   else if (r == 0) n     return 1; n   else n     return ((nCr(n - 1, r - 1) + nCr(n - 1, r)) % mod); n } n long long sqroot(long long number) { n   long long x = sqrt(number); n   while (x * x < number) x++; n   while (x * x > number) x--; n   return x; n } n long long cbroot(long long number) { n   long long x = cbrt(number); n   while (x * x * x < number) x++; n   while (x * x * x > number) x--; n   return x; n } n long long gcd(long long a, long long b) { n   if (a == 0) return b; n   if (b == 0) return a; n   return gcd(b % a, a); n } n long long power(long long a, long long b) { n   if (b == 0) return 1; n   if (b & 1) return (a * power(a, b - 1)); n   long long temp = power(a, b / 2); n   return (temp * temp); n } n long long powermod(long long a, long long b) { n   if (b == 0) return 1; n   if (b & 1) return (a * powermod(a, b - 1)) % mod; n   long long temp = powermod(a, b / 2) % mod; n   return (temp * temp) % mod; n } n vector<long long> factor(long long x) { n   vector<long long> fact; n   for (long long i = 1; i * i <= x; i++) { n     if (x % i == 0) { n       fact.push_back(i); n       if (i * i != x) { n         fact.push_back(x / i); n       } n     } n   } n   return fact; n } n long long fact[N]; n void Initial_Factorial() { n   fact[0] = 1; n   for (long long i = 1; i < N; i++) { n     fact[i] = (fact[i - 1] * i); n     fact[i] %= mod; n   } n } n long long binpow(long long val, long long deg, long long mod) { n   if (!deg) return 1 % mod; n   if (deg & 1) return binpow(val, deg - 1, mod) * val % mod; n   long long res = binpow(val, deg >> 1, mod); n   return (res * res) % mod; n } n long long nCr_Binomial(long long n, long long i) { n   long long res = fact[n]; n   long long div = fact[n - i] * fact[i]; n   div %= mod; n   div = binpow(div, mod - 2, mod); n   return (res * div) % mod; n } n vector<long long> adj[10]; n long long number_of_nodes = 10; n vector<long long> visited(number_of_nodes, 0); n void dfs(long long node) { n   visited[node] = 1; n   for (long long i = 0; i < adj[node].size(); ++i) { n     if (visited[adj[node][i]] == 0) dfs(adj[node][i]); n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   Initial_Factorial(); n   long long n; n   cin >> n; n   if (n == 1) { n     cout << 1 <<   n ; n     return 0; n   } n   long long ans = n; n   ans *= fact[n]; n   ans %= mod; n   long long curr = 1; n   long long sum = 1; n   long long st = n - 1; n   while (st > 1) { n     curr *= st; n     curr %= mod; n     sum += curr; n     sum %= mod; n     st--; n   } n   sum *= n; n   sum %= mod; n   cout << (ans + mod - sum) % mod <<   n ; n   cerr <<   ntime taken :   << (long double)clock() / CLOCKS_PER_SEC <<  secs  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nmax = 5e5 + 42; n struct info { n   int u, v, cost; n }; n info inp[nmax]; n pair<int, int> my[nmax]; n int n, k, m; n int parent[nmax]; n int root(int node) { n   if (parent[node] == node) return node; n   parent[node] = root(parent[node]); n   return parent[node]; n } n long long outp; n set<int> seen[nmax]; n vector<int> adj[nmax]; n set<pair<int, int> > my_edge; n void solve(int node, int par) { n   int biggest = -1; n   for (auto k : adj[node]) n     if (k != par) { n       solve(k, node); n       if (biggest == -1) n         biggest = k; n       else if (seen[biggest].size() < seen[k].size()) n         biggest = k; n     } n   if (biggest != -1) { n     swap(seen[biggest], seen[node]); n     for (auto w : seen[biggest]) n       if (seen[node].count(w)) n         seen[node].erase(w); n       else n         seen[node].insert(w); n   } n   for (auto k : adj[node]) n     if (k != par && k != biggest) { n       for (auto w : seen[k]) n         if (seen[node].count(w)) n           seen[node].erase(w); n         else n           seen[node].insert(w); n     } n   if (my_edge.count({node, par}) || my_edge.count({par, node})) { n     if (seen[node].size() == 0) { n       printf( -1 n ); n       exit(0); n     } n     outp += inp[*seen[node].begin()].cost; n   } n } n int main() { n   scanf( %i%i%i , &n, &k, &m); n   for (int i = 1; i <= n; i++) parent[i] = i; n   for (int i = 1; i <= k; i++) { n     scanf( %i%i , &my[i].first, &my[i].second); n     adj[my[i].first].push_back(my[i].second); n     adj[my[i].second].push_back(my[i].first); n     parent[root(my[i].first)] = root(my[i].second); n     my_edge.insert({my[i].first, my[i].second}); n   } n   for (int i = 1; i <= m; i++) { n     scanf( %i%i%i , &inp[i].u, &inp[i].v, &inp[i].cost); n     if (root(inp[i].u) != root(inp[i].v)) { n       parent[root(inp[i].u)] = root(inp[i].v); n       adj[inp[i].u].push_back(inp[i].v); n       adj[inp[i].v].push_back(inp[i].u); n     } else { n       seen[inp[i].u].insert(i); n       seen[inp[i].v].insert(i); n     } n   } n   solve(1, 0); n   printf( %lld n , outp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ld = long double; n using ll = long long; n using ull = unsigned long long; n const ll mod = 1004535809, mod_g = 3; n const int N = int(1e5 + 10); n template <typename T> n inline T read() { n   T x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n template <typename T> n inline T print(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) print(x / 10); n   putchar(x % 10 +  0 ); n } n const ld pi = acos(-1.0); n struct Complex { n   ld r, i; n   Complex(ld _r = 0, ld _i = 0) : r(_r), i(_i) {} n   Complex operator+(const Complex &b) const { n     return Complex(r + b.r, i + b.i); n   } n   Complex operator-(const Complex &b) const { n     return Complex(r - b.r, i - b.i); n   } n   Complex operator*(const Complex &b) const { n     return Complex(r * b.r - i * b.i, r * b.i + i * b.r); n   } n   Complex operator/(const Complex &b) const { n     return Complex((r * b.r + i * b.i) / (b.r * b.r + b.i * b.i), n                    (i * b.r - r * b.i) / (b.r * b.r + b.i * b.i)); n   } n }; n int R[int(1e6 + 10000)]; n Complex x[int(1e6 + 10000)], y[int(1e6 + 10000)]; n void get_R(int lim) { n   for (int i = 0; i < lim; i++) { n     R[i] = (i & 1) * (lim >> 1) + (R[i >> 1] >> 1); n   } n } n void FFT(Complex *f, int lim, int rev) { n   for (int i = 0; i < lim; i++) { n     if (i < R[i]) swap(f[i], f[R[i]]); n   } n   for (int mid = 1; mid < lim; mid <<= 1) { n     Complex wn = Complex(cos(pi / mid), rev * sin(pi / mid)); n     for (int len = mid << 1, cur = 0; cur < lim; cur += len) { n       Complex w = Complex(1, 0); n       for (int k = 0; k < mid; k++, w = w * wn) { n         Complex x = f[cur + k], y = w * f[cur + mid + k]; n         f[cur + k] = x + y, f[cur + mid + k] = x - y; n       } n     } n   } n   if (rev == -1) { n     for (int i = 0; i < lim; i++) { n       f[i].r /= lim; n     } n   } n } n ll quick_pow(ll ans, ll p, ll res = 1) { n   for (; p; p >>= 1, ans = ans * ans % mod) n     if (p & 1) res = res * ans % mod; n   return res % mod; n } n ll ans[200010]; n inline void solve() { n   int n, X; n   cin >> n >> X; n   for (int i = 1; i <= n; ++i) { n     int xx; n     cin >> xx; n     ans[i] = ans[i - 1] + (xx < X); n     x[ans[i]].r++; n     y[200000 - ans[i]].r++; n     x[i].i = y[i].i = 0; n   } n   x[0].r++, y[200000].r++; n   int lim = 1; n   while (lim <= 400000) lim <<= 1; n   get_R(lim); n   FFT(x, lim, 1); n   FFT(y, lim, 1); n   for (int i = 0; i <= lim - 1; ++i) x[i] = x[i] * y[i]; n   FFT(x, lim, -1); n   cout << (ll(x[200000].r + 0.5) - n - 1) / 2; n   for (int i = 1; i <= n; ++i) cout <<     << ll(x[200000 + i].r + 0.5); n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = (long long int)1e9 + 7; n long long int powmod(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % MOD; n     a = (a * a) % MOD; n     b = b >> 1; n   } n   return res % MOD; n } n void solve(long long int testnum) { n   long long int n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   string t; n   cin >> t; n   long long int ans = 0; n   long long int tmpmn = 0; n   long long int tmpmx = 0; n   long long int check = 0; n   for (long long int i = 0; i < n; i++) { n     if (s[i] ==  b ) { n       tmpmn++; n     } n     if (t[i] ==  b ) { n       tmpmx++; n     } n     long long int ort = tmpmx - tmpmn + 1; n     if (ort >= k) { n       check = 1; n     } n     if (check == 0) { n       ans += min(k, ort); n     } else { n       ans += k; n     } n     if (tmpmn == tmpmx) { n       tmpmn = 0; n       tmpmx = 0; n     } n     if (check == 0) { n       tmpmn *= 2; n       tmpmx *= 2; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   for (long long int i = 1; i <= t; i++) { n     solve(i); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10000; n const int MAXK = 20; n int V[MAXK + 3][MAXN + 3], Ans[MAXK + 3][MAXN + 3]; n int main() { n   V[0][1] = 0; n   for (int j = 2; j <= MAXN; j++) { n     V[0][j] = 1; n   } n   for (int i = 1; i <= MAXK; i++) { n     int k = 1; n     for (int j = 1; j <= MAXN; j++) { n       if (k < MAXN && V[i - 1][k] < V[i - 1][k + 1] && n           V[i - 1][j] + V[i - 1][k] < j - 1) n         k++; n       V[i][j] = V[i - 1][j] + V[i - 1][k]; n       Ans[i][j] = k; n     } n   } n   int N, K; n   while (~scanf( %d%d , &N, &K)) { n     for (int i = 1; i <= K; i++) { n       for (int j = N; j > 1; j--) printf( %d  , N - Ans[i][j] + 1); n       printf( %d n , N - Ans[i][1] + 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n void solve() { n   int n; n   cin >> n; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (auto i : a) { n     cout << i <<    ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   { solve(); } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int maxN = 1e5 + 10; n long long int n, i, a[maxN], mx, cnt, nxt; n stack<pair<long long int, long long int> > st; n int main() { n   cin >> n; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   for (long long int i = n - 1; i >= 0; i--) { n     while (!st.empty()) { n       if (a[i] < st.top().first) break; n       cnt++; n       cnt = max(cnt, st.top().second); n       st.pop(); n     } n     mx = max(mx, cnt); n     st.push(make_pair(a[i], cnt)); n     cnt = 0; n   } n   cout << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a, b, c, d, x, y, p, q, t, ans[400009], res, mi, T, lca[22][400009], n     sub[400009]; n vector<int> v[400009]; n int ma[2]; n void dfs(int id, int par) { n   lca[1][id] = par; n   lca[0][id] = id; n   for (int i = 0; i < v[id].size(); i++) { n     int u = v[id][i]; n     if (u == par) continue; n     dfs(u, id); n     sub[id] += sub[u]; n   } n   sub[id]++; n } n int centroid(int id, int par) { n   int f = 0, s = 0; n   for (int i = 0; i < v[id].size(); i++) { n     int u = v[id][i]; n     if (u == par) continue; n     if (sub[u] > T) n       return centroid(u, id); n     else n       s += sub[u]; n   } n   if (f == 0 && n - 1 - s <= T) return id; n } n int lim; n void init_lca() { n   lim = log(n) / log(2) + 1; n   for (int i = 2; i <= lim; i++) { n     for (int j = 1; j <= n; j++) { n       lca[i][j] = lca[1][lca[i - 1][lca[i - 1][j]]]; n     } n   } n } n void calc(int id, int par, int branch = 0) { n   for (int i = 0; i < v[id].size(); i++) { n     int u = v[id][i]; n     if (u == par) continue; n     int branch2 = (branch == 0 ? u : branch); n     if (branch2 != ma[0]) { n       if (n - sub[ma[0]] - sub[u] <= T) ans[u] = 1; n     } else { n       if (n - sub[ma[1]] - sub[u] <= T) ans[u] = 1; n     } n     if (n - sub[branch2] <= T) ans[u] = 1; n     calc(u, id, branch2); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   if (n <= 4) { n     for (int i = 1; i <= n; i++) cout << 1 <<    ; n     return 0; n   } n   dfs(1, 0); n   T = n / 2; n   c = centroid(1, 0); n   memset(sub, 0, sizeof(sub)); n   dfs(c, 0); n   ans[c] = 1; n   for (int i = 0; i < v[c].size(); i++) { n     int u = v[c][i]; n     if (sub[u] >= sub[ma[0]]) { n       ma[1] = ma[0]; n       ma[0] = u; n     } else if (sub[u] > sub[ma[1]]) n       ma[1] = u; n   } n   calc(c, 0); n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n template <class T1, class T2> n inline bool cmin(T1 &a, const T2 &b) { n   return b < a ? (a = b, true) : false; n } n template <class T1, class T2> n inline bool cmax(T1 &a, const T2 &b) { n   return a < b ? (a = b, true) : false; n } n template <class Type> n Type read() { n   Type a; n   bool b; n   unsigned char c; n   while (c = getchar() - 48, (c > 9) & (c != 253)) n     ; n   for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c) n     ; n   return b ? -a : a; n } n int (*rd)() = read<int>; n const int N = 2e5; n std::vector<int> b[N], g[N]; n int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } n std::pair<int, int> exgcd(int x, int y) { n   if (y == 0) return {1, 0}; n   int a, b; n   std::tie(b, a) = exgcd(y, x % y); n   return {a, b - x / y * a}; n } n void gg() { n   puts( -1 ); n   exit(0); n } n long long solve(int n, int m, const std::vector<int> &b, n                 const std::vector<int> &g) { n   long long ans = -1; n   std::vector<std::pair<int, int>> pos; n   int inv = exgcd(n, m).second % n; n   if (inv < 0) inv += n; n   for (int i : b) pos.emplace_back((long long)i * inv % n, 0); n   for (int i : g) pos.emplace_back((long long)i * inv % n, 1); n   std::sort(pos.begin(), pos.end()); n   pos.resize(std::unique(pos.begin(), pos.end(), n                          [](std::pair<int, int> p, std::pair<int, int> q) { n                            return p.first == q.first; n                          }) - n              pos.begin()); n   int i = pos.back().first; n   for (auto p : pos) { n     if ((p.first - 1 + n) % n != i) n       cmax(ans, n            (long long)(p.first - i - 1 + n) % n * m + (long long)i * m % n); n     if (p.second) cmax(ans, (long long)i * m % n); n     i = p.first; n   } n   return ans; n } n int main() { n   int n, m, d; n   long long ans = 0; n   std::vector<int> glob, glog; n   n = rd(), m = rd(), d = gcd(n, m); n   glob.resize(rd()); n   for (int &i : glob) i = rd(); n   glog.resize(rd()); n   for (int &i : glog) i = rd(); n   if (glob.size() + glog.size() < d) gg(); n   for (int i : glob) b[i % d].push_back(i / d); n   for (int i : glog) g[i % d].push_back(i / d); n   n /= d, m /= d; n   for (int i = 0; i < d; ++i) { n     if (b[i].empty() && g[i].empty()) gg(); n     cmax(ans, n          std::max(solve(n, m, b[i], g[i]), solve(m, n, g[i], b[i])) * d + i); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n pair<pair<int, int>, int> arr[2050]; n int vis[2050]; n char s[2050]; n double angle(pair<int, int> x, pair<int, int> y, pair<int, int> z) { n   pair<int, int> xy = {y.first - x.first, y.second - x.second}; n   pair<int, int> xz = {y.first - z.first, y.second - z.second}; n   double angyx = 1.0 * xy.first * xz.first + 1.0 * xy.second * xz.second; n   double angyz = 1.0 * xy.first * xz.second - 1.0 * xy.second * xz.first; n   return atan2(angyz, angyx); n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     arr[i] = {{x, y}, i + 1}; n   } n   scanf( %s , s); n   sort(arr, arr + N, n        [](const pair<pair<int, int>, int> &a, n           const pair<pair<int, int>, int> &b) { n          if (a.first.second == b.first.second) n            return a.first.first < b.first.first; n          return a.first.second < b.first.second; n        }); n   pair<int, int> tmp1 = {arr[0].first.first - 1, arr[0].first.second}; n   pair<int, int> tmp2 = arr[0].first; n   vis[0] = 1; n   pair<int, int> a = {-1, -1}; n   pair<int, int> b = {1, -1}; n   pair<int, int> c = {2, -1}; n   printf( %d  , arr[0].second); n   for (int i = 0; i < N - 2; i++) { n     double max = -1234567.0, min = 1234567.0; n     int maxi, mini; n     for (int j = 0; j < N; j++) { n       if (vis[j] == 1) continue; n       double ang = angle(tmp1, tmp2, arr[j].first); n       if (i == 0) { n       } n       if (i == 0 && arr[j].first.second == arr[0].first.second && n           arr[j].first.first > arr[0].first.first) { n         min = -1234, mini = j; n         continue; n       } n       if (i == 0 && arr[j].first.second == arr[0].first.second && n           arr[j].first.first < arr[0].first.first) { n         max = 1234, maxi = j; n         continue; n       } n       if (ang > max) max = ang, maxi = j; n       if (ang < min) min = ang, mini = j; n     } n     if (s[i] ==  R ) { n       tmp1 = tmp2; n       tmp2 = arr[maxi].first; n       vis[maxi] = 1; n       printf( %d  , arr[maxi].second); n     } else { n       tmp1 = tmp2; n       tmp2 = arr[mini].first; n       vis[mini] = 1; n       printf( %d  , arr[mini].second); n     } n   } n   for (int i = 0; i < N; i++) { n     if (vis[i] == 0) { n       printf( %d n , arr[i].second); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   os <<  {  << p.first <<  ,  << p.second <<  } ; n   return os; n } n const int N = 3e5 + 5; n const int oo = 1e9 + 7; n vector<pair<int, pair<int, int> > > g[N]; n int f[N]; n int ans[N]; n int x[N]; n int y[N]; n bool vis[N]; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int w; n     cin >> x[i] >> y[i] >> w; n     g[x[i]].push_back({i, {y[i], w}}); n     g[y[i]].push_back({i, {x[i], w}}); n   } n   for (int i = 2; i <= n - 1; i++) { n     for (auto p : g[i]) { n       f[i] += p.second.second; n     } n     assert(f[i] % 2 == 0); n     f[i] /= 2; n   } n   queue<int> q; n   q.push(1); n   vis[1] = 1; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (auto p : g[u]) { n       int i = p.first; n       int v = p.second.first; n       int w = p.second.second; n       if (vis[v]) continue; n       if (x[i] == u) n         ans[i] = 0; n       else n         ans[i] = 1; n       if (v == n) continue; n       f[v] -= w; n       if (f[v] == 0) { n         vis[v] = 1; n         q.push(v); n       } n     } n   } n   for (int i = 1; i <= m; i++) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string queue_[6] = {  ,  Sheldon ,  Leonard ,  Penny ,  Rajesh ,  Howard }; n int main() { n   cin >> n; n   double count = 1; n   bool used = false; n   while (count * 5 < n) { n     n -= count * 5; n     count *= 2; n     used = true; n   } n   int x = ceil(n / count); n   cout << queue_[x]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n const int logn = 19; n vector<int> adj[maxn]; n int idcnt, l[maxn], r[maxn], dep[maxn], anc[maxn][logn]; n void dfs1(int u, int up) { n   l[u] = ++idcnt; n   dep[u] = dep[up] + 1; n   anc[u][0] = up; n   for (int i = 1; i < logn; i++) { n     if (dep[u] <= (1 << i)) break; n     anc[u][i] = anc[anc[u][i - 1]][i - 1]; n   } n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (v == up) continue; n     dfs1(v, u); n   } n   r[u] = idcnt; n } n int qlca(int u, int v) { n   if (dep[u] > dep[v]) swap(u, v); n   for (int i = logn - 1; i >= 0; i--) n     if (dep[v] > (1 << i) && dep[anc[v][i]] >= dep[u]) v = anc[v][i]; n   if (u == v) return u; n   for (int i = logn - 1; i >= 0; i--) n     if (dep[u] > (1 << i) && anc[u][i] != anc[v][i]) { n       u = anc[u][i]; n       v = anc[v][i]; n     } n   return anc[u][0]; n } n vector<int> bus[maxn]; n int nex[maxn][logn]; n void dfs2(int u, int up) { n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (v == up) continue; n     dfs2(v, u); n     if (dep[nex[v][0]] < dep[nex[u][0]]) nex[u][0] = nex[v][0]; n   } n } n int n, st[maxn]; n int lowbit(int x) { return x & (-x); } n void add(int i, int x) { n   for (; i <= n; i += lowbit(i)) st[i] += x; n } n int qsum(int i) { n   int res = 0; n   for (; i > 0; i -= lowbit(i)) res += st[i]; n   return res; n } n struct node { n   int id, v; n   node(int id = 0, int v = 0) : id(id), v(v) {} n }; n vector<node> ql[maxn]; n int ans[maxn], cmp[maxn]; n void dfs3(int u, int up) { n   for (int i = 0; i < ql[u].size(); i++) { n     node cur = ql[u][i]; n     int id = cur.id, v = cur.v; n     cmp[id] = qsum(r[v]) - qsum(l[v] - 1); n   } n   for (int i = 0; i < bus[u].size(); i++) { n     int v = bus[u][i]; n     add(l[v], 1); n   } n   for (int i = 0; i < adj[u].size(); i++) { n     int v = adj[u][i]; n     if (v == up) continue; n     dfs3(v, u); n   } n   for (int i = 0; i < ql[u].size(); i++) { n     node cur = ql[u][i]; n     int id = cur.id, v = cur.v; n     if (qsum(r[v]) - qsum(l[v] - 1) != cmp[id]) ans[id]--; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     int v; n     scanf( %d , &v); n     adj[i].push_back(v); n     adj[v].push_back(i); n   } n   dfs1(1, 1); n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= n; i++) nex[i][0] = i; n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     bus[a].push_back(b); n     bus[b].push_back(a); n     int lca = qlca(a, b); n     if (dep[lca] < dep[nex[a][0]]) nex[a][0] = lca; n     if (dep[lca] < dep[nex[b][0]]) nex[b][0] = lca; n   } n   dfs2(1, 1); n   for (int i = 1; i < logn; i++) n     for (int j = 1; j <= n; j++) nex[j][i] = nex[nex[j][i - 1]][i - 1]; n   int q; n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     if (u > v) swap(u, v); n     int lca = qlca(u, v); n     for (int j = logn - 1; j >= 0; j--) n       if (dep[nex[v][j]] > dep[lca]) { n         v = nex[v][j]; n         ans[i] += (1 << j); n       } n     if (u == lca) { n       if (dep[nex[v][0]] > dep[lca]) { n         ans[i] = -1; n         continue; n       } n       if (dep[v] > dep[lca]) ans[i]++; n     } else { n       for (int j = logn - 1; j >= 0; j--) n         if (dep[nex[u][j]] > dep[lca]) { n           u = nex[u][j]; n           ans[i] += (1 << j); n         } n       if (dep[nex[u][0]] > dep[lca] || dep[nex[v][0]] > dep[lca]) { n         ans[i] = -1; n         continue; n       } n       ans[i] += 2; n       if (u > v) swap(u, v); n       ql[u].push_back(node(i, v)); n     } n   } n   dfs3(1, 1); n   for (int i = 1; i <= q; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long k, res, a[1111], n; n set<long long> s; n int main() { n   cin >> n >> k; n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) s.insert(i), s.insert(n / i); n   } n   for (long long i : s) { n     res++; n     if (res == k) { n       cout << i; n       return 0; n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const long long xx = 2e7; n const long long MOD = 1e9 + 7; n const long long inf = 1e18; n long long isprime(long long n) { n   if (n == 2) return 1; n   if (n % 2 == 0) return 0; n   for (long long i = 3; i * i <= n; i += 2) { n     if (n % i == 0) return 0; n   } n   return 1; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n; n   cin >> n; n   if (isprime(n)) { n     cout << 1 <<   n ; n   } else if (n % 2 == 0 || isprime(n - 2)) { n     cout << 2 <<   n ; n   } else n     cout << 3 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long N = 0, M, K; n long long MOD = 998244353; n string S, S1; n struct st { n   long long x, i; n }; n bool operator<(const st& a, const st& b) { n   if (a.x == b.x) return a.i < b.i; n   return a.x < b.x; n } n long long gcd(long long a, long long b) { n   while (b > 0) { n     a %= b; n     swap(a, b); n   } n   return a; n } n long long fact(long long x) { n   long long x1 = 1; n   while (x >= 1) { n     x1 *= x; n     x--; n   } n   return x1; n } n void prime(long long n, vector<long long>& pr) { n   vector<long long> lp(n + 90); n   for (long long i = 2; i <= n; ++i) { n     if (!lp[i]) { n       pr.push_back(i); n       lp[i] = i; n     } n     for (long long j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] <= n; n          ++j) { n       lp[i * pr[j]] = pr[j]; n     } n   } n } n void dfs(long long x, vector<long long>& b, vector<long long>& w, n          vector<vector<long long>>& v) { n   w[x] = 1; n   b.push_back(x); n   for (long long i : v[x]) { n     if (!w[i]) dfs(i, b, w, v); n   } n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s, s1; n   long long n, k = 0, m; n   long long x = 0, y = 0, ans = 0; n   cin >> s >> n; n   vector<long long> a; n   for (long long i = 0; i < n; i++) { n     s1 =   ; n     cin >> x >> y >> k; n     m = y - x + 1; n     k = k % m; n     for (long long j = y - k; j <= y - 1; j++) s1 += s[j]; n     s.erase(y - k, k); n     s.insert(x - 1, s1); n   } n   cout << s <<   n ; n   cin >> N; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9 + 7; n long long fastpo(long long a, long long x) { n   if (x == 0) return 1ll; n   if (x == 1) return a; n   long long y = fastpo(a, x / 2); n   if (x % 2 == 0) { n     return y * y; n   } n   return y * y * a; n } n long long inv(long long a, long long M) { return fastpo(a, M - 2); } n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long modInverse(long long a, long long m) { n   long long x, y; n   long long g = gcdExtended(a, m, &x, &y); n   if (g != 1) n     return -1; n   else { n     long long res = (x % m + m) % m; n     return res; n   } n } n long long gcd(long long a, long long b) { n   if (a == 0) { n     return b; n   } n   return gcd(b % a, a); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long N = 2e6 + 5; n vector<long long> dp(N, 0), ci(N, 0), ai(N, 0), bi(N, 0), ans(N, 0); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 1; i < N; i++) { n     if (i == 1) { n       dp[i] = 1; n       ci[i] = 0; n       ai[i] = 0; n       bi[i] = 1; n       ans[i] = 0; n     } else if (i == 2) { n       dp[i] = 2; n       ci[i] = 0; n       ai[i] = 1; n       bi[i] = 1; n       ans[i] = 0; n     } else { n       ci[i - 1] = dp[i - 3]; n       ai[i - 1] = dp[i - 2] - dp[i - 3]; n       bi[i - 1] = dp[i - 1] - dp[i - 2]; n       dp[i] = ((ci[i - 1] + ai[i - 1] * 3 + bi[i - 1] * 2) % M + M) % M; n       ans[i] = (ans[i - 3] + bi[i - 2]) % M; n     } n   } n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long res = ((ans[n] * 4) % M + M) % M; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void test() { n   int t; n   cin >> t; n   while (t--) { n     int i = 0; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int i = 0; n   int n; n   cin >> n; n   map<int, int> m; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     m[x]++; n   } n   int g = 0; n   for (auto i : m) { n     if (i.first != 0) g++; n   } n   cout << g; n   return 0; n } n


#include <bits/stdc++.h> n #define rep(i, a, b) for (int i = a; i <= b; i++) n #define per(i, a, b) for (int i = a; i >= b; i--) n using namespace std; n  n typedef unsigned long long ull; n typedef pair <int, int> pii; n typedef long long ll; n  n template <typename T> n inline void read(T &f) { n     f = 0; T fu = 1; char c = getchar(); n     while (c <  0  || c >  9 ) { if (c ==  - ) { fu = -1; } c = getchar(); } n     while (c >=  0  && c <=  9 ) { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } n     f *= fu; n } n  n template <typename T> n void print(T x) { n     if (x < 0) putchar( - ), x = -x; n     if (x < 10) putchar(x + 48); n     else print(x / 10), putchar(x % 10 + 48); n } n  n template <typename T> n void print(T x, char t) { n     print(x); putchar(t); n } n  n const int N = 3e5 + 5; n  n struct seg_t { n     int mx[N << 2]; n  n     void build(int u, int l, int r) { n         mx[u] = 0; n         if (l == r) return; n         int mid = (l + r) >> 1; n         build(u << 1, l, mid); n         build(u << 1 | 1, mid + 1, r); n     } n  n     void modify(int u, int l, int r, int x, int y) { n         mx[u] = max(mx[u], y); n         if (l == r) return; n         int mid = (l + r) >> 1; n         if (mid >= x) modify(u << 1, l, mid, x, y); n         else modify(u << 1 | 1, mid + 1, r, x, y); n     } n  n     int query(int u, int L, int R, int l, int r) { n         if (l <= L && R <= r) return mx[u]; n         int mid = (L + R) >> 1, ans = 0; n         if (mid >= l) ans = max(ans, query(u << 1, L, mid, l, r)); n         if (mid + 1 <= r) ans = max(ans, query(u << 1 | 1, mid + 1, R, l, r)); n         return ans; n     } n } tr, rmq; n  n set <int> pos; n set <int> :: iterator it; n int a[N], cando[N], lpos[N], pre[N], ans[N]; n int T, n; n  n int main() { n     read(T); n     while (T--) { n         read(n); n         rmq.build(1, 1, n); n         for (int i = 1; i <= n; i++) read(a[i]), rmq.modify(1, 1, n, i, min(n, i + a[i])); n         tr.build(1, 1, n); n         for (int i = n; i >= 1; i--) { n             int r = min(i + a[i], n); n             if (i + 1 <= r) tr.modify(1, 1, n, i, tr.query(1, 1, n, i + 1, r)); n             else tr.modify(1, 1, n, i, i); n         } n         for (int i = 1; i <= n + 1; i++) cando[i] = 0; n         cando[1] = 1; n         pos.clear(); n         for (int i = 2; i <= n; i++) { n             if (cando[i - 1]) pos.insert(i - 1); n             it = pos.lower_bound(i - a[i]); n             if (it != pos.end()) { n                 pre[i] = lpos[*it]; n                 int r = i - 1; n                 if (lpos[*it] != *it) r = rmq.query(1, 1, n, *it, i - 1); n                 else if (*it + 1 <= i - 1) r = rmq.query(1, 1, n, *it + 1, i - 1); n                 if (r >= i + 1) r = tr.query(1, 1, n, i + 1, r); n                 if (!cando[r + 1]) { n                     cando[r + 1] = 1; n                     lpos[r + 1] = i; n                 } n                 if (r == n) break; n             } n         } n         if (cando[n + 1]) { n             printf( YES n ); n             for (int i = 1; i <= n; i++) ans[i] = 0; n             int now = lpos[n + 1]; n             while (now) { n                 ans[now] = 1; n                 now = pre[now]; n             } n             for (int i = 1; i <= n; i++) { n                 if (ans[i]) putchar( L ); n                 else putchar( R ); n             } n             putchar(  n ); n         } else { n             printf( NO n ); n         } n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long int M, tp, xx, lll, cc, ndl = 0, N, dl, nf, nef, T; n struct bl { n   long long int type; n   long long int l, c, x; n }; n bl t; n vector<bl> B; n vector<long long int> C; n map<long long int, long long int> MP; n ifstream in( input.txt ); n long long int find_bl(long long int n) { n   if (MP.count(n) == 0) { n     long long int num = (lower_bound(C.begin(), C.end(), n) - C.begin()); n     t = B[num]; n     if (t.type == 1) { n       T = t.x; n       MP[n] = T; n       return T; n     } else { n       nf = n - C[num - 1]; n       nef = (nf % t.l == 0) ? t.l : (nf % t.l); n       T = find_bl(nef); n       MP[n] = T; n       return T; n     } n   } else n     return MP[n]; n } n int main() { n   cin >> M; n   for (int i = 1; i <= M; i++) { n     cin >> tp; n     t.type = tp; n     if (tp == 1) { n       cin >> xx; n       t.x = xx; n       B.push_back(t); n       C.push_back(ndl + 1); n       ndl++; n     } else { n       cin >> lll >> cc; n       t.l = lll; n       t.c = cc; n       B.push_back(t); n       C.push_back(ndl + (lll * cc)); n       ndl += lll * cc; n     } n   } n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> xx; n     cout << find_bl(xx) <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 102, T = 1000 * 1000 * 1000 + 7; n int a[2600][M]; n bool mrk[2600][M]; n string s; n int ff(long long sum, int n) { n   if (sum < 0) return 0; n   if (mrk[sum][n]) return a[sum][n]; n   if (sum > 25 && n == 1) return 0; n   if (sum <= 25 && n == 1) return 1; n   long long temp = 0; n   for (int i = 0; i < 26; i++) temp += ff(sum - i, n - 1), temp %= T; n   a[sum][n] = temp; n   mrk[sum][n] = true; n   return temp; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     long long sum = 0; n     for (int i = 0; i < s.length(); i++) sum += s[i] -  a ; n     cout << (ff(sum, s.length()) + T - 1) % T << endl; n   } n   return 0; n   ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxv = 10001; n map<string, int> tidx; n map<int, int> fp[maxv]; n struct Edge { n   int to, next; n } edge[maxv * 2]; n int m, idx, head[maxv], ednum, deg[maxv]; n char tmp[22]; n bool mp[maxv][maxv]; n void addedge(int u, int v) { n   edge[ednum] = Edge{v, head[u]}; n   head[u] = ednum++; n   edge[ednum] = Edge{u, head[v]}; n   head[v] = ednum++; n } n void cal(int u) { n   int i, j, vi, vj; n   deg[u] = 1; n   for (i = head[u]; i != -1; i = edge[i].next) { n     deg[u]++; n     for (j = edge[i].next; j != -1; j = edge[j].next) { n       vi = edge[i].to; n       vj = edge[j].to; n       if (!mp[vi][vj] && !mp[vj][vi]) fp[vi][vj] += 1, fp[vj][vi] += 1; n     } n   } n } n int main() { n   int a, b, i, maxv, num; n   string u, v; n   memset(head, -1, sizeof(head)); n   map<string, int>::iterator it; n   map<int, int>::iterator jt; n   idx = ednum = 0; n   scanf( %d , &m); n   for (i = 0; i < m; i++) { n     scanf( %s , tmp); n     u = tmp; n     scanf( %s , tmp); n     v = tmp; n     if (tidx.find(u) == tidx.end()) n       tidx[u] = a = idx++; n     else n       a = tidx[u]; n     if (tidx.find(v) == tidx.end()) n       tidx[v] = b = idx++; n     else n       b = tidx[v]; n     mp[a][b] = mp[b][a] = true; n     addedge(a, b); n   } n   printf( %d n , idx); n   for (i = 0; i < idx; i++) cal(i); n   for (it = tidx.begin(); it != tidx.end(); it++) { n     i = it->second; n     maxv = 0, num = idx - fp[i].size() - deg[i]; n     for (jt = fp[i].begin(); jt != fp[i].end(); jt++) { n       if (jt->second > maxv) { n         maxv = jt->second; n         num = 1; n       } else if (jt->second == maxv) n         num++; n     } n     printf( %s %d n , it->first.c_str(), num); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e, f, k, m; n   int n[101][2]; n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> a >> b >> c >> d >> k; n     if (a % c == 0) n       e = a / c; n     else n       e = a / c + 1; n     if (b % d == 0) n       f = b / d; n     else n       f = b / d + 1; n     if ((e + f) <= k) { n       n[i][0] = e; n       n[i][1] = f; n     } else { n       n[i][0] = -1; n     } n   } n   for (int i = 0; i < m; i++) { n     if (n[i][0] != -1) n       cout << n[i][0] <<     << n[i][1] << endl; n     else n       cout <<  -1  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, y; n string s; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   cin >> n >> x >> y >> s; n   long long zeros = 0; n   int last = -1; n   for (auto c : s) { n     int b = (c -  0 ); n     if (b != last && !b) zeros++; n     last = b; n   } n   if (zeros == 0) { n     cout << 0 << endl; n     return 0; n   } n   long long ans1 = x * (zeros - 1) + y; n   long long ans2 = y * (zeros - 1) + y; n   cout << min(ans1, ans2) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sq(T x) { n   return x * x; n } n const long long inf = 2147383647; n const double pi = 2 * acos(0.0); n const double eps = 1e-9; n const long long maxint = 2147483647; n const long long minint = -2147483648; n int n, m; n long long arr[100010], brr[100010]; n long long dp1[100010], dp2[100010]; n void input() { n   int i; n   for (i = 0; i < n; i++) { n     scanf( %I64d , &arr[i]); n   } n   for (i = 0; i < m; i++) { n     scanf( %I64d , &brr[i]); n   } n   sort(arr, arr + n); n   sort(brr, brr + m); n } n void dpcalc() { n   dp1[0] = 0; n   int i; n   for (i = 1; i < n; i++) { n     dp1[i] = dp1[i - 1]; n     dp1[i] += i * (arr[i] - arr[i - 1]); n   } n   dp2[m - 1] = 0; n   for (i = m - 2; i >= 0; i--) { n     dp2[i] = dp2[i + 1]; n     int e = m - i - 1; n     dp2[i] += e * (brr[i + 1] - brr[i]); n   } n } n long long findCost(long long x) { n   long long res = 0; n   long long pos = upper_bound(arr, arr + n, x) - arr; n   if (pos > 0) { n     pos--; n     res += dp1[pos]; n     res += (pos + 1) * (x - arr[pos]); n   } n   pos = lower_bound(brr, brr + m, x) - brr; n   if (pos < m) { n     res += dp2[pos]; n     res += (m - pos) * (brr[pos] - x); n   } n   return res; n } n int main() { n   scanf( %d %d , &n, &m); n   int i, j; n   input(); n   dpcalc(); n   long long low = 1, high = 1000000000; n   long long res = -1; n   while (high - low > 5) { n     long long m1 = (2 * low + high) / 3; n     long long m2 = (low + 2 * high) / 3; n     long long u = findCost(m1); n     long long v = findCost(m2); n     if (res == -1) res = u; n     res = min(res, u); n     res = min(res, v); n     if (u > v) { n       low = m1 + 1; n     } else { n       high = m2 - 1; n     } n   } n   while (low <= high) { n     res = min(res, findCost(low)); n     low++; n   } n   printf( %I64d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5000 + 100; n const int M = 30; n int n; n string s; n string t; n int mat[M][M][N]; n int ones[N]; n int ans; n long double javab; n set<char> g; n bool mark[30]; n int chand[30]; n bool oomade[30]; n int main() { n   cin >> s; n   n = s.size(); n   for (int i = 0; i < n; i++) { n     g.insert(s[i]); n     chand[s[i] -  a ]++; n     oomade[s[i] -  a ] = 1; n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n + i; j++) { n       int y = j % n; n       int f = (int)s[i] - (int) a ; n       int l = (int)s[y] - (int) a ; n       mat[f][l][j - i]++; n     } n   } n   for (int i = 0; i < 26; i++) { n     if (oomade[i] == 1) { n       for (int j = 0; j < n; j++) { n         int tmp = 0; n         for (int k = 0; k < 26; k++) { n           if (mat[i][k][j] == 1) { n             tmp++; n           } n         } n         ones[i] = max(ones[i], tmp); n       } n       ans += ones[i]; n     } n   } n   javab = (long double)ans / (n); n   cout << fixed << setprecision(10) << javab; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int months[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n   int n, m; n   cin >> n >> m; n   vector<int> ans; n   string s; n   int idx = 0; n   while (getline(cin, s)) { n     int month = (s[5] -  0 ) * 10 + (s[6] -  0 ); n     int day = (s[8] -  0 ) * 10 + (s[9] -  0 ); n     int hour = (s[11] -  0 ) * 10 + (s[12] -  0 ); n     int mnt = (s[14] -  0 ) * 10 + (s[15] -  0 ); n     int sec = (s[17] -  0 ) * 10 + (s[18] -  0 ); n     int totalSec = sec + mnt * 60 + hour * 3600 + day * 24 * 3600; n     for (int i = 0; i < month - 1; i++) { n       totalSec += months[i] * 24 * 3600; n     } n     while (idx < ans.size() and ans[idx] + n <= totalSec) { n       idx++; n     } n     ans.push_back(totalSec); n     if (ans.size() - idx >= m) { n       for (int i = 0; i < 19; i++) { n         printf( %c , s[i]); n       } n       puts(  ); n       return 0; n     } n   } n   puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fir[5000]; n int sec[5000]; n int init(int x, int y) { n   printf( ? %d %d n , x, y); n   fflush(stdout); n   scanf( %d , &x); n   return x; n } n void print(int sch, const vector<int> &ans) { n   printf( ! n ); n   fflush(stdout); n   printf( %d n , sch); n   fflush(stdout); n   for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]); n   fflush(stdout); n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) fir[i] = init(0, i); n   for (int i = 0; i < n; i++) sec[i] = init(i, 0); n   vector<int> ans; n   int sch = 0; n   for (int i = 0; i < n; i++) { n     bool t = true; n     int col[5000], p[5000], b[5000]; n     b[0] = i; n     memset(col, 0, sizeof col); n     for (int j = 0; j < n; j++) { n       int x = sec[j] ^ b[0]; n       if (x >= n || col[x]) { n         t = false; n         break; n       } n       p[j] = x; n       col[x]++; n     } n     if (t) { n       memset(col, 0, sizeof col); n       col[i]++; n       for (int j = 1; j < n; j++) { n         int x = fir[j] ^ p[0]; n         if (x >= n || col[x]) { n           t = false; n           break; n         } n         b[j] = x; n         col[x]++; n       } n     } n     if (t) { n       for (int j = 0; j < n; j++) n         if (j != b[p[j]]) t = false; n     } n     if (t) { n       if (!sch) { n         for (int j = 0; j < n; j++) ans.push_back(p[j]); n       } n       sch++; n     } n   } n   print(sch, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n, m, ans = 999999999999999999, mn = 123456789000LL; n   cin >> n >> m; n   long long x = n; n   vector<pair<long long, long long> > v; n   long long cnt = 0; n   for (long long i = 2; i <= sqrt(m); i++) { n     if (m % i == 0) { n       cnt = 0; n       while (m % i == 0) { n         cnt++; n         m = m / i; n       } n       v.push_back({i, cnt}); n     } n   } n   if (m > 1) { n     mn = 1; n     v.push_back({m, 1}); n   } n   for (int i = 0; i < v.size(); i++) { n     long long y = x; n     long long temp = 0; n     while (y) { n       temp += y / v[i].first; n       y = y / v[i].first; n     } n     temp = temp / v[i].second; n     ans = min(temp, ans); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   int min1 = a; n   int min2 = b / 2; n   int min3 = c / 4; n   int res = min(min(min1, min2), min3); n   cout << res * 7; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n  n void solve() n { n     int n,i,j=2,x,m,d,k; n     cin >> n; n     if(n%2==1) n     {cout <<  NO  << endl;return;} n     while(j<1000000009 && j<=n) n     { n         if(n==j) n         { n            // cout <<  loop  << endl; n  n             cout <<  YES  << endl; n             return; n         } n         //cout << n <<     << j << endl; n         j*=2; n     } n  n  n     n=n/2; n     j=sqrt(n); n     if(j*j < n){ n  n     if(n%2==1) n     { n         cout <<  NO  << endl;return; n     } n     n/=2; n     j=sqrt(n); n         if(j*j < n) n             { n         cout <<  NO  << endl;return; n     } n     else { n         { n         cout <<  YES  << endl;return; n     } n     } n  n     } n  n     //if(j%2==1) {cout <<  NO  << endl;return;} n     cout <<  YES  << endl; n  n  n } n  n  n int main() n { n     ios_base::sync_with_stdio(false); cin.tie(NULL); n     int t=1; n     cin >> t; n     while(t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n vector<long long> v; n long long dp[1001][2001][4]; n long long rec(long long i, long long mask, long long comp) { n   if (i == n && comp == k) n     return 1; n   else if (i == n) n     return 0; n   else if (comp > k) n     return 0; n   if (dp[i][comp][mask] != -1) return dp[i][comp][mask]; n   if (i == 0) { n     return dp[i][comp][mask] = n                (rec(i + 1, 0, comp + 1) + rec(i + 1, 1, comp + 2) + n                 rec(i + 1, 2, comp + 2) + rec(i + 1, 3, comp + 1)) % n                998244353; n   } n   if (mask == 0) { n     return dp[i][comp][mask] = n                (rec(i + 1, 0, comp) + rec(i + 1, 3, comp + 1) + n                 rec(i + 1, 1, comp + 1) + rec(i + 1, 2, comp + 1)) % n                998244353; n   } else if (mask == 1) { n     return dp[i][comp][mask] = (rec(i + 1, 0, comp) + rec(i + 1, 1, comp) + n                                 rec(i + 1, 2, comp + 2) + rec(i + 1, 3, comp)) % n                                998244353; n   } else if (mask == 2) { n     return dp[i][comp][mask] = (rec(i + 1, 0, comp) + rec(i + 1, 1, comp + 2) + n                                 rec(i + 1, 2, comp) + rec(i + 1, 3, comp)) % n                                998244353; n   } else if (mask == 3) { n     return dp[i][comp][mask] = n                (rec(i + 1, 0, comp + 1) + rec(i + 1, 1, comp + 1) + n                 rec(i + 1, 2, comp + 1) + rec(i + 1, 3, comp)) % n                998244353; n   } n } n void solve() { n   memset(dp, -1, sizeof(dp)); n   cin >> n >> k; n   cout << rec(0, 0, 0); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long q = 1; n   while (q--) { n     v.clear(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long g, x, y, z; n int n, m; n int nn, mm; n deque<long long> q; n long long a[3010][3010]; n long long b[3010][3010]; n long long c[3010][3010]; n int main() { n   scanf( %d%d%d%d , &nn, &mm, &n, &m); n   scanf( %lld%lld%lld%lld , &g, &x, &y, &z); n   for (int i = 1; i <= nn; i++) { n     for (int j = 1; j <= mm; j++) { n       a[i][j] = g; n       g = g * x + y; n       g %= z; n     } n   } n   for (int i = 1; i <= nn; i++) { n     for (int j = mm; j >= 1; j--) { n       while (!q.empty() && a[i][q.back()] >= a[i][j]) { n         q.pop_back(); n       } n       q.push_back(j); n       while (!q.empty() && q.front() - q.back() + 1 > m) { n         q.pop_front(); n       } n       if (j <= mm - m + 1) b[i][j] = a[i][q.front()]; n     } n     while (!q.empty()) q.pop_front(); n   } n   for (int i = 1; i <= mm - m + 1; i++) { n     for (int j = nn; j >= 1; j--) { n       while (!q.empty() && b[q.back()][i] >= b[j][i]) { n         q.pop_back(); n       } n       q.push_back(j); n       while (!q.empty() && q.front() - q.back() + 1 > n) { n         q.pop_front(); n       } n       if (j <= nn - n + 1) c[j][i] = b[q.front()][i]; n     } n     while (!q.empty()) q.pop_front(); n   } n   long long ans = 0; n   for (int i = 1; i <= nn - n + 1; i++) { n     for (int j = 1; j <= mm - m + 1; j++) { n       ans += c[i][j]; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long _pow(long long a, long long b, long long m) { n   if (b == 0) return 1; n   long long t = _pow(a, b / 2, m); n   t = (t * t) % m; n   if (b & 1) n     return (t * a) % m; n   else n     return t; n } n int main(int argc, char *argv[]) { n   int n; n   cin >> n; n   vector<string> v; n   int cnt = 0; n   bool zero = false; n   string ex =  1 ; n   for (int i = 0; i < n; i++) { n     string x; n     cin >> x; n     v.push_back(x); n     bool f = true; n     if (x[0] ==  0  and x.size() == 1) n       zero = true; n     else if (x[0] ==  1 ) { n       int cn = 0; n       int j; n       for (j = 1; j < x.size(); j++) n         if (x[j] !=  0 ) { n           ex = x; n           break; n         } else n           cn++; n       if (j == x.size()) cnt += cn; n     } else n       ex = x; n   } n   if (zero) n     cout << 0 << endl; n   else { n     cout << ex; n     for (int i = 0; i < cnt; i++) cout << 0; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int mod = 1e9 + 7; n const int N = 1e5 + 10; n inline int add(int x, int y) { n   x += y; n   if (x >= mod) x -= mod; n   return x; n } n inline int mul(int x, int y) { n   x = (1LL * x * y) % mod; n   return x; n } n int main() { n   string s; n   cin >> s; n   string a =  abcdefghijklmnopqrstuvwxyz ; n   long long k = 0; n   for (int i = 0; i <= s.size() - 1; ++i) { n     if (s[i] <= a[k]) { n       s[i] = a[k]; n       k++; n     } n   } n   if (k == 26) { n     cout << s; n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   vector<pair<int, int>> a; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     a.push_back({x, i}); n   } n   sort(a.begin(), a.end(), greater<pair<int, int>>()); n   int numRow = a[0].first + 1; n   vector<vector<int>> ans(numRow, vector<int>(n, 0)); n   for (int i = 0; i < a[0].first; i++) ans[i][a[0].second] = 1; n   int row = 0; n   for (int i = 1; i < n; i++) { n     auto [block, col] = a[i]; n     for (int i = 1; i <= block; i++) ans[(row + i) % numRow][col] = 1; n     if (row < numRow - 2) row++; n   } n   if (!accumulate(ans[numRow - 1].begin(), ans[numRow - 1].end(), 0)) numRow--; n   cout << numRow << endl; n   for (int i = 0; i < numRow; i++) { n     for (auto x : ans[i]) cout << x; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n int q; n unsigned int a[200002]; n unsigned int b[200002]; n unsigned int w; n int main() { n   scanf( %d , &q); n   for (int i = 0; i < q; ++i) { n     int t, l, r, k; n     scanf( %d%d%d , &t, &l, &r); n     --l, --r; n     if (t == 1) { n       scanf( %d , &k); n       if (k > 0) { n         w = k; n         for (int i = l; i < r; ++i) n           if (a[i]) { n             a[i] = min(a[i], w); n           } else { n             a[i] = w; n           } n       } else { n         w = -k; n         for (int i = l; i < r; ++i) n           if (b[i]) { n             b[i] = min(b[i], w); n           } else { n             b[i] = w; n           } n       } n     } else { n       long long ans = 0; n       for (int i = l; i < r; ++i) n         if (a[i] > 0 && b[i] > 0) ans += a[i] + b[i]; n       printf( n            %lld  n             n , n           ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x; n } n struct Question { n   int x, l, r, dat; n   inline Question(int tmp1 = 0, int tmp2 = 0, int tmp3 = 0, int tmp4 = 0) { n     x = tmp1, l = tmp2, r = tmp3, dat = tmp4; n   } n   inline int operator<(const Question &a) const { return x < a.x; } n } opt[100010]; n int k; n inline int lowbit(int l, int r) { n   int res = 0; n   --l; n   for (int i = 1; i <= k; i <<= 1) n     res |= (((r / i - l / i) - n              (((i << 1) <= k) ? (r / (i << 1) - l / (i << 1)) : (0))) & n             1) * n            i; n   return res; n } n struct SegmentTree { n   int tot = 0, rot = 0; n   int L[100010 * 30], R[100010 * 30], tag[100010 * 30], val[100010 * 30], n       low[100010 * 30]; n   inline void upd(int k) { n     if (tag[k]) n       val[k] = low[k]; n     else n       val[k] = val[L[k]] ^ val[R[k]]; n   } n   inline void Mod(int &k, int l, int r, int x, int y, int dat) { n     if (y < l || r < x) return; n     if (!k) k = ++tot, low[k] = lowbit(l, r); n     if (x <= l && r <= y) return tag[k] += dat, upd(k); n     Mod(L[k], l, ((l + r) >> 1), x, y, dat), n         Mod(R[k], ((l + r) >> 1) + 1, r, x, y, dat), upd(k); n   } n } T; n int main() { n   int n = read(), m = read(), ans = 0; n   k = read(); n   int lim = 1, cnt = 0; n   for (; lim < k; lim <<= 1) n     ; n   while (m--) { n     int xl = read(), yl = read(); n     int xr = read(), yr = read(); n     opt[++cnt] = Question(xl, yl, yr, 1); n     opt[++cnt] = Question(xr + 1, yl, yr, -1); n   } n   sort(opt + 1, opt + cnt + 1); n   for (int i = 1; i <= cnt; i++) { n     if (opt[i].x != opt[i - 1].x) { n       int x = lowbit(opt[i - 1].x, opt[i].x - 1), y = T.val[T.rot]; n       int a = 0, b = 0, sum = 0; n       for (int j = lim; j; j >>= 1) { n         sum = -a * b, a += (x & j) > 0, b += (y & j) > 0, sum += a * b; n         if (sum & 1) ans ^= j; n       } n     } n     T.Mod(T.rot, 1, n, opt[i].l, opt[i].r, opt[i].dat); n   } n   if (ans) n     puts( Hamed ); n   else n     puts( Malek ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isgood(const vector<vector<char> > &graph, const vector<char> &choice) { n   int n = (int)graph.size() / 2; n   assert((int)graph[0].size() == 2 * n); n   assert((int)choice.size() == n); n   for (int i = 0; i < n; i++) { n     bool ok = false; n     int lbound = 2 * i; n     int rbound = 2 * i + 1; n     if (choice[i] != -1) lbound = rbound = 2 * i + choice[i]; n     for (int who = lbound; who <= rbound; who++) { n       bool cur = true; n       for (int j = 0; j < n; j++) { n         if (choice[j] != -1 && graph[who][2 * j + 1 - choice[j]]) cur = false; n         if (graph[who][2 * j] && graph[who][2 * j + 1]) cur = false; n       } n       ok |= cur; n     } n     if (!ok) return false; n   } n   return true; n } n void solve(string alph) { n   int n, m; n   cin >> n >> m; n   vector<vector<char> > graph(2 * n, vector<char>(2 * n)); n   int pos1, pos2; n   char t1, t2; n   for (int i = 0; i < m; i++) { n     scanf(  %d %c %d %c , &pos1, &t1, &pos2, &t2); n     int x1 = 2 * (pos1 - 1) + (t1 ==  V  ? 0 : 1); n     int x2 = 2 * (pos2 - 1) + (t2 ==  V  ? 0 : 1); n     graph[x1][x2] = 1; n     graph[x2 ^ 1][x1 ^ 1] = 1; n   } n   string word; n   cin >> word; n   assert((int)word.size() == n); n   for (int i = 0; i < 2 * n; i++) graph[i][i] = 1; n   for (int k = 0; k < 2 * n; k++) n     for (int i = 0; i < 2 * n; i++) n       for (int j = 0; j < 2 * n; j++) n         graph[i][j] |= (graph[i][k] & graph[k][j]); n   for (int i = 0; i < 2 * n; i++) n     if (graph[i][i ^ 1] && graph[i ^ 1][i]) { n       puts( -1 ); n       return; n     } n   vector<char> choice(n, -1); n   for (int i = 0; i < n; i++) choice[i] = (alph[word[i] -  a ] ==  V  ? 0 : 1); n   vector<int> next_vowel(alph.size() + 1, -1), next_cons(alph.size() + 1, -1); n   for (int i = 0; i < (int)alph.size(); i++) { n     for (int j = i; j < (int)alph.size(); j++) { n       if (alph[j] ==  V  && next_vowel[i] == -1) next_vowel[i] = j; n       if (alph[j] ==  C  && next_cons[i] == -1) next_cons[i] = j; n     } n   } n   if (isgood(graph, choice)) { n     puts(word.c_str()); n     return; n   } n   int lcp; n   for (lcp = n - 1; lcp > 0; lcp--) { n     int num = word[lcp] -  a  + 1; n     if (next_vowel[num] != -1) { n       choice[lcp] = 0; n       if (isgood(graph, choice)) break; n     } n     if (next_cons[num] != -1) { n       choice[lcp] = 1; n       if (isgood(graph, choice)) break; n     } n     choice[lcp] = -1; n   } n   choice[lcp] = -1; n   string ans = word.substr(0, lcp); n   for (int i = lcp; i < n; i++) { n     char start = (i == lcp ? word[i] + 1 :  a ); n     bool was_vowel = false; n     bool was_cons = false; n     bool ok = false; n     for (char ch = start; ch <  a  + (int)alph.size(); ch++) { n       if (!was_vowel && alph[ch -  a ] ==  V ) { n         was_vowel = true; n         choice[i] = 0; n         ok |= isgood(graph, choice); n         if (ok) { n           ans += ch; n           break; n         } n       } n       if (!was_cons && alph[ch -  a ] ==  C ) { n         was_cons = true; n         choice[i] = 1; n         ok |= isgood(graph, choice); n         if (ok) { n           ans += ch; n           break; n         } n       } n     } n     if (!ok) { n       puts( -1 ); n       return; n     } n   } n   puts(ans.c_str()); n } n int main() { n   string n; n   while (cin >> n) solve(n); 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 n, s, a, b, c, d; n   cin >> n >> s; n   d = s; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     c = a + b; n     d = max(c, d); n   } n   cout << d; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n long long Time; n int Free; n multiset<long long> Working; n int main() { n   scanf( %d%d , &N, &K); n   Free = K; n   Time = 0; n   long long S, M; n   for (int i = 0; i < N; ++i) { n     scanf( %I64d%I64d , &S, &M); n     S = max(S, Time); n     if (Free > 0) { n       --Free; n       printf( %I64d n , S + M); n       Working.insert(S + M); n       Time = S; n     } else { n       Time = *Working.begin(); n       Time = max(Time, S); n       printf( %I64d n , Time + M); n       Working.erase(Working.begin()); n       Working.insert(Time + M); n     } n     while ((not Working.empty()) and ((*Working.begin()) <= Time)) { n       ++Free; n       Working.erase(Working.begin()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 2e5 + 1; n vector<long long int> a[N]; n vector<long long int> order, pos(N); n bool topsort(long long int n) { n   order.clear(); n   queue<long long int> q; n   vector<long long int> indeg(n + 1, 0); n   for (long long int i = 1; i <= n; i++) n     for (auto &it : a[i]) indeg[it]++; n   for (long long int i = 1; i <= n; i++) n     if (!indeg[i]) q.push(i); n   long long int idx = 0; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     order.push_back(v); n     idx++; n     pos[v] = idx; n     for (auto &u : a[v]) { n       indeg[u]--; n       if (!indeg[u]) q.push(u); n     } n   } n   return (order.size() == n); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int n; n   cin >> n; n   vector<long long int> a1(n + 1), b(n + 1), c; n   for (long long int i = 1; i <= n; i++) cin >> a1[i]; n   for (long long int i = 1; i <= n; i++) { n     cin >> b[i]; n     if (b[i] != -1) a[i].push_back(b[i]); n   } n   topsort(n); n   vector<long long int> ans, tmp; n   long long int sum1 = 0, k = 0; n   for (long long int i = 0; i < order.size(); i++) { n     long long int pos = order[i]; n     sum1 += a1[pos]; n     if (b[pos] != -1 && a1[pos] < 0) n       tmp.push_back(pos); n     else { n       if (b[pos] != -1) a1[b[pos]] += a1[pos]; n       ans.push_back(pos); n     } n   } n   reverse(tmp.begin(), tmp.end()); n   for (long long int i = 0; i < tmp.size(); i++) ans.push_back(tmp[i]); n   cout << sum1 <<   n ; n   for (long long int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double optN(long long m, int k) { n   long double ret = 1; n   m *= k; n   long long nowC = k; n   for (int i = 1; i <= k; ++i) { n     if (m < nowC * i) { n       ret += m / i; n       return ret; n     } n     ret += nowC; n     m -= nowC * i; n     if (m / (i + 1.) / nowC <= (k - i) / (i + 1.)) return ret + m / (i + 1); n     nowC *= k - i; n     nowC /= (i + 1); n   } n   return ret; n }; n int main() { n   int CASE; n   cin >> CASE; n   for (int TCASE = 1; TCASE <= CASE; ++TCASE) { n     long long n, m; n     cin >> n >> m; n     long long l = 0, r = (0x3f3f3f3f); n     while (l < r) { n       long long mid = l + r >> 1; n       if (optN(m, mid) >= n) n         r = mid; n       else n         l = mid + 1; n     } n     cout << l << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const int INF = 1 << 28; n const long long INFL = 1LL << 62; n int toi(string x) { n   int z; n   istringstream iss(x); n   iss >> z; n   return z; n } n string str[] = { YES ,  NO }; n int modulo(int m, int n) { return m >= 0 ? m % n : (n - abs(m % n)) % n; } n using namespace std; n int arr[101] = {0}, n, m; n int main() { n   cin >> n >> m; n   for (int i = 1, a, b, c; i <= m; i++) { n     cin >> a >> b >> c; n     arr[a] -= c; n     arr[b] += c; n   } n   int sum = 0; n   for (int i = 1; i <= n; i++) n     if (arr[i] > 0) sum += arr[i]; n   cout << sum << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, b[100005], a[200005]; n void solve() { n   cin >> n; n   for (long long i = 1; i < n / 2 + 1; i++) cin >> b[i]; n   a[1] = 0; n   a[n] = b[1]; n   for (long long i = 2; i < n / 2 + 1; i++) { n     a[i] = max(a[i - 1], b[i] - a[n - i + 2]); n     a[n - i + 1] = b[i] - a[i]; n   } n   for (long long i = 1; i < n + 1; i++) cout << a[i] <<    ; n   cout <<   n ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, x1, x2, y1, y2, i, sum = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> x1 >> y1 >> x2 >> y2; n     sum += ((x2 - x1) + 1) * ((y2 - y1) + 1); n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int Inf = (int)1e9; n const long long InfL = (long long)1e18; n const int MaxN = (int)2e5 + 5; n vector<int> adj[MaxN], ans; n int n, a, deg[MaxN], dead[MaxN]; n void dfs2(int x, int p) { n   dead[x] = true; n   ans.push_back(x); n   for (auto u : adj[x]) --deg[u]; n   for (auto u : adj[x]) n     if (u != p && !dead[u]) dfs2(u, x); n } n void dfs1(int x, int p) { n   for (auto u : adj[x]) n     if (u != p) dfs1(u, x); n   if (!(deg[x] & 1)) dfs2(x, p); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     if (!a) continue; n     adj[i].push_back(a); n     deg[i]++; n     adj[a].push_back(i); n     deg[a]++; n   } n   dfs1(1, 0); n   if (ans.size() == n) { n     cout <<  YES  <<   n ; n     for (int i = 0; i < n; i++) cout << ans[i] <<   n ; n   } else { n     cout <<  NO  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int mod = 1000000007; n const int M = INT_MAX; n using namespace std; n int powb(int x, int y) { n   int res = 1; n   x = x % M; n   while (y > 0) { n     if (y % 2) res = (res * x) % M; n     y /= 2; n     x = (x * x) % M; n   } n   return res; n } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int solve() { n   int n, t, s = 0, x, s1 = 0, i, j; n   cin >> n >> t; n   vector<int> v(2 * n); n   for (i = 0; i < n; i++) { n     cin >> x; n     s1 += x; n     v[i] = x; n     v[i + n] = x; n   } n   if (s1 <= t) return n; n   int max = 0; n   x = 0; n   for (i = 0; i < 2 * n; i++) { n     s += v[i]; n     if (s > t) { n       s -= v[i]; n       break; n     } n     x++; n     if (x > max) max = x; n   } n   for (i = 1; i < n; i++) { n     s -= v[i - 1]; n     x--; n     for (j = i + x; j < n; j++) { n       s += v[j]; n       if (s > t) { n         s -= v[j]; n         break; n       } n       x++; n       if (x > max) max = x; n     } n     if (j == n - 1) break; n   } n   return max; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout << solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read(int &val) { n   int x = 0; n   int bz = 1; n   char c; n   for (c = getchar(); (c <  0  || c >  9 ) && c !=  - ; c = getchar()) n     ; n   if (c ==  - ) { n     bz = -1; n     c = getchar(); n   } n   for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48; n   val = x * bz; n } n const int INF = 0x3f3f3f3f; n const int maxn = 1e6 + 100; n const int mod = 998244353; n long long a[maxn], b[maxn]; n int n, k; n long long sum[maxn], tim[maxn]; n struct node { n   int id; n   bool operator<(const node bb) const { return tim[id] > tim[bb.id]; } n }; n bool check(long long mid) { n   priority_queue<node> q; n   for (int i = 1; i <= n; i++) { n     tim[i] = a[i] / b[i]; n     sum[i] = a[i]; n     q.push(node{i}); n   } n   for (int i = 0; i <= k - 1; i++) { n     node top = q.top(); n     q.pop(); n     int xx = top.id; n     if (tim[xx] < i) return false; n     if (tim[xx] >= k) return true; n     sum[xx] += mid; n     tim[xx] = sum[xx] / b[xx]; n     if (tim[xx] < i) return false; n     q.push(node{xx}); n   } n   return true; n } n int main() { n   read(n); n   read(k); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   for (int i = 1; i <= n; i++) scanf( %lld , &b[i]); n   long long ans = -1, l = 0, r = 1e13; n   while (l <= r) { n     long long mid = l + r >> 1; n     if (check(mid)) { n       ans = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   printf( %lld n , ans); n   return 0; n } n