#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n int main() { n   int n; n   long long a = 1, b = 1; n   char s[10]; n   scanf( %d , &n); n   for (int i = int(1); i <= int(n); ++i) { n     scanf( %s , s); n     if (strlen(s) == 4) { n       a++; n       b++; n     } else { n       if (s[0] ==  U  && s[1] ==  L ) b++; n       if (s[0] ==  U  && s[1] ==  R ) a++; n       if (s[0] ==  D  && s[1] ==  L ) a++; n       if (s[0] ==  D  && s[1] ==  R ) b++; n     } n   } n   cout << a * b << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long temp; n   long long a[n]; n   int fg = 0; n   for (int(i) = 0; (i) < (n); (i)++) { n     cin >> temp; n     fg++; n     a[i] = temp; n   } n   sort(a, a + n); n   for (int(i) = 0; (i) < (n - 1); (i)++) { n     if (a[i] == a[i + 1]) continue; n     if (a[i + 1] < 2 * a[i]) { n       cout <<  YES n ; n       return 0; n     } n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, x, n, m; n   scanf( %d%d%d%d , &k, &x, &n, &m); n   for (int f1 = 0; f1 <= 1; f1++) { n     for (int f2 = 0; f2 <= 1; f2++) { n       for (int f3 = 0; f3 <= 1; f3++) { n         int h1 = n, h2 = m; n         if (f1) h1--; n         if (f1 || f3) h2--; n         if (f2) h1--, h2--; n         if (!f2 && f3) h2--; n         if (h1 < 0 || h2 < 0) continue; n         for (int i = 0; i <= h1 / 2; i++) { n           for (int j = 0; j <= h2 / 2; j++) { n             long long las1 = i, las2 = j; n             for (int t = 3; t <= k; t++) { n               long long tmp1 = las2, tmp2 = las1 + las2; n               las1 = tmp1, las2 = tmp2; n               if (t == 3 && f1) las2++; n               if (t >= 4 && t % 2 == 0 && f2) las2++; n               if (t >= 4 && t % 2 == 1 && f3) las2++; n             } n             if (las2 == x) { n               if (f2) printf( C ); n               for (int h = 1; h <= i; h++) printf( AC ); n               for (int h = 1; h <= h1 - 2 * i; h++) printf( Z ); n               if (f1) printf( A ); n               printf(  n ); n               if (f1 || f3) printf( C ); n               for (int h = 1; h <= j; h++) printf( AC ); n               for (int h = 1; h <= h2 - 2 * j; h++) printf( Z ); n               if (f2 || f3) printf( A ); n               printf(  n ); n               return 0; n             } n           } n         } n       } n     } n   } n   printf( Happy new year! n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using db = double; n using str = string; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using pd = pair<db, db>; n using vi = vector<int>; n using vb = vector<bool>; n using vl = vector<ll>; n using vd = vector<db>; n using vs = vector<str>; n using vpi = vector<pi>; n using vpl = vector<pl>; n using vpd = vector<pd>; n template <class T> n using V = vector<T>; n template <class T, size_t SZ> n using AR = array<T, SZ>; n const int MOD = 1e9 + 7; n const int MX = 2e5 + 5; n const ll INF = 1e18; n const ld PI = acos((ld)-1); n const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1}; n mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); n constexpr int pct(int x) { return __builtin_popcount(x); } n constexpr int bits(int x) { return 31 - __builtin_clz(x); } n ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } n ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n template <class T, class U> n T fstTrue(T lo, T hi, U first) { n   hi++; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo) / 2; n     first(mid) ? hi = mid : lo = mid + 1; n   } n   return lo; n } n template <class T, class U> n T lstTrue(T lo, T hi, U first) { n   lo--; n   assert(lo <= hi); n   while (lo < hi) { n     T mid = lo + (hi - lo + 1) / 2; n     first(mid) ? lo = mid : hi = mid - 1; n   } n   return lo; n } n template <class T> n void remDup(vector<T>& v) { n   sort(begin(v), end(v)); n   v.erase(unique(begin(v), end(v)), end(v)); n } n template <class T, class U> n void erase(T& t, const U& u) { n   auto it = t.find(u); n   assert(it != end(t)); n   t.erase(u); n } n template <class T> n void re(complex<T>& c); n template <class T, class U> n void re(pair<T, U>& p); n template <class T> n void re(vector<T>& v); n template <class T, size_t SZ> n void re(AR<T, SZ>& a); n template <class T> n void re(T& x) { n   cin >> x; n } n void re(db& d) { n   str t; n   re(t); n   d = stod(t); n } n void re(ld& d) { n   str t; n   re(t); n   d = stold(t); n } n template <class T, class... U> n void re(T& t, U&... u) { n   re(t); n   re(u...); n } n template <class T> n void re(complex<T>& c) { n   T a, b; n   re(a, b); n   c = {a, b}; n } n template <class T, class U> n void re(pair<T, U>& p) { n   re(p.first, p.second); n } n template <class T> n void re(vector<T>& x) { n   for (auto& a : x) re(a); n } n template <class T, size_t SZ> n void re(AR<T, SZ>& x) { n   for (auto& a : x) re(a); n } n str to_string(char c) { return str(1, c); } n str to_string(const char* second) { return (str)second; } n str to_string(str second) { return second; } n str to_string(bool b) { return to_string((int)b); } n template <class T> n str to_string(complex<T> c) { n   stringstream ss; n   ss << c; n   return ss.str(); n } n str to_string(vector<bool> v) { n   str res =  { ; n   for (int i = (0); i < ((int)(v).size()); ++i) res += char( 0  + v[i]); n   res +=  } ; n   return res; n } n template <size_t SZ> n str to_string(bitset<SZ> b) { n   str res =   ; n   for (int i = (0); i < (SZ); ++i) res += char( 0  + b[i]); n   return res; n } n template <class T, class U> n str to_string(pair<T, U> p); n template <class T> n str to_string(T v) { n   bool fst = 1; n   str res =   ; n   for (const auto& x : v) { n     if (!fst) res +=    ; n     fst = 0; n     res += to_string(x); n   } n   return res; n } n template <class T, class U> n str to_string(pair<T, U> p) { n   return to_string(p.first) +     + to_string(p.second); n } n template <class T> n void pr(T x) { n   cout << to_string(x); n } n template <class T, class... U> n void pr(const T& t, const U&... u) { n   pr(t); n   pr(u...); n } n void ps() { pr(  n ); } n template <class T, class... U> n void ps(const T& t, const U&... u) { n   pr(t); n   if (sizeof...(u)) pr(   ); n   ps(u...); n } n void DBG() { cerr <<  ]  << endl; } n template <class T, class... U> n void DBG(const T& t, const U&... u) { n   cerr << to_string(t); n   if (sizeof...(u)) cerr <<  ,  ; n   DBG(u...); n } n void setIn(str second) { freopen(second.c_str(),  r , stdin); } n void setOut(str second) { freopen(second.c_str(),  w , stdout); } n void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } n void setIO(str second =   ) { n   unsyncIO(); n   if ((int)(second).size()) { n     setIn(second +  .in ), setOut(second +  .out ); n   } n } n int N, A[1000][1000]; n bool active[1000][1000]; n deque<int> pref[1000]; n int propose[1000], proposed[1000]; n void fin() { n   ps(-1); n   exit(0); n } n void rem(int x, int y) { active[x][y] = active[y][x] = 0; } n void clip(int x) { n   while ((int)(pref[x]).size() && !active[x][pref[x].front()]) n     pref[x].pop_front(); n   while ((int)(pref[x]).size() && !active[x][pref[x].back()]) n     pref[x].pop_back(); n   if (!(int)(pref[x]).size()) fin(); n } n void ad(int x, int y) { n   assert(x != y && propose[x] == -1 && proposed[y] == -1); n   propose[x] = y, proposed[y] = x; n   while (1) { n     clip(y); n     if (pref[y].back() != x) n       rem(y, pref[y].back()); n     else n       break; n   } n   assert(pref[y].back() == x); n } n int nex(int x) { n   assert((int)(pref[x]).size() > 1); n   clip(x); n   int y = pref[x].front(); n   pref[x].pop_front(); n   clip(x); n   pref[x].push_front(y); n   return proposed[pref[x][1]]; n } n int main() { n   setIO(); n   re(N); n   if (N & 1) fin(); n   for (int i = (0); i < (N); ++i) { n     for (int j = (0); j < (N); ++j) n       if (i != j) { n         re(A[i][j]); n         pref[i].push_back(j); n         active[i][j] = 1; n       } n     sort(begin(pref[i]), end(pref[i]), n          [&](int x, int y) { return A[i][x] < A[i][y]; }); n   } n   for (int i = (0); i < (N); ++i) propose[i] = proposed[i] = -1; n   queue<int> q; n   for (int i = (0); i < (N); ++i) q.push(i); n   while ((int)(q).size()) { n     int x = q.front(); n     q.pop(); n     assert(propose[x] == -1); n     while (1) { n       clip(x); n       int y = pref[x].front(), X = proposed[y]; n       if (X != -1 && A[y][X] < A[y][x]) { n         rem(x, y); n         continue; n       } n       if (X != -1) propose[X] = -1, proposed[y] = -1, q.push(X); n       ad(x, y); n       break; n     } n   } n   for (int i = (0); i < (N); ++i) assert(propose[i] != -1); n   int cur = 0; n   while (1) { n     for (; cur < N; ++cur) { n       clip(cur); n       assert(proposed[cur] != -1 && pref[cur].back() == proposed[cur]); n       if ((int)(pref[cur]).size() > 1) break; n     } n     for (int i = (0); i < (N); ++i) { n       vi tmp; n       for (auto& j : pref[i]) n         if (active[i][j]) tmp.push_back(j); n     } n     if (cur == N) { n       for (int i = (0); i < (N); ++i) { n         assert(proposed[propose[i]] == i); n         ps(propose[i] + 1); n       } n       exit(0); n     } n     vi cyc, CYC; n     { n       int x = cur, y = cur; n       do { n         x = nex(x), y = nex(nex(y)); n       } while (x != y); n       do { n         cyc.push_back(y); n         y = nex(y); n       } while (x != y); n     } n     for (auto& x : cyc) { n       int y = propose[x]; n       CYC.push_back(y); n       assert(y != -1); n       propose[x] = -1, proposed[y] = -1, rem(x, y); n     } n     for (int i = (0); i < ((int)(cyc).size()); ++i) n       ad(cyc[i], CYC[(i + 1) % (int)(cyc).size()]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long inf = 1e9; n const long long N = 1000 + 5; n long long ar[N], done[N], cnt[N]; n long long n; n long long mex() { n   for (long long i = 0; i < n; i++) cnt[i] = 0; n   for (long long i = 0; i < n; i++) cnt[ar[i]] = 1; n   long long mex = 0; n   while (cnt[mex]) mex++; n   return mex; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     cin >> n; n     for (long long i = 0; i < n; i++) { n       cin >> ar[i]; n     } n     vector<long long> ans; n     while (1) { n       long long m = mex(); n       if (m < n) { n         ar[m] = m; n         ans.push_back(m + 1); n       } else { n         long long ind = 0; n         while (ind < n && ar[ind] == ind) ind++; n         if (ind == n) break; n         long long p = -1; n         for (long long i = 0; i < n && p == -1; i++) n           if (ar[i] == ind) p = i; n         ar[p] = n; n         ans.push_back(p + 1); n       } n     } n     cout << ans.size() <<   n ; n     for (auto &inx : ans) cout << inx <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:32100000 ) n #pragma GCC optimize( O3 ) n using namespace std; n void solve() { n   int n, k; n   string str; n   cin >> n >> k >> str; n   string need; n   for (int i = 0; i < k - 1; i++) { n     need +=  () ; n   } n   for (int i = 0; i < (n - 2 * k + 2) / 2; i++) { n     need +=  ( ; n   } n   for (int i = 0; i < (n - 2 * k + 2) / 2; i++) { n     need +=  ) ; n   } n   vector<pair<int, int>> ans; n   for (int i = 0; i < n; i++) { n     if (str[i] == need[i]) { n       continue; n     } n     int pos = i + 1; n     for (; pos < n && str[pos] != need[i]; pos++) n       ; n     ans.push_back({i, pos}); n     for (int j = 0; j < (pos - i + 1) / 2; j++) { n       swap(str[i + j], str[pos - j]); n     } n   } n   cout << ans.size() <<   n ; n   for (auto &i : ans) { n     cout << i.first + 1 <<     << i.second + 1 <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin.sync_with_stdio(0); n   cout.sync_with_stdio(0); n   cout.precision(9); n   srand(time(0)); n   int q; n   cin >> q; n   while (q--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[111111]; n int isp2[222222]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int i = 1, p = 1; i < 222222; i *= 2, ++p) { n     isp2[i] = p; n   } n   sort(a, a + n); n   int ans = 1e9; n   for (int dv = 0; a[n - 1] >= (1 << dv); ++dv) { n     for (int mul = 0; mul <= dv + 1; ++mul) { n       int val = a[n - 1]; n       for (int i = 0; i < dv; ++i) { n         val /= 2; n       } n       for (int i = 0; i < mul; ++i) { n         val *= 2; n       } n       int tot = 0; n       for (int i = 0; i < n; ++i) { n         int cur = a[i]; n         while (cur > 0 && !(val % cur == 0 && isp2[val / cur])) { n           cur /= 2; n           ++tot; n         } n         if (cur > 0) { n           tot += isp2[val / cur] - 1; n         } else { n           tot = 1e9; n           break; n         } n       } n       ans = min(ans, tot); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n inline int read() { n   int s = 0; n   char c; n   while ((c = getchar()) <  0  || c >  9 ) n     ; n   do { n     s = s * 10 + c -  0 ; n   } while ((c = getchar()) >=  0  && c <=  9 ); n   return s; n } n int n, l, r, ql, qr; n long long ans; n int main() { n   for (n = read(), l = r = read(); n--;) { n     ql = read(), qr = read(); n     if (ql <= l && r <= qr) continue; n     if (qr < l) n       ans += l - qr, r = l, l = qr; n     else if (r < ql) n       ans += ql - r, l = r, r = ql; n     else n       l = ql > l ? ql : l, r = qr < r ? qr : r; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k, a, b, v; n   cin >> k >> a >> b >> v; n   int x = (a + v - 1) / v; n   int t, y; n   t = b / (k - 1); n   y = t * k; n   while (y > x) { n     b--; n     t = b / (k - 1); n     y = t * k; n   } n   int c; n   c = b % (k - 1) + 1; n   int m; n   if (x > c + y) n     m = x - (c + y); n   else n     m = 0; n   if (y < x) n     cout << m + t + 1; n   else n     cout << m + t; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 5e3 + 5, mum = 1e9 + 7; n int Pow(int A, long long B) { n   int num = 1; n   while (B) { n     if (B & 1) num = 1LL * num * A % mum; n     A = 1LL * A * A % mum; n     B >>= 1; n   } n   return num; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, m, k, r, c, ax, ay, bx, by; n   cin >> n >> m >> k >> r >> c >> ax >> ay >> bx >> by; n   cout << (ax == bx && ay == by ? Pow(k, 1LL * n * m) n                                 : Pow(k, 1LL * n * m - 1LL * r * c)) n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace ::std; n const int V = 1e5 + 25; n int arr[V]; n map<int, int> mmap; n int main() { n   int n; n   cin >> n; n   int mx = INT_MIN; n   int mn = INT_MAX; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     mx = max(mx, arr[i]); n     mn = min(mn, arr[i]); n     mmap[arr[i]]++; n   } n   if (mx - mn < 2) { n     cout << n << endl; n     for (int i = 0; i < n; i++) { n       cout << arr[i] <<    ; n     } n     cout << endl; n     return 0; n   } n   int cnt = 0; n   int a, b, c; n   int p, q, r; n   if (mmap.size() == 2) { n     for (auto x : mmap) { n       if (cnt == 0) p = x.first, a = x.second; n       if (cnt == 1) r = x.first, c = x.second; n       cnt++; n     } n     q = p + 1; n     b = 0; n   } else { n     for (auto x : mmap) { n       if (cnt == 0) p = x.first, a = x.second; n       if (cnt == 1) q = x.first, b = x.second; n       if (cnt == 2) r = x.first, c = x.second; n       cnt++; n     } n   } n   int b1 = b + 2 * min(a, c); n   int a1 = a - min(a, c); n   int c1 = c - min(a, c); n   int b2 = b % 2; n   int a2 = a + (b - b % 2) / 2; n   int c2 = c + (b - b % 2) / 2; n   int lhs = min(a1, a) + min(b1, b) + min(c1, c); n   int rhs = min(a2, a) + min(b2, b) + min(c2, c); n   if (lhs <= rhs) { n     printf( %d n , lhs); n     for (int i = 0; i < a1; i++) printf( %d  , p); n     for (int i = 0; i < b1; i++) printf( %d  , q); n     for (int i = 0; i < c1; i++) printf( %d  , r); n   } else { n     printf( %d n , rhs); n     for (int i = 0; i < a2; i++) printf( %d  , p); n     for (int i = 0; i < b2; i++) printf( %d  , q); n     for (int i = 0; i < c2; i++) printf( %d  , r); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double PI = atan(1.0) * 4.0; n const long long int MOD = 1e9 + 7; n const long long int INF = 1e5; n const long double EPS = 0.0000001; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   int a[1005], k; n   a[0] = -1; n   a[1] = 0; n   for (int i = 2; i <= 1005; i++) { n     a[i] = a[i - 1] + i - 1; n   } n   cin >> k; n   if (k == 0) { n     cout <<  a  << endl; n     return 0; n   } n   char ch =  a ; n   while (k > 0) { n     int lb = lower_bound(a, a + 1005, k) - a; n     if (a[lb] != k) lb--; n     for (int i = 1; i <= lb; i++) cout << ch; n     k -= a[lb]; n     ch++; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n int n, k, q; n int pref[200005]; n int main() { n   cin >> n >> k >> q; n   int maxRight = 0; n   for (int i = 0; i < n; ++i) { n     int left, right; n     cin >> left >> right; n     maxRight = max(maxRight, right); n     ++pref[left], --pref[right + 1]; n   } n   for (int i = 1; i <= maxRight; ++i) { n     pref[i] += pref[i - 1]; n   } n   for (int i = 0; i <= 200001; ++i) { n     pref[i] = (int)(pref[i] >= k); n     pref[i] += pref[i - 1]; n   } n   while (q--) { n     int a, b; n     cin >> a >> b; n     cout << pref[b] - pref[a - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int arr[n]; n     for (int i = 0; i < n; i++) cin >> arr[i]; n     bool prev = false; n     for (int i = 0; true; i++) { n       int change = 0; n       if (i & 1) { n         for (int j = 1; j < n - 1; j++) { n           if (arr[j] > arr[j + 1]) { n             swap(arr[j], arr[j + 1]); n             change++; n           } n           j++; n         } n       } else { n         for (int j = 0; j < n - 2; j++) { n           if (arr[j] > arr[j + 1]) { n             swap(arr[j], arr[j + 1]); n             change++; n           } n           j++; n         } n       } n       if (!change) { n         if (prev) { n           cout << i - 1 <<   n ; n           break; n         } n         prev = true; n       } else { n         prev = false; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, c, d; n long long f(long long k) { return (d * b * k - 2 * a) * (k + 1) / -2; } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> a >> b >> c >> d; n     if (a > b * c) { n       cout <<  -1 n ; n       continue; n     } n     double k = a * 1.0 / (d * b) - 0.5; n     cout << max(f(k), f(k + 1)) <<   n ; n   } n } n


#include <bits/stdc++.h> n int main(void) { n   char a[100001]; n   long long current, jump[100001], n, i; n   int flag = 1, visited[100001]; n   memset(visited, 0, sizeof(visited)); n   scanf( %lld , &n); n   if (n == 1) { n     printf( FINITE ); n     return 0; n   } n   scanf( %s , a); n   for (i = 1; i <= n; i++) scanf( %lld , &jump[i]); n   current = 1; n   i = 1; n   while (flag == 1) { n     visited[current] = 1; n     if (a[current - 1] ==  > ) { n       current = current + jump[current]; n     } else { n       current = current - jump[current]; n     } n     if (current < 1 || current > n) { n       flag = 0; n       break; n     } n     if (visited[current] == 1) { n       break; n     } n   } n   if (flag == 0) { n     printf( FINITE ); n   } else { n     printf( INFINITE ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr1[26], arr2[26][26]; n signed main() { n   string s; n   cin >> s; n   long long n = s.length(); n   for (long long i = 0; i < n; i++) { n     long long ct = s[i] -  a ; n     for (long long j = 0; j < 26; j++) { n       arr2[j][ct] += arr1[j]; n     } n     arr1[ct]++; n   } n   long long ans = 0; n   for (long long i = 0; i < 26; i++) ans = max(ans, arr1[i]); n   for (long long i = 0; i < 26; i++) { n     for (long long j = 0; j < 26; j++) { n       ans = max(ans, arr2[i][j]); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i; n   cin >> n; n   for (i = 1; i <= n; i++) { n     if (i % 4 == 1 || i % 4 == 2) n       cout <<  a ; n     else n       cout <<  b ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int m, n; n int main() { n   int n; n   string vic1, vic2, tmp1, tmp2; n   cin >> vic1 >> vic2; n   cin >> n; n   cout << vic1 <<     << vic2 << endl; n   for (int i = 0; i < n; ++i) { n     cin >> tmp1 >> tmp2; n     if (vic1 == tmp1) n       vic1 = tmp2; n     else n       vic2 = tmp2; n     cout << vic1 <<     << vic2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch[6700][3000]; n char c[3000]; n int vis[2000]; n vector<int> ans; n int len; n void shift(int x, int k) { n   int num = 0; n   for (int i = len - 1; i > len - 1 - x; i--) { n     ch[k][num++] = ch[k - 1][i]; n   } n   for (int i = 0; i < len - x; i++) { n     ch[k][num++] = ch[k - 1][i]; n   } n   ch[k][num] =   0 ; n } n int main() { n   scanf( %d , &len); n   scanf( %s , ch[0]); n   while (ch[0][0] ==     || ch[0][0] ==   n  || ch[0][0] ==   r ) n     scanf( %s , ch[0]); n   scanf( %s , c); n   while (c[0] ==     || c[0] ==   n  || c[0] ==   r ) scanf( %s , c); n   if (strlen(c) != strlen(ch[0])) { n     printf( -1 ); n     return 0; n   } n   for (int i = 0; i < len; i++) { n     vis[ch[0][i]]++; n     vis[c[i]]--; n   } n   for (int i =  a ; i <=  z ; i++) { n     if (vis[i] != 0) { n       printf( -1 ); n       return 0; n     } n   } n   int num = 1; n   for (int i = 1; i <= len; i++) { n     for (int j = 0; j <= len - i; j++) { n       if (c[i - 1] == ch[num - 1][j]) { n         ans.push_back(len - j - 1); n         ans.push_back(1); n         ans.push_back(len - 1); n         shift(len - j - 1, num++); n         shift(1, num++); n         shift(len - 1, num++); n         break; n       } n     } n   } n   printf( %d n , num - 1); n   for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n char str[10]; n bool check(int x, int y) { n   sprintf(str,  %02d:%02d , x, y); n   return (str[0] == str[4] && str[1] == str[3]); n } n int main() { n   int i, j, n, m; n   scanf( %d:%d , &n, &m); n   for (i = n; i < 24; ++i) { n     for (j = 0; j < 60; ++j) { n       if (i == n && j <= m) continue; n       if (check(i, j)) { n         printf( %s , str); n         return 0; n       } n     } n   } n   cout <<  00:00  << endl; n   return 0; n } n


#include<bits/stdc++.h> n #define fi                first n #define se                 second n #define ll               long long n #define mod              1000000007LL n #define endl                n  n #define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); n #define pb                push_back n #define all(v)             v.begin(),v.end() n #define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];} n #define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] <<      ;} cout << endl;} n #define pll              pair<long long,long long> n #define pi            3.141592653589793238 n using namespace std; n //vector<ll> adj[5000005]; n //vector<bool> vis(3000005,false); n ll factorial(ll n) n { n     return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); n } n ll gcd(ll a, ll b) n { n     if (a == 0) n       return b; n     return gcd(b % a, a); n } n ll lcm(ll a, ll b) n { n    return (a*b)/gcd(a, b); n } n bool sortByVal(const pair<ll,ll> &a, n               const pair<ll,ll> &b) n { n       if(a.fi == b.fi) n         return a.se < b.se; n      else n         return a.fi > b.fi; n } n ll Powb(ll b,ll n) n { n     if(n==0) return 1LL; n     if(n==1) return b; n     ll temp = Powb(b,n/2); n     if(n%2==0){return (temp*temp)%mod;} n     else{return (b*((temp*temp)%mod))%mod;} n } n int main() n { n  fast; n      int t=1; n      //cin>>t; n      while(t--) n      { n      ll q,i,j,m,n,k,sum=0,c=0,d=0,e=0,f=0,g=0,h=0,maxi=0; n       cin>>n>>q>>k; n       vector<ll> a(n); n       inp(a,n); n       vector<ll> b(n); n       if(n == 1) n       { n           while(q--) n           { n               cin>>c>>d; n               cout<<k-1<<endl; n           } n       } n       else n       { n           for(i=0;i<n;i++) n           { n               if(i == 0) n               { n                   c=a[i+1]-2; n                   b[i]=c; n               } n               else if(i == n-1) n               { n                   c=k-a[n-1]; n                   b[i]=c; n               } n               else n               { n                   c=a[i-1]; n                   d=a[i+1]; n                   d-=c; n                   d-=2; n                   b[i]=d; n               } n  n           } n           vector<ll> p(n); n           sum=0; n           for(i=0;i<n;i++) n           { n               sum+=b[i]; n               p[i]=sum; n           } n  n           //oup(b,n); n           //oup(p,n); n           while(q--) n           { n               sum=0; n               cin>>c>>d; n               c--; n               d--; n               if(c == d) n               { n                   cout<<k-1<<endl; n               } n               else if((d-c) == 1) n               { n                   e=a[d]-2; n                   f=k-a[c]-1; n                   cout<<e+f<<endl; n               } n               else n               { n                   sum=p[d-1]-p[c]; n                   e=k-a[d-1]-1; n                   sum+=e; n                   f=a[c+1]-2; n                   sum+=f; n                   cout<<sum<<endl; n               } n  n           } n       } n  n  n      } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 255; n const int MAXM = 30; n const int MAX = 10000; n const int INF = -1U >> 1; n int arr[MAXN]; n struct MinCostFlow { n   struct edge { n     int n, f, c; n     edge *next, *rev; n     edge(int _n, int _f, int _c, edge* _next) n         : n(_n), f(_f), c(_c), next(_next) {} n   }; n   vector<edge*> edges; n   int addV() { n     edges.push_back((edge*)0); n     return edges.size() - 1; n   } n   edge* makeE(int s, int t, int f, int c) { n     return edges[s] = new edge(t, f, c, edges[s]); n   } n   void addE(int s, int t, int f, int c) { n     edge *e1 = makeE(s, t, f, c), *e2 = makeE(t, s, 0, -c); n     e1->rev = e2, e2->rev = e1; n   } n   void mcflow(int vs, int vt, int vr, int vn, int vm) { n     int n = edges.size(); n     int cflow = 0, ccost = 0; n     vector<int> dist(n); n     vector<int> flow(n); n     vector<edge*> from(n); n     vector<bool> in(n); n     queue<int> que; n     while (1) { n       fill(dist.begin(), dist.end(), INF); n       fill(flow.begin(), flow.end(), 0); n       dist[vs] = 0; n       flow[vs] = INF; n       que.push(vs); n       while (!que.empty()) { n         int v = que.front(); n         que.pop(); n         in[v] = 0; n         for (edge* e = edges[v]; e; e = e->next) n           if (e->f) { n             int nc = dist[v] + e->c; n             if (nc < dist[e->n]) { n               dist[e->n] = nc; n               flow[e->n] = min(flow[v], e->f); n               from[e->n] = e; n               if (!in[e->n]) { n                 que.push(e->n); n                 in[e->n] = 1; n               } n             } n           } n       } n       if (!flow[vt]) break; n       int f = flow[vt]; n       cflow += f; n       ccost += f * dist[vt]; n       int cur = vt; n       while (cur != vs) { n         edge* e = from[cur]; n         e->f -= f; n         e->rev->f += f; n         cur = e->rev->n; n       } n     } n     vector<int> var(vn); n     vector<pair<int, int> > ans; n     for (int i = 0; i < vm; i++) { n       int cur = vr; n       while (cur != vt) { n         for (edge* e = edges[cur]; e; e = e->next) { n           if (!e->f) { n             e->f++; n             if (e->n < vn) var[e->n] = i; n             cur = e->n; n             break; n           } n         } n       } n     } n     vector<int> num(vn, -1); n     for (int i = 0; i < vn; i++) { n       if (num[var[i]] != arr[i]) n         ans.push_back(pair<int, int>(var[i], 0)), num[var[i]] = arr[i]; n       ans.push_back(pair<int, int>(var[i], 1)); n     } n     cout << ans.size() <<     << ccost + MAX * vn <<   n ; n     int cnt = 0; n     for (int i = 0; i < ans.size(); i++) { n       if (!ans[i].second) n         cout << char(ans[i].first +  a ) <<  =  << arr[cnt] <<   n ; n       else { n         cout <<  print(  << char(ans[i].first +  a ) <<  ) n ; n         cnt++; n       } n     } n   } n }; n int n, m; n int main() { n   ios ::sync_with_stdio(0); n   if (fopen( input.txt ,  r )) freopen( input.txt ,  r , stdin); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   MinCostFlow net; n   for (int i = 0; i < n + n; i++) net.addV(); n   int vs = net.addV(), vt = net.addV(), vr = net.addV(); n   net.addE(vs, vr, m, 0); n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) n       if (arr[i] == arr[j]) n         net.addE(i + n, j, 1, 0); n       else n         net.addE(i + n, j, 1, __builtin_popcount(arr[j])); n   for (int i = 0; i < n; i++) { n     net.addE(vr, i, 1, __builtin_popcount(arr[i])); n     net.addE(i, i + n, 1, -MAX); n   } n   for (int i = 0; i < m; i++) net.addE(vr, vt, 1, 0); n   for (int i = 0; i < n; i++) net.addE(i + n, vt, 1, 0); n   net.mcflow(vs, vt, vr, n, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   while (n % 10 == 0) n /= 10; n   stringstream ss; n   ss << n; n   string str = ss.str(); n   string tmp = str; n   reverse(tmp.begin(), tmp.end()); n   if (str == tmp) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n inline int read() { n   int x = 0, w = 1; n   char ch = 0; n   while (ch <  0  || ch >  9 ) { n     ch = getchar(); n     if (ch ==  - ) w = -1; n   } n   while (ch <=  9  && ch >=  0 ) { n     x = (x << 1) + (x << 3) + ch -  0 ; n     ch = getchar(); n   } n   return x * w; n } n int p[10]; n int k1[10], k2[10], ans1[10], ans2[10]; n int a, b, p1, p2, flag; n inline void chk(int n, int c1, int c2) { n   int cnt1 = 0, cnt2 = 0; n   memset(k1, 0, sizeof(k1)); n   memset(k2, 0, sizeof(k2)); n   if ((c1 - c2 <= p1 - p2)) return; n   for (int i = 1; i <= n; ++i) { n     if (p[i] == 1) n       cnt1 += (k1[i] = (i == 5) ? 15 : 25); n     else n       cnt2 += (k2[i] = (i == 5) ? 15 : 25); n   } n   if (cnt1 > a || cnt2 > b) return; n   if (n == 5) { n     if (p[5]) { n       if (cnt2 + 13 <= b) { n         cnt2 += 13; n         k2[5] = 13; n         int now = min(a - cnt1, b - cnt2); n         cnt1 += now, cnt2 += now; n         k1[5] += now, k2[5] += now; n       } n     } else { n       if (cnt1 + 13 <= a) { n         cnt1 += 13; n         k1[5] = 13; n         int now = min(a - cnt1, b - cnt2); n         cnt1 += now, cnt2 += now; n         k1[5] += now, k2[5] += now; n       } n     } n     for (int i = 1; i <= n; ++i) { n       int k = (i == 5) ? 13 : 23; n       if (!p[i]) { n         if (k1[i]) continue; n         if (cnt1 + k > a) n           k1[i] = a - cnt1; n         else n           k1[i] = k; n         cnt1 += k1[i]; n       } else { n         if (k2[i]) continue; n         if (cnt2 + k > b) n           k2[i] = b - cnt2; n         else n           k2[i] = k; n         cnt2 += k2[i]; n       } n     } n     if (cnt1 == a && cnt2 == b && c1 - c2 > p1 - p2) { n       p1 = c1, p2 = c2; n       flag = 1; n       for (int i = 1; i <= n; ++i) ans1[i] = k1[i], ans2[i] = k2[i]; n       return; n     } n   } n   cnt1 = 0, cnt2 = 0; n   memset(k1, 0, sizeof(k1)); n   memset(k2, 0, sizeof(k2)); n   for (int i = 1; i <= n; ++i) { n     if (p[i] == 1) n       cnt1 += (k1[i] = (i == 5) ? 15 : 25); n     else n       cnt2 += (k2[i] = (i == 5) ? 15 : 25); n   } n   if (p[1]) { n     if (cnt2 + 23 <= b) { n       cnt2 += 23; n       k2[1] = 23; n       int now = min(a - cnt1, b - cnt2); n       cnt1 += now, cnt2 += now; n       k1[1] += now, k2[1] += now; n     } n   } else { n     if (cnt1 + 23 <= a) { n       cnt1 += 23; n       k1[1] = 23; n       int now = min(a - cnt1, b - cnt2); n       cnt1 += now, cnt2 += now; n       k1[1] += now, k2[1] += now; n     } n   } n   for (int i = 1; i <= n; ++i) { n     int k = (i == 5) ? 13 : 23; n     if (!p[i]) { n       if (k1[i]) continue; n       if (cnt1 + k > a) n         k1[i] = a - cnt1; n       else n         k1[i] = k; n       cnt1 += k1[i]; n     } else { n       if (k2[i]) continue; n       if (cnt2 + k > b) n         k2[i] = b - cnt2; n       else n         k2[i] = k; n       cnt2 += k2[i]; n     } n   } n   if (cnt1 != a || cnt2 != b) return; n   if (c1 - c2 > p1 - p2) { n     p1 = c1, p2 = c2; n     flag = 1; n     for (int i = 1; i <= n; ++i) ans1[i] = k1[i], ans2[i] = k2[i]; n   } n } n void dfs(int x, int c1, int c2) { n   if (c1 >= 3 || c2 >= 3) { n     chk(x - 1, c1, c2); n     return; n   } n   p[x] = 1; n   dfs(x + 1, c1 + 1, c2); n   p[x] = 0; n   dfs(x + 1, c1, c2 + 1); n } n int main() { n   int T = read(); n   while (T--) { n     a = read(); n     b = read(); n     flag = 0; n     p1 = 0, p2 = 5; n     dfs(1, 0, 0); n     if (!flag) { n       printf( Impossible n ); n       continue; n     } n     printf( %d:%d n , p1, p2); n     for (int i = 1; i <= p1 + p2; ++i) printf( %d:%d  , ans1[i], ans2[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 500, Maxm = 500; n int n, m, x[Maxn], y[Maxn], seq[Maxm]; n bool canGet(int from) { n   bool taken[Maxm] = {}; n   vector<int> ans; n   for (int i = 0; i < n; i++) n     if ((i - from) % 2) n       ans.push_back(-1); n     else { n       int prv = (i - 1 + n) % n; n       int nxt = (i + 1) % n; n       int need = 0; n       if (x[prv] == x[i]) n         need += abs(y[prv] - y[i]); n       else n         need += abs(x[prv] - x[i]); n       if (x[i] == x[nxt]) n         need += abs(y[i] - y[nxt]); n       else n         need += abs(x[i] - x[nxt]); n       int j; n       for (j = 0; j < m; j++) n         if (!taken[j] && seq[j] == need) break; n       if (j == m) return false; n       ans.push_back(j + 1); n       taken[j] = true; n     } n   cout <<  YES n ; n   for (int i = 0; i < ans.size(); i++) { n     if (i) cout <<    ; n     cout << ans[i]; n   } n   cout << endl; n   return true; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; n   for (int i = 0; i < m; i++) cin >> seq[i]; n   if (!canGet(0)) n     if (!canGet(1)) cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1}; n int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n bool cmp(vector<long long> a, vector<long long> b) { return a[2] > b[2]; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   vector<vector<long long>> v; n   for (long long i = 0; i < n; i++) { n     long long a, b, c; n     cin >> a >> b >> c; n     v.push_back({a, b, c}); n   } n   sort((v).begin(), (v).end(), cmp); n   vector<int> adj[n + 1]; n   for (int i = 0; i < n; i++) { n     for (int j = i - 1; j >= 0; j--) { n       long double dis = (v[j][0] - v[i][0]) * (v[j][0] - v[i][0]) + n                         (v[j][1] - v[i][1]) * (v[j][1] - v[i][1]); n       long double dis1 = v[i][2] + v[j][2]; n       if (dis1 * dis1 <= dis) { n         continue; n       } else { n         adj[i].push_back(j); n         adj[j].push_back(i); n         break; n       } n     } n   } n   vector<int> vis(n, 0); n   vector<int> dis(n, 0); n   for (int i = 0; i < n; i++) { n     if (vis[i] == 0) { n       queue<int> q; n       q.push(i); n       vis[i] = 1; n       dis[i] = 1; n       while (!q.empty()) { n         auto a = q.front(); n         q.pop(); n         for (auto i : adj[a]) { n           if (vis[i] == 0) { n             vis[i] = 1; n             dis[i] = dis[a] + 1; n             q.push(i); n           } n         } n       } n     } n   } n   long double ans = 0; n   for (int i = 0; i < n; i++) { n     if (dis[i] % 2 == 0 || dis[i] == 1) { n       ans = n           ans + n           3.141592653589793238462643383279502884197169399375105820974944592307816406286 * n               v[i][2] * v[i][2]; n     } else { n       ans = n           ans - n           3.141592653589793238462643383279502884197169399375105820974944592307816406286 * n               v[i][2] * v[i][2]; n     } n   } n   cout << setprecision(15) << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename L> n inline bool smax(T &x, L y) { n   return x < y ? (x = y, true) : false; n } n template <typename T, typename L> n inline bool smin(T &x, L y) { n   return y < x ? (x = y, true) : false; n } n constexpr int MAXN = 1e5 + 15; n int n; n int a[MAXN]; n int ttime[MAXN]; n stack<int> dq; n int mx; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     ttime[i] = 1; n     while (!dq.empty() && a[i] > a[dq.top()]) { n       smax(ttime[i], ttime[dq.top()] + 1); n       dq.pop(); n     } n     if (!dq.empty()) { n       smax(mx, ttime[i]); n     } else { n       ttime[i] = 1e6 + 15; n     } n     dq.push(i); n   } n   return cout << mx <<   n , false; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1111; n long long fact[N], invfact[N]; n long long n, m, k; n long long powmod(long long x, long long n, long long m = 1000000007) { n   long long ans = 1; n   while (n) { n     if (n & 1) { n       ans = ans * x % m; n     } n     x = x * x % m; n     n >>= 1; n   } n   return ans; n } n inline long long invmod(long long x, long long m = 1000000007) { n   return powmod(x, m - 2); n } n inline long long ncr(long long n, long long r) { n   if (r < 0 || r > n) return 0; n   return fact[n] * invfact[r] % 1000000007 * invfact[n - r] % 1000000007; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> k; n   fact[0] = 1; n   invfact[0] = 1; n   for (long long i = (1); i <= (N - 1); i++) { n     fact[i] = fact[i - 1] * i % 1000000007; n     invfact[i] = invmod(fact[i]); n   } n   long long ans = ncr(n - 1, 2 * k) * ncr(m - 1, 2 * k) % 1000000007; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int data = 0, w = 1; n   char ch = getchar(); n   while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar(); n   if (ch ==  - ) w = -1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) n     data = (data << 3) + (data << 1) + (ch ^ 48), ch = getchar(); n   return data * w; n } n const int maxn(200010); n long long n, a[maxn], x, f, ans; n int main() { n   n = read(); n   for (register int i = 1; i <= n; i++) a[i] = read(); n   x = read(); n   f = read(); n   for (register int i = 1; i <= n; i++) { n     a[i] -= x; n     if (a[i] > 0) { n       if (!(a[i] % (x + f))) n         ans += (a[i] / (x + f)) * f; n       else n         ans += (1 + a[i] / (x + f)) * f; n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   long long int n, l, r; n   cin >> n >> l >> r; n   if (n == 0) { n     cout << 0 << endl; n     return 0; n   } else if (n == 1) { n     cout << 1 << endl; n     return 0; n   } else if (n == 2) { n     vector<long long int> a; n     a.push_back(1), a.push_back(0), a.push_back(1); n     int i; n     int c = 0; n     for (i = l - 1; i < r; i++) { n       if (a[i] == 1) c++; n     } n     cout << c << endl; n     return 0; n   } else if (n == 3) { n     vector<long long int> a; n     a.push_back(1), a.push_back(1), a.push_back(1); n     int i; n     int c = 0; n     for (i = l - 1; i < r; i++) { n       if (a[i] == 1) c++; n     } n     cout << c << endl; n     return 0; n   } n   long long int t = n; n   long long int ct = 1; n   while (t != 3 && t != 2) { n     ct++; n     t = t / 2; n   } n   long long int tt = n; n   long long int ans3 = 0; n   while (tt > 3) { n     long long int kk = 0; n     long long int vv = 0; n     long long int ll, rr; n     vv = pow(2, ct); n     ll = l - vv - 1; n     if (ll >= 0) { n       ll = ll / pow(2, ct + 1) + 1; n     } n     rr = r - vv + 1; n     if (rr >= 0) { n       rr = rr / pow(2, ct + 1) + 1; n     } n     if (ll < 0) ll = 0; n     if ((rr >= 0 && ll >= 0) && (tt & 1)) { n       ans3 += rr - ll; n     } n     kk++; n     ct--; n     tt = tt / 2; n   } n   if (t == 2) { n     long long int ans; n     long long int left = 0; n     long long int right = 0; n     left = 2 * ((l - 1) / 4); n     if ((l - 1) % 4 == 1 || ((l - 1) % 4) == 2) n       left++; n     else if ((l - 1) % 4 == 3) n       left += 2; n     right = 2 * (r / 4); n     if ((r % 4) == 1 || (r % 4) == 2) n       right++; n     else if ((r % 4) == 3) n       right += 2; n     ans = right - left; n     t = 2 * t + t % 2; n     cout << ans + ans3 << endl; n   } else if (t == 3) { n     long long int ans; n     long long int left = 0; n     long long int right = 0; n     left = 3 * ((l - 1) / 4); n     left += (l - 1) % 4; n     right = 3 * (r / 4); n     right += r % 4; n     ans = right - left; n     cout << ans + ans3 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 1010; n const int INF = 1000000000; n int n; n int x[MaxN], y[MaxN], tx[MaxN], ty[MaxN]; n long double L, R; n long double det(long double x1, long double y1, long double x2, long double y2, n                 long double x3, long double y3) { n   return x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3; n } n void line(long double x1, long double y1, long double x2, long double y2, n           long double y0, long double& x0) { n   long double A = y1 - y2; n   long double B = x2 - x1; n   long double C = A * x1 + B * y1; n   x0 = (C - B * y0) / A; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i]; n   L = x[1], R = x[2]; n   if (L > R) { n     for (int i = 1, j = 2; i <= n; ++i) { n       tx[i] = x[j]; n       ty[i] = -y[j]; n       --j; n       if (!j) j = n; n     } n     for (int i = 1; i <= n; ++i) { n       x[i] = tx[i]; n       y[i] = ty[i]; n     } n     swap(L, R); n   } n   for (int i = 3; i <= n; ++i) { n     int px = x[1], py = y[1]; n     for (int j = i + 1; j <= n; ++j) n       if (det(x[i], y[i], x[j], y[j], px, py) > 0) { n         px = x[j]; n         py = y[j]; n       } n     long double tmp; n     line(x[i], y[i], px, py, y[1], tmp); n     L = max(L, tmp); n     px = x[2], py = y[2]; n     for (int j = 3; j < i; ++j) n       if (det(x[i], y[i], px, py, x[j], y[j]) > 0) { n         px = x[j]; n         py = y[j]; n       } n     line(x[i], y[i], px, py, y[1], tmp); n     R = min(R, tmp); n   } n   int ans = 0; n   for (int i = L - 1; i <= R + 1; ++i) n     if (L <= i && i <= R) ++ans; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (T& x : v) is >> x; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] << (i + 1 == (int)v.size() ?    :    ); n   } n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const map<T, U>& m) { n   os <<  { ; n   for (auto itr = m.begin(); itr != m.end();) { n     os <<  (  << itr->first <<  ,  << itr->second <<  ) ; n     if (++itr != m.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const unordered_map<T, U>& m) { n   os <<  { ; n   for (auto itr = m.begin(); itr != m.end();) { n     os <<  (  << itr->first <<  ,  << itr->second <<  ) ; n     if (++itr != m.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const multiset<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const unordered_set<T>& s) { n   os <<  { ; n   for (auto itr = s.begin(); itr != s.end();) { n     os << *itr; n     if (++itr != s.end()) os <<  , ; n   } n   os <<  } ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const deque<T>& v) { n   for (int i = 0; i < (int)v.size(); i++) { n     os << v[i] << (i + 1 == (int)v.size() ?    :    ); n   } n   return os; n } n template <int i, typename T> n void print_tuple(ostream&, const T&) {} n template <int i, typename T, typename 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 <typename... 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 debug_out() { cerr <<   n ; } n template <class Head, class... Tail> n void debug_out(Head&& head, Tail&&... tail) { n   cerr << head; n   if (sizeof...(Tail) > 0) cerr <<  ,  ; n   debug_out(move(tail)...); n } n template <typename T> n T gcd(T x, T y) { n   return y != 0 ? gcd(y, x % y) : x; n } n template <typename T> n T lcm(T x, T y) { n   return x / gcd(x, y) * y; n } n int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } n int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } n int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); } n int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); } n int popcount(signed t) { return __builtin_popcount(t); } n int popcount(long long t) { return __builtin_popcountll(t); } n bool ispow2(int i) { return i && (i & -i) == i; } n template <class T> n T ceil(T x, T y) { n   assert(y >= 1); n   return (x > 0 ? (x + y - 1) / y : x / y); n } n template <class T> n T floor(T x, T y) { n   assert(y >= 1); n   return (x > 0 ? x / y : (x - y + 1) / y); n } n template <class T1, class T2> n inline bool chmin(T1& a, T2 b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T1, class T2> n inline bool chmax(T1& a, T2 b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n const int INF = 1e9; n const long long IINF = 1e18; n const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n const char dir[4] = { D ,  R ,  U ,  L }; n const long long MOD = 1000000007; n void solve() { n   long long n; n   cin >> n; n   long long l = -(n - 1), r = n; n   cout << l <<     << r <<   n ; n } n int main() { n   cin.tie(0); n   ios::sync_with_stdio(false); n   int t; n   cin >> t; n   for (; t--;) solve(); 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 s1, s2; n     cin >> s1 >> s2; n     int len1 = s1.length(), len2 = s2.length(); n     int a[26] = {0}, mark = 0; n     multiset<char, greater<int> > st1, st2; n     for (int i = 0; i < len1; i++) { n       a[s1[i] - 97]++; n       st1.insert(s1[i]); n     } n     for (int i = 0; i < len2; i++) { n       if (a[s2[i] - 97] > 0) { n         int b[26] = {0}; n         st2.clear(); n         for (int j = i; j < len2; j++) { n           b[s2[j] - 97]++; n           if (b[s2[j] - 97] > a[s2[j] - 97]) { n             break; n           } else { n             st2.insert(s2[j]); n           } n         } n         if (st1 == st2) { n           mark = 1; n           break; n         } n       } n     } n     if (mark == 0) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 2e5 + 5; n const long long SQRTN = 1003; n const long long LOGN = 22; n const double PI = acos(-1.0); n const long long INF = 1e18; n const long long MOD = 1e9 + 7; n const long long FMOD = 998244353; n const double eps = 1e-9; n void __print(long long x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   long long f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); n template <typename T> n T gcd(T a, T b) { n   if (b == 0) return a; n   a %= b; n   return gcd(b, a); n } n template <typename T> n T lcm(T a, T b) { n   return (a * (b / gcd(a, b))); n } n long long add(long long a, long long b, long long c = MOD) { n   long long res = a + b; n   return (res >= c ? res % c : res); n } n long long sub(long long a, long long b, long long c = MOD) { n   long long res; n   if (abs(a - b) < c) n     res = a - b; n   else n     res = (a - b) % c; n   return (res < 0 ? res + c : res); n } n long long mul(long long a, long long b, long long c = MOD) { n   long long res = (long long)a * b; n   return (res >= c ? res % c : res); n } n long long muln(long long a, long long b, long long c = MOD) { n   long long res = (long long)a * b; n   return ((res % c) + c) % c; n } n long long mulmod(long long a, long long b, long long m = MOD) { n   long long q = (long long)(((long double)a * (long double)b) / (long double)m); n   long long r = a * b - q * m; n   if (r > m) r %= m; n   if (r < 0) r += m; n   return r; n } n template <typename T> n T binpow(T e, T n) { n   T x = 1, p = e; n   while (n) { n     if (n & 1) x = x * p; n     p = p * p; n     n >>= 1; n   } n   return x; n } n template <typename T> n T binpow2(T e, T n, T m = MOD) { n   T x = 1, p = e; n   while (n) { n     if (n & 1) x = mul(x, p, m); n     p = mul(p, p, m); n     n >>= 1; n   } n   return x; n } n template <typename T> n T extended_euclid(T a, T b, T &x, T &y) { n   T xx = 0, yy = 1; n   y = 0; n   x = 1; n   while (b) { n     T q = a / b, t = b; n     b = a % b; n     a = t; n     t = xx; n     xx = x - q * xx; n     x = t; n     t = yy; n     yy = y - q * yy; n     y = t; n   } n   return a; n } n template <typename T> n T mod_inverse(T a, T n = MOD) { n   T x, y, z = 0; n   T d = extended_euclid(a, n, x, y); n   return (d > 1 ? -1 : sub(x, z, n)); n } n const long long FACSZ = 1e4; n long long fact[FACSZ], ifact[FACSZ]; n void precom(long long c = MOD) { n   fact[0] = 1; n   for (long long i = 1; i < FACSZ; i++) fact[i] = mul(fact[i - 1], i, c); n   ifact[FACSZ - 1] = mod_inverse(fact[FACSZ - 1], c); n   for (long long i = FACSZ - 1 - 1; i >= 0; i--) { n     ifact[i] = mul(i + 1, ifact[i + 1], c); n   } n } n vector<long long> primes; n void prime_precom() { n   primes.push_back(2); n   for (long long x = 3; primes.size() <= MAXN; x += 2) { n     bool isPrime = true; n     for (auto p : primes) { n       if (x % p == 0) { n         isPrime = false; n         break; n       } n       if (p * p > x) { n         break; n       } n     } n     if (isPrime) { n       primes.push_back(x); n     } n   } n } n long long ncr(long long n, long long k) { n   if (n < k) return 0; n   if (k == 0) return 1; n   long long res = 1; n   if (k > n - k) k = n - k; n   for (long long i = 0; i < k; ++i) { n     res *= (n - i); n     res /= (i + 1); n   } n   return res; n } n long long ncr_modp(long long n, long long k, long long c = MOD) { n   if (n < k) return 0; n   if (k == 0) return 1; n   long long res = 1; n   if (k > n - k) k = n - k; n   for (long long i = 0; i < k; ++i) { n     res = mul(res, n - i, c); n     res = mul(res, binpow2(i + 1, c - 2, c), c); n   } n   return res; n } n vector<long long> factors; n void factorize(long long a) { n   factors.clear(); n   for (long long i = 1; i * i <= a; i++) { n     if (a % i == 0) { n       factors.push_back(i); n       factors.push_back(a / i); n     } n   } n   sort(factors.begin(), factors.end()); n } n long long ncr_precom(long long n, long long r, long long c = MOD) { n   return mul(mul(ifact[r], ifact[n - r], c), fact[n], c); n } n long long ceil(long long a, long long b) { return (a + b - 1) / b; } n bool is_prime(long long n) { n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       return 0; n     } n   } n   return 1; n } n bool diophantine_checker(long long a, long long b, long long n) { n   for (long long i = 0; i * a <= n; i++) { n     if ((n - (i * a)) % b == 0) { n       return true; n     } n   } n   return false; n } n long long count_divisors(long long n) { n   long long c; n   long long ans = 1; n   for (long long i = 2; i * i <= n; i++) { n     c = 0; n     while (n % i == 0) { n       c++; n       n /= i; n     } n     ans *= (c + 1); n   } n   if (n > 2) { n     return ans * 2; n   } n   return ans; n } n string to_binary(long long n) { n   string r; n   while (n != 0) { n     r = (n % 2 == 0 ?  0  :  1 ) + r; n     n /= 2; n   } n   return r; n } n bool ispower2(long long x) { return x && (!(x & (x - 1))); } n vector<long long> spf; n void sieve() { n   spf.resize(MAXN); n   spf[1] = 1; n   for (long long i = 2; i < MAXN; i++) { n     spf[i] = i; n   } n   for (long long i = 4; i < MAXN; i += 2) { n     spf[i] = 2; n   } n   for (long long i = 3; i * i <= MAXN; i++) { n     if (spf[i] == i) { n       for (long long j = i * i; j < MAXN; j += i) { n         if (spf[j] == j) { n           spf[j] = i; n         } n       } n     } n   } n } n void pfactor(long long x, vector<long long> &ret) { n   while (x != 1) { n     ret.push_back(spf[x]); n     x = x / spf[x]; n   } n } n struct point { n   long long x, y; n   void read() { cin >> x >> y; } n   point operator-=(const point &b) { return {x -= b.x, y -= b.y}; } n   long long operator*(const point &b) { return x * b.y - y * b.x; } n   point operator-(const point &b) { return {x - b.x, y - b.y}; } n }; n long long n, k; n long double dist[MAXN], angle[MAXN]; n bool check(long double r) { n   vector<pair<long double, long long>> val; n   long long cnt = 0; n   for (long long i = 0; i < n; i++) { n     if (dist[i] + eps >= 2 * r) { n       continue; n     } n     long double bd = acos(dist[i] / (2. * r)); n     long double mn = angle[i] - bd, mx = angle[i] + bd; n     while (mn < -PI) { n       mn += 2 * PI; n     } n     while (mx < -PI) { n       mx += 2 * PI; n     } n     while (mn > PI) { n       mn -= 2 * PI; n     } n     while (mx > PI) { n       mx -= 2 * PI; n     } n     val.push_back(make_pair(mn, 1)); n     val.push_back(make_pair(mx, -1)); n     if (mn > mx) { n       cnt += 1; n     } n   } n   long long ans = cnt; n   sort(val.begin(), val.end()); n   for (auto x : val) { n     cnt += x.second, ans = max(ans, cnt); n   } n   return ans >= k; n } n void solvethetestcase() { n   cin >> n >> k; n   vector<point> vv; n   for (long long i = 0; i < n; i++) { n     long long xx, yy; n     cin >> xx >> yy; n     if (xx == 0 && yy == 0) { n       --k, --n, --i; n     } else { n       vv.push_back(point{xx, yy}); n     } n   } n   if (k <= 0) { n     cout << 0.0 <<   n ; n     return; n   } n   for (long long i = 0; i < n; i++) { n     angle[i] = atan2(vv[i].y, vv[i].x); n     dist[i] = sqrtl(1. * vv[i].x * vv[i].x + 1. * vv[i].y * vv[i].y); n   } n   long double l = 0, r = 2e5; n   for (long long i = 0; i < 50; i++) { n     long double md = (l + r) * 0.5; n     if (check(md)) { n       r = md; n     } else { n       l = md; n     } n   } n   cout << r <<   n ; n } n signed main() { n   cout << fixed << setprecision(12); n   ; n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   for (long long testcase = 1; testcase < t + 1; testcase++) { n     solvethetestcase(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, t[100005]; n int l1, l2; n int dp[100005]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &t[i]); n   l1 = 1; n   l2 = 1; n   for (int i = 1; i <= n; ++i) { n     while (t[i] - t[l1] > 89) ++l1; n     while (t[i] - t[l2] > 1439) ++l2; n     dp[i] = 1e9; n     dp[i] = min(dp[i], dp[i - 1] + 20); n     dp[i] = min(dp[i], dp[l1 - 1] + 50); n     dp[i] = min(dp[i], dp[l2 - 1] + 120); n   } n   for (int i = 1; i <= n; ++i) printf( %d n , dp[i] - dp[i - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[105]; n int n, k; n char s[105]; n int main(void) { n   int i, j, x, y, z; n   scanf( %d %d , &n, &k); n   scanf( %s , s); n   x = 0; n   for (i = 0; i < s[i]; i++) { n     a[x++] = s[i] -  a  + 1; n   } n   sort(a, a + n); n   x = 1; n   y = a[0]; n   z = 0; n   if (x == k) { n     printf( %d n , y); n     return 0; n   } n   for (i = 1; i < n; i++) { n     if (a[i] - a[z] > 1) { n       x++; n       y += a[i]; n       z = i; n       if (x == k) break; n     } n   } n   if (i >= n) { n     printf( -1 ); n     return 0; n   } n   printf( %d n , y); 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   cout.tie(0); n   int n, m, k = 0, k1 = 0, kol1 = 0, kol2 = 0; n   cin >> n >> m; n   int a[n + 10], b[m + 10]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] % 2 == 1) n       k++; n     else n       k1++; n   } n   for (int i = 1; i <= m; i++) { n     cin >> b[i]; n     if (b[i] % 2 == 1) n       kol1++; n     else n       kol2++; n   } n   cout << min(k, kol2) + min(k1, kol1); 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, a, b, x, y, flag = 0; n   cin >> n >> a >> x >> b >> y; n   int in = 0; n   for (int i = 0; i < n; i++) { n     a = a % n + 1; n     b = b - 1; n     if (b == 0) b = n; n     if (a == b) { n       cout <<  YES ; n       flag = 1; n       break; n     } n     if (a == x or b == y) break; n   } n   if (flag == 0) cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[301]; n int l[301], r[301]; n void INPUT() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= m; i++) cin >> l[i] >> r[i]; n } n void SOLVE() { n   int res = 0; n   int ans[301], tam[301]; n   int sl = 0; n   int i, j, k; n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) n       if (i == j) n         continue; n       else { n         int dem = 0; n         for (k = 1; k <= m; k++) n           if (l[k] <= j & j <= r[k] & (l[k] > i || r[k] < i)) { n             dem++; n             tam[dem] = k; n           } n         if (res < a[i] - a[j] + dem) { n           res = a[i] - a[j] + dem; n           sl = dem; n           for (k = 1; k <= sl; k++) ans[k] = tam[k]; n         } n       } n   cout << res << endl; n   cout << sl << endl; n   for (i = 1; i <= sl; i++) cout << ans[i] <<    ; n } n int main() { n   INPUT(); n   SOLVE(); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 500010; n bool f[MAXN]; n int main() { n   int n, d; n   scanf( %d %d , &n, &d); n   f[0] = 1; n   for (int i = 0; i < n; i++) { n     int x; n     scanf( %d , &x); n     for (int j = MAXN - 1 - x; j >= 0; --j) f[j + x] |= f[j]; n   } n   int r = 1, sum = 0, ans = 0; n   while (r < MAXN) { n     int next = -1; n     while (r <= sum + d && r < MAXN) { n       if (f[r]) next = r; n       r++; n     } n     if (next == -1) break; n     sum = next; n     ans++; n   } n   printf( %d %d n , sum, ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 7; n long long a[N]; n long long l[N]; n long long r[N]; n int32_t main() { n   long long ans = 0, n, i; n   for (i = 1, scanf( %I64d , &n); i <= n; scanf( %I64d , &a[i++])) n     ; n   for (i = 1; i <= n; l[i] = r[i] = i, i++) n     ; n   for (i = 2; i <= n; i++) { n     long long num = i; n     while (num > 1 && a[num - 1] <= a[i]) num = l[num - 1]; n     l[i] = num; n   } n   for (i = n - 1; i >= 1; i--) { n     long long num = i; n     while (num < n && a[num + 1] < a[i]) num = r[num + 1]; n     r[i] = num; n   } n   for (i = 1; i <= n; ans += (i - l[i] + 1) * (r[i] - i + 1) * a[i], i++) n     ; n   for (i = 1; i <= n; l[i] = r[i] = i, i++) n     ; n   for (i = 2; i <= n; i++) { n     long long num = i; n     while (num > 1 && a[num - 1] >= a[i]) num = l[num - 1]; n     l[i] = num; n   } n   for (i = n - 1; i >= 1; i--) { n     long long num = i; n     while (num < n && a[num + 1] > a[i]) num = r[num + 1]; n     r[i] = num; n   } n   for (i = 1; i <= n; i++) { n     ans -= (i - l[i] + 1) * (r[i] - i + 1) * a[i]; n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353, inv2 = (mod + 1) / 2; n const int N = (1 << 24); n int n, m, X, Y, Z, mu, v1, v2, v3, v4, inv; n vector<int> a, b, c, ans; n inline int add(const int &x, const int &y) { n   return x + y < mod ? x + y : x + y - mod; n } n inline int sub(const int &x, const int &y) { n   return x - y < 0 ? x - y + mod : x - y; n } n inline int mul(const int &x, const int &y) { n   return (int)((long long)x * y % mod); n } n int ksm(int x, int y = mod - 2) { n   int ss = 1; n   for (; y; y >>= 1, x = mul(x, x)) n     if (y & 1) ss = mul(ss, x); n   return ss; n } n void fwt(vector<int> &A, int lmt, int opt) { n   A.resize(lmt); n   for (int mid = 1; mid < lmt; mid <<= 1) n     for (int j = 0; j < lmt; j += mid << 1) n       for (int k = 0; k < mid; k++) { n         int x = A[j + k], y = A[j + mid + k]; n         A[j + k] = add(x, y), A[j + mid + k] = sub(x, y); n         if (opt == -1) { n           A[j + k] = mul(A[j + k], inv2); n           A[j + mid + k] = mul(A[j + mid + k], inv2); n         } n       } n } n int main() { n   scanf( %d%d , &n, &m), m = 1 << m, inv = ksm(4); n   a.resize(m), b.resize(m), c.resize(m), ans.resize(m); n   scanf( %d%d%d , &X, &Y, &Z); n   for (int i = 1, x, y, z; i <= n; i++) { n     scanf( %d%d%d , &x, &y, &z), mu ^= x; n     ++a[x ^ y], ++b[x ^ z], ++c[y ^ z]; n   } n   fwt(a, m, 1), fwt(b, m, 1), fwt(c, m, 1); n   v1 = add(X, add(Y, Z)), v2 = add(X, sub(Y, Z)); n   v3 = add(X, sub(Z, Y)), v4 = sub(X, add(Z, Y)); n   for (int i = 0; i < m; i++) { n     int x1 = ksm( n         v1, ((long long)n + a[i] + b[i] + c[i] + 4ll * mod) % mod * inv % mod); n     int x2 = ksm( n         v2, ((long long)n + a[i] - b[i] - c[i] + 4ll * mod) % mod * inv % mod); n     int x3 = ksm( n         v3, ((long long)n - a[i] + b[i] - c[i] + 4ll * mod) % mod * inv % mod); n     int x4 = ksm( n         v4, ((long long)n - a[i] - b[i] + c[i] + 4ll * mod) % mod * inv % mod); n     ans[i] = mul(x1, mul(x2, mul(x3, x4))); n   } n   fwt(ans, m, -1); n   for (int i = 0; i < m; i++) printf( %d  , ans[i ^ mu]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n int fans = 1; n long long getnum(long long x) { n   long long fx, fy; n   if (x >= (n - k + 1)) { n     fx = (n - k + 1 + 1) * (n - k + 1) / 2 + (x - (n - k + 1)) * (n - k + 1); n   } else { n     fx = (x - 1 + 1) * (x - 1) / 2 + (n - k + 1); n   } n   if (x >= k) { n     fy = (k + 1) * k / 2 + (x - k) * k; n   } else { n     fy = (x - 1 + 1) * (x - 1) / 2 + k; n   } n   return fx + fy - x; n } n void start(int l, int r) { n   if ((l + r) / 2 == l) { n     if (getnum((l + r) / 2) <= m) fans = (l + r) / 2; n     return; n   } n   int mid = (l + r) / 2; n   if (getnum(mid) <= m) { n     fans = max(fans, mid); n     start(mid + 1, r); n   } else n     start(l, mid); n } n int main() { n   cin >> n >> m >> k; n   start(1, m); n   cout << fans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   char ch[106][106]; n   scanf( %d%d  , &n, &m); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> ch[i][j]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if (ch[i][j] ==  C  || ch[i][j] ==  M  || ch[i][j] ==  Y ) { n         printf( #Color n ); n         return 0; n       } n   printf( #Black&White n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int cnt[2][2]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     cnt[0][x % 2]++; n   } n   for (int i = 1; i <= m; i++) { n     int x; n     cin >> x; n     cnt[1][x % 2]++; n   } n   cout << min(cnt[0][0], cnt[1][1]) + min(cnt[0][1], cnt[1][0]) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 10; n int ans[maxn]; n bool build(int l, int r, int base, int top, int sum) { n   if (l > r) return true; n   int len = r - l + 1; n   int tmp = len * base; n   if (tmp > sum) return false; n   if (tmp == sum) { n     for (int i = l; i <= r; ++i) ans[i] = base; n     return true; n   } n   if (base == top) return false; n   if (tmp + len >= sum) { n     for (int i = l; i <= r; ++i) { n       sum -= base; n       ans[i] = base; n     } n     for (int i = l; i <= r; ++i) { n       if (!sum) break; n       sum--; n       ans[i]++; n     } n     return true; n   } n   return false; n } n int main() { n   int n, k, l, r, sall, sk; n   scanf( %d%d%d%d%d%d , &n, &k, &l, &r, &sall, &sk); n   int lim; n   for (int i = r; i >= l; --i) { n     if (build(1, k, i, r, sk)) { n       lim = i; n       break; n     } n   } n   for (int i = lim; i >= l; --i) { n     if (build(k + 1, n, i, lim, sall - sk)) { n       break; n     } n   } n   for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = 2000000000000000000; n long long int MOD(long long int a, long long int b) { n   if (a > b) n     return a - b; n   else n     return b - a; n } n long long int max3(long long int a, long long int b, long long int c) { n   return max(c, max(a, b)); n } n long long int min3(long long int a, long long int b, long long int c) { n   return min(a, min(b, c)); n } n long long int power(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % 1000000007; n     y = y >> 1; n     x = (x * x) % 1000000007; n   } n   return res; n } n long long int logg(long long int a) { n   long long int x = 0; n   while (a > 1) { n     x++; n     a /= 2; n   } n   return x; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<string> grid; n   grid.resize(n); n   for (int i = 0; i < n; i++) { n     cin >> grid[i]; n   } n   vector<int> columns; n   columns.resize(n, 0); n   vector<int> rows; n   rows.resize(m, 0); n   for (int i = 0; i < n; i++) { n     vector<int> cnt; n     for (int j = 0; j < m; j++) { n       if (grid[i][j] ==  # ) { n         cnt.push_back(j); n       } n     } n     if (!cnt.empty()) { n       vector<int> b; n       for (int j = 0; j < n; j++) { n         if (grid[j][cnt[0]] ==  # ) { n           b.push_back(j); n         } n       } n       sort(b.begin(), b.end()); n       sort(cnt.begin(), cnt.end()); n       for (int j = 0; j < cnt.size(); j++) { n         int num = 0; n         for (int i = 0; i < n; i++) { n           if (grid[i][cnt[j]] ==  #  && n               binary_search(b.begin(), b.end(), i) == false) { n             cout <<  NO ; n             return 0; n           } else { n             if (grid[i][cnt[j]] ==  # ) { n               num++; n             } n           } n         } n         if (num != b.size()) { n           cout <<  NO ; n           return 0; n         } n       } n       for (int i = 0; i < b.size(); i++) { n         int num = 0; n         for (int j = 0; j < m; j++) { n           if (grid[b[i]][j] ==  #  && n               binary_search(cnt.begin(), cnt.end(), j) == false) { n             cout <<  NO ; n             return 0; n           } else { n             if (grid[b[i]][j] ==  # ) { n               num++; n             } n           } n         } n         if (num != cnt.size()) { n           cout <<  NO ; n           return 0; n         } n       } n     } n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const long long mod = 1e9 + 7; n const int inf = 1 << 30; n const int maxn = 900500; n const double EPS = 1e-7; n struct da { n   int x, ty; n   double p; n   bool operator<(const da& ot) const { n     return (make_pair(x, make_pair(ty, p)) < n             make_pair(ot.x, make_pair(ot.ty, ot.p))); n   } n }; n vector<da> ev; n void solve() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < (int)(n); ++i) { n     int ai, hi, li, ri; n     scanf( %d%d , &ai, &hi); n     scanf( %d%d , &li, &ri); n     double lp = 1.0 - li / 100., rp = 1.0 - ri / 100.; n     ev.push_back({ai - hi, -1, lp}); n     ev.push_back({ai - 1, 1, lp}); n     ev.push_back({ai + 1, -1, rp}); n     ev.push_back({ai + hi, 1, rp}); n   } n   for (int i = 0; i < (int)(m); ++i) { n     int bj, zj; n     scanf( %d%d , &bj, &zj); n     ev.push_back({bj, 0, 1. * zj}); n   } n   sort(ev.begin(), ev.end()); n   int ze = 0; n   double pr = 0, ret = 0; n   for (auto e : ev) { n     if (e.ty == 0) { n       if (!ze) ret += exp(pr) * e.p; n     } else if (e.ty == -1) { n       if (abs(e.p) < 1e-7) n         ++ze; n       else n         pr += log(e.p); n     } else { n       if (abs(e.p) < 1e-7) n         --ze; n       else n         pr -= log(e.p); n     } n   } n   printf( %lf n , ret); n } n int main() { n   int tc = 1; n   for (int tt = 0; tt < (int)(tc); ++tt) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char *argv[]) { n   int t; n   cin >> t; n   while (t--) { n     int len; n     cin >> len; n     string s1, s2; n     cin >> s1 >> s2; n     int cnt1 = 0, cnt2 = 0; n     if (s1[0] >  2 ) { n       cnt1++; n       if (s2[0] <=  2 ) { n         puts( NO ); n         continue; n       } n       cnt2++; n     } n     bool flag = true; n     for (int i = 1; i < s1.size(); ++i) { n       if (cnt1 % 2) { n         if (s2[i] >  2 ) { n           cnt2++; n           if (s1[i] <=  2 ) { n             flag = false; n             break; n           } n           cnt1++; n         } n       } else { n         if (s1[i] >  2 ) { n           cnt1++; n           if (s2[i] <=  2 ) { n             flag = false; n             break; n           } n           cnt2++; n         } n       } n     } n     if (cnt2 % 2 == 0) flag = false; n     if (flag) { n       puts( YES ); n     } else { n       puts( NO ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(time(0)); n const long long N = 3e5 + 7; n const long long MOD = 1e9 + 7; n long long pw(long long b, long long p) { n   b %= MOD; n   long long res = 1; n   while (p > 0) { n     if (p & 1) res = res * b % MOD; n     b = b * b % MOD; n     p >>= 1; n   } n   return res; n } n long long n, m, cur; n vector<vector<pair<long long, char>>> g(107); n bool vis[107][107][26], dp[107][107][26]; n bool dfs(long long u, long long v, char ch) { n   if (vis[u][v][ch -  a ]) return dp[u][v][ch -  a ]; n   for (auto i : g[u]) { n     if (i.second >= ch && !dfs(v, i.first, i.second)) dp[u][v][ch -  a ] = 1; n   } n   vis[u][v][ch -  a ] = 1; n   return dp[u][v][ch -  a ]; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   long long u, v; n   char ch; n   for (long long i = 1; i < m + 1; i++) { n     cin >> u >> v >> ch; n     g[u].emplace_back(v, ch); n   } n   for (long long i = 1; i < n + 1; i++) { n     for (long long j = 1; j < n + 1; j++) { n       if (dfs(i, j,  a )) n         cout <<  A ; n       else n         cout <<  B ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n struct number_iterator : iterator<random_access_iterator_tag, T> { n   T v; n   number_iterator(T _v) : v(_v) {} n   operator T &() { return v; } n   T operator*() const { return v; } n }; n template <typename T> n struct number_range { n   T b, e; n   number_range(T b, T e) : b(b), e(e) {} n   number_iterator<T> begin() { return b; } n   number_iterator<T> end() { return e; } n }; n template <typename T> n number_range<T> range(T e) { n   return number_range<T>(0, e); n } n template <typename T> n number_range<T> range(T b, T e) { n   return number_range<T>(b, e); n } n template <typename... Args> n void logger(string vars, Args &&...values) { n   cout <<  [  << vars <<  ]  n        <<   =  ; n   string delim =   ; n   cout <<  [  << (..., (cout << delim << values, delim =  ,  )) <<  ]  n        <<   n ; n } n template <typename T> n void debug(vector<T> v) { n   cout <<  { ; n   for (auto i : range(v.size())) n     cout << v[i] << (i + 1 == v.size() ?    :  ,  ); n   cout <<  }  n        <<   n ; n } n template <typename T, typename S> n void debug(pair<T, S> &p) { n   cout <<  ( ; n   cout << p.first <<  ,   << p.second; n   cout <<  ) ; n } n template <typename T, typename S> n void debug(vector<pair<T, S>> vp) { n   cout <<  { ; n   for (auto i : range(vp.size())) { n     debug(vp[i]); n     cout << (i + 1 == vp.size() ?    :  ,  ); n   } n   cout <<  }  n        <<   n ; n } n template <typename T> n void debug(vector<vector<T>> vv) { n   cout <<  [ ; n   for (auto i : range(vv.size())) debug(vv[i]); n   cout <<  ]  n        <<   n ; n } n template <typename T> n void debug(T a[], long long n) { n   cout <<  { ; n   for (auto i : range(n)) cout << a[i] << (i + 1 == n ?    :  ,  ); n   cout <<  }  n        <<   n ; n } n template <typename T> n void debug(set<T> s) { n   cout <<  { ; n   for (auto i = s.begin(); i != s.end();) n     cout << *i << (++i == s.end() ?    :  ,  ); n   cout <<  }  n        <<   n ; n } n template <typename T> n void debug(multiset<T> s) { n   cout <<  { ; n   for (auto i = s.begin(); i != s.end();) n     cout << *i << (++i == s.end() ?    :  ,  ); n   cout <<  }  n        <<   n ; n } n template <typename T1, typename T2> n void debug(map<T1, T2> make_pair) { n   cout <<  { ; n   for (auto i = make_pair.begin(); i != make_pair.end();) n     cout <<  (  << i->first <<   :   << i->second <<  )  n          << (++i == make_pair.end() ?    :  , ); n   cout <<  }  n        <<   n ; n } n long long modExpo(long long a, long long b, long long m = 1000000007) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % m; n     a = (a * a) % m; n     b = b >> 1; n   } n   return res; n } n void extendEuclids(long long a, long long b, long long *v) { n   if (b == 0) { n     v[0] = 1, v[1] = 0, v[2] = a; n     return; n   } n   extendEuclids(b, a % b, v); n   long long x = v[1]; n   v[1] = v[0] - v[1] * (a / b); n   v[0] = x; n   return; n } n long long modInv(long long a, long long b) { n   long long arr[3]; n   extendEuclids(a, b, arr); n   return arr[0]; n } n long long modInv_lil(long long a, long long b) { return modExpo(a, b - 2, b); } n long long add(long long a, long long b, long long c = 1000000007) { n   long long res = a + b; n   return (res >= c ? res - c : res); n } n long long mod_mul(long long a, long long b, long long c = 1000000007) { n   long long res = a * b; n   return (res >= c ? res % c : res); n } n long long mod_sub(long long a, long long b, long long m = 1000000007) { n   a = a % m; n   b = b % m; n   return (((a - b) % m) + m) % m; n } n long long mod_div(long long a, long long b, long long m = 1000000007) { n   a = a % m; n   b = b % m; n   return (mod_mul(a, modInv_lil(b, m), m) + m) % m; n } n class Solution { n  public: n   void Solve() { n     string t, s; n     cin >> t >> s; n     deque<char> a, b; n     sort((t).begin(), (t).end()); n     sort((s).begin(), (s).end(), greater<long long>()); n     long long n = t.length(), i = 0, j = 0, cnt1, cnt2; n     string ansr, ansl; n     cnt1 = ceil((double)n / (double)2); n     cnt2 = n / 2; n     for (auto i : range(cnt1)) a.push_back(t[i]); n     for (auto i : range(cnt2)) b.push_back(s[i]); n     while (i < n) { n       if (i & 1) { n         if (!a.empty() && a[0] >= b[0]) { n           ansr += b.back(); n           b.pop_back(); n         } else { n           ansl += b[0]; n           b.pop_front(); n         } n       } else { n         if (!b.empty() && a[0] >= b[0]) { n           ansr += a.back(); n           a.pop_back(); n         } else { n           ansl += a[0]; n           a.pop_front(); n         } n       } n       i += 1; n     } n     reverse((ansr).begin(), (ansr).end()); n     cout << ansl + ansr; n   } n }; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   Solution ob; n   { ob.Solve(); } n   return 0; n } n template <typename T> n inline T Max(const T a, const T b) { n   return a < b ? b : a; n } n template <typename T, typename... Args> n T Max(const T a, const Args... args) { n   return Max(a, Max(args...)); n } n template <typename T> n inline T Min(const T a, const T b) { n   return a < b ? a : b; n } n template <typename T, typename... Args> n T Min(const T a, const Args... args) { n   return Min(a, Min(args...)); n } n template <typename T> n inline T LCM(const T a, const T b) { n   return ((a) * (b)) / __gcd((a), (b)); n } n template <typename T, typename... Args> n T LCM(const T a, const Args... args) { n   return LCM(a, LCM(args...)); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   int k; n   cin >> k; n   int n = 2000; n   k += n; n   int arr[n]; n   arr[0] = -1; n   for (int i = 1; i < 2000; i++) { n     if (k >= 1000000) n       arr[i] = 1000000; n     else n       arr[i] = k; n     k -= arr[i]; n   } n   cout << 2000 <<   n ; n   for (int i = 0; i < 2000; i++) cout << arr[i] <<    ; n } n


#include <bits/stdc++.h> n int ___read_tmp; n using namespace std; n int fwt[1010000]; n int query(int sz) { n   int sum = 0; n   sz++; n   while (sz > 0) { n     sum += fwt[sz]; n     sz -= sz & (-sz); n   } n   return sum; n } n void upd(int id, int add) { n   id++; n   for (; id < 1010000; id += (id & (-id))) { n     fwt[id] += add; n   } n } n int range(int from, int to) { n   if (to < from) return 0; n   int tmp = query(to); n   if (from > 0) tmp -= query(from - 1); n   return tmp; n } n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   k = min(k, n - k); n   unsigned long long res = 1; n   int curr = 0; n   for (int i = (0); i < (n); i++) { n     if (curr + k <= n) { n       res += range(curr + 1, curr + k - 1) + 1; n     } else { n       res += range(curr + 1, n - 1) + range(0, (curr + k) % n - 1) + 1; n     } n     printf( %I64d  , res); n     upd(curr, 1); n     curr = (curr + k) % n; n     upd(curr, 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n long long mod = 1000000007; n using namespace std; n int n; n int b1[200005]; n struct node { n   int x, y; n }; n bool cmp(node a, node b) { return a.y - a.x > b.y - b.x; } n node a1[200005]; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n int main() { n   int i, j, fl, test, k; n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; i++) { n     scanf( %d , &a1[i].x); n   } n   for (i = 0; i < n; i++) { n     scanf( %d , &a1[i].y); n   } n   long long ans = 0; n   sort(a1, a1 + n, cmp); n   for (i = 0; i < n; i++) { n     if (k) { n       ans += a1[i].x; n       k--; n     } else n       ans += min(a1[i].x, a1[i].y); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f[100010], r[2][100010]; n vector<int> mat[2][100010]; n void DFS(int a, int x) { n   r[x][a] = 1; n   if (x == 1 && f[a] == 1) return; n   for (int i = 0; i < mat[x][a].size(); i++) { n     int b = mat[x][a][i]; n     if (!r[x][b]) DFS(b, x); n   } n } n int main() { n   int n, m, a, b; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> f[i]; n   for (int i = 0; i < m; i++) { n     cin >> a >> b; n     a--; n     b--; n     mat[0][a].push_back(b); n     mat[1][b].push_back(a); n   } n   for (int i = 0; i < n; i++) n     if (!r[0][i] && f[i] == 1 && mat[0][i].size()) n       DFS(i, f[i] - 1); n     else if (!r[1][i] && f[i] == 2) n       DFS(i, f[i] - 1); n   for (int i = 0; i < n; i++) n     if (r[0][i] && r[1][i]) n       cout << 1 <<    ; n     else n       cout << 0 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long good[3000]; n long long fact[20]; n int q = 0; n void gen(long long sum, int left) { n   if (!left) { n     good[q++] = sum; n   } else { n     if (!sum) { n       gen(sum, left - 1); n     } n     gen(sum * 10 + 4, left - 1); n     gen(sum * 10 + 7, left - 1); n   } n } n bool is_lucky(int v) { n   while (v) { n     if (v % 10 != 4 && v % 10 != 7) { n       return false; n     } n     v /= 10; n   } n   return true; n } n void true_main() { n   gen(0, 10); n   vector<int> per(20); n   vector<bool> fre(20); n   int n; n   long long k; n   fact[0] = 1; n   for (int i = 1; i < 20; i++) { n     fact[i] = fact[i - 1] * i; n   } n   cin >> n >> k; n   if (n < 15) { n     if (k > fact[n]) { n       puts( -1 ); n       return; n     } n   } n   int ans = 0; n   for (int i = 1; i < q; i++) { n     if (good[i] <= n - 15) { n       ans++; n     } n   } n   int m = min(n, 15); n   k--; n   for (int i = 0; i < m; i++) { n     long long q = k / fact[m - i - 1]; n     k -= q * fact[m - i - 1]; n     for (int j = 0;; j++) { n       if (!fre[j]) { n         if (!q) { n           fre[j] = true; n           per[i] = j; n           break; n         } n         q--; n       } n     } n   } n   for (int i = 0; i < m; i++) { n     if (is_lucky(n - m + per[i] + 1) && is_lucky(n - m + i + 1)) { n       ans++; n     } n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   while (t--) { n     true_main(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int n; n   cin >> n; n   long long int ans = 0; n   long long int t = 1; n   long long int x = 2; n   while (n - (t * (t + 1) / 2) >= 0) { n     long long int val = t * (t + 1) / 2; n     n -= val; n     t += x; n     x *= 2; n     ans++; n   } n   cout << ans << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5, M = 1e5 + 5, P = 105; n int n, m, p; n long long d[N]; n int h[M], t[M]; n long long a[M], s[M]; n long long f[P][M]; n int q[M]; n long long Y(int j, int k) { return f[j - 1][k] + s[k]; } n int32_t main() { n   cin >> n >> m >> p; n   for (int i = 2; i <= n; ++i) { n     cin >> d[i]; n     d[i] += d[i - 1]; n   } n   for (int i = 1; i <= m; ++i) { n     cin >> h[i] >> t[i]; n     a[i] = t[i] - d[h[i]]; n   } n   sort(a + 1, a + 1 + m); n   for (int i = 1; i <= m; ++i) s[i] = s[i - 1] + a[i]; n   memset(f[0], 0x3f, sizeof f[0]); n   f[0][0] = 0; n   for (int j = 1; j <= p; ++j) { n     int hh = 0, tt = 0; n     q[0] = 0; n     for (int i = 1; i <= m; ++i) { n       while (hh < tt && n              (Y(j, q[hh + 1]) - Y(j, q[hh])) <= a[i] * (q[hh + 1] - q[hh])) n         hh++; n       int k = q[hh]; n       f[j][i] = f[j - 1][k] + a[i] * (i - k) - (s[i] - s[k]); n       while (hh < tt && (Y(j, q[tt]) - Y(j, q[tt - 1])) * (i - q[tt]) >= n                             (Y(j, i) - Y(j, q[tt])) * (q[tt] - q[tt - 1])) n         tt--; n       q[++tt] = i; n     } n   } n   cout << f[p][m] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, count[8] = {0}; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x; n     count[x] = count[x] + 1; n   } n   if ((count[5] == 0) && (count[7] == 0) && (count[2] >= count[4]) && n       (count[1] == count[4] + count[6]) && n       (count[2] + count[3] == count[4] + count[6])) { n     for (int i = 0; i < count[4]; i++) { n       cout <<  1 2 4  << endl; n     } n     count[2] -= count[4]; n     for (int i = 0; i < count[2]; i++) { n       cout <<  1 2 6  << endl; n     } n     for (int i = 0; i < count[3]; i++) { n       cout <<  1 3 6  << endl; n     } n   } else { n     cout <<  -1  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int grid[n][n]; n   int nro = 1; n   for (int i = 0; i < n; i++) { n     if (!(i & 1)) n       for (int j = 0; j < n; j++) grid[j][i] = nro++; n     else n       for (int j = 0; j < n; j++) grid[n - 1 - j][i] = nro++; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) cout << grid[i][j] <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long mod(long long n, long long m) { n   long long ret = n % m; n   if (ret < 0) ret += m; n   return ret; n } n long long gcd(long long a, long long b) { n   return (b == 0LL ? a : gcd(b, a % b)); n } n long long exp(long long a, long long b, long long m) { n   if (b == 0LL) return 1LL; n   if (b == 1LL) return mod(a, m); n   long long k = mod(exp(a, b / 2, m), m); n   if (b & 1LL) { n     return mod(a * mod(k * k, m), m); n   } else n     return mod(k * k, m); n } n vector<int> z_function(string s) { n   int n = s.size(); n   vector<int> z(n); n   int L = 0, R = 0; n   for (int i = 1; i < n; i++) { n     if (i <= R) { n       if (i - L + z[i - L] > i - L + (R - i)) { n         z[i] = R - i + 1; n         while (i + z[i] < n and s[z[i]] == s[z[i] + i]) { n           z[i]++; n         } n       } else n         z[i] = z[i - L]; n     } else { n       while (i + z[i] < n and s[z[i]] == s[z[i] + i]) { n         z[i]++; n       } n     } n     if (i + z[i] - 1 > R) { n       L = i, R = i + z[i] - 1; n     } n   } n   return z; n } n const int N = 1000100; n int n, m, k; n vector<int> order[N]; n vector<int> get(string s, string t) { n   string aux = t +  #  + s; n   vector<int> z = z_function(aux); n   for (int i = 0; i < N; i++) order[i].clear(); n   for (int i = 0; i < n; i++) { n     if (z[i + m + 1] > 0) order[z[i + m + 1]].push_back(i); n   } n   set<int> best; n   vector<int> res((int)s.size() + 10, -1); n   for (int x = m; x > 0; x--) { n     for (int id : order[x]) { n       best.insert(id); n     } n     auto it = best.lower_bound(k - x); n     if (it == best.end()) continue; n     res[x] = *it; n   } n   return res; n } n vector<int> lpos, rpos; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m >> k; n   string s, t; n   cin >> s >> t; n   string aux = t +  #  + s; n   vector<int> z = z_function(aux); n   for (int i = 0; i < n; i++) { n     if (z[i + 1 + m] >= m) { n       cout <<  Yes  n            <<   n ; n       int l = min(i + 1, n - 2 * k + 1); n       int r = l + k; n       cout << l <<     << r <<   n ; n       return 0; n     } n   } n   lpos = get(s, t); n   reverse(s.begin(), s.end()); n   reverse(t.begin(), t.end()); n   rpos = get(s, t); n   for (int i = 1; i <= min(m - 1, k); i++) { n     if (m - i > k) continue; n     int id1 = lpos[i], id2 = rpos[m - i]; n     if (id1 == -1 or id2 == -1) continue; n     int L = lpos[i] + i - 1, R = rpos[m - i] + (m - i) - 1; n     if (L + R >= n - 1) continue; n     id1 = lpos[i] + i - (k - 1); n     id2 = n - rpos[m - i] - (m - i) + 1; n     if (id1 + k - 1 < id2 and id2 + k - 1 <= n) { n       cout <<  Yes  n            <<   n ; n       cout << id1 <<     << id2 <<   n ; n       return 0; n     } n   } n   cout <<  No  n        <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3; n const double eps = 1e-8; n int n; n struct point { n   double x, y, z; n } p[maxn], pp; n double dis(point a, point b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + n          (a.z - b.z) * (a.z - b.z); n } n double get(double x, double y, double z) { n   double res = 0; n   for (int i = 1; i <= n; i++) res = max(res, dis(point{x, y, z}, p[i])); n   return res; n } n double findz(double x, double y) { n   double l = -1e4, r = 1e4; n   while (r - l > eps) { n     double m1 = (l + l + r) / 3; n     double m2 = (l + r + r) / 3; n     if (get(x, y, m1) < get(x, y, m2)) n       r = m2; n     else n       l = m1; n   } n   pp.z = (l + r) / 2; n   return get(x, y, (l + r) / 2); n } n double findy(double x) { n   double l = -1e4, r = 1e4; n   while (r - l > eps) { n     double m1 = (l + l + r) / 3; n     double m2 = (l + r + r) / 3; n     if (findz(x, m1) < findz(x, m2)) n       r = m2; n     else n       l = m1; n   } n   pp.y = (l + r) / 2; n   return findz(x, (l + r) / 2); n } n double findx() { n   double l = -1e4, r = 1e4; n   while (r - l > eps) { n     double m1 = (l + l + r) / 3; n     double m2 = (l + r + r) / 3; n     if (findy(m1) < findy(m2)) n       r = m2; n     else n       l = m1; n   } n   pp.x = (l + r) / 2; n   return findy((l + r) / 2); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %lf%lf%lf , &p[i].x, &p[i].y, &p[i].z); n   findx(); n   printf( %.9lf %.9lf %.9lf n , pp.x, pp.y, pp.z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 1e9, I = 1e18; n const int mxn = 1e5; n int t, n; n string s, pr, ans; n bool fl; n void solve() { n   fl = 0; n   ans =   ; n   cin >> n; n   cin >> pr; n   ans = pr; n   for (int i = 1; i < n - 2; i++) { n     cin >> s; n     if (pr[1] != s[0]) { n       fl = 1; n       ans += s[0]; n     } n     ans += s[1]; n     pr = s; n   } n   if (!fl) ans =  a  + ans; n   cout << ans << endl; n } n int main() { n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:64000000 ) n template <class T> n inline T sqr(T x) { n   return x * x; n } n int n, k; n int a[1 << 17]; n map<int, int> d; n set<pair<int, int> > s; n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < k; ++i) ++d[a[i]]; n   for (int i = 0; i < k; ++i) s.insert(make_pair(d[a[i]], -a[i])); n   for (int i = 0; i + k - 1 < n; ++i) { n     if (s.begin()->first == 1) n       printf( %d n , -s.begin()->second); n     else n       puts( Nothing ); n     if (i + k == n) continue; n     pair<int, int> cur(d[a[i]], -a[i]); n     s.erase(cur); n     if (--d[a[i]] == 0) n       d.erase(a[i]); n     else { n       --cur.first; n       s.insert(cur); n     } n     cur = make_pair(d[a[i + k]], -a[i + k]); n     s.erase(cur); n     ++d[a[i + k]]; n     ++cur.first; n     s.insert(cur); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n static char buf[1 << 20], *fs, *ft; n inline char gc() { n   if (fs == ft) { n     ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin); n     if (fs == ft) return EOF; n   } n   return *fs++; n } n inline int read() { n   int x = 0, f = 1; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -f; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = x * 10 + s -  0 ; n     s = getchar(); n   } n   return x * f; n } n }  // namespace IO n using IO::read; n map<pair<int, int>, int> pos; n const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; n int p[256]; n void move(int n) { n   static char c; n   while ((c = getchar()) !=  U  and c !=  L  and c !=  R  and c !=  D ) n     ; n   pos.clear(); n   pair<int, int> now = make_pair(dx[p[c]], dy[p[c]]); n   pos[make_pair(0, 0)] = 1, pos[now] = 2; n   int ans = 1 << 30, ansl = 0, ansr = 0; n   for (int i = 2; i <= n; i++) { n     c = getchar(); n     int rex = now.first + dx[p[c]], rey = now.second + dy[p[c]]; n     pair<int, int> Next = make_pair(rex, rey); n     if (pos[Next]) { n       if (i - pos[Next] + 1 < ans) n         ans = i - pos[Next] + 1, ansl = pos[Next], ansr = i; n     } n     pos[now = Next] = i + 1; n   } n   if (ansl and ansr) n     printf( %d %d n , ansl, ansr); n   else n     puts( -1 ); n } n int main() { n   p[ U ] = 1, p[ D ] = 3; n   p[ L ] = 2, p[ R ] = 0; n   int T = read(); n   while (T--) move(read()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 200010; n const long long MOD = (int)1e9 + 7; n const int INF = 1e9; n const long long LLINF = 0x3f3f3f3f3f3f3f3f; n const long double EPS = 1e-8; n int r, g, h, total; n inline int add(int a, int b) { return (a + b) % MOD; } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> r >> g; n   total = r + g; n   vector<int> ant(MAX, 0); n   if (g) ant[r] = 1; n   if (r) ant[r - 1] = 1; n   int res = 0; n   for (int l = 2; true; l++) { n     vector<int> cur(MAX, 0); n     bool eita = false; n     for (int red = 0; red <= r; red++) { n       long long minus = (l * (l - 1)) / 2 - (r - red); n       if (minus < 0) continue; n       int green = g - minus; n       if (red - l >= 0 and ant[red]) { n         eita = true; n         cur[red - l] = add(cur[red - l], ant[red]); n       } n       if (green - l >= 0 and ant[red]) { n         eita = true; n         cur[red] = add(cur[red], ant[red]); n       } n     } n     if (!eita) break; n     swap(ant, cur); n   } n   for (int red = 0; red <= r; red++) { n     res = (res + ant[red]) % MOD; n   } n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool check(int x1, int y1, int r1, int x2, int y2, int r2, int R2) { n   int l = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n   int rr1 = (r1 - r2) * (r1 - r2); n   int rr2 = (r1 + r2) * (r1 + r2); n   int RR1 = (r1 - R2) * (r1 - R2); n   int RR2 = (r1 + R2) * (r1 + R2); n   if (l <= rr1 && l <= RR1 && (r1 <= r2 || r1 >= R2)) return 1; n   if (rr2 <= l && RR2 <= l) return 1; n   return 0; n } n int main() { n   int x1, y1, r1, R1, x2, y2, r2, R2; n   while (scanf( %d %d %d %d , &x1, &y1, &r1, &R1) != EOF) { n     scanf( %d %d %d %d , &x2, &y2, &r2, &R2); n     int ans = 0; n     if (check(x1, y1, r1, x2, y2, r2, R2)) ans++; n     if (check(x1, y1, R1, x2, y2, r2, R2)) ans++; n     if (check(x2, y2, r2, x1, y1, r1, R1)) ans++; n     if (check(x2, y2, R2, x1, y1, r1, R1)) ans++; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n int ex[] = {1, -1, 0, 0}; n int wye[] = {0, 0, 1, -1}; n using namespace std; n vector<int> vt[10005]; n bool visit[10005]; n int n, x, y, an; n void dfs(int node) { n   if (visit[node]) return; n   visit[node] = true; n   int siz = vt[node].size(); n   int tmp; n   for (int i = 0; i < siz; i++) { n     tmp = vt[node][i]; n     if (visit[tmp]) continue; n     dfs(tmp); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     vt[i].push_back(x); n     vt[x].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     if (visit[i]) continue; n     dfs(i); n     an++; n   } n   printf( %d n , an); n   return 0; n } n