#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6, maxm = 1e6; n unsigned int degree[maxn + 10], blk[maxn + 10]; n namespace find { n unsigned int fa[maxn + 10], siz[maxn + 10]; n inline void Init(const unsigned int n) { n   iota(fa, fa + n + 1, 0); n   fill(siz, siz + n + 1, 1); n } n unsigned int GetFather(const unsigned int x) { n   return fa[x] == x ? x : fa[x] = GetFather(fa[x]); n } n inline void Merge(const unsigned int x, const unsigned int y) { n   unsigned int fx = GetFather(x), fy = GetFather(y); n   if (fx == fy) return; n   if (siz[fx] < siz[fy]) swap(fx, fy); n   fa[fy] = fx; n   siz[fx] += siz[fy]; n } n }  // namespace find n int main() { n   ios_base::sync_with_stdio(false); n   unsigned int n, m; n   cin >> n >> m; n   find::Init(n); n   for (unsigned int i = 0; i < m; ++i) { n     unsigned int a, b; n     cin >> a >> b; n     find::Merge(a, b); n     ++degree[a]; n     ++degree[b]; n   } n   unsigned long long ans = 0; n   const unsigned int r = find::GetFather(1); n   bool fl = true; n   for (unsigned int i = 1; i <= n; ++i) { n     if (degree[i] & 0x01) ++blk[find::GetFather(i)]; n     if (degree[i] && find::GetFather(i) != r) fl = false; n   } n   if (fl && !blk[r]) { n     cout <<  0  << endl; n     return 0; n   } n   for (unsigned int i = 1; i <= n; ++i) n     if (find::GetFather(i) == i) { n       ans += blk[i] / 2; n       if (degree[i] && !blk[i]) ++ans; n     } n   if (!degree[1] && find::siz[1] == 1 && find::GetFather(1) == 1) ++ans; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int count = 0, count1 = 0; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >= 97 && s[i] <= 122) n       count++; n     else n       count1++; n   } n   if (count >= count1) { n     for (int i = 0; i < s.size(); i++) { n       if (isupper(s[i])) s[i] = s[i] + 32; n     } n   } else { n     for (int i = 0; i < s.size(); i++) { n       if (islower(s[i])) s[i] = s[i] - 32; n     } n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; n int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1}; n vector<string> vec_splitter(string s) { n   s +=  , ; n   vector<string> res; n   while (!s.empty()) { n     res.push_back(s.substr(0, s.find( , ))); n     s = s.substr(s.find( , ) + 1); n   } n   return res; n } n void debug_out(vector<string> __attribute__((unused)) args, n                __attribute__((unused)) int idx, n                __attribute__((unused)) int LINE_NUM) { n   cerr << endl; n } n template <typename Head, typename... Tail> n void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { n   if (idx > 0) n     cerr <<  ,  ; n   else n     cerr <<  Line(  << LINE_NUM <<  )  ; n   stringstream ss; n   ss << H; n   cerr << args[idx] <<   =   << ss.str(); n   debug_out(args, idx + 1, LINE_NUM, T...); n } n int const lmt = 2e5 + 5; n int a[lmt]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     if (a[0] + a[1] <= a[n - 1]) { n       cout << 1 <<    ; n       cout << 2 <<    ; n       cout << n <<   n ; n     } else { n       cout << -1 <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[300005], p[300005], out[300005]; n long long f[300005]; n bool v[300005]; n int n, m, cnt; n void work(int p) { n   int t = min(a[p], a[p + 1]); n   if (t) out[++m] = p; n   a[p] -= t; n   a[p + 1] -= t; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     long long O = f[max(i - 2, 0)] + a[i]; n     long long E = f[max(i - 3, 0)] + max(a[i], a[i - 1]); n     f[i] = min(O, E); n     v[i] = (f[i] != O); n   } n   long long ans = min(f[n - 1], f[n]); n   for (int i = n - (ans == f[n - 1]); i > 0; i -= 2 + v[i]) p[++cnt] = i; n   reverse(p + 1, p + cnt + 1); n   for (int i = 1; i <= cnt; i++) { n     int pre = p[i - 1], now = p[i]; n     if (v) work(now - 1); n     work(pre + 1); n     work(now); n   } n   printf( %d n , m); n   for (int i = 1; i <= m; i++) printf( %d n , out[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int a[4] = {1, 2, 3, 5}; n int main(void) { n   int n, k; n   scanf( %d%d , &n, &k); n   printf( %d n , (5 + 6 * (n - 1)) * k); n   for (int i = 0; i < n; i++) { n     printf( %d %d %d %d n , (a[0] + 6 * i) * k, (a[1] + 6 * i) * k, n            (a[2] + 6 * i) * k, (a[3] + 6 * i) * k); n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, mxpos = 0, mx = 0, temp, i; n   scanf( %d , &n); n   int p[n]; n   for (i = 0; i < n; i++) { n     scanf( %d , &p[i]); n     if (mx < p[i]) { n       mx = p[i]; n       mxpos = i; n     } n   } n   int loopno = 0, j; n   int notsorted = 1; n   while (notsorted) { n     notsorted = 0; n     for (j = 0; j < n - loopno - 1; j++) { n       if (p[j] > p[j + 1]) { n         temp = p[j]; n         p[j] = p[j + 1]; n         p[j + 1] = temp; n         notsorted = 1; n       } n     } n     loopno++; n   } n   printf( %d %d , mxpos + 1, p[n - 2]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 32000; n const int mod = 1000000007; n const int inf = 2 * mod; n int dp[5001][5001]; n pair<long long, long long> hashVal[5001]; n pair<long long, long long> powVal[5001]; n const long long base1 = 37; n const long long base2 = 2017; n const long long mod1 = 1e9 + 7; n const long long mod2 = 1e9 + 297; n int ans[50001]; n string s; n inline int ceil(int p, int q) { return (p + q - 1) / q; } n int call(int l, int r) { n   if (l > r) return 0; n   if (l == r) return 1; n   if (l == r - 1) return (s[l] == s[r] ? 2 : 0); n   if (dp[l][r] != -1) return dp[l][r]; n   int ret; n   if (s[l] != s[r] || call(l + 1, r - 1) == 0) n     ret = 0; n   else n     ret = 1 + call(l, ceil(l + r, 2) - 1); n   return dp[l][r] = ret; n } n int main() { n   cin >> s; n   int len = s.length(); n   memset(dp, -1, sizeof(dp)); n   for (int i = 0; i < len; i++) { n     for (int j = 0; j < len; j++) { n       ans[call(i, j)]++; n     } n   } n   for (int i = len - 1; i >= 1; i--) ans[i] += ans[i + 1]; n   for (int i = 1; i <= len; i++) { n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = LLONG_MAX; n const long long mod = 1e9 + 7; n inline long long power(long long n, long long k, long long mod = INF) { n   long long ans = 1; n   while (k > 0) { n     if (k & 1) ans = (ans * n) % mod; n     n = (n * n) % mod; n     k >>= 1; n   } n   return ans; n } n void sum() { n   string s; n   cin >> s; n   long long n = (long long)s.size(); n   long long pre[n + 1]; n   long long suf[n + 2]; n   pre[1] = s[0] -  0 ; n   suf[n] = s[n - 1] -  0 ; n   suf[n + 1] = 0; n   suf[0] = 0; n   pre[0] = 0; n   long long st = pre[1]; n   long long en = suf[n]; n   long long t = 1; n   long long ans = 0; n   for (long long i = 1; i < n; ++i) { n     t = (t * 10) % mod; n     st = (st * 10 + s[i] -  0 ) % mod; n     pre[i + 1] = (pre[i] % mod + st) % mod; n     en = (en + t * (s[n - i - 1] -  0 )) % mod; n     suf[n - i] = en; n   } n   for (long long i = 2; i <= n + 1; ++i) { n     long long temp = i - 1; n     temp %= mod; n     ans += (((pre[i - 2] * t) % mod) + (((temp)*suf[i]) % mod)) % mod; n     ans %= mod; n     t = ((t % mod) * power(10, mod - 2, mod)) % mod; n   } n   cout << (ans) % mod <<   n ; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   sum(); n   return 0; n } n


#include <bits/stdc++.h> n int a[100005], s[100005]; n int main() { n   int l, r, q1, q2, i, N, S; n   scanf( %d%d%d%d%d , &N, &l, &r, &q1, &q2); n   s[0] = 0; n   for (i = 1; i <= N; i++) { n     scanf( %d , &a[i]); n     s[i] = s[i - 1] + a[i]; n   } n   int mx = s[N] * l + q1 * (N - 1); n   for (i = 0; i <= N; i++) { n     int t = s[i] * l + (s[N] - s[i]) * r; n     int p = N - 2 * i; n     if (p < 0) p = -p; n     if (p) p--; n     if (l > r) n       t += p * q2; n     else n       t += p * q1; n     if (t < mx) mx = t; n   } n   printf( %d n , mx); n } n


#include <bits/stdc++.h> n using namespace std; n int arr[1000] = {0}; n int main() { n   int n, m, i, j, k; n   cin >> n; n   for (i = 0; i < n; i++) cin >> arr[i]; n   if (n % 2 == 0) { n     cout <<  No  << endl; n     return 0; n   } else { n     if (arr[0] % 2 == 1 && arr[n - 1] % 2 == 1) { n       cout <<  Yes  << endl; n     } else n       cout <<  No  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int pages, readPages[7]; n   scanf( %d , &pages); n   for (int i = 0; i < 7; i++) scanf( %d , &readPages[i]); n   int day = 1, i = 0; n   while (pages > 0) { n     if (day == 8) day = 1; n     if (i == 7) i = 0; n     pages -= readPages[i]; n     day++, i++; n   } n   printf( %d n , day - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 3000 + 50; n const int MAX_D = 15; n struct DP { n   int d1; n   int d2; n   int d3; n   int v1; n   int v2; n   int v3; n }; n bool operator<(const DP& l, const DP& r) { n   return l.v1 < r.v1 || (l.v1 == r.v1 && l.v2 < r.v2) || n          (l.v1 == r.v1 && l.v2 == r.v2 && l.v3 < r.v3); n } n class SparseTable { n  public: n   SparseTable(vector<pair<int, int> >& vals) { n     N = vals.size(); n     depths.assign(MAX_N, -1); n     table.assign(N, vector<pair<int, int> >(MAX_D)); n     init(); n     build(vals); n   } n   void init() { n     for (int i = 1; i < MAX_N; ++i) { n       depths[i] = depths[i - 1]; n       if ((i & (i - 1)) == 0) { n         ++depths[i]; n       } n     } n   } n   void build(vector<pair<int, int> >& vals) { n     for (int i = 0; i < N; ++i) { n       table[i][0] = vals[i]; n     } n     for (int d = 1; d <= depths[N] + 1; ++d) { n       for (int i = 0; i < N; ++i) { n         int left = i; n         int right = min(N - 1, left + (1 << (d - 1))); n         table[i][d] = max(table[left][d - 1], table[right][d - 1]); n       } n     } n   } n   pair<int, int> getMax(int left, int right) { n     int len = right - left + 1; n     int d = depths[len]; n     return max(table[left][d], table[left + len - (1 << d)][d]); n   } n  n  private: n   vector<vector<pair<int, int> > > table; n   vector<int> depths; n   int N = 0; n }; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> vec(n); n   vector<pair<int, int> > vec_with_index(n); n   for (int i = 0; i < n; ++i) { n     cin >> vec[i]; n     vec_with_index[i].first = vec[i]; n     vec_with_index[i].second = i; n   } n   sort(vec_with_index.begin(), vec_with_index.end()); n   vector<pair<int, int> > vals; n   vals.push_back({vec_with_index[0].first, 0}); n   for (int i = 1; i < vec_with_index.size(); ++i) { n     vals.push_back({vec_with_index[i].first - vec_with_index[i - 1].first, i}); n   } n   SparseTable st(vals); n   DP ret; n   ret.v1 = -1; n   ret.v2 = -1; n   ret.v3 = -1; n   for (int d1 = n - 1; d1 >= 0; --d1) { n     for (int d2 = d1 - 1; d2 >= 0; --d2) { n       int len1 = n - 1 - d1 + 1; n       int len2 = d1 - 1 - d2 + 1; n       if (len1 > 2 * len2 || len2 > 2 * len1) { n         continue; n       } n       int min_len3 = max({1, (len1 + 1) / 2, (len2 + 1) / 2}); n       int max_len3 = min({d2, 2 * len1, 2 * len2}); n       if (min_len3 > max_len3) { n         continue; n       } n       int min_d3 = d2 - max_len3; n       int max_d3 = d2 - min_len3; n       pair<int, int> max_val = st.getMax(min_d3, max_d3); n       DP temp; n       temp.d1 = d1; n       temp.d2 = d2; n       temp.d3 = max_val.second; n       temp.v1 = vec_with_index[d1].first - vec_with_index[d1 - 1].first; n       temp.v2 = vec_with_index[d2].first - vec_with_index[d2 - 1].first; n       temp.v3 = max_val.first; n       if (ret < temp) { n         ret = temp; n       } n     } n   } n   vector<int> ret_vec(n); n   for (int i = 0; i < ret.d3; ++i) { n     ret_vec[vec_with_index[i].second] = -1; n   } n   for (int i = ret.d3; i < ret.d2; ++i) { n     ret_vec[vec_with_index[i].second] = 3; n   } n   for (int i = ret.d2; i < ret.d1; ++i) { n     ret_vec[vec_with_index[i].second] = 2; n   } n   for (int i = ret.d1; i < n; ++i) { n     ret_vec[vec_with_index[i].second] = 1; n   } n   for (auto item : ret_vec) { n     cout << item <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   long long l, r; n   mutable long long val; n   Node(long long l = 0, long long r = 0, long long v = 0) n       : l(l), r(r), val(v) {} n   bool operator<(const Node& rv) const { return l < rv.l; } n }; n long long n, m; n set<Node> t; n long long a[100005]; n long long seed; n long long vmax; n long long qpow(long long x, long long p, long long m) { n   long long ans = 1; n   long long base = x; n   while (p) { n     if (p & 1) ans = (ans * base) % m; n     base = (base * base) % m; n     p >>= 1; n   } n   return ans; n } n long long rnd() { n   long long ans = seed; n   seed = (seed * 7 + 13) % 1000000007; n   return ans; n } n set<Node>::iterator split(long long p) { n   set<Node>::iterator it = t.lower_bound(Node(p)); n   if (it != t.end() && it->l == p) { n     return it; n   } n   --it; n   long long l = it->l, r = it->r, val = it->val; n   t.erase(it); n   t.insert(Node(l, p - 1, val)); n   return t.insert(Node(p, r, val)).first; n } n void assign(long long l, long long r, long long v) { n   set<Node>::iterator end = split(r + 1); n   set<Node>::iterator begin = split(l); n   t.erase(begin, end); n   t.insert(Node(l, r, v)); n } n void add(long long l, long long r, long long k) { n   set<Node>::iterator end = split(r + 1); n   set<Node>::iterator begin = split(l); n   for (set<Node>::iterator it = begin; it != end; ++it) { n     it->val += k; n   } n } n long long kth(long long l, long long r, long long k) { n   vector<pair<long long, long long> > v; n   set<Node>::iterator end = split(r + 1); n   set<Node>::iterator begin = split(l); n   for (set<Node>::iterator it = begin; it != end; ++it) { n     v.push_back(make_pair(it->val, it->r - it->l + 1)); n   } n   sort(v.begin(), v.end()); n   for (long long i = 0; i < v.size(); ++i) { n     k -= v[i].second; n     if (k <= 0) return v[i].first; n   } n   return -1; n } n long long power(long long l, long long r, long long k, long long mod) { n   set<Node>::iterator end = split(r + 1); n   set<Node>::iterator begin = split(l); n   long long ans = 0; n   for (set<Node>::iterator it = begin; it != end; ++it) { n     ans = (ans + n            (((qpow(it->val % mod, k, mod) % mod) * (it->r - it->l + 1 % mod)) % n             mod)) % n           mod; n   } n   return ans % mod; n } n signed main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> seed >> vmax; n   for (long long i = 1; i <= n; ++i) { n     a[i] = (rnd() % vmax) + 1; n     t.insert(Node(i, i, a[i])); n   } n   for (long long i = 1; i <= m; ++i) { n     long long opt = (rnd() % 4) + 1, l = (rnd() % n) + 1, r = (rnd() % n) + 1, n               x, y; n     if (l > r) swap(l, r); n     if (opt == 3) n       x = (rnd() % (r - l + 1)) + 1; n     else n       x = (rnd() % vmax) + 1; n     if (opt == 4) y = (rnd() % vmax) + 1; n     if (opt == 1) { n       add(l, r, x); n     } else if (opt == 2) { n       assign(l, r, x); n     } else if (opt == 3) { n       cout << kth(l, r, x) << endl; n     } else { n       cout << power(l, r, x, y) << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxp = 22; n const long double EPS = 1e-18; n const long long INF = 1e18; n const int MOD = 1e9 + 7; n const int N = 2e5 + 1; n void yesno(bool a) { n   if (a) { n     cout <<  YES  <<   n ; n   } else { n     cout <<  NO  <<   n ; n   } n } n long long power(long long x, long long n, long long m) { n   if (n == 0) return 1; n   long long u = power(x, n / 2, m); n   u = (u * u) % m; n   if (n % 2) u = (u * x) % m; n   return u; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   long long i, arr[n]; n   for (i = 0; i < n; i++) cin >> arr[i]; n   if (n == 1) { n     cout << 1 <<     << 1 <<   n ; n     cout << -arr[0] <<   n ; n     cout << 1 <<     << 1 <<   n ; n     cout << 0 <<   n ; n     cout << 1 <<     << 1 <<   n ; n     cout << 0 <<   n ; n     return 0; n   } n   cout << 1 <<     << n - 1 <<   n ; n   for (i = 0; i < n - 1; i++) { n     long long num = arr[i] % n; n     cout << num * (n - 1) <<    ; n     arr[i] += num * (n - 1); n   } n   cout <<   n ; n   cout << n <<     << n <<   n ; n   long long num = arr[n - 1] % n; n   cout << (n - num) <<   n ; n   arr[n - 1] += n - num; n   cout << 1 <<     << n <<   n ; n   for (i = 0; i < n; i++) cout << -arr[i] <<    ; n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   char c[n][n]; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < n; j++) { n       cin >> c[i][j]; n     } n   } n   bool re = 1, ce = 1; n   for (long long i = 0; i < n; i++) { n     re = 1; n     for (long long j = 0; j < n; j++) { n       if (c[i][j] !=  E ) { n         re = 0; n       } n     } n     if (re == 1) { n       break; n     } n   } n   for (long long j = 0; j < n; j++) { n     ce = 1; n     for (long long i = 0; i < n; i++) { n       if (c[i][j] !=  E ) { n         ce = 0; n       } n     } n     if (ce == 1) { n       break; n     } n   } n   if (re == 1 && ce == 1) { n     cout <<  -1 ; n     return 0; n   } n   if (re == 1) { n     for (long long j = 0; j < n; j++) { n       for (long long i = 0; i < n; i++) { n         if (c[i][j] !=  E ) { n           cout << i + 1 <<     << j + 1 <<   n ; n           break; n         } n       } n     } n   } else { n     for (long long i = 0; i < n; i++) { n       for (long long j = 0; j < n; j++) { n         if (c[i][j] !=  E ) { n           cout << i + 1 <<     << j + 1 <<   n ; n           break; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n; n   std::string s; n   std::cin >> n >> s; n   int cnt = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  1 ) n       cnt++; n     else { n       std::cout << cnt; n       cnt = 0; n     } n   } n   std::cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[105][105][2]; n struct seg { n   int a; n   long long len; n   bool operator<(const seg &p) const { return a < p.a; } n } a[105]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%lld , &a[i].a, &a[i].len); n   } n   sort(a + 1, a + n + 1); n   long long ans = 0; n   a[0].a = -2e9; n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= i; ++j) { n       for (int k = 0; k <= 1; ++k) { n         ans = max(ans, f[i][j][k]); n         int pr = a[j].a + k * a[j].len; n         int R, x; n         for (int p = i + 1, mx = -2e9; p <= n; ++p) { n           for (int q = 0; q <= 1; ++q) { n             int r = a[p].a + q * a[p].len; n             if (r > mx) mx = r, R = p, x = q; n             f[p][R][x] = n                 max(f[p][R][x], n                     f[i][j][k] + min(a[p].len, (long long)r - pr) + (mx - r)); n           } n         } n       } n     } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n const int maxn = 1e5 + 10, lg = 18; n int n, m, q, cid[maxn], csize = 0, H[maxn], low[maxn], ok[maxn], par[maxn][lg], n                         comp[maxn], c1; n bool dp[maxn][lg]; n vector<int> G[maxn]; n bool mark[maxn]; n void dfs1(int a, int p) { n   par[a][0] = p; n   for (int i = 1; i < lg; i++) { n     par[a][i] = par[par[a][i - 1]][i - 1]; n   } n   low[a] = H[a]; n   mark[a] = 1; n   for (int b : G[a]) { n     if (!mark[b]) { n       H[b] = H[a] + 1; n       comp[b] = comp[a]; n       dfs1(b, a); n       low[a] = min(low[a], low[b]); n     } else if (b != p) { n       low[a] = min(low[a], H[b]); n     } n   } n } n void dfs2(int a) { n   mark[a] = 1; n   for (int b : G[a]) { n     if (!mark[b]) { n       if (low[b] >= H[a]) { n         cid[b] = csize++; n       } else { n         cid[b] = cid[a]; n       } n       dfs2(b); n     } else if (H[a] > H[b]) { n       int dis = H[a] - H[b]; n       if ((dis & 1) == 0) { n         ok[cid[a]] = 1; n       } n     } n   } n } n void dfs3(int a) { n   mark[a] = 1; n   dp[a][0] = (ok[cid[a]]); n   for (int b : G[a]) { n     if (!mark[b]) { n       dfs3(b); n     } n   } n } n bool lca(int a, int b) { n   bool ans = 0; n   if (H[a] > H[b]) swap(a, b); n   for (int i = lg - 1; i >= 0; i--) { n     if (H[par[b][i]] >= H[a]) { n       ans |= dp[b][i]; n       b = par[b][i]; n     } n   } n   if (a == b) { n     return ans; n   } n   for (int i = lg - 1; i >= 0; i--) { n     if (par[b][i] != par[a][i]) { n       ans |= dp[a][i]; n       ans |= dp[b][i]; n       a = par[a][i]; n       b = par[b][i]; n     } n   } n   ans |= dp[a][0]; n   ans |= dp[b][0]; n   return ans; n } n int32_t main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--, b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     if (!mark[i]) { n       comp[i] = c1++; n       dfs1(i, i); n     } n   } n   fill(mark, mark + n, 0); n   for (int i = 0; i < n; i++) { n     if (!mark[i]) { n       cid[i] = csize++; n       dfs2(i); n     } n   } n   fill(mark, mark + n, 0); n   for (int i = 0; i < n; i++) { n     if (!mark[i]) { n       dfs3(i); n     } n   } n   for (int j = 0; j < lg - 1; j++) { n     for (int i = 0; i < n; i++) { n       dp[i][j + 1] = dp[i][j] | dp[par[i][j]][j]; n     } n   } n   scanf( %d , &q); n   while (q--) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--, b--; n     if (H[a] > H[b]) swap(a, b); n     if (a == b || comp[a] != comp[b]) { n       printf( No n ); n       continue; n     } n     if ((H[b] - H[a]) & 1) { n       printf( Yes n ); n       continue; n     } n     bool ans = lca(a, b); n     printf(ans ?  Yes n  :  No n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int a[n]; n   int count[5005] = {0}; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     count[a[i]]++; n   } n   int c[n]; n   int d = 1; n   for (int i = 1; i <= 5000; i++) { n     if (count[i] > k) { n       cout <<  NO  n            <<   n ; n       return 0; n     } n   } n   cout <<  YES  n        <<   n ; n   if (k == 1) { n     for (int i = 0; i < n; i++) { n       cout <<  1  n            <<    ; n     } n   } else { n     for (int i = 1; i <= 5000; i++) { n       for (int j = 0; j < n; j++) { n         if (a[j] == i) { n           c[j] = d; n           d++; n         } n         if (d > k) d = d % k; n       } n     } n     for (int i = 0; i < n; i++) { n       cout << c[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 10; n const long long int LINF = 1LL * INF * INF; n const int MAXN = 2e5 + 10; n const int MAXM = 5e3 + 10; n priority_queue<int> pq; n vector<vector<int> > graph; n queue<int> que; n pair<int, int> A[20]; n long long int dp[20][(1 << 20)]; n long long int sum[(1 << 20)]; n long long int solve(int here, int cur, int n) { n   if (dp[here][cur] != -1) return dp[here][cur]; n   long long int res = 0; n   for (int i = 0; i < n; i++) { n     if (i == here) continue; n     if ((1 << i) & cur) { n       if (A[i].second == A[here].second) continue; n       res += solve(i, cur ^ (1 << here), n); n       res %= 1000000007; n     } n   } n   return dp[here][cur] = res; n } n int main() { n   int n, m, k, a, b, x, y; n   int cnt = 0; n   int mx = 0; n   int mn = INF; n   int cur = 0, idx = -1; n   int T; n   cin >> n >> T; n   for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < (1 << n); j++) dp[i][j] = -1; n   for (int i = 0; i < n; i++) dp[i][(1 << i)] = 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < (1 << n); j++) solve(i, j, n); n   for (int i = 0; i < (1 << n); i++) n     for (int j = 0; j < n; j++) n       if ((1 << j) & i) sum[i] += (long long int)A[j].first; n   long long int res = 0; n   for (int i = 0; i < (1 << n); i++) { n     if (sum[i] != T) continue; n     for (int j = 0; j < n; j++) n       if ((1 << j) & i) { n         res += (long long int)dp[j][i]; n         res %= 1000000007; n       } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q[1000005]; n long long i, j, t, tot, C, cnt; n long long loc[10005], op[10005]; n long long n, m, k, H, x, y, ans, tmp; n long long a[100005], w[100005], e[25], dis[10005], heap[10005]; n bool used[100005], f[10005]; n map<long long, long long> A; n map<long long, long long>::iterator it; n void Spfa(long long s) { n   long long i, head, tail, x, v; n   for (i = 1; i <= k; i++) { n     dis[i] = 1999999999999999999LL; n     f[i] = false; n   } n   dis[s + 1] = 1; n   f[s + 1] = true; n   q[1] = s + 1; n   head = 1; n   tail = 2; n   while (head != tail) { n     x = q[head]; n     f[x] = false; n     for (i = 1; i <= tot; i++) n       if (dis[x] + e[i] < dis[(dis[x] + e[i]) % k + 1]) { n         v = (dis[x] + e[i]) % k + 1; n         dis[v] = dis[x] + e[i]; n         if (!f[v]) { n           q[tail] = v; n           f[v] = true; n           tail++; n         } n       } n     head++; n   } n } n int main() { n   scanf( %I64d%I64d%I64d%I64d , &H, &n, &m, &k); n   for (i = 1; i <= n; i++) scanf( %I64d%I64d , &a[i], &w[i]); n   tot = 0; n   memset(used, false, sizeof used); n   x = 1 % k; n   for (i = 1; i <= n; i++) { n     if (a[i] % k == x) { n       used[i] = true; n       it = A.find(w[i]); n       if (it == A.end()) n         A.insert(make_pair(w[i], 1)); n       else n         A[w[i]]++; n     } n   } n   for (t = 1; t <= m; t++) { n     scanf( %I64d , &C); n     if (C == 1) { n       scanf( %I64d , &x); n       e[++tot] = x; n       Spfa(1 % k); n       for (i = 1; i <= n; i++) n         if (dis[a[i] % k + 1] <= a[i]) { n           if (!used[i]) { n             used[i] = true; n             it = A.find(w[i]); n             if (it == A.end()) n               A.insert(make_pair(w[i], 1)); n             else n               A[w[i]]++; n           } n         } n     } else if (C == 2) { n       scanf( %I64d%I64d , &x, &y); n       if (used[x]) { n         it = A.find(w[x]); n         tmp = it->second; n         if (tmp == 1) n           A.erase(w[x]); n         else n           A[w[x]]--; n         w[x] -= y; n         it = A.find(w[x]); n         if (it != A.end()) n           A[w[x]]++; n         else n           A.insert(make_pair(w[x], 1)); n       } else n         w[x] -= y; n     } else { n       if (A.size() == 0) { n         printf( 0 n ); n         continue; n       } n       it = A.end(); n       it--; n       ans = it->first; n       printf( %I64d n , ans); n       tmp = it->second; n       if (tmp == 1) n         A.erase(ans); n       else n         A[ans]--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long arr[100000], arr1[100000], n, x, z, co = 0, co1 = 0, k, m, n                                                 fin = 1000000; n   map<long long, long long> left; n   map<long long, long long> right; n   cin >> n; n   if (n % 2 == 0) n     k = n / 2; n   else n     k = (n / 2) + 1; n   for (int i = 0; i < n; i++) { n     cin >> x >> z; n     if (x == z) { n       if (left[x] == 0) { n         arr[co++] = x; n         left[x]++; n       } else n         left[x]++; n     } else { n       if (left[x] == 0) { n         arr[co++] = x; n         left[x]++; n       } else n         left[x]++; n       if (right[z] == 0) { n         arr1[co1++] = z; n         right[z]++; n       } else n         right[z]++; n     } n   } n   for (int i = 0; i < co; i++) { n     m = 1000001; n     if ((left[arr[i]] + right[arr[i]]) >= k) { n       m = k - left[arr[i]]; n       if (m < 0) { n         cout <<  0 ; n         exit(0); n       } n     } n     if (m < fin) { n       fin = m; n     } n   } n   if (fin == 1000000) { n     for (int i = 0; i < co1; i++) { n       if (right[arr1[i]] >= k) { n         cout << k; n         exit(0); n       } n     } n   } n   if (fin == 1000000) n     cout <<  -1 ; n   else n     cout << fin; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N6 = 1e6 + 6; n using namespace std; n long long n, m, x, y, sum1, sum2, ans1, ans2; n int main() { n   cin >> n >> x >> y; n   if (n > y) { n     cout << -1; n     return 0; n   } n   sum1 = y - n + 1; n   sum1 *= sum1; n   sum1 += (n - 1); n   if (sum1 >= x) { n     for (int i = 1; i < n; ++i) { n       cout << 1 <<    ; n     } n     cout << y - n + 1; n   } else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1050; n int dp[maxn][9], nxt[maxn][9][maxn], a[maxn], n, cnt[9]; n inline int ask(int k) { return (1 << (k - 1)); } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= 8; ++j) cnt[j] = 0; n     for (int j = 1; j <= 8; ++j) n       for (int k = 1; k <= n; ++k) nxt[i][j][k] = 1e9; n     for (int j = i; j <= n; ++j) nxt[i][a[j]][++cnt[a[j]]] = j; n   } n   int ans = 0; n   for (int num = 0; num * 8 <= n; ++num) { n     for (int i = 0; i < 256; ++i) n       for (int k = 0; k <= 8; ++k) dp[i][k] = 1e9; n     dp[0][0] = 1; n     for (int i = 0; i < 256; ++i) n       for (int j = 0; j <= 8; ++j) n         for (int k = 1; k <= 8; ++k) { n           if (dp[i][j] > n || ask(k) & i) continue; n           dp[i ^ ask(k)][j] = min(dp[i ^ ask(k)][j], nxt[dp[i][j]][k][num] + 1); n           dp[i ^ ask(k)][j + 1] = n               min(dp[i ^ ask(k)][j + 1], nxt[dp[i][j]][k][num + 1] + 1); n         } n     for (int i = 0; i <= 8; ++i) n       if (dp[255][i] <= n + 1) ans = max(ans, 8 * num + i); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using lint = long long; n using ldouble = long double; n void solve() { n   int n, d; n   std::cin >> n >> d; n   std::vector<int> vs(n, 1); n   int diff = n * (n - 1) / 2 - d; n   if (diff < 0) { n     std::cout <<  NO  << std::endl; n     return; n   } n   int head = 1; n   for (int v = n - 1; v > head; --v) { n     int to = std::max(v - diff, head); n     --vs[v]; n     ++vs[to]; n     diff -= v - to; n     if (diff == 0) break; n     while (vs[head] == (1 << head)) ++head; n   } n   if (diff > 0) { n     std::cout <<  NO  << std::endl; n     return; n   } n   std::cout <<  YES  << std::endl; n   int p = 1; n   for (int i = 1; i < n; ++i) { n     int v = p, ch = 0; n     for (int j = 0; j < vs[i]; ++j) { n       std::cout << v <<    ; n       if (++ch == 2) { n         ++v; n         ch = 0; n       } n     } n     p += vs[i - 1]; n   } n   std::cout << std::endl; n } n int main() { n   std::cin.tie(nullptr); n   std::cout.tie(nullptr); n   std::ios::sync_with_stdio(false); n   int q; n   std::cin >> q; n   while (q--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long inf = 1e18; n int main(void) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     k++; n     long long A[n]; n     for (long long i = 0; i < n; i++) { n       cin >> A[i]; n       long long t = 1; n       while (A[i]--) { n         t *= 10; n       } n       A[i] = t; n     } n     long long ans = 0; n     for (long long i = 0; i < n; i++) { n       long long cnt = k; n       if (i != n - 1) { n         cnt = min(cnt, A[i + 1] / A[i] - 1); n       } n       ans += A[i] * 1LL * cnt; n       k -= cnt; n       if (k == 0) break; n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void r(int b, int p, int f, int h, int c); n int main() { n   int b, p, f, h, c, t; n   cin >> t; n   while (t--) { n     cin >> b >> p >> f >> h >> c; n     r(b, p, f, h, c); n   } n } n void r(int b, int p, int f, int h, int c) { n   int i, j, k, t = 0; n   i = b / 2; n   if (i == 0) { n     cout << 0 << endl; n   } else { n     if (i >= (p + f)) { n       t = (p * h) + (c * f); n       cout << t << endl; n     } else { n       if (h >= c) { n         if (p >= i) { n           t = (i * h); n           cout << t << endl; n         } else { n           t = (h * p); n           i = i - p; n           t = t + (i * c); n           cout << t << endl; n         } n       } else { n         if (f >= i) { n           t = (i * c); n           cout << t << endl; n         } else { n           t = (c * f); n           i = i - f; n           t = t + (i * h); n           cout << t << endl; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n ; n clock_t start; n mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); n const long long N = 501, lmx = 11; n long long mx[N][N][lmx][lmx], n, m, q, col[4][N][N], logg[N]; n long long sum(long long k, long long r1, long long c1, long long r2, n               long long c2) { n   return col[k][r2][c2] - col[k][r2][c1] - col[k][r1][c2] + col[k][r1][c1]; n } n void sparse() { n   for (long long i = 2; i < N; i++) logg[i] = logg[i / 2] + 1; n   for (long long lgi = 1; lgi < lmx; lgi++) { n     for (long long i = 1; i <= n; i++) { n       for (long long j = 1; j <= m; j++) { n         if (i + (1 << (lgi - 1)) <= n) n           mx[i][j][lgi][0] = max(mx[i][j][lgi - 1][0], n                                  mx[i + (1 << (lgi - 1))][j][lgi - 1][0]); n       } n     } n   } n   for (long long lgi = 0; lgi < lmx; lgi++) { n     for (long long lgj = 1; lgj < lmx; lgj++) { n       for (long long i = 1; i <= n; i++) { n         for (long long j = 1; j <= m; j++) { n           long long k = lgj - 1; n           if (j + (1 << k) <= m) n             mx[i][j][lgi][lgj] = n                 max(mx[i][j][lgi][k], mx[i][j + (1 << k)][lgi][k]); n         } n       } n     } n   } n } n long long query(long long r1, long long c1, long long r2, long long c2) { n   if (r1 > r2 || c1 > c2) return 0; n   long long k1 = logg[r2 - r1 + 1], k2 = logg[c2 - c1 + 1]; n   long long m1 = max(mx[r1][c1][k1][k2], mx[r2 - (1 << k1) + 1][c1][k1][k2]); n   long long m2 = max(mx[r1][c2 - (1 << k2) + 1][k1][k2], n                      mx[r2 - (1 << k1) + 1][c2 - (1 << k2) + 1][k1][k2]); n   return max(m1, m2); n } n void solve() { n   string s, ss =  RGYB ; n   cin >> n >> m >> q; n   for (long long i = 0; i < n; i++) { n     cin >> s; n     for (long long j = 0; j < m; j++) { n       for (long long k = 0; k < 4; k++) n         if (ss[k] == s[j]) col[k][i + 1][j + 1] = 1; n     } n   } n   for (long long k = 0; k < 4; k++) { n     for (long long i = 1; i <= n; i++) n       for (long long j = 1; j <= m; j++) n         col[k][i][j] += n             col[k][i - 1][j] + col[k][i][j - 1] - col[k][i - 1][j - 1]; n   } n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= m; j++) { n       long long lim = min(min(i, j), min(n - i, m - j)); n       for (long long len = 1; len <= lim; len++) { n         if (sum(0, i - len, j - len, i, j) != len * len) break; n         if (sum(1, i - len, j, i, j + len) != len * len) break; n         if (sum(2, i, j - len, i + len, j) != len * len) break; n         if (sum(3, i, j, i + len, j + len) != len * len) break; n         mx[i][j][0][0] = len * len; n       } n     } n   } n   sparse(); n   while (q--) { n     long long r1, c1, r2, c2, ans = 0; n     cin >> r1 >> c1 >> r2 >> c2; n     long long s = 1, e = min(r2 - r1 + 1, c2 - c1 + 1); n     while (s <= e) { n       long long mid = (s + e) / 2; n       if (query(r1 + mid - 1, c1 + mid - 1, r2 - mid, c2 - mid) >= mid * mid) { n         s = mid + 1, ans = mid; n       } else n         e = mid - 1; n     } n     cout << 4 * ans * ans <<   n ; n   } n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   start = clock(); n   cout << fixed << setprecision(15); n   while (t--) { n     solve(); n   } n   double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC); n   cerr << time_taken; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n bool is_simple(int a) { n   for (int i = 2; i < a; ++i) { n     if (a % i == 0) return false; n   } n   return true; n } n int elems[200009] = {0}; n int addings[200009] = {0}; n int removes[200009] = {0}; n vector<string> orders; n int main() { n   int n; n   double current_mean = 0.; n   long long cur_num = 1; n   scanf( %d , &n); n   char buf[100]; n   gets(buf); n   orders.reserve(n); n   for (int i = 1; i < n + 1; ++i) { n     gets(buf); n     orders.push_back(string(buf)); n     int t = orders[i - 1][0] -  0 ; n     addings[i] = addings[i - 1]; n     removes[i] = removes[i - 1]; n     if (t == 2) addings[i]++; n     if (t == 3) removes[i]++; n   } n   for (int i = 0; i < n; ++i) { n     stringstream ss(orders[i]); n     int t; n     ss >> t; n     if (t == 1) { n       int x, a; n       ss >> a >> x; n       double ttt = current_mean * cur_num; n       ttt += a * x; n       current_mean = ttt / cur_num; n       int start_change = cur_num - (removes[n] - removes[i]); n       if (start_change < 0) start_change = 0; n       for (int i = start_change; i < a && i < cur_num; ++i) elems[i] += x; n     } n     if (t == 2) { n       int k; n       ss >> k; n       elems[cur_num] = k; n       cur_num++; n       double ttt = current_mean * (cur_num - 1); n       ttt += k; n       current_mean = ttt / cur_num; n     } n     if (t == 3) { n       double ttt = current_mean * (cur_num); n       ttt -= elems[cur_num - 1]; n       cur_num--; n       current_mean = ttt / cur_num; n     } n     printf( %.6f n , current_mean); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void chkmin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline void chkmax(T &a, T b) { n   if (a < b) a = b; n } n long long sum[30]; n char fir[210000], sec[210000]; n int main() { n   int len, i; n   double ans, cnt; n   scanf( %d , &len); n   scanf( %s%s , fir, sec); n   cnt = 1LL * len * (len + 1) * (2 * len + 1) / 6; n   ans = 0; n   memset(sum, 0, sizeof(sum)); n   for (i = len - 1; i >= 0; i--) { n     sum[fir[i] -  A ] += len - i; n     ans += sum[sec[i] -  A ] * (i + 1) / cnt; n   } n   memset(sum, 0, sizeof(sum)); n   for (i = len - 1; i >= 0; i--) { n     ans += sum[fir[i] -  A ] * (i + 1) / cnt; n     sum[sec[i] -  A ] += len - i; n   } n   printf( %.15lf n , 1.0 * ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, k, ans[5]; n char s[N]; n void solve(int l, int r) { n   while (l != r) { n     int mid = l + r >> 1; n     printf( 1 %d %d n , mid, mid + 1); n     fflush(stdout); n     scanf( %s , s); n     if (!strcmp(s,  NIE )) n       l = mid + 1; n     else n       r = mid; n   } n   ans[++m] = l; n } n int main() { n   scanf( %d%d , &n, &k); n   solve(1, n); n   if (ans[1] > 1) solve(1, ans[1] - 1); n   if (ans[1] < n) solve(ans[1] + 1, n); n   if (m == 2) { n     printf( 2 %d %d n , ans[1], ans[2]); n     exit(0); n   } n   printf( 1 %d %d n , ans[2], ans[3]); n   fflush(stdout); n   scanf( %s , s); n   if (!strcmp(s,  NIE )) ans[2] = ans[3]; n   printf( 2 %d %d n , ans[1], ans[2]); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 2e5 + 5; n const int highestboolN = 1e9; n const long long unsigned inf = 1234568901234567890; n const long double pi = 3.141592653589793; n const int md = 1e9 + 7; n using namespace std; n int here = 1; n void force_break() { n   here++; n   if (here >= (N * 100)) { n     cout <<   n n t Infinite loop  n n ; n     exit(1); n   } n   return; n } n int board[105][105]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   scanf( %d , &n); n   memset(board, 0, sizeof(board)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (board[i][j]) continue; n       char temp; n       if ((i + j) % 2) { n         board[i][j] = 1; n         temp = 2; n       } else { n         board[i][j] = 2; n         temp = 1; n       } n       if (i + 2 < n and j + 1 < n) board[i + 2][j + 1] = temp; n       if (i + 1 < n and j + 2 < n) board[i + 1][j + 2] = temp; n       if (i + 2 < n and j - 1 >= 0) board[i + 2][j - 1] = temp; n       if (i + 1 < n and j - 2 >= 0) board[i + 1][j - 2] = temp; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (board[i][j] == 1) n         cout <<  B ; n       else if (board[i][j] == 2) n         cout <<  W ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[1010], brr[1010]; n int main() { n   long long n, i, j, x, y, ans; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> arr[i]; n   for (i = 1; i <= n; i++) cin >> brr[i]; n   ans = 0; n   for (i = 1; i <= n; i++) { n     x = arr[i]; n     y = brr[i]; n     ans = max(ans, x + y); n     for (j = i + 1; j <= n; j++) { n       x = (x | arr[j]); n       y = (y | brr[j]); n       ans = max(ans, x + y); n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long dp[26][2][2]; n long long need; n bool hasone = 0; n int ans[55]; n inline void upd(long long &a, long long b) { a += b; } n inline long long getval(int p, int v) { n   memset(dp, 0, sizeof(dp)); n   dp[0][0][0] = 1; n   for (int i = 0; i < (n + 1) / 2; i++) { n     for (int x = 0; x < 2; x++) { n       for (int y = 0; y < 2; y++) { n         if (!dp[i][x][y]) continue; n         for (int a = 0; a < 2; a++) { n           if (!i && a) continue; n           if (i <= p && a != ans[i]) continue; n           for (int b = 0; b < 2; b++) { n             if ((n - 1 - i) <= p && b != ans[n - 1 - i]) continue; n             if (i == n - 1 - i && a != b) continue; n             if (a > b && !x) continue; n             if (a > !b && !y) continue; n             upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]); n           } n         } n       } n     } n   } n   return dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] + dp[(n + 1) / 2][1][0] + n          dp[(n + 1) / 2][1][1] - !hasone; n } n int main() { n   cin >> n >> need; n   dp[0][0][0] = 1; n   for (int i = 0; i < (n + 1) / 2; i++) { n     for (int x = 0; x < 2; x++) { n       for (int y = 0; y < 2; y++) { n         if (!dp[i][x][y]) continue; n         for (int a = 0; a < 2; a++) { n           if (!i && a) continue; n           for (int b = 0; b < 2; b++) { n             if (i == n - 1 - i && a != b) continue; n             if (a > b && !x) continue; n             if (a > !b && !y) continue; n             upd(dp[i + 1][x | (a < b)][y | (a < !b)], dp[i][x][y]); n           } n         } n       } n     } n   } n   long long all = dp[(n + 1) / 2][0][0] + dp[(n + 1) / 2][0][1] + n                   dp[(n + 1) / 2][1][0] + dp[(n + 1) / 2][1][1]; n   all--; n   if (all < need) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 0; i < n; i++) { n     ans[i] = 0; n     long long num = getval(i, ans[i]); n     if (num < need || (i == n - 1 && !hasone)) { n       ans[i] = 1; n       need -= num; n       hasone = 1; n     } n   } n   for (int i = 0; i < n; i++) printf( %d , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T& x) { n   int f = 0, c = getchar(); n   x = 0; n   while (!isdigit(c)) f |= c ==  - , c = getchar(); n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   if (f) x = -x; n } n template <typename T, typename... Args> n inline void read(T& x, Args&... args) { n   read(x); n   read(args...); n } n template <typename T> n void write(T x) { n   if (x < 0) x = -x, putchar( - ); n   if (x > 9) write(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n void writes(T x) { n   write(x); n   putchar(   ); n } n template <typename T> n void writeln(T x) { n   write(x); n   puts(  ); n } n template <typename T> n inline bool chkmin(T& x, const T& y) { n   return y < x ? (x = y, true) : false; n } n template <typename T> n inline bool chkmax(T& x, const T& y) { n   return x < y ? (x = y, true) : false; n } n const int maxn = (int)3e5 + 10; n const long long inf = (long long)1e18; n const int mod = (int)1e9 + 7; n int n, a[maxn]; n long long ans; n vector<int> v[maxn]; n int main() { n   read(n); n   for (int i = (1); i < (2 * n + 1); i++) read(a[i]); n   for (int i = (1); i < (2 * n + 1); i++) { n     v[a[i]].push_back(i); n   } n   int now = 1; n   for (int i = (1); i < (n + 1); i++) { n     ans += abs(v[i][0] - now); n     now = v[i][0]; n   } n   now = 1; n   for (int i = (1); i < (n + 1); i++) { n     ans += abs(v[i][1] - now); n     now = v[i][1]; n   } n   write(ans); n } n


#include <bits/stdc++.h> n using namespace std; n const bool debug = 1; n int xl = 1 << 30, xr = -(1 << 30), yl = 1 << 30, yr = -(1 << 30), zl = 1 << 30, n     zr = -(1 << 30); n bool getpod(pair<int, int> p, int s) { n   int pzl = p.first - p.second - s; n   int pzr = p.first - p.second + s; n   int pxl = p.first - s; n   int pxr = p.first + s; n   int pyl = p.second - s; n   int pyr = p.second + s; n   if (pzl <= zl && pzr >= zr && pyl <= yl && pyr >= yr && pxl <= xl && n       pxr >= xr) n     return 1; n   return 0; n } n int main() { n   if (!debug) { n     cin.tie(0); n     cout.tie(0); n     ios::sync_with_stdio(0); n   } n   int n; n   cin >> n; n   vector<pair<int, int>> pt(n, {0, 0}); n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < s.size(); j++) n       if (s[j] ==  B ) n         pt[i].first++; n       else n         pt[i].second++; n   } n   for (int i = 0; i < n; i++) { n     xl = min(pt[i].first, xl); n     xr = max(pt[i].first, xr); n     yl = min(pt[i].second, yl); n     yr = max(pt[i].second, yr); n     zl = min(pt[i].first - pt[i].second, zl); n     zr = max(pt[i].first - pt[i].second, zr); n   } n   vector<pair<int, int>> p(12); n   vector<int> s(12); n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {zr + yl, yl + c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[0] = r; n     p[0] = {zr + yl, yl + s[0]}; n   } n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xl + c, xl - zl}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[1] = r; n     p[1] = {xl + s[1], xl - zl}; n   } n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {zl + yr, yr - c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[2] = r; n     p[2] = {zl + yr, yr - s[2]}; n   } n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xr - c, xr - zr}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[3] = r; n     p[3] = {xr - s[3], xr - zr}; n   } n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xr - c, yr - c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[4] = r; n     p[4] = {xr - s[4], yr - s[4]}; n   } n   { n     int l = -1, r = 1 << 23; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xl + c, yl + c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[5] = r; n     p[5] = {xl + s[5], yl + s[5]}; n   } n   { n     int l = -1, r = zl - xl + yr; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xl + c, yr - c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[6] = r; n     p[6] = {xl + s[6], yr - s[6]}; n   } n   { n     int l = -1, r = xr - yl - zr; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xr - c, yl + c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[7] = r; n     p[7] = {xr - s[7], yl + s[7]}; n   } n   { n     int l = -1, r = xr - zl - yr; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xr - c, xr - zl - 2 * c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[8] = r; n     p[8] = {xr - s[8], xr - zl - 2 * s[8]}; n   } n   { n     int l = -1, r = zr + yr - xr; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {zr + yr - 2 * c, yr - c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[9] = r; n     p[9] = {zr + yr - 2 * s[9], yr - s[9]}; n   } n   { n     int l = -1, r = yl + zr - xl; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {xl + c, xl - zr + 2 * c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[10] = r; n     p[10] = {xl + s[10], xl - zr + 2 * s[10]}; n   } n   { n     int l = -1, r = xl - zl - yl; n     while (l + 1 < r) { n       int c = (l + r) / 2; n       pair<int, int> p = {zl + yl + 2 * c, yl + c}; n       if (getpod(p, c)) n         r = c; n       else n         l = c; n     } n     s[11] = r; n     p[11] = {zl + yl + 2 * s[11], yl + s[11]}; n   } n   int iout = 0; n   for (int i = 0; i < 12; i++) n     if (s[i] < s[iout] && getpod(p[i], s[i])) iout = i; n   cout << s[iout] <<   n ; n   for (int i = 0; i < p[iout].first; i++) cout <<  B ; n   for (int i = 0; i < p[iout].second; i++) cout <<  N ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int arr[3][3]; n   int cnt1, cnt2, cnt3; n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) scanf( %d , &arr[i][j]); n   cnt1 = arr[0][1] + arr[0][2]; n   cnt2 = arr[1][0] + arr[1][2]; n   cnt3 = arr[2][0] + arr[2][1]; n   if (cnt1 >= cnt2 && cnt1 >= cnt3) { n     for (int i = 1; i <= 1e5; i++) n       if (cnt1 + i == cnt2 + (cnt1 - cnt2 + i) && n           cnt1 + i == cnt3 + (cnt1 - cnt3 + i) && n           i + (cnt1 - cnt3 + i) + (cnt1 - cnt2 + i) == cnt1 + i) { n         arr[0][0] = i; n         arr[1][1] = (cnt1 - cnt2 + i); n         arr[2][2] = (cnt1 - cnt3 + i); n         break; n       } n   } else if (cnt2 >= cnt1 && cnt2 >= cnt3) { n     for (int i = 1; i <= 1e5; i++) n       if (cnt2 + i == cnt1 + (cnt2 - cnt1 + i) && n           cnt2 + i == cnt3 + (cnt2 - cnt3 + i) && n           i + (cnt2 - cnt3 + i) + (cnt2 - cnt1 + i) == cnt2 + i) { n         arr[0][0] = (cnt2 - cnt1 + i); n         arr[1][1] = i; n         arr[2][2] = (cnt2 - cnt3 + i); n         break; n       } n   } else if (cnt3 >= cnt1 && cnt3 >= cnt2) { n     for (int i = 1; i <= 1e5; i++) n       if (cnt3 + i == cnt1 + (cnt3 - cnt1 + i) && n           cnt3 + i == cnt2 + (cnt3 - cnt2 + i) && n           i + (cnt3 - cnt2 + i) + (cnt3 - cnt1 + i) == cnt3 + i) { n         arr[0][0] = (cnt3 - cnt1 + i); n         arr[1][1] = (cnt3 - cnt2 + i); n         arr[2][2] = i; n         break; n       } n   } n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) printf( %d  , arr[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, x, a1, a2; n int main() { n   scanf( %lld , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &x); n     if (i % 2 == 0) { n       a1 += (x + 1) / 2; n       a2 += x / 2; n     } else { n       a1 += x / 2; n       a2 += (x + 1) / 2; n     } n   } n   printf( %lld n , min(a1, a2)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); n   int a, b, c; n   cin >> a >> b >> c; n   cout << ((a + c - 1) * (b + c - 1) - c * (c - 1)) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long dx[] = {-1, 0, 1, 0}; n long long dy[] = {0, -1, 0, 1}; n vector<long long> p(10000005, -1); n void f(long long n = 10000005) { n   p[2] = 2; n   for (long long i = 4; i < n; i += 2) { n     p[i] = 2; n   } n   for (long long i = 3; i < n; i += 2) { n     if (p[i] == -1) { n       p[i] = i; n       for (long long j = i * i; j < n; j += i) { n         if (p[j] == -1) p[j] = i; n       } n     } n   } n } n void find(long long x, vector<long long>& v) { n   while (x != 1) { n     v.push_back(p[x]); n     x /= p[x]; n   } n } n void solve() { n   long long n, m; n   cin >> n >> m; n   vector<vector<long long>> v(n, vector<long long>(m)); n   map<long long, vector<long long>> z; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       cin >> v[i][j]; n       z[i + j].push_back(v[i][j]); n     } n   } n   long long f = 0, r = n + m - 2; n   long long ans = 0; n   while (f < r) { n     map<long long, long long> p; n     for (auto x : z[f]) p[x]++; n     for (auto x : z[r]) p[x]++; n     long long t = 0, mx = 0; n     for (auto x : p) { n       t += x.second; n       mx = max(mx, x.second); n     } n     ans += t - mx; n     f++; n     r--; n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char str[100005]; n int cnt[250]; n int main() { n   scanf( %s , &str); n   int len = strlen(str); n   set<char> myset; n   for (int i = 0; i < len; i++) { n     myset.insert(str[i]); n     cnt[str[i]]++; n   } n   if (myset.size() == 1 || myset.size() > 4) { n     printf( NO ); n     return 0; n   } n   if (myset.size() == 4) { n     printf( YES ); n     return 0; n   } n   if (myset.size() == 3) { n     if (len == 3) { n       printf( NO ); n       return 0; n     } else { n       printf( YES ); n       return 0; n     } n   } n   if (myset.size() == 2) { n     for (int i =  a ; i <=  z ; i++) { n       if (cnt[i] == 1) { n         printf( NO ); n         return 0; n       } n     } n     printf( YES ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100005; n int n, m; n int t[MAX_N], x[MAX_N]; n int nxt; n int idx[MAX_N]; n int res[MAX_N]; n bool mycmp(const int a, const int b) { n   if (x[a] != x[b]) return x[a] < x[b]; n   return a < b; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) scanf( %d%d , &t[i], &x[i]); n   int time = 0; n   for (int step = 0; step < n; step += m) { n     nxt = 0; n     for (int i = step; i < min(step + m, n); ++i) idx[nxt++] = i; n     time += max(0, t[idx[nxt - 1]] - time); n     sort(idx, idx + nxt, mycmp); n     for (int i = 0; i < nxt;) { n       int j = i; n       for (; j < nxt && x[idx[i]] == x[idx[j]]; ++j) n         ; n       time += x[idx[i]]; n       if (i > 0) time -= x[idx[i - 1]]; n       for (int k = i; k < j; ++k) res[idx[k]] = time; n       time += 1 + (j - i) / 2; n       i = j; n     } n     time += x[idx[nxt - 1]]; n   } n   printf( %d , res[0]); n   for (int i = 1; i < n; ++i) printf(  %d , res[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n const int mod = 1e9 + 7; n const long long INF = 1e18; n string a[30], b[30], ans[407]; n void rua() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   int cnt = 0, s1 = -1, s2 = -1; n   while (cnt < n * m) { n     s1 = (s1 + 1) % n; n     s2 = (s2 + 1) % m; n     ans[cnt++] = a[s1] + b[s2]; n   } n   int q; n   cin >> q; n   while (q--) { n     int x; n     cin >> x; n     cout << ans[(x - 1) % (n * m)] << endl; n   } n } n int main() { n   rua(); n   return 0; n } n


#include <bits/stdc++.h> n int main(int argc, char *argv[]) { n   int n, i, a, b, c, d; n   long int s; n   scanf( %d , &n); n   s = 0; n   for (i = 1; i <= n; i++) { n     scanf( %d %d %d %d , &a, &b, &c, &d); n     s = s + (1 + abs(a - c)) * (1 + abs(b - d)); n   } n   printf( %ld , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n int main() { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   vector<vector<int> > edges(n + 10, vector<int>()); n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     edges[x].push_back(y); n     edges[y].push_back(x); n   } n   map<int, int> not_first; n   map<int, int> not_second; n   map<int, int> not_third; n   set<int> first; n   set<int> second; n   set<int> third; n   for (int i = 1; i < n + 1; i++) { n     if (not_first.find(i) == not_first.end()) { n       first.insert(i); n       for (int j = 0; j < edges[i].size(); j++) { n         not_first[edges[i][j]]++; n       } n     } else if (not_second.find(i) == not_second.end()) { n       second.insert(i); n       for (int j = 0; j < edges[i].size(); j++) { n         not_second[edges[i][j]]++; n       } n     } else if (not_third.find(i) == not_third.end()) { n       third.insert(i); n       for (int j = 0; j < edges[i].size(); j++) { n         not_third[edges[i][j]]++; n       } n     } else { n       cout << -1; n       return 0; n     } n   } n   if (second.size() == 0 or third.size() == 0) { n     cout << -1; n   } else { n     for (auto i = not_first.begin(); i != not_first.end(); i++) { n       if (i->second != first.size()) { n         cout << -1; n         return 0; n       } n     } n     for (auto i = not_second.begin(); i != not_second.end(); i++) { n       if (i->second != second.size()) { n         cout << -1; n         return 0; n       } n     } n     for (auto i = not_third.begin(); i != not_third.end(); i++) { n       if (i->second != third.size()) { n         cout << -1; n         return 0; n       } n     } n     vector<int> cols(n + 1, 0); n     for (auto i = first.begin(); i != first.end(); i++) { n       cols[*i] = 1; n     } n     for (auto i = second.begin(); i != second.end(); i++) { n       cols[*i] = 2; n     } n     for (auto i = third.begin(); i != third.end(); i++) { n       cols[*i] = 3; n     } n     for (int i = 1; i < n + 1; i++) { n       cout << cols[i] <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimization( unroll-loops ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) n using namespace std; n const int BASE = 1000000; n char what[1 << 20]; n pair<int, int> nxt[10][1 << 20]; n pair<long long, int> to[10][10]; n inline long long Calc(long long x) { n   long long suff = x / BASE, pref = x % BASE; n   long long ans = suff; n   while (suff > 0) { n     ans += nxt[what[suff]][pref].first; n     pref = nxt[what[suff]][pref].second; n     pref += BASE - max(what[suff], what[pref]); n     --suff; n   } n   return ans + nxt[0][pref].first; n } n inline long long Process(long long x) { n   long long suff = x / (1LL * BASE * BASE), psuff = x / BASE % BASE, n             pref = x % BASE; n   if (suff == 0) { n     return Calc(x); n   } n   long long ans = 0; n   while (psuff >= 0) { n     ans += nxt[max(what[psuff], what[suff])][pref].first + 1; n     pref = nxt[max(what[psuff], what[suff])][pref].second; n     pref += BASE - max(what[psuff], max(what[suff], what[pref])); n     --psuff; n   } n   --suff; n   while (suff > 0) { n     ans += to[what[suff]][BASE - pref].first; n     pref = to[what[suff]][BASE - pref].second; n     --suff; n   } n   return ans + Calc(1LL * (BASE - 1) * BASE + pref); n } n int main() { n   for (int i = 1; i <= BASE; ++i) { n     what[i] = i % 10 > what[i / 10] ? i % 10 : what[i / 10]; n     for (int d = 0; d < 10; ++d) { n       char r = what[i] < d ? d : what[i]; n       if (i >= r) { n         nxt[d][i] = make_pair(nxt[d][i - r].first + 1, nxt[d][i - r].second); n       } else { n         nxt[d][i] = make_pair(0, i); n       } n     } n   } n   for (char d = 1; d < 10; ++d) { n     for (int l = 0; l < 10; ++l) { n       int suff = BASE - 1, pref = BASE - l; n       to[d][l].first = BASE; n       while (suff >= 0) { n         char r = (d < what[suff] ? what[suff] : d); n         to[d][l].first += nxt[r][pref].first; n         pref = nxt[r][pref].second; n         pref += BASE - (r < what[pref] ? what[pref] : r); n         --suff; n       } n       to[d][l].second = pref; n     } n   } n   long long n; n   cin >> n; n   cout << Process(n) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 200000 + 10; n const int INF = 0x7fffffff; n using namespace std; n struct EDGE { n   int u, v, w; n   bool operator<(const EDGE &b) const { return w > b.w; } n }; n int fa[MAXN + MAXN]; n int n, m, vis[MAXN]; n int Min[MAXN]; n vector<EDGE> edge; n int Find(int x) { return fa[x] < 0 ? x : fa[x] = Find(fa[x]); } n int main() { n   edge.clear(); n   scanf( %d%d , &n, &m); n   memset(fa, -1, sizeof(fa)); n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= m; i++) { n     int a, b, w; n     scanf( %d%d%d , &a, &b, &w); n     edge.push_back((EDGE){a, b, w}); n   } n   sort(edge.begin(), edge.end()); n   long long Ans = 0ll; n   for (int i = 0; i < m; i++) { n     int u = edge[i].u, v = edge[i].v; n     u = Find(u); n     v = Find(v); n     if (u == v) { n       if (fa[u] == -2) continue; n       fa[u] = -2; n       Ans += (long long)edge[i].w; n       continue; n     } n     if (fa[u] == -2 && fa[v] == -2) continue; n     fa[v] = min(fa[v], fa[u]); n     Ans += (long long)edge[i].w; n     fa[u] = v; n   } n   printf( %lld n , Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int intervalo[200010]; n int aparicoes[200010]; n int aceito[200010]; n int main() { n   int n, k, q; n   cin >> n >> k >> q; n   int l, r; n   for (int i = 0; i < n; i++) { n     cin >> l >> r; n     intervalo[l] += 1; n     intervalo[r + 1] -= 1; n   } n   int x = 0; n   for (int i = 1; i <= 200000; i++) { n     x += intervalo[i]; n     aparicoes[i] = x; n   } n   for (int i = 1; i <= 200000; i++) { n     if (aparicoes[i] >= k) n       aceito[i] = 1; n     else n       aceito[i] = 0; n     aceito[i] += aceito[i - 1]; n   } n   for (int i = 0; i < q; i++) { n     cin >> l >> r; n     cout << aceito[r] - aceito[l - 1] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   cin >> a; n   b = a; n   for (string::reverse_iterator itr = a.rbegin(); itr != a.rend(); itr++) n     b += *itr; n   cout << b << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n const int inf = 1000000007; n const int MOD = 1000000007; n int f(int x) { n   int res = 0; n   while (x > 0) { n     res += x % 10; n     x /= 10; n   } n   return res; n } n bool calc(int n, int k) { n   int sm = 0; n   for (int i = 0; i < k; ++i) { n     sm += f(i); n   } n   for (int i = k; i <= 100000; ++i) { n     sm += f(i); n     if (sm == n) { n       cout << i - k <<   n ; n       return true; n     } n     sm -= f(i - k); n   } n   if (n <= 45) { n     cout << -1 <<   n ; n     return true; n   } n   return false; n } n void solve() { n   int n, k; n   cin >> n >> k; n   if (calc(n, k)) return; n   n -= k * (k + 1) / 2; n   if (n < 0) { n     cout << -1 <<   n ; n     return; n   } n   int top = 0; n   string mid; n   int last = 0; n   int cnt = 0; n   while (n % (k + 1) != 0) { n     n += 9; n     cnt++; n     if (cnt > 9) { n       cout << -1 <<   n ; n       return; n     } n   } n   if (n - cnt * 9 < (k - cnt) * 9) { n     cout << -1 <<   n ; n     return; n   } n   last = 9 - (k - cnt); n   n /= (k + 1); n   n -= last; n   while (n > 9) { n     n -= 9; n     mid +=  9 ; n   } n   top = n; n   if (cnt > 0) { n     int l = mid.length(); n     if (l != 0) { n       mid[l - 1] =  8 ; n       top++; n     } n   } n   string hoge; n   while (top > 9) { n     top -= 9; n     hoge +=  9 ; n   } n   if (top > 0) cout << top; n   cout << hoge << mid << last <<   n ; n } n signed main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3,no-stack-protector,unroll-loops,fast-math ) n using namespace std; n struct coor { n   long long x, y, x1, y1; n }; n vector<struct coor> v; n struct coor ldp[200005], rdp[200005]; n struct coor inter(struct coor l, struct coor r) { n   struct coor res = {INT_MIN, INT_MIN, INT_MIN, INT_MIN}; n   if (min(l.x1, r.x1) < max(r.x, l.x) || min(l.y1, r.y1) < max(r.y, l.y)) n     return res; n   res.x = max(l.x, r.x); n   res.x1 = min(l.x1, r.x1); n   res.y = max(l.y, r.y); n   res.y1 = min(l.y1, r.y1); n   return res; n } n bool check(struct coor l) { return (l.x != INT_MIN); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a >> b >> c >> d; n     v.push_back({a, b, c, d}); n   } n   ldp[0] = v[0]; n   for (i = 1; i < n; i++) { n     ldp[i] = inter(ldp[i - 1], v[i]); n   } n   rdp[n - 1] = v[n - 1]; n   for (i = n - 2; i >= 0; i--) { n     rdp[i] = inter(rdp[i + 1], v[i]); n   } n   if (check(ldp[n - 2])) { n     cout << ldp[n - 2].x <<     << ldp[n - 2].y <<   n ; n   } else if (check(rdp[1])) { n     cout << rdp[1].x <<     << rdp[1].y <<   n ; n   } else { n     for (i = 1; i < n - 1; i++) { n       struct coor fin = inter(ldp[i - 1], rdp[i + 1]); n       if (check(fin)) { n         cout << fin.x <<     << fin.y <<   n ; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, a, b, c, d; n   cin >> t; n   while (t--) { n     cin >> n >> a >> b >> c >> d; n     int mi = (a - b) * n, ma = (a + b) * n; n     if ((mi > c + d) || (ma < c - d)) n       cout <<  NO  << endl; n     else n       cout <<  YES  << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n const long long mod = 1000000007; n void solve() { n   int n, m, u, v; n   cin >> n >> m; n   vector<int> adj[n + 1]; n   for (int i = 0; i < m; i++) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   vector<pair<long long, long long> > hash, hash_orig; n   hash.reserve(n); n   long long p1 = 31, p2 = 53, h1, h2; n   long long pow_p1[n + 1], pow_p2[n + 1]; n   pow_p1[0] = pow_p2[0] = 1; n   for (int i = 1; i <= n; i++) { n     pow_p1[i] = pow_p1[i - 1] * p1 % mod; n     pow_p2[i] = pow_p2[i - 1] * p2 % mod; n   } n   for (int i = 1; i <= n; i++) { n     h1 = 0; n     h2 = 0; n     for (int &j : adj[i]) { n       h1 += pow_p1[j]; n       h2 += pow_p2[j]; n     } n     hash.push_back({h1, h2}); n   } n   hash_orig = hash; n   sort((hash).begin(), (hash).end()); n   long long ans = 0; n   int cnt = 1; n   for (int i = 1; i < n; i++) { n     if (hash[i] != hash[i - 1]) { n       ans += 1ll * cnt * (cnt - 1) / 2; n       cnt = 1; n     } else n       cnt++; n   } n   ans += 1ll * cnt * (cnt - 1) / 2; n   for (int i = 1; i <= n; i++) { n     hash_orig[i - 1].first += pow_p1[i]; n     hash_orig[i - 1].second += pow_p2[i]; n   } n   for (int i = 1; i <= n; i++) { n     for (int &j : adj[i]) { n       if (j < i || adj[i].size() != adj[j].size()) continue; n       if (hash_orig[i - 1] == hash_orig[j - 1]) ans++; n     } n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n typedef long long int ll; n typedef unsigned long long int ull; n inline void smax(int &x, int y) { x = max(x, y); } n inline void smin(int &x, int y) { x = min(x, y); } n ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } n const double PI = acos(-1.0l); n vector<long long> rev; n vector<complex<double> > omega; n void calc_rev(long long n, long long log_n) { n   rev.resize(n); n   omega.resize(n); n   for (long long i = 0; i < n; i++) { n     rev[i] = 0; n     for (long long j = 0; j < log_n; j++) { n       if ((i >> j) & 1) rev[i] |= 1 << (log_n - j - 1); n     } n   } n } n void fft(vector<complex<double> > &A, long long n, bool invert) { n   for (long long i = 0; i < n; i++) { n     if (i < rev[i]) swap(A[i], A[rev[i]]); n   } n   for (long long len = 2; len <= n; len <<= 1) { n     double ang = 2 * PI / len * (invert ? -1 : +1); n     long long half = (len >> 1); n     complex<double> curomega(cos(ang), sin(ang)); n     omega[0] = complex<double>(1, 0); n     for (long long i = 1; i < half; i++) omega[i] = omega[i - 1] * curomega; n     for (long long i = 0; i < n; i += len) { n       complex<double> t; n       long long pu = i, pv = i + half, pu_end = i + half, pw = 0; n       for (; pu != pu_end; pu++, pv++, pw++) { n         t = A[pv] * omega[pw]; n         A[pv] = A[pu] - t; n         A[pu] += t; n       } n     } n   } n   if (invert) n     for (long long i = 0; i < n; i++) A[i] /= n; n } n void multiply(long long n, vector<complex<double> > &A, n               vector<complex<double> > &B, vector<long long> &C) { n   fft(A, n, false); n   fft(B, n, false); n   for (long long i = 0; i < n; i++) A[i] *= B[i]; n   fft(A, n, true); n   for (long long i = 0; i < n; i++) { n     C[i] = (long long)(A[i].real() + 0.5); n     C[i] = min(C[i], 1LL); n   } n } n void Solve(long long n, vector<long long> &coeffA, vector<long long> &coeffB, n            vector<long long> &result) { n   vector<complex<double> > A(n), B(n); n   for (long long i = 0; i < n; i++) A[i] = coeffA[i]; n   for (long long i = 0; i < n; i++) B[i] = coeffB[i]; n   multiply(n, A, B, result); n } n void do_FFT(vector<long long> &A, vector<long long> &B, n             vector<long long> &result) { n   long long n = 1, bits = 0; n   while (n < 2 * A.size() || n < 2 * B.size()) n <<= 1, bits++; n   result.resize(n, 0); n   calc_rev(n, bits); n   vector<long long> tempA(A.begin(), A.end()); n   vector<long long> tempB(B.begin(), B.end()); n   tempA.resize(n); n   tempB.resize(n); n   Solve(n, tempA, tempB, result); n } n vector<ll> polpow(vector<ll> &arr, long long k) { n   vector<ll> sol; n   while (k > 0) { n     if (k % 2) { n       if (sol.size() == 0) n         for (__typeof(arr.size()) i = (0) - ((0) > (arr.size())); n              i != (arr.size()) - ((0) > (arr.size())); n              i += 1 - 2 * ((0) > (arr.size()))) n           sol.push_back(arr[i]); n       else n         do_FFT(sol, arr, sol); n     } n     do_FFT(arr, arr, arr); n     k = k / 2; n   } n   return sol; n } n int32_t main() { n   long long n, k; n   cin >> n >> k; n   vector<long long> v(n); n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) n     cin >> v[i]; n   vector<ll> arr(1001); n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) { n     arr[v[i]] = 1; n   } n   while (arr.back() == 0) { n     arr.pop_back(); n   } n   vector<ll> res = polpow(arr, k); n   for (__typeof(res.size()) i = (1) - ((1) > (res.size())); n        i != (res.size()) - ((1) > (res.size())); n        i += 1 - 2 * ((1) > (res.size()))) { n     if (res[i] > 0) cout << i <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m = 0; n   cin >> n; n   int last; n   for (int(i) = 0; (i) < (n); ++(i)) { n     cin >> last; n     m += last; n   } n   cout << ((n - m == 1 && n > 1) || (n == 1 && m == 1) ?  YES n  :  NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, trie[100100][27], sz = 1, ok[2][100100]; n char s[100100]; n void add() { n   int v = 0; n   for (int i = 0; s[i] !=   0 ; i++) { n     if (trie[v][s[i] -  a ] == 0) trie[v][s[i] -  a ] = sz++; n     v = trie[v][s[i] -  a ]; n   } n } n void calc(int v, bool bo, int temp[30]) { n   int arr[5]; n   for (int i = 0; i < 5; i++) arr[i] = 0; n   for (int i = 0; i < 26; i++) { n     if (temp[i] == -1) continue; n     if (temp[i] == 0) { n       ok[bo][v] = 0; n       break; n     } n     if (temp[i] == 1) { n       if (arr[2]) { n         ok[bo][v] = 0; n         break; n       } n     } n     if (temp[i] == 2) { n       if (arr[1]) { n         ok[bo][v] = 0; n         break; n       } n     } n     arr[temp[i]]++; n   } n   if (ok[bo][v] != 0) n     ok[bo][v] = (arr[3] && !arr[1] && !arr[2] ? 3 : (arr[1] ? 1 : 2)); n } n int dfs(int v, bool st, bool bo) { n   int cnt = 0, temp[26]; n   for (int i = 0; i < 26; i++) temp[i] = -1; n   for (int i = 0; i < 26; i++) { n     if (!trie[v][i]) continue; n     cnt++; n     temp[i] = dfs(trie[v][i], !st, bo); n     if (temp[i] == 1) n       ok[bo][v] = (ok[bo][v] < 2 ? 1 : 3); n     else if (temp[i] == 2) n       ok[bo][v] = (ok[bo][v] == 2 || ok[bo][v] == 0 ? 2 : 3); n     else if (temp[i] == 3) n       ok[bo][v] = 3; n   } n   if (cnt > 1 && !st && !bo) calc(v, bo, temp); n   if (cnt > 1 && st && bo) calc(v, bo, temp); n   if (cnt == 0) ok[bo][v] = (st ? 2 : 1); n   return ok[bo][v]; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %s , &s); n     add(); n   } n   dfs(0, 1, 0); n   dfs(0, 1, 1); n   if (ok[0][0] == 3) n     printf( First n ); n   else if (ok[0][0] == 1) { n     if (k % 2) n       printf( First n ); n     else n       printf( Second n ); n   } else if (ok[0][0] == 2) n     printf( Second n ); n   else { n     if (ok[1][0] == 3) n       printf( Second n ); n     else if (ok[1][0] == 1) { n       if (k % 2) n         printf( First n ); n       else n         printf( Second n ); n     } else if (ok[1][0] == 2) n       printf( Second n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int t, id, n, m, x, y, k, c, p, dif, ans, sum, pre, rem, cur, tmp, tot, r, l, u, n     d, xx, yy; n int a[N], vis[N], f[N], b[N], cu[N]; n vector<int> v, adj[N]; n bool fl, ok; n int dp[N]; n int mem[N]; n int sol(int i = n) { n   int &ret = mem[i]; n   if (~ret) return ret; n   if (!i) return ret = 0; n   ret = sol(i - 1) + 20; n   int B90 = upper_bound(a + 1, a + n + 1, a[i] - 90) - (a + 1); n   ret = min(ret, sol(B90) + 50); n   int Bday = upper_bound(a + 1, a + n + 1, a[i] - 1440) - (a + 1); n   ret = min(ret, sol(Bday) + 120); n   return ret; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= (int)n; ++i) scanf( %d , &a[i]); n   memset(mem, -1, sizeof mem); n   ; n   sol(); n   for (int i = 1; i <= (int)n; ++i) printf( %d n , sol(i) - sol(i - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n char maz[505][505]; n int dp[10][505][505]; n inline void cm(int& x) { n   if (x >= mod) x -= mod; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %s , maz[i] + 1); n   int up = (n + m - 1) / 2; n   if (maz[1][1] != maz[n][m]) { n     puts( 0 ); n     return 0; n   } n   dp[0][1][m] = 1; n   for (int i = 0; i < up; ++i) { n     int ni = (i + 1) & 1, li = i & 1; n     memset(dp[ni], 0, sizeof(dp[ni])); n     for (int j = 1; j <= m; ++j) { n       int y1 = i + 2 - j; n       if (y1 < 1 || y1 > n) continue; n       for (int k = m; k >= 1; --k) { n         int y2 = n + m - i - k; n         if (y2 < 1 || y2 > n || maz[y1][j] != maz[y2][k]) continue; n         if (y1 < n && y2 > 1 && maz[y1 + 1][j] == maz[y2 - 1][k]) n           dp[ni][j][k] += dp[li][j][k]; n         if (y1 < n && k > 1 && maz[y1 + 1][j] == maz[y2][k - 1]) n           dp[ni][j][k - 1] += dp[li][j][k]; n         if (j < m && y2 > 1 && maz[y1][j + 1] == maz[y2 - 1][k]) n           dp[ni][j + 1][k] += dp[li][j][k]; n         if (j < m && k > 1 && maz[y1][j + 1] == maz[y2][k - 1]) n           dp[ni][j + 1][k - 1] += dp[li][j][k]; n         cm(dp[ni][j][k]); n         cm(dp[ni][j][k - 1]); n         cm(dp[ni][j + 1][k]); n         cm(dp[ni][j + 1][k - 1]); n       } n     } n   } n   int ans = 0; n   if ((n + m - 1) % 2) { n     for (int i = 1; i <= n; ++i) { n       ans += dp[up & 1][up + 2 - i][up + 2 - i]; n       cm(ans); n     } n   } else { n     up--; n     for (int i = 1; i <= n; ++i) { n       ans += dp[up & 1][up + 2 - i][up + 3 - i]; n       cm(ans); n       ans += dp[up & 1][up + 2 - i][up + 2 - i]; n       cm(ans); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n void task(); n int main() { n   task(); n   return 0; n } n const int N = 2e5 + 10; n const long long int MOD = (long long int)1e9 + 7; n const int INF = 0x3f3f3f3f; n const long long int LINF = (long long int)4e18 + 100; n const int BUF_SIZE = (int)1e6 + 10; n const double PI = acos(-1); n pair<int, int> a[N]; n double u[N], ad[N], bd[N]; n long long int sq_dist(long long int x1, long long int y1, long long int x2, n                       long long int y2) { n   return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); n } n double dist(long long int x1, long long int y1, long long int x2, n             long long int y2) { n   return sqrt(sq_dist(x1, y1, x2, y2)); n } n double dp[N][2][2]; n void task() { n   int ai, aj, bi, bj, ui, uj; n   cin >> ai >> aj >> bi >> bj >> ui >> uj; n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i].first >> a[i].second; n   } n   for (int i = 0; i < n; ++i) { n     u[i] = dist(ui, uj, a[i].first, a[i].second); n     (void(1)); n     ; n   } n   for (int i = 0; i < n; ++i) { n     ad[i] = dist(ai, aj, a[i].first, a[i].second) + u[i]; n     (void(1)); n     ; n   } n   for (int i = 0; i < n; ++i) { n     bd[i] = dist(bi, bj, a[i].first, a[i].second) + u[i]; n     (void(1)); n     ; n   } n   fill(dp[0][0], dp[0][0] + N * 2 * 2, LINF); n   dp[0][1][1] = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < 2; ++j) { n       for (int k = 0; k < 2; ++k) { n         (void(1)); n         ; n         if (j == 1) { n           dp[i + 1][j - 1][k] = min(dp[i][j][k] + ad[i], dp[i + 1][j - 1][k]); n         } n         if (k == 1) { n           dp[i + 1][j][k - 1] = min(dp[i][j][k] + bd[i], dp[i + 1][j][k - 1]); n         } n         dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + 2 * u[i]); n       } n     } n   } n   double ans = LINF; n   for (int i = 0; i < 2; ++i) { n     for (int j = 0; j < 2; ++j) n       if (!(i == 1 && j == 1)) { n         (void(1)); n         ; n         ans = min(ans, dp[n][i][j]); n       } n   } n   cout << fixed << setprecision(12) << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int f = 1; n     int s = 0; n     vector<int> A; n     for (int i = 0; i < n; i++) { n       int a; n       cin >> a; n       A.push_back(a); n     } n     if (A.size() == 1) { n       cout <<  First  << endl; n       continue; n     } n     if (n == 2) { n       if (A[0] != 1) { n         cout <<  First  << endl; n         continue; n       } else { n         cout <<  Second  << endl; n         continue; n       } n     } n     for (int i = 0; i < n - 2; i++) { n       if (A[i] != 1 && A[i + 1] != 1) { n         if (f == 1) { n           f = 1; n           s = 0; n         } else { n           s = 1; n           f = 0; n         } n       } else if (A[i] != 1 && A[i + 1] == 1) { n         int count = 0; n         int j = i + 1; n         while (A[j] == 1 && j <= n - 2) { n           count++; n           j++; n         } n         if (count % 2 == 1) { n           if (f == 1) { n             s = 1; n             f = 0; n           } else { n             f = 1; n             s = 0; n           } n         } else { n           if (f == 1) { n             f = 1; n             s = 0; n           } else { n             s = 1; n             f = 0; n           } n         } n       } else if (A[i] == 1) { n         if (f == 1) { n           s = 1; n           f = 0; n         } else { n           f = 1; n           s = 0; n         } n       } n     } n     if (A[n - 2] != 1 && f == 1) { n       cout <<  First  << endl; n       continue; n     } else if (A[n - 2] == 1 && f == 1) { n       cout <<  Second  << endl; n       continue; n     } else if (A[n - 2] != 1 && s == 1) { n       cout <<  Second  << endl; n       continue; n     } else if (A[n - 2] == 1 && s == 1) { n       cout <<  First  << endl; n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500100; n multiset<pair<long long, long long> > intervals; n long long n, k; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 0; i < k; i++) intervals.insert(make_pair(0, i)); n   long long s, d; n   for (int i = 0; i < n; i++) { n     cin >> s >> d; n     auto x = intervals.begin(); n     long long stx = (*x).first; n     long long idx = (*x).second; n     if (stx < s) stx = s; n     stx += d; n     cout << stx <<   n ; n     intervals.erase(x); n     intervals.insert(make_pair(stx, idx)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n }; n vector<node> q; n int n, m, sum[2020][2020]; n char g[2020][2020]; n void init() { n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (g[i][j] ==  w ) q.push_back((node){i, j}); n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (g[i][j] ==  w ) sum[i][j] = 1; n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (j - 1 >= 0) sum[i][j] = sum[i][j - 1] + sum[i][j]; n   for (int i = 0; i < (m); i++) n     for (int j = 0; j < (n); j++) n       if (j - 1 >= 0) sum[j][i] = sum[j - 1][i] + sum[j][i]; n } n bool cmpx(node a, node b) { return a.x < b.x; } n bool cmpy(node a, node b) { return a.y < b.y; } n int getlen() { n   int res = -1; n   sort(q.begin(), q.end(), cmpx); n   res = max(res, abs(q[0].x - q[q.size() - 1].x) + 1); n   sort(q.begin(), q.end(), cmpy); n   res = max(res, abs(q[0].y - q[q.size() - 1].y) + 1); n   return res; n } n int getarea(int x1, int y1, int x2, int y2) { n   if (x1 > x2 || y1 > y2) return 0; n   int res = sum[x2][y2]; n   if (x1 - 1 >= 0) res -= sum[x1 - 1][y2]; n   if (y1 - 1 >= 0) res -= sum[x2][y1 - 1]; n   if (x1 - 1 >= 0 && y1 - 1 >= 0) res += sum[x1 - 1][y1 - 1]; n   return res; n } n bool check(int x, int y, int len) { n   int x2 = x - len + 1; n   int y2 = y - len + 1; n   int in = getarea(x2 + 1, y2 + 1, x - 1, y - 1); n   int out = getarea(0, 0, n - 1, m - 1) - getarea(x2, y2, x, y); n   if (in || out) n     return false; n   else n     return true; n } n void filling(int x, int y, int x2, int y2) { n   for (int i = x; i <= x2; i++) n     for (int j = y; j <= y2; j++) n       if (i == x || i == x2 || j == y || j == y2) n         g[i][j] = (g[i][j] ==  . ) ?  +  :  w ; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < (n); i++) scanf( %s , g[i]); n   init(); n   int len = getlen(); n   bool flg = 0; n   for (int i = 0; i < (n); i++) n     for (int j = 0; j < (m); j++) n       if (i + 1 >= len && j + 1 >= len) { n         if (flg) break; n         if (check(i, j, len)) { n           flg = true; n           filling(i - len + 1, j - len + 1, i, j); n           break; n         } n       } n   if (flg) n     for (int i = 0; i < (n); i++) printf( %s n , g[i]); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class U> n void maximize(T &x, U y) { n   if (x < y) x = y; n } n template <class T, class U> n void minimize(T &x, U y) { n   if (x > y) x = y; n } n template <class T> n T Abs(T x) { n   return (x < (T)0 ? -x : x); n } n template <class T> n T safe_sqrt(T x) { n   return sqrt(max((T)0, x)); n } n template <class T, class U, class V> n T addmod(T x, U k, V mod) { n   return ((x + k) % mod + mod) % mod; n } n template <class T, class U, class V> n T submod(T x, U k, V mod) { n   return ((x - k) % mod + mod) % mod; n } n template <class T, class U, class V> n T mulmod(T x, U k, V mod) { n   return (int64_t)x * k % mod; n } n namespace task { n int64_t dp[11][100][1200]; n int b; n int64_t l, r; n vector<int> digits; n vector<int> trans(int64_t x, int b) { n   vector<int> vec; n   while (x > 0) vec.push_back(x % b), x /= b; n   return vec; n } n int64_t calc(int base, int idx, int mask, bool flag) { n   if (idx == -1) return (mask == 0); n   if (~dp[base][idx][mask] and flag) return dp[base][idx][mask]; n   int64_t ret = 0; n   int k = flag ? b - 1 : digits[idx]; n   for (int i = 0; i <= k; ++i) n     ret += calc(base, idx - 1, mask ^ ((1LL) << (i)), flag | (i < k)); n   if (flag) dp[base][idx][mask] = ret; n   return ret; n } n int64_t f(int64_t x) { n   if (!x) return 0ll; n   digits.clear(); n   digits = trans(x, b); n   int64_t ret = 0; n   for (int i = 0; i < ((digits).size()); ++i) { n     int up = (i == ((digits).size()) - 1 ? digits[i] : b - 1); n     for (int j = 1; j <= up; ++j) n       ret += n           calc(b, i - 1, ((1LL) << (j)), (i < ((digits).size()) - 1 or j < up)); n   } n   return ret; n } n void solve() { n   int q; n   scanf( %d , &q); n   memset(dp, -1ll, sizeof(dp)); n   while (q--) { n     scanf( %d%I64d%I64d , &b, &l, &r); n     int64_t x = f(r); n     int64_t y = f(l - 1); n     int64_t ans = f(r) - f(l - 1); n     printf( %I64d n , ans); n   } n } n }  // namespace task n int main(void) { task::solve(); } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1050]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int tens = a[0]; n   set<int> answer; n   for (int rem = 0; rem < 10000000; rem++) { n     double fuel = tens * 10 + static_cast<double>(rem) / 1000000; n     double addend = fuel; n     bool isValid = true; n     for (int i = 0; isValid and i < n; i++) { n       fuel -= (a[i] - (i == 0 ? 0 : a[i - 1])) * 10; n       if (fuel < 0 or fuel >= 10 - 1e-6) { n         isValid = false; n       } n       fuel += addend; n     } n     if (isValid) { n       answer.insert(static_cast<int>(fuel) / 10 + a[n - 1]); n     } n   } n   if (answer.size() > 1) n     cout <<  not unique  << endl; n   else n     cout <<  unique  << endl << *answer.begin() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)2e5 + 10; n vector<pair<int, int> > a, b; n vector<int> L; n int n, m, q[MAXN], id[MAXN], Tohka[MAXN], l[MAXN], r[MAXN], t[MAXN], fa[MAXN], n     T[MAXN]; n bool cmp(int first, int second) { return q[first] < q[second]; } n bool cmp1(int first, int second) { return t[first] < t[second]; } n int Getp(int a) { return lower_bound(L.begin(), L.end(), a) - L.begin(); } n int getf(int first) { n   if (fa[first] == first) return first; n   fa[first] = getf(fa[first]); n   return fa[first]; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     scanf( %d%d%d , &l[i], &r[i], &t[i]); n     L.push_back(l[i]), L.push_back(r[i]); n     id[i] = i; n   } n   sort(L.begin(), L.end()); n   L.erase(unique(L.begin(), L.end()), L.end()); n   for (int i = 0; i < ((int)(L).size()); ++i) fa[i] = i; n   sort(id + 1, id + m + 1, cmp1); n   memset(T, -1, sizeof(T)); n   for (int i = 1; i <= m; ++i) { n     int tl = Getp(l[id[i]]), tr = Getp(r[id[i]]), tT = t[id[i]]; n     for (tl = getf(tl); tl < tr; T[tl] = tT, fa[tl] = tl + 1, tl = getf(tl)) n       ; n   } n   for (int i = 0; i + 1 < ((int)(L).size()); ++i) { n     int l = L[i], r = L[i + 1], t = T[i]; n     if (T[i] == -1) continue; n     a.push_back(make_pair(t - r, 1)), a.push_back(make_pair(t - l, -1)); n     b.push_back(make_pair(t - r, -(t - r))), n         b.push_back(make_pair(t - l, (t - r))); n     b.push_back(make_pair(t - l, (r - l))); n   } n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   for (int i = 1; i <= n; ++i) scanf( %d , &q[i]), id[i] = i; n   sort(id + 1, id + n + 1, cmp); n   long long s1 = 0, s2 = 0; n   for (int i = 1, p1 = 0, p2 = 0; i <= n; ++i) { n     for (; p1 < ((int)(a).size()) && a[p1].first <= q[id[i]]; n          s1 += a[p1].second, ++p1) n       ; n     for (; p2 < ((int)(b).size()) && b[p2].first <= q[id[i]]; n          s2 += b[p2].second, ++p2) n       ; n     Tohka[id[i]] = s1 * q[id[i]] + s2; n   } n   for (int i = 1; i <= n; ++i) printf( %d n , Tohka[i]); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, q; n   scanf( %d %d %d , &n, &m, &q); n   int log_n = 0; n   while (1 << log_n <= n) { n     ++log_n; n   } n   int jump_small = pow(n, 1.0 / 3), jump_large = pow(n, 2.0 / 3); n   vector<vector<int>> rmq_min(log_n, vector<int>(n)), n       rmq_max(log_n, vector<int>(n)); n   vector<int> a(n), next(n), jump(n), times(n), now_min(n), now_max(n); n   priority_queue<pair<int, int>> heap; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     rmq_min[0][i] = rmq_max[0][i] = a[i]; n     next[i] = i + 1; n     jump[i] = min(i + jump_small, n); n     times[i] = jump[i] - i; n   } n   for (int i = 0; i < n - 1; ++i) { n     now_min[i] = min(a[i], a[i + 1]); n     now_max[i] = max(a[i], a[i + 1]); n     heap.push(make_pair(now_min[i] - now_max[i], i)); n   } n   for (int i = 1; i < log_n; ++i) { n     for (int j = 0; j + (1 << i) <= n; ++j) { n       rmq_min[i][j] = min(rmq_min[i - 1][j], rmq_min[i - 1][j + (1 << i - 1)]); n       rmq_max[i][j] = max(rmq_max[i - 1][j], rmq_max[i - 1][j + (1 << i - 1)]); n     } n   } n   vector<int> last(n); n   vector<bool> visit(n); n   auto update = [&](int x, int limit) { n     while (next[x] < n && next[x] - x <= jump_large && n            now_max[x] - now_min[x] <= limit) { n       ++next[x]; n       if (next[x] < n) { n         now_max[x] = max(now_max[x], a[next[x]]); n         now_min[x] = min(now_min[x], a[next[x]]); n       } n     } n     if (next[x] < n && next[x] - x <= jump_small) { n       heap.push(make_pair(now_min[x] - now_max[x], x)); n     } n     vector<int> stack; n     jump[x] = x; n     times[x] = 0; n     stack.push_back(jump[x]); n     while (jump[x] < n && next[jump[x]] - x <= jump_small) { n       jump[x] = next[jump[x]]; n       ++times[x]; n       stack.push_back(jump[x]); n     } n     last[x] = stack.size(); n     visit[x] = true; n     for (int i = x - 1; i >= x - jump_small && ~i; --i) { n       if (next[i] < n && visit[next[i]]) { n         while (stack.back() - i > jump_small) { n           stack.pop_back(); n         } n         jump[i] = stack.back(); n         times[i] = times[next[i]] + 1 + stack.size() - last[next[i]]; n         last[i] = stack.size(); n         visit[i] = true; n       } n     } n     for (int i = x; i >= x - jump_small && ~i; --i) { n       visit[i] = false; n     } n   }; n   auto query = [&](int limit) { n     while (!heap.empty() && -heap.top().first <= limit) { n       int x = heap.top().second; n       heap.pop(); n       update(x, limit); n     } n     int answer = -1, x = 0; n     while (x < n) { n       int dist = next[x] - x; n       if (dist <= jump_small) { n         answer += times[x]; n         x = jump[x]; n       } else { n         while (next[x] < n && next[x] - x <= jump_large && n                now_max[x] - now_min[x] <= limit) { n           ++next[x]; n           if (next[x] < n) { n             now_max[x] = max(now_max[x], a[next[x]]); n             now_min[x] = min(now_min[x], a[next[x]]); n           } n         } n         dist = next[x] - x; n         if (dist <= jump_large) { n           ++answer; n           x = next[x]; n         } else { n           ++answer; n           int current_min = a[x], current_max = a[x]; n           for (int i = log_n - 1; ~i; --i) { n             if (x + (1 << i) <= n) { n               int next_min = min(current_min, rmq_min[i][x]); n               int next_max = max(current_max, rmq_max[i][x]); n               if (next_max - next_min <= limit) { n                 current_min = next_min; n                 current_max = next_max; n                 x += 1 << i; n               } n             } n           } n         } n       } n     } n     return answer; n   }; n   vector<pair<int, int>> queries(q); n   vector<int> answer(q); n   for (int i = 0; i < q; ++i) { n     scanf( %d , &queries[i].first); n     queries[i].first = m - queries[i].first; n     queries[i].second = i; n   } n   sort(queries.begin(), queries.end()); n   for (auto p : queries) { n     answer[p.second] = query(p.first); n   } n   for (int i = 0; i < q; ++i) { n     printf( %d n , answer[i]); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 6; n const long long M = 1e9 + 7; n const double eps = 1e-7; n int a[N]; n int Int() { n   int x; n   scanf( %d , &x); n   return x; n } n long long Lnt() { n   long long x; n   scanf( %I64d , &x); n   return x; n } n long long Bigmod(long long A, long long B, long long C) { n   if (B == 0LL) return 1LL; n   long long x = Bigmod(A, B / 2LL, C); n   x = (x * x) % C; n   if (B % 2 == 1) x = (x * A) % C; n   return x; n } n struct mar { n   int i, j, c, d; n } cr[N]; n bool cmp(mar a, mar b) { n   if (a.i == b.i) return a.j < b.j; n   return a.i < b.i; n } n bool Cmp(int a, int b) { return a > b; } n void print(int n) { printf( %d n , n); } n void Print(long long n) { printf( %I64d n , n); } n void debug(int n) { printf( %d  , n); } n int main() { n   int x1 = Int(), x2 = Int(), x3 = Int(), x4 = Int(), x5 = Int(), x6 = Int(); n   int c = x3 + x5; n   int d = max(x4, x6); n   if (x1 > x2) swap(x1, x2); n   if ((x1 >= c && x2 >= d) or (x2 >= c && x1 >= d)) return puts( YES ), 0; n   c = x3 + x6; n   d = max(x4, x5); n   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0; n   c = x4 + x5; n   d = max(x3, x6); n   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0; n   c = x4 + x6; n   d = max(x3, x5); n   if ((x1 >= c && x2 >= d) or (x1 >= d and x2 >= c)) return puts( YES ), 0; n   return puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[2005]; n long long int cnt[2005]; n long long int b[2005]; n long long int vis[2005]; n vector<long long int> v; n vector<long long int> vv; n vector<long long int> ans; n long long int prime[2005]; n bool pr[2005]; n set<char> st; n priority_queue<long long int> bob; n priority_queue<long long int> ali; n priority_queue<long long int> bth; n queue<long long int> q; n map<long long int, long long int> mp; n long long int taken[105]; n map<long long int, long long int>::iterator it; n map<long long int, vector<long long int> > ck; n string ss, tt; n long long int pos[205]; n long long int afs[205]; n long long int pre[2005]; n long long int aa[2005]; n long long int cs[27]; n long long int ct[27]; n long long int power(long long int k, long long int i) { n   long long int res = 1; n   for (long long int j = 1; j <= i; j++) { n     res = res * k; n   } n   return res; n } n int main() { n   long long int n, i, j, k, t, m; n   cin >> t; n   long long int minis; n   long long int res; n   long long int x, y; n   long long int pp; n   string fg; n   long long int l, r; n   long long int h; n   long long int p, q; n   string tt; n   while (t--) { n     v.clear(); n     cin >> n; n     cin >> ss >> tt; n     string fg; n     long long int kk = n; n     res = 0; n     for (i = n - 1; i >= 0; i--) { n       if (ss[i] == tt[i]) { n         kk--; n         continue; n       } else { n         if (ss[0] == tt[i]) { n           res = res + 1; n           v.push_back(1); n           if (ss[0] ==  0 ) n             ss[0] =  1 ; n           else n             ss[0] =  0 ; n         } n         fg.clear(); n         for (j = 0; j <= i; j++) { n           if (ss[j] ==  0 ) n             fg.push_back( 1 ); n           else n             fg.push_back( 0 ); n         } n         reverse(fg.begin(), fg.end()); n         res = res + 1; n         v.push_back(kk); n         for (j = 0; j <= i; j++) { n           ss[j] = fg[j]; n         } n       } n       kk--; n     } n     cout << res <<    ; n     for (i = 0; i < v.size(); i++) cout << v[i] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = (int)int(s.size()); n   int num = (s[n - 1] -  0 ) + 10 * (s[n - 2] -  0 ); n   if (num % 4 == 0) n     cout << 4; n   else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void dfs(long long a, long long b, char A, char B) { n   if (a == 1 && b == 1) return; n   if (a < b) swap(a, b), swap(A, B); n   printf( %I64d%c , (a - 1) / b, A); n   dfs(a - (a - 1) / b * b, b, A, B); n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   long long a, b; n   cin >> a >> b; n   if (gcd(a, b) != 1) { n     puts( Impossible ); n     return 0; n   } n   dfs(a, b,  A ,  B ); n   puts(  ); n } n