#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <class t, class u> n void chmax(t& first, u second) { n   if (first < second) first = second; n } n template <class t, class u> n void chmin(t& first, u second) { n   if (second < first) first = second; n } n template <class t> n using vc = vector<t>; n template <class t> n using vvc = vc<vc<t>>; n using pi = pair<int, int>; n using vi = vc<int>; n template <class t, class u> n ostream& operator<<(ostream& os, const pair<t, u>& p) { n   return os <<  {  << p.first <<  ,  << p.second <<  } ; n } n template <class t> n ostream& operator<<(ostream& os, const vc<t>& v) { n   os <<  { ; n   for (auto e : v) os << e <<  , ; n   return os <<  } ; n } n using uint = unsigned; n using ull = unsigned long long; n template <class t, size_t n> n ostream& operator<<(ostream& os, const array<t, n>& first) { n   return os << vc<t>(first.begin(), first.end()); n } n template <int i, class T> n void print_tuple(ostream&, const T&) {} n template <int i, class T, class H, class... Args> n void print_tuple(ostream& os, const T& t) { n   if (i) os <<  , ; n   os << get<i>(t); n   print_tuple<i + 1, T, Args...>(os, t); n } n template <class... Args> n ostream& operator<<(ostream& os, const tuple<Args...>& t) { n   os <<  { ; n   print_tuple<0, tuple<Args...>, Args...>(os, t); n   return os <<  } ; n } n template <class t> n void print(t x, int suc = 1) { n   cout << x; n   if (suc == 1) cout <<   n ; n   if (suc == 2) cout <<    ; n } n ll read() { n   ll i; n   cin >> i; n   return i; n } n vi readvi(int n, int off = 0) { n   vi v(n); n   for (int i = int(0); i < int(n); i++) v[i] = read() + off; n   return v; n } n template <class T> n void print(const vector<T>& v, int suc = 1) { n   for (int i = int(0); i < int(v.size()); i++) n     print(v[i], i == int(v.size()) - 1 ? suc : 2); n } n string readString() { n   string s; n   cin >> s; n   return s; n } n template <class T> n T sq(const T& t) { n   return t * t; n } n void yes(bool ex = true) { n   cout <<  Yes  n        <<   n ; n   if (ex) exit(0); n } n void no(bool ex = true) { n   cout <<  No  n        <<   n ; n   if (ex) exit(0); n } n void possible(bool ex = true) { n   cout <<  Possible  n        <<   n ; n   if (ex) exit(0); n } n void impossible(bool ex = true) { n   cout <<  Impossible  n        <<   n ; n   if (ex) exit(0); n } n constexpr ll ten(int n) { return n == 0 ? 1 : ten(n - 1) * 10; } n const ll infLL = LLONG_MAX / 3; n const int inf = INT_MAX / 2 - 100; n int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); } n int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); } n int botbit(signed first) { return first == 0 ? 32 : __builtin_ctz(first); } n int botbit(ll first) { return first == 0 ? 64 : __builtin_ctzll(first); } n int popcount(signed t) { return __builtin_popcount(t); } n int popcount(ll t) { return __builtin_popcountll(t); } n bool ispow2(int i) { return i && (i & -i) == i; } n ll mask(int i) { return (ll(1) << i) - 1; } n bool inc(int first, int second, int c) { n   return first <= second && second <= c; n } n template <class t> n void mkuni(vc<t>& v) { n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n } n ll rand_int(ll l, ll r) { n   static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count()); n   return uniform_int_distribution<ll>(l, r)(gen); n } n template <class t> n void myshuffle(vc<t>& first) { n   for (int i = int(0); i < int(int(first.size())); i++) n     swap(first[i], first[rand_int(0, i)]); n } n template <class t> n int lwb(const vc<t>& v, const t& first) { n   return lower_bound(v.begin(), v.end(), first) - v.begin(); n } n using uint = unsigned; n using ull = unsigned long long; n struct modinfo { n   uint mod, root; n }; n template <modinfo const& ref> n struct modular { n   static constexpr uint const& mod = ref.mod; n   static modular root() { return modular(ref.root); } n   uint v; n   modular(ll vv = 0) { s(vv % mod + mod); } n   modular& s(uint vv) { n     v = vv < mod ? vv : vv - mod; n     return *this; n   } n   modular operator-() const { return modular() - *this; } n   modular& operator+=(const modular& rhs) { return s(v + rhs.v); } n   modular& operator-=(const modular& rhs) { return s(v + mod - rhs.v); } n   modular& operator*=(const modular& rhs) { n     v = ull(v) * rhs.v % mod; n     return *this; n   } n   modular& operator/=(const modular& rhs) { return *this *= rhs.inv(); } n   modular operator+(const modular& rhs) const { return modular(*this) += rhs; } n   modular operator-(const modular& rhs) const { return modular(*this) -= rhs; } n   modular operator*(const modular& rhs) const { return modular(*this) *= rhs; } n   modular operator/(const modular& rhs) const { return modular(*this) /= rhs; } n   modular pow(int n) const { n     modular res(1), x(*this); n     while (n) { n       if (n & 1) res *= x; n       x *= x; n       n >>= 1; n     } n     return res; n   } n   modular inv() const { return pow(mod - 2); } n   friend modular operator+(int x, const modular& y) { return modular(x) + y; } n   friend modular operator-(int x, const modular& y) { return modular(x) - y; } n   friend modular operator*(int x, const modular& y) { return modular(x) * y; } n   friend modular operator/(int x, const modular& y) { return modular(x) / y; } n   friend ostream& operator<<(ostream& os, const modular& m) { n     return os << m.v; n   } n   friend istream& operator>>(istream& is, modular& m) { n     ll x; n     is >> x; n     m = modular(x); n     return is; n   } n   bool operator<(const modular& r) const { return v < r.v; } n   bool operator==(const modular& r) const { return v == r.v; } n   bool operator!=(const modular& r) const { return v != r.v; } n   explicit operator bool() const { return v; } n }; n extern constexpr modinfo base{998244353, 3}; n using mint = modular<base>; n const int vmax = (1 << 21) + 10; n mint fact[vmax], finv[vmax], invs[vmax]; n void initfact() { n   fact[0] = 1; n   for (int i = int(1); i < int(vmax); i++) { n     fact[i] = fact[i - 1] * i; n   } n   finv[vmax - 1] = fact[vmax - 1].inv(); n   for (int i = vmax - 2; i >= 0; i--) { n     finv[i] = finv[i + 1] * (i + 1); n   } n   for (int i = vmax - 1; i >= 1; i--) { n     invs[i] = finv[i] * fact[i - 1]; n   } n } n mint choose(int n, int k) { return fact[n] * finv[n - k] * finv[k]; } n mint binom(int first, int second) { n   return fact[first + second] * finv[first] * finv[second]; n } n mint catalan(int n) { n   return binom(n, n) - (n - 1 >= 0 ? binom(n - 1, n + 1) : 0); n } n void swapbit(ll& first, int i, int j) { n   if (i == j) return; n   for (int _ = int(0); _ < int(3); _++) { n     ll x = (first >> i) & 1; n     first ^= x << j; n     swap(i, j); n   } n } n const int S = 17; n mint dp[S + 1][1 << S]; n signed main() { n   cin.tie(0); n   ios::sync_with_stdio(0); n   cout << fixed << setprecision(20); n   int n, m; n   cin >> n >> m; n   vc<ll> vs; n   mint w = 1; n   for (int _ = int(0); _ < int(n); _++) { n     ll first; n     cin >> first; n     for (auto v : vs) chmin(first, first ^ v); n     if (first == 0) n       w *= 2; n     else n       vs.push_back(first); n   } n   vc<mint> ans(m + 1); n   int s = int(vs.size()); n   if (int(vs.size()) <= 18) { n     for (int bit = int(0); bit < int(1 << s); bit++) { n       ll x = 0; n       for (int i = int(0); i < int(s); i++) n         if (bit & 1 << i) x ^= vs[i]; n       ans[popcount(x)] += 1; n     } n   } else { n     for (int i = int(0); i < int(s); i++) { n       assert(vs[i]); n       int j = botbit(vs[i]); n       assert(j >= i); n       for (int k = int(0); k < int(s); k++) n         if (k != i && vs[k] & 1LL << j) vs[k] ^= vs[i]; n       for (int k = int(0); k < int(s); k++) swapbit(vs[k], i, j); n     } n     int len = m - s; n     assert(len <= S); n     dp[0][0] = 1; n     for (int i = int(0); i < int(s); i++) { n       int v = vs[i] >> s; n       for (int j = int(i + 1) - 1; j >= int(0); j--) { n         for (int k = int(0); k < int(1 << len); k++) { n           dp[j + 1][k ^ v] += dp[j][k]; n         } n       } n     } n     for (int i = int(0); i < int(s + 1); i++) n       for (int j = int(0); j < int(1 << len); j++) { n         ans[i + popcount(j)] += dp[i][j]; n       } n   } n   for (auto& v : ans) v *= w; n   print(ans); n } n


#include <bits/stdc++.h> n using namespace std; n #define pi acos(-1) n #define mod 1000000007 n #define lli long long int n #define li long int n #define pb push_back n #define mp make_pair n #define ff first n #define ss second n #define nl   n  n  n  n int main() n { n ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n  n     lli t,n; n     cin>>t; n     while(t--) n     { n         cin>>n; n        int count=0; n         for(lli i=1; i<=n; i=i*10 +1) n         { n             for(int j=1; j<=9; j++) n             { n                 if(i*j<=n) n                 { n                     count++; n                 } n             } n         } n         cout<<count<<  n ; n     } n     return 0; n }


#include <bits/stdc++.h> n using LL = long long; n using ULL = unsigned long long; n using namespace std; n long long n, m; n vector<long long> a; n vector<pair<long long, long long> > vec; n signed main() { n   ios::sync_with_stdio(false), cin.tie(NULL); n   cin >> n; n   a.resize(n, 0); n   vec.resize(n, {0, 0}); n   for (long long i = (0); i < (n); i++) cin >> a[i]; n   for (long long i = (0); i < (n); i++) n     vec[i].first = a[i], vec[i].second = n - i; n   sort(vec.rbegin(), vec.rend()); n   cin >> m; n   for (long long i = (0); i < (m); i++) { n     long long k, pos; n     cin >> k >> pos; n     vector<pair<long long, long long> > tmp; n     tmp.resize(k, {0, 0}); n     for (long long i = (0); i < (k); i++) n       tmp[i].first = n - vec[i].second, tmp[i].second = vec[i].first; n     sort(tmp.begin(), tmp.end()); n     cout << tmp[pos - 1].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   cin >> s >> t; n   reverse(s.begin(), s.end()); n   if (s == t) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int Maxn = 20 + 5, Mod = 1e9 + 7, Inf = 1e9; n int n, p[Maxn], ansss, m, fac[Maxn]; n bool mrk[Maxn], mark[Maxn]; n int ans[] = {1,         0, 18,        0, 1800,      0, 670320,    0, n              734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0}; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   cout << ans[n - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n const int pN = 1e6; n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n void add(long long &x, long long y) { n   x += y; n   x %= MOD; n } n bool vis[MAXN]; n int a[MAXN]; n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int ans = INF; n   int id; n   for (int i = 0; i < n; i++) { n     if (vis[i]) continue; n     int sum = 0; n     for (int j = i;; j = (j + k) % n) { n       if (vis[j]) break; n       vis[j] = true; n       sum += a[j]; n     } n     if (sum < ans) { n       id = i; n       ans = sum; n     } n   } n   cout << id + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long data[100010], diff[100010], change[100010]; n vector<vector<long long> > adj; n vector<pair<long long, int> > vp; n int main(void) { n   scanf( %d%d , &n, &m); n   adj.resize(n + 1, vector<long long>()); n   for (int i = 0; i < m; i++) scanf( %I64d , &data[i]); n   if (m == 1) { n     puts( 0 ); n     return 0; n   } n   for (int i = 0; i < m; i++) { n     if (i == 0 && data[i] != data[i + 1]) n       adj[data[i]].push_back(data[i + 1]); n     else if (i == m - 1 && data[i] != data[i - 1]) n       adj[data[i]].push_back(data[i - 1]); n     else if (i > 0 && i < m - 1) { n       if (data[i] != data[i - 1]) adj[data[i]].push_back(data[i - 1]); n       if (data[i] != data[i + 1]) adj[data[i]].push_back(data[i + 1]); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (adj[i].empty()) continue; n     long long sum = 0; n     sort(adj[i].begin(), adj[i].end()); n     long long avg1 = adj[i][adj[i].size() / 2]; n     long long newMid = adj[i].size() / 2 - 1; n     if (newMid < 0) newMid = 0; n     long long avg2 = adj[i][newMid]; n     long long sum1 = 0, sum2 = 0; n     for (int j = 0; j < adj[i].size(); j++) sum += abs(adj[i][j] - i); n     for (int j = 0; j < adj[i].size(); j++) sum1 += abs(adj[i][j] - avg1); n     for (int j = 0; j < adj[i].size(); j++) sum2 += abs(adj[i][j] - avg2); n     if (sum1 < sum2) { n       vp.push_back(make_pair(sum - sum1, i)); n       change[i] = avg1; n     } else { n       vp.push_back(make_pair(sum - sum2, i)); n       change[i] = avg2; n     } n   } n   sort(vp.begin(), vp.end()); n   if (vp.empty()) { n     puts( 0 ); n     return 0; n   } n   int target = vp[vp.size() - 1].second; n   for (int i = 0; i < m; i++) n     if (data[i] == target) data[i] = change[target]; n   long long sol = 0; n   for (int i = 0; i < m - 1; i++) sol += abs(data[i] - data[i + 1]); n   printf( %I64d n , sol); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n const char nl =   n ; n using namespace std; n using ll = long long; n using vi = vector<ll>; n using vl = vector<ll>; n using pii = pair<ll, ll>; n using pll = pair<ll, ll>; n using str = string; n str to_string(char c) { return str(1, c); } n str to_string(bool b) { return b ?  true  :  false ; } n str to_string(const char* second) { return (str)second; } n str to_string(str second) { return second; } n template <class A> n str to_string(complex<A> c) { n   stringstream ss; n   ss << c; n   return ss.str(); n } n str to_string(vector<bool> v) { n   str res =  { ; n   for (ll i = 0; i < (ll)v.size(); i++) res += char( 0  + v[i]); n   res +=  } ; n   return res; n } n template <size_t SZ> n str to_string(bitset<SZ> b) { n   str res =   ; n   for (ll i = 0; i < b.size(); i++) res += char( 0  + b[i]); n   return res; n } n template <class A, class B> n str to_string(pair<A, B> p); n template <class T> n str to_string(T v) { n   bool fst = 1; n   str res =  { ; n   for (const auto& x : v) { n     if (!fst) res +=  ,  ; n     fst = 0; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <class A, class B> n str to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n void DBG() { cerr <<  ]  << endl; } n template <class H, class... T> n void DBG(H h, T... t) { n   cerr << to_string(h); n   if (sizeof...(t)) cerr <<  ,  ; n   DBG(t...); n } n ll n; n string c; n vector<vi> pref; n set<ll> vis; n bool notone = 0; n ll bruh(ll idx, char tr, ll len) { n   vis.insert(idx); n   ll amt = n       pref[idx + len - 1][tr -  a ] - ((idx > 0) ? pref[idx - 1][tr -  a ] : 0); n   0; n   ll add = len - amt; n   if (len == n / 2) { n     return add; n   } else { n     if (len == 1 && notone) { n       if ((idx + 1) / 2 == idx / 2) { n         ; n         notone = 0; n         add += bruh(idx + 1, tr - 1, len); n       } else { n         notone = 0; n         add += bruh(idx - 1, tr - 1, len); n       } n     } else { n       bool minus = 1; n       if ((idx + len * 2) / (len * 2) * (len * 2) / (len * 4) == n           idx / (len * 4)) { n         minus = 0; n       } n       if (!minus) { n         add += bruh((idx + len * 2) / (len * 2) * (len * 2), tr - 1, len * 2); n       } else { n         add += bruh((idx - len * 2) / (len * 2) * (len * 2), tr - 1, len * 2); n       } n     } n   } n   return add; n } n void solve() { n   cin >> n >> c; n   if (n == 1) { n     if (c[0] ==  a ) n       cout << 0 << nl; n     else { n       cout << 1 << nl; n     } n     return; n   } else if (n == 2) { n     sort(c.begin(), c.end()); n     ll ans = 0; n     if (c[0] ==  a  && c[1] ==  b ) { n       cout << 0 << nl; n     } else { n       if (c[0] ==  a ) { n         cout << 1 << nl; n       } else if (c[0] ==  b ) { n         cout << 1 << nl; n       } else { n         cout << 2 << nl; n       } n     } n     return; n   } n   ll x = 1; n   ll atharv = 0; n   for (; x != n; atharv++) { n     x *= 2; n   } n   ll amt = atharv + 1; n   pref.resize(n); n   for (ll i = 0; i < n; i++) { n     pref[i].resize(26); n   } n   for (ll i = 0; i < n; i++) { n     for (ll j = 0; j < 26; j++) { n       if (i) pref[i][j] = pref[i - 1][j]; n     } n     pref[i][c[i] -  a ]++; n   } n   0; n   ll ans = 1e9; n   for (ll i = 0; i < n; i++) { n     notone = 1; n     vis.clear(); n     ans = min(bruh(i,  a  + amt - 1, 1), ans); n     0; n     0; n   } n   cout << ans << nl; n   pref.clear(); n } n signed main() { n   cin.tie(nullptr); n   ios_base::sync_with_stdio(false); n   ll t; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int mp[100][100]; n int cnt[100]; n int main() { n   int n, x, y; n   cin >> n; n   while (cin >> x) { n     cin >> y; n     mp[x][y] = 1; n     mp[y][x] = 1; n     cnt[x]++; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (!mp[i][j]) { n         if (cnt[i] > cnt[j]) n           cout << i <<     << j; n         else n           cout << j <<     << i; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n int n, m; n std::vector<std::vector<int> > gr; n std::vector<int> par; n std::vector<bool> vis; n std::vector<int> lev; n void dfsgr(int v) { n   vis[v] = true; n   for (auto& ch : (gr[v])) { n     if (vis[ch]) continue; n     lev[ch] = lev[v] + 1; n     par[ch] = v; n     dfsgr(ch); n   } n } n int lca(int a, int b) { n   if (lev[a] > lev[b]) std::swap(a, b); n   while (lev[b] != lev[a]) b = par[b]; n   while (a != b) { n     a = par[a]; n     b = par[b]; n   } n   return a; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(0); n   std::cin >> n >> m; n   gr.resize(n); n   vis.resize(n); n   par.resize(n, -1); n   lev.resize(n); n   for (int i = 0; i < (m); ++i) { n     int a, b; n     std::cin >> a >> b; n     a--; n     b--; n     gr[a].push_back(b); n     gr[b].push_back(a); n   } n   dfsgr(0); n   int q; n   std::cin >> q; n   std::vector<int> dd(n); n   std::vector<std::vector<int> > paths; n   for (int _ = 0; _ < (q); ++_) { n     int a, b; n     std::cin >> a >> b; n     a--; n     b--; n     int lc = lca(a, b); n     int pos = a; n     std::vector<int> pth; n     while (pos != lc) { n       dd[pos] ^= 1; n       pth.push_back(pos); n       pos = par[pos]; n     } n     pth.push_back(lc); n     std::vector<int> nd; n     pos = b; n     while (pos != lc) { n       dd[pos] ^= 1; n       nd.push_back(pos); n       pos = par[pos]; n     } n     while (((int)(nd).size())) pth.push_back(nd.back()), nd.pop_back(); n     paths.push_back(std::move(pth)); n   } n   bool good = true; n   for (int i = 0; i < (n); ++i) { n     if (dd[i]) good = false; n   } n   if (good) { n     std::cout <<  YES n ; n     for (auto& p : (paths)) { n       std::cout << ((int)(p).size()) <<   n ; n       for (auto& i : (p)) std::cout << i + 1 <<    ; n       std::cout <<   n ; n     } n   } else { n     std::cout <<  NO n ; n     std::vector<std::vector<int> > ed(n); n     for (int i = 0; i < (n); ++i) n       if (dd[i]) { n         ed[i].push_back(par[i]); n         ed[par[i]].push_back(i); n       } n     std::fill(vis.begin(), vis.end(), false); n     int xd = 0; n     std::function<int(int)> dfs = [&](int v) { n       vis[v] = true; n       int mam = 0; n       for (auto& ch : (ed[v])) n         if (!vis[ch]) { n           dfs(ch); n           mam++; n         } n       xd += mam / 2; n       return mam % 2; n     }; n     int ans = 0; n     for (int i = 0; i < (n); ++i) n       if (!vis[i]) { n         xd = 0; n         if (dfs(i)) xd++; n         ans += xd; n       } n     std::cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n inline void rd(int &x) { n   int k; n   int m = 0; n   x = 0; n   for (;;) { n     k = getchar(); n     if (k ==  - ) { n       m = 1; n       break; n     } n     if ( 0  <= k && k <=  9 ) { n       x = k -  0 ; n       break; n     } n   } n   for (;;) { n     k = getchar(); n     if (k <  0  || k >  9 ) { n       break; n     } n     x = x * 10 + k -  0 ; n   } n   if (m) { n     x = -x; n   } n } n inline void rd(char &c) { n   int i; n   for (;;) { n     i = getchar(); n     if (i !=     && i !=   n  && i !=   r  && i !=   t  && i != EOF) { n       break; n     } n   } n   c = i; n } n inline int rd(char c[]) { n   int i; n   int sz = 0; n   for (;;) { n     i = getchar(); n     if (i !=     && i !=   n  && i !=   r  && i !=   t  && i != EOF) { n       break; n     } n   } n   c[sz++] = i; n   for (;;) { n     i = getchar(); n     if (i ==     || i ==   n  || i ==   r  || i ==   t  || i == EOF) { n       break; n     } n     c[sz++] = i; n   } n   c[sz] =   0 ; n   return sz; n } n inline void wt_L(char a) { putchar(a); } n inline void wt_L(int x) { n   int s = 0; n   int m = 0; n   char f[10]; n   if (x < 0) { n     m = 1; n     x = -x; n   } n   while (x) { n     f[s++] = x % 10; n     x /= 10; n   } n   if (!s) { n     f[s++] = 0; n   } n   if (m) { n     putchar( - ); n   } n   while (s--) { n     putchar(f[s] +  0 ); n   } n } n template <class S, class T> n inline S chmin(S &a, T b) { n   if (a > b) { n     a = b; n   } n   return a; n } n int N; n char S[300002]; n int sz; n int lis[300002]; n int main() { n   int i, m; n   int k; n   int mn; n   int y; n   int f; n   int cnt; n   int res; n   int res1; n   int res2; n   int ini; n   rd(N); n   rd(S); n   k = mn = 0; n   for (i = (0); i < (N); i++) { n     if (S[i] ==  ( ) { n       k++; n     } else { n       k--; n     } n     chmin(mn, k); n   } n   if (k) { n     wt_L(0); n     wt_L(  n ); n     wt_L(1); n     wt_L(   ); n     wt_L(1); n     wt_L(  n ); n     return 0; n   } n   k = 0; n   res = res1 = res2 = 0; n   for (i = (0); i < (N); i++) { n     if (S[i] ==  ( ) { n       k++; n     } else { n       k--; n     } n     if (k == mn) { n       res++; n       lis[sz++] = i; n     } n   } n   ini = res; n   for (m = (0); m < (sz); m++) { n     k = 0; n     if (m == sz - 1) { n       y = lis[0] + N; n     } else { n       y = lis[m + 1]; n     } n     f = -1; n     for (i = (lis[m] + 1); i < (y); i++) { n       if (S[i % N] ==  ( ) { n         k++; n       } else { n         k--; n       } n       if (k < 2) { n         f = -1; n         cnt = 0; n       } n       if (k == 2 && f == -1) { n         f = i; n       } n       if (k == 2) { n         cnt++; n       } n       if (k == 2 && ini + cnt > res) { n         res = ini + cnt; n         res1 = f % N; n         res2 = (i + 1) % N; n       } n     } n   } n   for (m = (0); m < (sz); m++) { n     k = 0; n     if (m == sz - 1) { n       y = lis[0] + N; n     } else { n       y = lis[m + 1]; n     } n     cnt = 0; n     for (i = (lis[m] + 1); i < (y); i++) { n       if (S[i % N] ==  ( ) { n         k++; n       } else { n         k--; n       } n       if (k == 1) { n         cnt++; n       } n     } n     if (cnt > res) { n       res = cnt; n       res1 = (lis[m] + 1) % N; n       res2 = y % N; n     } n   } n   wt_L(res); n   wt_L(  n ); n   wt_L(res1 + 1); n   wt_L(   ); n   wt_L(res2 + 1); n   wt_L(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n long long n, k, t, m, q, flag = 0; n long long po(long long k, long long n, long long ans, long long temp, n              long long ans1) { n   if (n == 0) return ans; n   while (temp <= n) { n     ans *= ans1; n     ans %= mod; n     ans1 = ans1 * ans1; n     ans1 %= mod; n     n = n - temp; n     temp *= 2; n   } n   return po(k, n, ans, 1, k) % mod; n } n long long min(long long a, long long b) { n   if (a > b) n     return b; n   else n     return a; n } n long long max(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n long long md[100 + 1][100 + 1]; n vector<long long> v[100 + 1]; n long long bfs(long long i, long long j, queue<long long> q, long long z, n               map<long long, long long> m1) { n   long long o = q.size(); n   if (o == 0) return -1; n   for (int l = 0; l < o; l++) { n     long long b = q.front(); n     if (b == j) n       return z; n     else { n       if (m1[b] != 1) n         for (int i = 0; i < v[b].size(); i++) { n           q.push(v[b][i]); n         } n       m1[b] = 1; n       q.pop(); n     } n   } n   return bfs(i, j, q, z + 1, m1); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   t = 1; n   while (t--) { n     cin >> n; n     char c[n][n]; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < n; j++) cin >> c[i][j]; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (c[i][j] ==  1 ) v[i + 1].push_back(j + 1); n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         queue<long long> q; n         map<long long, long long> m1; n         q.push(i + 1); n         md[i + 1][j + 1] = bfs(i + 1, j + 1, q, 0, m1); n       } n     } n     long long m; n     cin >> m; n     long long a[m]; n     for (int i = 0; i < m; i++) cin >> a[i]; n     vector<long long> ans; n     long long pi = a[0], pii = 0; n     ans.push_back(a[0]); n     for (int i = 1; i < m; i++) { n       if (md[pi][a[i]] == i - pii) n         ; n       else { n         ans.push_back(a[i - 1]); n         pi = a[i - 1]; n         pii = i - 1; n       } n     } n     cout << ans.size() + 1; n     cout <<   n ; n     for (int i = 0; i < ans.size(); i++) { n       cout << ans[i] <<    ; n     } n     cout << a[m - 1]; n   } n   return 0; n } n


#include<bits/stdc++.h> n #include<unordered_map> n #include<unordered_set> n #define f(i,a,b) for( int i=a;i<=b;++i) n #define ff(i,a,b) for( int i=a;i>=b;--i) n #define debug(x) cerr << #x <<   :   << x <<     << endl n using namespace std; n typedef long long ll; n typedef unsigned long long ull; n typedef long double ld; n typedef pair<int, int> pii; n typedef pair<string, string> pss; n const ll mod = 1e9 + 7; n const ll mod2 = 998244353; n const ll inf = 2e18; n const double tiaohe = 0.57721566490153286060651209; n ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; } n ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; } n ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } n void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } } n ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; } n bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; } n inline ll in() { char ch = getchar();ll x = 0, f = 1;while (ch< 0  || ch> 9 ) { if (ch ==  - )f = -1;ch = getchar(); }while (ch >=  0 &&ch <=  9 ) { x = x * 10 + ch -  0 ;ch = getchar(); }return x * f; } n void print(double x) { printf( %.6lf n , x); } n //double a = log(n) +tiaohe + 1.0 / (2 * n); n double eqa = (1 + sqrt(5.0)) / 2.0; n double E = 2.7182818284; n const double eps = 1e-8; n double pi = acos(-1); n const int N = 5e5 + 100; n int n, m; n ll k; n int a[N], b[N],id; n ll M[2], LCM; n pair<ll,ll> st[N];//等价类起点 n pair<ll,ll> linear( ll B[], ll M[], int n) n { n  //求解 A[i]x = B[i] (mod M[i]), 总共 n 个线性 方程组, →  n  ll x = 0, m = 1; n  for (int i = 0; i < n; i++) n  { n   ll a =  m, b = B[i] -  x, d = gcd(M[i], a); n   if (b % d != 0) return pair<ll,ll>(0, -1);//答案不存在，返回-1  n   ll t = b / d * inv(a / d, M[i] / d) % (M[i] / d); n   x = x + m * t; n   m *= M[i] / d; n  } n  x = (x % m + m) % m; n  return pair<ll, ll>{x,m};//返回的 x 就是答案，m 是最后的 lcm 值 n } n ll pos[N][2]; n bool check(ll mid) { n  ll res = mid;//减去命中的 n  f(i, 1, id) { n   if (st[i].second == -1) { n    continue; n   } n   if (st[i].first > mid)continue; n   ll num = (ll)ceil((mid-1-st[i].first)*1.0/LCM); n   res -= num; n  } n  //cout << mid <<     << res << endl; n  return res <= k; n } n void work(ll k) { n  ll l = 0, r = 2e18,res=0; n  while (l <= r) { n   ll mid = l + r >> 1; n   if (check(mid)) { n    res = mid; n    l = mid + 1; n   } n   else { n    r = mid - 1; n   } n  } n  cout << res << endl; n } n int main() n { n #ifndef ONLINE_JUDGE n  freopen( in.txt ,  r , stdin); n #endif n  cin >> n >> m >> k; n  unordered_map<int, int> mp; n  f(i, 1, n)a[i] = in(), mp[a[i]] = i-1; n  f(i, 1, m)b[i] = in(); n  id = 0; n  f(i, 1, m) { n   if (mp.count(b[i])) { n    pos[++id][0] = mp[b[i]]; n    pos[id][1] = i-1; n   } n  } n  LCM= 1ll*n * m / gcd(n, m); n  M[0] = n, M[1] = m; n  f(i, 1, id) { n   st[i] = linear(pos[i], M, 2); n   //cout << st[i].first <<     << st[i].second << endl; n  } n  work(k); n  return 0; n }


#include <bits/stdc++.h> n const int N = 600000 + 7; n using namespace std; n char o[] = { I ,  E ,  A ,  O ,  U ,  Y }; n bool mark[N]; n long long sum[N]; n long double ans; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string s; n   cin >> s; n   for (int i = 0; i < (((int)s.size())); i++) n     for (int j = 0; j < (6); j++) n       if (s[i] == o[j]) mark[i + 1] = true; n   int n = ((int)s.size()); n   for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + mark[i]; n   long long cnt = sum[n]; n   ans = cnt; n   for (int i = 2; i <= n; i++) { n     cnt += (sum[n - i + 1] - sum[i - 1]); n     ans += (long double)cnt / (long double)i; n   } n   cout << setprecision(7) << fixed << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long x; n   bool s; n   node(long long a, bool b) { x = a, s = b; } n }; n bool operator<(node a, node b) { return a.x > b.x; } n priority_queue<node> pq; n int main() { n   int n; n   long long temp; n   cin >> n; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     cin >> temp; n     if (pq.empty() || pq.top().x > temp) { n       pq.push(node(temp, 0)); n     } else { n       long long now = pq.top().x; n       bool se = pq.top().s; n       pq.pop(); n       if (se) pq.push(node(now, 0)); n       ans += temp - now, pq.push(node(temp, 1)); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   long long int a[100005] = {0}; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   a[n + 1] = 0; n   for (int i = 1; i <= n; i++) { n     cout << a[i] + a[i + 1]; n     cout <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long SZ = 107; n const long long N = 1e6 + 7; n const long long M = 1e4 + 7; n long long n, m, c; n void solve() { n   long long n; n   cin >> n; n   long long a[n]; n   vector<long long> b, c; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   long long sm1 = 0, sm2 = 0; n   if (n % 2) { n     for (long long i = 0; i < n / 2; i++) { n       b.push_back(a[i]); n       sm1 += a[i]; n     } n     for (long long i = n / 2; i < n; i++) { n       c.push_back(a[i]); n       sm2 += a[i]; n     } n   } else { n     for (long long i = 0; i < n / 2; i++) { n       b.push_back(a[i]); n       sm1 += a[i]; n     } n     for (long long i = n / 2; i < n; i++) { n       c.push_back(a[i]); n       sm2 += a[i]; n     } n   } n   cout << sm1 * sm1 + sm2 * sm2 <<   n ; n   cout <<   n ; n } n signed main() { n   long long t = 1; n   for (long long i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n string tos(T a) { n   stringstream ss; n   string ret; n   ss << a; n   ss >> ret; n   return ret; n } n void read(int &_a) { int temp = scanf( %d , &_a); } n void read(int &_a, int &_b) { int temp = scanf( %d %d , &_a, &_b); } n void read(int &_a, int &_b, int &_c) { n   int temp = scanf( %d %d %d , &_a, &_b, &_c); n } n const int SZ = 3e5 + 2; n int N, M, AR[SZ], FR[2 * SZ], MN[SZ], MX[SZ], LOC[2 * SZ]; n void addc(int idx, int v) { n   if (idx < 1) return; n   int mx = 2 * SZ; n   while (idx < mx) { n     FR[idx] += v; n     idx += (idx & -idx); n   } n } n void addr(int L, int R, int v) { n   addc(L, v); n   addc(R + 1, -v); n } n int get(int idx) { n   if (idx < 1) return 0; n   int sum = 0; n   while (idx > 0) { n     sum += FR[idx]; n     idx -= (idx & -idx); n   } n   return sum; n } n int main() { n   while (cin >> N >> M) { n     memset(FR, 0, sizeof FR); n     ; n     int head = SZ; n     for (int(p) = (1); (p) < (N + 1); (p)++) { n       MN[p] = MX[p] = p; n       LOC[p] = SZ + p - 1; n       addc(SZ + p, 1); n     } n     for (int(x) = (0); (x) < (M); (x)++) { n       int p; n       read(p); n       MN[p] = 1; n       int loc = LOC[p]; n       int pos = get(loc); n       MX[p] = max(MX[p], pos + 1); n       LOC[p] = --head; n       addr(head + 1, loc, 1); n     } n     for (int(p) = (1); (p) < (N + 1); (p)++) { n       int loc = LOC[p]; n       int pos = get(loc); n       MX[p] = max(MX[p], pos + 1); n       printf( %d %d n , MN[p], MX[p]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int arr[1000], n, k, s = 0, c = 0, v = 0; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   for (int i = 1; i <= n; i++) { n     if (arr[i] <= 8) { n       s = s + arr[i]; n       c++; n       if (s >= k) break; n     } else if (arr[i] > 8) { n       v = arr[i] - 8; n       arr[i + 1] += v; n       s = s + 8; n       c++; n       if (s >= k) break; n     } n   } n   if (s >= k) n     cout << c; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1); n long long a[200002] = {}; n long long b[200002] = {}; n long long c[200002] = {}; n string s =   , ss =   ; n long long n, m, k, w; n long long ans, ans1; n long long mod = 1e9 + 7; n int main() { n   cin.tie(0); n   cin.sync_with_stdio(0); n   int t = 1; n   while (t--) { n     cin >> n >> m; n     for (int i = 0; i < n; i++) cin >> a[i]; n     ; n     b[n - 1] = a[n - 1]; n     for (int i = n - 2; i >= 0; i--) b[i] = max(b[i + 1], a[i]); n     c[0] = a[0]; n     for (long long i = 1; i < n; i++) c[i] = min(a[i], c[i - 1]); n     ans = m; n     for (long long i = 0; i < n - 1; i++) { n       k = m / c[i]; n       k *= b[i + 1]; n       k += m % c[i]; n       ans = max(ans, k); n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int MOD2 = MOD + 2; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n inline long long isqrt(long long k) { n   long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; } n inline int sign(long double x, long double y) { return sign(x - y); } n int modulo(int a, int b) { return (a % b + b) % b; } n long long v1, v2, t, d; n long long dp[110][2000]; n long long solve(long long i, long long cur) { n   if (i == t) { n     if (cur == v2) { n       return dp[i][cur] = cur; n     } else { n       return dp[i][cur] = -LINF; n     } n   } n   if (dp[i][cur] != -1) { n     return dp[i][cur]; n   } n   long long ans = -LINF; n   for (int j = -d; j <= d; j++) { n     if (cur + j > 0) { n       ans = max(ans, solve(i + 1, cur + j)); n     } n   } n   return dp[i][cur] = ans + cur; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> v1 >> v2 >> t >> d; n   memset(dp, -1, sizeof(dp)); n   cout << solve(1, v1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n list<pair<int, long long> > l; n long long get(int x) { n   long long ans = 0; n   for (list<pair<int, long long> >::iterator it = l.begin(), e = l.end(); n        it != e; ++it) { n     ans = max(ans, it->second); n     if (x <= it->first) { n       break; n     } n     x -= it->first; n   } n   return ans; n } n void update(int ox, long long v) { n   int x = ox; n   list<pair<int, long long> >::iterator now = l.begin(), e = l.end(); n   for (; now != e; ++now) { n     if (x < now->first) { n       break; n     } n     x -= now->first; n   } n   while (l.begin() != now) { n     l.pop_front(); n   } n   l.begin()->first = l.begin()->first - x; n   l.push_front(make_pair(ox, v)); n } n int main() { n   int n, m; n   cin >> n; n   l.clear(); n   for (int i = 1; i <= n; i++) { n     long long t; n     cin >> t; n     l.push_back(make_pair(1, t)); n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     int w; n     long long h; n     cin >> w >> h; n     long long ans = get(w); n     cout << ans <<   n ; n     update(w, ans + h); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Map[30][30]; n int N, M, T; n void Swap(int x, int y) { n   for (int i = 1; i <= N; i++) { n     swap(Map[i][x], Map[i][y]); n   } n } n bool Find() { n   int ans = 0; n   for (int i = 1; i <= N; i++) { n     int s = 0; n     for (int j = 1; j <= M; j++) { n       if (Map[i][j] != j) s++; n     } n     if (s > 2) return 0; n   } n   return 1; n } n int main() { n   cin >> N; n   cin >> M; n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= M; j++) scanf( %d , &Map[i][j]); n   int flag = 0; n   if (Find()) flag = 1; n   for (int i = 1; i <= M; i++) { n     for (int j = i + 1; j <= M; j++) { n       if (i == j) continue; n       Swap(i, j); n       if (Find()) { n         flag = 1; n         break; n       } n       Swap(i, j); n     } n     if (flag) break; n   } n   if (flag) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string func(pair<int, int> a, pair<int, int> b) { n   return to_string(a.first) +     + to_string(a.second) +     + n          to_string(b.first) +     + to_string(b.second); n } n int nSmallFactor(int n, vector<int>& primes) { n   for (int prime : primes) { n     if (n % prime == 0) { n       return prime; n     } n   } n   return -1; n } n void DFS(vector<int>& ve, vector<int>& visited, int n, int start) { n   int ans = 0; n   for (int i = start + start; i <= n; i += start) { n     if (visited[i] == -1) { n       DFS(ve, visited, n, i); n     } n     if (ve[i] > ve[start]) { n       ans = max(ans, visited[i]); n     } n   } n   visited[start] = ans + 1; n } n long long sum(long long a) { n   if (a % 2 == 0) { n     return (a / 2) * (a + 1); n   } n   return ((a + 1) / 2) * a; n } n long long sum(long long a, long long b) { return sum(b) - sum(a - 1); } n vector<int> getPrimes(int n) { n   vector<int> primes; n   primes.push_back(2); n   bool isPrime; n   for (int i = 3; i * i <= n; i++) { n     isPrime = true; n     for (int p = 0; p < primes.size() && primes[p] * primes[p] <= i; p++) { n       if (i % primes[p] == 0) { n         isPrime = false; n         break; n       } n     } n     if (isPrime) { n       primes.push_back(i); n     } n   } n   return primes; n } n int findMaxPrime(vector<int> primes, int n, int k) { n   int ans = INT_MAX; n   bool findAns = true; n   int ncpy = n; n   for (int i = 0; primes[i] <= k && primes[i] * primes[i] <= n; i++) { n     if (findAns && n % primes[i] == 0) { n       ans = primes[i]; n     } n     while (n % primes[i] == 0) { n       n /= primes[i]; n     } n   } n   if (n <= k) { n     ans = min(ans, ncpy / n); n   } n   ans = min(ans, ncpy); n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int ttt = 1; n   cin >> ttt; n   string s; n   int temp; n   int n, k; n   int p, q, a, b, c, d; n   bool ans; n   vector<int> primes = getPrimes(1000000005); n   int row, col; n   while (ttt--) { n     cin >> n; n     bool a[n][n]; n     string s; n     for (int i = (int)0; i < (int)n; i++) { n       cin >> s; n       for (int j = (int)0; j < (int)n; j++) { n         if (s[j] ==  1 ) { n           a[i][j] = true; n         } else { n           a[i][j] = false; n         } n       } n     } n     bool possible = true; n     for (int i = 1; possible && i < n; i++) { n       row = n - i - 1; n       p = row; n       for (p; p >= 0; p--) { n         if (a[row][p]) { n           if (!a[row][p + 1] && !a[row + 1][p]) { n             possible = false; n             break; n           } n         } n       } n       col = row; n       p = col; n       for (p; p >= 0; p--) { n         if (a[p][col]) { n           if (!a[p][col + 1] && !a[p + 1][col]) { n             possible = false; n             break; n           } n         } n       } n     } n     if (possible) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMax = 110000; n struct edge { n   int num; n   edge *next; n } * G[NMax], pool[NMax * 2]; n int N, M, K, cant[NMax], L, deg[NMax], cnt[NMax], del[NMax], cur[NMax]; n void Build(int x, int y) { n   edge *p = &pool[L++], *q = &pool[L++]; n   p->num = y; n   p->next = G[x]; n   G[x] = p; n   q->num = x; n   q->next = G[y]; n   G[y] = q; n } n void DFS(int a, long double k) { n   for (edge *p = G[a]; p; p = p->next) n     if (!del[p->num]) cur[p->num]--; n   for (edge *p = G[a]; p; p = p->next) n     if (!del[p->num]) { n       if ((long double)cur[p->num] / (long double)deg[p->num] < k) { n         del[p->num] = 1; n         DFS(p->num, k); n       } n     } n } n int main() { n   scanf( %d%d%d , &N, &M, &K); n   for (int i = 1; i <= K; i++) { n     int x; n     scanf( %d , &x); n     cant[x] = 1; n   } n   for (int i = 1; i <= M; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     Build(x, y); n     deg[x]++; n     deg[y]++; n   } n   for (int i = 1; i <= N; i++) n     if (!cant[i]) n       for (edge *p = G[i]; p; p = p->next) n         if (!cant[p->num]) cnt[i]++; n   long double l = -1e-4f, r = 1.0; n   while (l + 1e-6f < r) { n     long double mid = (l + r) / 2; n     for (int i = 1; i <= N; i++) del[i] = cant[i], cur[i] = cnt[i]; n     for (int i = 1; i <= N; i++) n       if (!del[i]) { n         if ((long double)cur[i] / (long double)deg[i] < mid) { n           del[i] = 1; n           DFS(i, mid); n         } n       } n     int flag = 0; n     for (int i = 1; i <= N; i++) n       if (!del[i]) flag = 1; n     if (flag) n       l = mid; n     else n       r = mid; n   } n   for (int i = 1; i <= N; i++) del[i] = cant[i], cur[i] = cnt[i]; n   for (int i = 1; i <= N; i++) n     if (!del[i]) { n       if ((long double)cur[i] / (long double)deg[i] < l) { n         del[i] = 1; n         DFS(i, l); n       } n     } n   int ans = 0; n   for (int i = 1; i <= N; i++) n     if (!del[i]) ans++; n   printf( %d n , ans); n   for (int i = 1; i <= N; i++) n     if (!del[i]) printf( %d  , i); n   puts(  ); n   getchar(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cumu[200005]; n int main() { n   int n, k, x; n   while (scanf( %d %d , &n, &k) == 2) { n     memset(cumu, 0ll, sizeof cumu); n     int mn = INT_MAX; n     for (int i = 0; i < n; i++) n       scanf( %d , &x), cumu[x + 1] -= 1, mn = min(mn, x); n     cumu[1] = n; n     for (int i = 1; i <= 200001; i++) cumu[i] += cumu[i - 1]; n     for (int i = 1; i <= 200001; i++) cumu[i] += cumu[i - 1]; n     int last = 200001; n     int cut = 0; n     int ans = 0; n     for (int i = 200000; i >= mn; i--) { n       cut = cumu[last] - cumu[i]; n       if (cut > k) ans++, last = i + 1, cut = cumu[last] - cumu[i]; n     } n     ans += (cut != 0); n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n long long x, y; n long long gcd(long long a, long long b) { n   if (!b) { n     x = 1; n     y = 0; n     return a; n   } n   long long t1 = gcd(b, a % b); n   long long t2 = x; n   x = y; n   y = t2 - a / b * y; n   return t1; n } n int main() { n   long long a1, b1, a2, b2, l, r, g, t; n   double dl, dr; n   scanf( %I64d%I64d%I64d%I64d%I64d%I64d , &a1, &b1, &a2, &b2, &l, &r); n   g = gcd(a1, a2); n   if ((b2 - b1) % g != 0) { n     printf( 0 n ); n     return 0; n   } n   x *= (b2 - b1) / g; n   y *= (b2 - b1) / g; n   t = ceil((double)g * (-x) / a2); n   x += a2 / g * t; n   y -= a1 / g * t; n   if (y > 0) { n     t = floor((double)g * (-y) / a1); n     x -= a2 / g * t; n     y += a1 / g * t; n   } n   dl = ((double)(l - b1) / a1 - x) * (double)g / a2; n   dr = ((double)(r - b1) / a1 - x) * (double)g / a2; n   dl = (dl - 0 > 1e-20 ? dl : 0); n   long long ans = floor(dr) - ceil(dl) + 1; n   if (dr < 0) { n     printf( 0 n ); n     return 0; n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n string s[105]; n int n, m; n int main() { n   long long l, r; n   cin >> l >> r; n   int digit1, digit2; n   digit1 = digit2 = 0; n   long long l1, r1; n   l1 = l; n   r1 = r; n   while (l1 != 0) { n     l1 /= 10; n     digit1++; n   } n   while (r1 != 0) { n     r1 /= 10; n     digit2++; n   } n   int digit = max(digit1, digit2); n   long long min_val = 1; n   long long max_val = 9; n   digit--; n   while (digit != 0) { n     min_val *= 10; n     digit--; n     max_val *= 10; n     max_val += 9; n   } n   if ((max_val + 1) / 2 >= l && (max_val + 1) / 2 <= r) { n     cout << (max_val - (max_val + 1) / 2) * (max_val + 1) / 2 << endl; n   } else if (r < (max_val + 1) / 2) { n     cout << (max_val - r) * r << endl; n   } else { n     if (l < min_val) n       cout << max((max_val - l) * l, n                   (max_val - (max_val + 1) / 2) * (max_val + 1) / 2) n            << endl; n     else n       cout << (max_val - l) * l << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> s(n, 0); n   vector<int> m(n, 0); n   map<int, int> freq, freq2; n   string sher, mori; n   cin >> sher; n   cin >> mori; n   for (int i = 0; i < n; i++) { n     s[i] = sher[i] -  0 ; n   } n   for (int i = 0; i < n; i++) { n     m[i] = mori[i] -  0 ; n     freq[m[i]] += 1; n     freq2[m[i]] += 1; n   } n   int sflick = 0; n   for (int i = 0; i < n; i++) { n     for (int j = (s[i] + 1) % 10;; j = (j + 1) % 10) { n       if (freq.find(j) != freq.end() && freq[j] > 0) { n         freq[j]--; n         if (j > s[i]) sflick++; n         break; n       } n     } n   } n   int mflick = 0; n   for (int i = 0; i < n; i++) { n     for (int j = s[i];; j = (j + 1) % 10) { n       if (freq2.find(j) != freq2.end() && freq2[j] > 0) { n         freq2[j]--; n         if (j < s[i]) mflick++; n         break; n       } n     } n   } n   cout << mflick <<     << sflick << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5100; n const int oo = 1e9; n const int MX = 100000000; n const int FF = 33000; n int n, m, a[N], gc[N]; n int dp[5010], pre[5010]; n map<int, bool> bad; n map<int, int> cache; n vector<int> prime; n bool mark[FF + 200]; n int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } n int fact(int num) { n   if (cache.find(num) != cache.end()) return cache[num]; n   int &ret = cache[num]; n   long long idx = 0, pf = prime[0]; n   while (pf * pf <= num) { n     int cnt = 0; n     while (num % pf == 0) num /= pf, cnt++; n     ret += cnt * (bad[pf] ? -1 : 1); n     if (++idx < prime.size()) pf = prime[idx]; n   } n   if (num != 1) ret += bad[num] ? -1 : 1; n   return ret; n } n int eval() { n   int res = 0; n   for (int i = 0; i < n; ++i) res += fact(a[i]); n   return res; n } n int rn(int l, int r, int gc) { n   return pre[r] - (!l ? 0 : pre[l - 1]) - (r - l + 1) * fact(gc); n } n int calc(int idx) { n   if (idx == n) return 0; n   int &ret = dp[idx]; n   if (ret != -oo) return ret; n   ret = rn(idx, n - 1, 1); n   for (int j = idx; j < n; ++j) { n     ret = max(ret, rn(idx, j, gc[j]) + calc(j + 1)); n   } n   return ret; n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   for (int first, i = 0; i < m; ++i) { n     scanf( %d , &first); n     bad[first] = 1; n   } n   for (long long i = 2; i <= FF; ++i) { n     if (mark[i]) continue; n     for (int j = i; j <= FF; j += i) mark[j] = 1; n     prime.push_back(i); n   } n   for (int i = 0; i < n; ++i) gc[i] = !i ? a[i] : gcd(a[i], gc[i - 1]); n   for (int i = 0; i <= n; ++i) dp[i] = -oo; n   for (int i = 0; i < n; ++i) { n     pre[i] = fact(a[i]); n     if (i) pre[i] += pre[i - 1]; n   } n   cout << calc(0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, a, b, dp[200005][2]; n   cin >> n >> a >> b; n   string t; n   cin >> t; n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][0] = b; n   for (int i = 0; i < n; i++) { n     if (t[i] ==  1 ) n       dp[i + 1][1] = dp[i][1] + a + 2 * b; n     else { n       dp[i + 1][0] = min(dp[i][0] + a + b, dp[i][1] + 2 * a + b); n       dp[i + 1][1] = min(dp[i][0] + 2 * (a + b), dp[i][1] + a + 2 * b); n     } n   } n   cout << dp[n][0] << endl; n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, m, ans; n   cin >> n >> m; n   vector<long long> ar(n); n   for (long long i = 0; i < n; i++) cin >> ar[i]; n   sort(ar.begin(), ar.end()); n   ans = 1; n   if (n > m) { n     cout << 0; n     return; n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = i + 1; j < n; j++) { n       ans = (ans % m * abs(ar[i] - ar[j]) % m) % m; n       if (ans == 0) { n         cout << 0; n         return; n       } n     } n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long q = 1; n   while (q--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9; n const int mod = 1e9 + 7; n const int N = 1234; n int n, m; n long long k; n int a[N][N], h[N * N], p[N * N]; n long long b[N][N]; n bool used[N][N]; n vector<pair<int, int> > go = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n bool check(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } n int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); } n void unite(int x, int y) { n   x = get(x); n   y = get(y); n   if (x == y) return; n   p[x] = y; n   h[y] += h[x]; n   h[x] = 0; n } n long long qwe; n void dfs(int i, int j) { n   k -= qwe; n   used[i][j] = true; n   b[i][j] = qwe; n   for (auto w : go) { n     int x = i + w.first, y = j + w.second; n     if (check(x, y) && !used[x][y] && k > 0ll && a[x][y] >= qwe) dfs(x, y); n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n >> m >> k; n   vector<pair<int, pair<int, int> > > v; n   v.reserve(n * m); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       p[i * m + j] = i * m + j; n       h[i * m + j] = 1; n       v.push_back({a[i][j], {i, j}}); n     } n   } n   sort(v.rbegin(), v.rend()); n   for (int i = 0; i < n * m; i++) { n     int x = v[i].second.first, y = v[i].second.second, w = v[i].first; n     for (auto z : go) { n       int nx = x + z.first, ny = y + z.second; n       if (check(nx, ny) && a[nx][ny] >= w) { n         unite(x * m + y, nx * m + ny); n       } n     } n     int sz = h[get(x * m + y)]; n     if (k % (long long)w == 0ll && k / (long long)w <= (long long)sz) { n       qwe = w; n       dfs(x, y); n       cout <<  YES n ; n       for (int j = 0; j < n; j++) { n         for (int z = 0; z < m; z++) { n           cout << b[j][z] <<    ; n         } n         cout <<   n ; n       } n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &f) { n   f = 0; n   T fu = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) fu = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     f = (f << 3) + (f << 1) + (c & 15); n     c = getchar(); n   } n   f *= fu; n } n template <typename T> n void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x < 10) n     putchar(x + 48); n   else n     print(x / 10), putchar(x % 10 + 48); n } n template <typename T> n void print(T x, char t) { n   print(x); n   putchar(t); n } n const int N = 55, M = 7777; n char c[N]; n int isp[M + 5], val[N]; n int T, n; n bool check(int x) { n   for (int i = 2; i * i <= x; i++) { n     if (x % i == 0) return 0; n   } n   return 1; n } n int main() { n   for (int i = 2; i <= M; i++) isp[i] = check(i); n   read(T); n   while (T--) { n     read(n); n     scanf( %s , c + 1); n     for (int i = 1; i <= M; i++) { n       if (isp[i]) continue; n       int len = 0, tmp = i; n       while (tmp) { n         val[++len] = tmp % 10; n         tmp /= 10; n       } n       reverse(val + 1, val + len + 1); n       int pos = 1; n       for (int j = 1; j <= n; j++) { n         if (c[j] -  0  == val[pos]) ++pos; n         if (pos == len + 1) break; n       } n       if (pos == len + 1) { n         print(len,   n ); n         print(i,   n ); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct item_t { n   int cost; n   int gain; n   int when; n   bool operator<(const item_t& other) const { return when < other.when; } n   bool operator<(const int t) const { return when < t; } n } item[4000]; n bool operator<(int v, const item_t& item) { return v < item.when; } n struct dp_t { n   int maxgain[4000 + 1]; n   void update(int c, int g) { n     for (int b = 4000; b >= 0; b--) n       if (b + c <= 4000) maxgain[b + c] = max(maxgain[b + c], maxgain[b] + g); n   } n } toleft[4000], toright[4000]; n int main() { n   int n, window; n   scanf( %d %d , &n, &window); n   for (int i = 0; i < n; i++) { n     scanf( %d %d %d , &item[i].cost, &item[i].gain, &item[i].when); n   } n   sort(item, item + n); n   memset(toleft, 0, sizeof(toleft)); n   memset(toright, 0, sizeof(toright)); n   for (int i = 0; i < n; i++) { n     if (i - 1 >= 0 && item[i - 1].when / window == item[i].when / window) n       toleft[i] = toleft[i - 1]; n     toleft[i].update(item[i].cost, item[i].gain); n   } n   for (int i = n - 1; i >= 0; i--) { n     if (i + 1 < n && item[i + 1].when / window == item[i].when / window) n       toright[i] = toright[i + 1]; n     toright[i].update(item[i].cost, item[i].gain); n   } n   int nq; n   scanf( %d , &nq); n   for (int q = 0; q < nq; q++) { n     int vis_when, budget; n     scanf( %d %d , &vis_when, &budget); n     int b = vis_when; n     int a = b - window + 1; n     int lb = lower_bound(item, item + n, a) - item; n     int _ub = upper_bound(item, item + n, b) - item; n     int gain; n     if (lb == _ub) n       gain = 0; n     else { n       int ub1 = _ub - 1; n       if (item[lb].when / window != item[ub1].when / window) { n         gain = 0; n         for (int lbud = 0; lbud <= budget; lbud++) n           gain = max(gain, toright[lb].maxgain[lbud] + n                                toleft[ub1].maxgain[budget - lbud]); n       } else { n         if (item[ub1].when / window == b / window) n           gain = toleft[ub1].maxgain[budget]; n         else n           gain = toright[lb].maxgain[budget]; n       } n     } n     printf( %d n , gain); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug_out() { cerr << endl; } n template <class T> n ostream& prnt(ostream& out, T v) { n   out << v.size() <<   n ; n   for (auto e : v) out << e <<    ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, vector<T> v) { n   return prnt(out, v); n } n template <class T> n ostream& operator<<(ostream& out, set<T> v) { n   return prnt(out, v); n } n template <class T1, class T2> n ostream& operator<<(ostream& out, map<T1, T2> v) { n   return prnt(out, v); n } n template <class T1, class T2> n ostream& operator<<(ostream& out, pair<T1, T2> p) { n   return out <<  (  << p.first <<     << p.second <<  ) ; n } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << H; n   debug_out(T...); n } n struct Flow { n   const static int MAX_EDGES = 2510005; n   const static int MAX_NODES = 6105; n   const int INF = 1e9 + 50; n   int S = MAX_NODES - 2, D = MAX_NODES - 1; n   int G[MAX_NODES]; n   struct Edge { n     int vec, flow, cap, cost, rev, nxt; n   }; n   Edge E[MAX_EDGES]; n   int edges = 0; n   int ParentNode[MAX_NODES], ParentEdge[MAX_NODES], Dist[MAX_NODES]; n   bool InQ[MAX_NODES]; n   queue<int> Q; n   Flow() { Reset(); } n   void setSource(int s) { S = s; } n   void setSink(int d) { D = d; } n   void _addEdge(int a, int b, int cap, int cost, int rev) { n     ++edges; n     E[edges] = (Edge){b, 0, cap, cost, rev, G[a]}; n     G[a] = edges; n   } n   void AddEdge(int a, int b, int cap, int cost) { n     _addEdge(a, b, cap, cost, edges + 2); n     _addEdge(b, a, 0, -cost, edges); n   } n   bool Bellman() { n     memset(ParentNode, 0, sizeof(ParentNode)); n     Dist[S] = 0; n     Q.push(S); n     while (!Q.empty()) { n       int top = Q.front(); n       InQ[top] = 0; n       Q.pop(); n       for (int i = G[top]; i; i = E[i].nxt) { n         int vec = E[i].vec; n         if (E[i].flow < E[i].cap && n             (ParentNode[vec] == 0 || Dist[vec] > Dist[top] + E[i].cost)) { n           Dist[vec] = Dist[top] + E[i].cost; n           ParentNode[vec] = top; n           ParentEdge[vec] = i; n           if (!InQ[vec]) { n             Q.push(vec); n             InQ[vec] = 1; n           } n         } n       } n     } n     return ParentNode[D] != 0; n   } n   void Reset() { n     edges = 0; n     memset(G, 0, sizeof(G)); n   } n   int MFMC() { n     int cost = 0, flow = 0; n     while (Bellman()) { n       int M = INF; n       for (int node = D; node != S; node = ParentNode[node]) { n         int ei = ParentEdge[node]; n         M = min(M, E[ei].cap - E[ei].flow); n       } n       for (int node = D; node != S; node = ParentNode[node]) { n         int ei = ParentEdge[node], ri = E[ei].rev; n         E[ei].flow += M; n         E[ri].flow -= M; n         cost += E[ei].cost * M; n       } n       flow += M; n     } n     cerr <<  flow  n          <<   -> , n         debug_out(flow); n     return cost; n   } n }; n Flow F; n const int MAX_DAY = 101; n int n, m, k, c, d, a[55], x, y; n int vert(int nr, int day) { return 51 * day + nr; } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> k >> c >> d; n   for (int i = 1; i <= k; i++) { n     cin >> a[i]; n     F.AddEdge(F.S, vert(a[i], 0), 1, 0); n   } n   for (int i = 1; i <= m; i++) { n     cin >> x >> y; n     for (int day = 0; day < MAX_DAY; day++) { n       for (int cost = 0; cost < 50; cost++) { n         F.AddEdge(vert(x, day), vert(y, day + 1), 1, (2 * cost + 1) * d); n         F.AddEdge(vert(y, day), vert(x, day + 1), 1, (2 * cost + 1) * d); n       } n     } n   } n   for (int day = 0; day <= MAX_DAY; day++) { n     for (int i = 1; i <= n; i++) n       F.AddEdge(vert(i, day), vert(i, day + 1), 51, 0); n     for (int i = 0; i < k; i++) F.AddEdge(vert(1, day), F.D, 1, c * day); n   } n   cout << F.MFMC() <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 1; n int a[N]; n int main() { n   float n, x, y; n   cin >> x >> y; n   printf( %.12f , (y * y - x * x) / (2 * x)); n } n


#include <bits/stdc++.h> n using namespace std; n string lines[10000]; n int scheme[4]; n int quart = -1; n bool is_vowel(char c) { n   return c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ; n } n bool rhyme(int s, int a, int b) { n   int A = lines[s + a].length() - scheme[a]; n   int B = lines[s + b].length() - scheme[b]; n   if (A != B) { n     return false; n   } n   return lines[s + a].substr(scheme[a]) == lines[s + b].substr(scheme[b]); n } n int main() { n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < 4 * n; i++) { n     cin >> lines[i]; n   } n   for (int i = 0; i < n; i++) { n     int s = i * 4; n     for (int x = 0; x < 4; x++) { n       scheme[x] = -1; n       int v = 0; n       for (int j = lines[s + x].length() - 1; j >= 0; j--) { n         if (is_vowel(lines[s + x][j])) { n           v++; n           if (v == k) { n             scheme[x] = j; n             break; n           } n         } n       } n       if (scheme[x] == -1) { n         cout <<  NO  << endl; n         return 0; n       } n     } n     bool ab = rhyme(s, 0, 1); n     bool ac = rhyme(s, 0, 2); n     bool ad = rhyme(s, 0, 3); n     bool bc = rhyme(s, 1, 2); n     bool bd = rhyme(s, 1, 3); n     bool cd = rhyme(s, 2, 3); n     int nq; n     if (ab && bc && cd) { n       nq = 0; n     } else if (ab && cd) { n       nq = 1; n     } else if (ac && bd) { n       nq = 2; n     } else if (ad && bc) { n       nq = 3; n     } else { n       cout <<  NO  << endl; n       return 0; n     } n     if (quart == -1 || quart == 0) { n       quart = nq; n     } else if (nq == 0 || nq == quart) { n       continue; n     } else { n       cout <<  NO  << endl; n       return 0; n     } n   } n   if (quart == 0) { n     cout <<  aaaa  << endl; n   } else if (quart == 1) { n     cout <<  aabb  << endl; n   } else if (quart == 2) { n     cout <<  abab  << endl; n   } else if (quart == 3) { n     cout <<  abba  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const long long INF = 1e15; n using Graph = vector<vector<long long>>; n signed main() { n   long long T; n   cin >> T; n   for (long long t = 0; t < T; t++) { n     long long N; n     cin >> N; n     vector<long long> A(N); n     for (long long i = 0; i < N; i++) cin >> A[i]; n     sort(A.begin(), A.end()); n     long long ans = 1000000; n     for (long long i = 1; i < N; i++) { n       ans = min(ans, A[i] - A[i - 1]); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n struct node { n   int v, next; n } p[200005 << 1]; n int head[200005], n, k; n long long dp[200005][10], size[200005], ans; n void dfs(int x, int fa, int depth) { n   size[x] = dp[x][depth % k] = 1; n   for (int i = head[x]; ~i; i = p[i].next) { n     if (p[i].v == fa) continue; n     dfs(p[i].v, x, depth + 1); n     for (int a = 0; a < k; a++) { n       for (int b = 0; b < k; b++) { n         int dis = ((a + b) % k - (depth * 2) % k + k) % k; n         ans += ((k - dis) % k) * dp[x][a] * dp[p[i].v][b]; n       } n     } n     for (int a = 0; a < k; a++) { n       dp[x][a] += dp[p[i].v][a]; n     } n     ans += size[p[i].v] * (n - size[p[i].v]); n     size[x] += size[p[i].v]; n   } n } n int main() { n   scanf( %d%d , &n, &k); n   memset(head, -1, sizeof(head)); n   int len = 0; n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     p[len].v = v; n     p[len].next = head[u]; n     head[u] = len++; n     p[len].v = u; n     p[len].next = head[v]; n     head[v] = len++; n   } n   dfs(1, 0, 0); n   printf( %lld n , ans / k); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, M = 1 << 20 | 10; n const int mod = 1e9 + 7; n long long n, m, sum; n int a[M]; n int main() { n   scanf( %lld%lld , &n, &m); n   for (int i = 1; i <= n; i++) a[i] = i, sum += i; n   if (sum > m) return puts( -1 ), 0; n   for (int i = 1, j = n; i <= j;) { n     if (sum + j - i <= m) n       swap(a[i], a[j]), sum += j - i, i++, j--; n     else n       j--; n   } n   printf( %lld n , sum); n   for (int i = 1; i <= n; i++) printf( %d  , i); n   puts(  ); n   for (int i = 1; i <= n; i++) printf( %d  , a[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n const int Dian = 200005; n const int Bian = Dian * 2; n const int M = Dian; n const int Segment_Size = Dian * 4; n int fir[Dian], ne[Bian], to[Bian], cnt, n, m; n int dp[Dian], depth[Dian], fa[Dian], Bigson[Dian], top[Dian], S[Dian], n     dep[Dian], info[Dian]; n struct One { n   int from, to, C, LCA; n } Road[M]; n vector<One> G[Dian]; n void add(int x, int y) { n   ne[++cnt] = fir[x]; n   fir[x] = cnt; n   to[cnt] = y; n } n void link(int x, int y) { n   add(x, y); n   add(y, x); n } n void getinfo(int x, int f) { n   S[x] = 1; n   dep[x] = dep[f] + 1; n   int mx = -1; n   for (int i = fir[x]; i; i = ne[i]) { n     int V = to[i]; n     if (V == f) continue; n     getinfo(V, x); n     if (S[V] > mx) Bigson[x] = V, mx = S[V]; n     S[x] += S[V]; n   } n } n void getidx(int x, int T) { n   top[x] = T; n   if (Bigson[x]) getidx(Bigson[x], T); n   for (int i = fir[x]; i; i = ne[i]) { n     int V = to[i]; n     if (V == fa[x] || V == Bigson[x]) continue; n     getidx(V, V); n   } n } n int LCA(int x, int y) { n   while (top[x] != top[y]) { n     if (dep[top[x]] < dep[top[y]]) swap(x, y); n     x = fa[top[x]]; n   } n   if (dep[y] < dep[x]) return y; n   return x; n } n void read(void) { n   scanf( %d%d , &n, &m); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &fa[i]); n     link(i, fa[i]); n   } n   getinfo(1, 0); n   getidx(1, 1); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &Road[i].from, &Road[i].to, &Road[i].C); n     Road[i].LCA = LCA(Road[i].from, Road[i].to); n     G[Road[i].LCA].push_back(Road[i]); n   } n } n int getans(One Query) { n   int x = Query.from, y = Query.to, now = Query.C; n   while (top[x] != top[y]) { n     if (dep[top[x]] < dep[top[y]]) swap(x, y); n     now = now + info[top[x]] - info[Bigson[x]]; n     x = fa[top[x]]; n   } n   if (dep[x] > dep[y]) swap(x, y); n   now = now + info[x] - info[Bigson[y]]; n   return now; n } n int dfs(int x, int f) { n   int sum = 0; n   for (int i = fir[x]; i; i = ne[i]) { n     int V = to[i]; n     if (V == f) continue; n     sum += dfs(V, x); n   } n   info[x] = info[Bigson[x]] + sum; n   dp[x] = sum; n   for (int i = 0; i < (int)G[x].size(); i++) n     dp[x] = max(dp[x], getans(G[x][i])); n   info[x] -= dp[x]; n   return dp[x]; n } n void doit(void) { printf( %d n , dfs(1, 0)); } n int main(void) { n   read(); n   doit(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t; n   cin >> t; n   while (t--) { n     long long n, i, j; n     string s; n     cin >> s; n     long long x; n     cin >> x; n     n = s.length(); n     string w = s; n     for (i = 0; i < n; i++) { n       w[i] =  1 ; n     } n     for (i = 0; i < n; i++) { n       if (s[i] ==  0 ) { n         if (i - x >= 0) { n           w[i - x] =  0 ; n         } n         if (i + x < n) { n           w[i + x] =  0 ; n         } n       } n     } n     bool con = true; n     for (i = 0; i < n; i++) { n       if (s[i] ==  1 ) { n         long long c1 = 0; n         long long c2 = 0; n         if (i - x >= 0) { n           c1 = w[i - x] -  0 ; n         } n         if (i + x < n) { n           c2 = w[i + x] -  0 ; n         } n         long long num = c1 | c2; n         if (num != 1) { n           con = false; n           break; n         } n       } n     } n     if (con) n       cout << w <<   n ; n     else n       cout <<  -1  n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getnum() { n   char c = getchar(); n   long long num, sign = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (num = 0; c >=  0  && c <=  9 ;) { n     c -=  0 ; n     num = num * 10 + c; n     c = getchar(); n   } n   return num * sign; n } n int nxt[400005], A[400005], store[400005], at[400005]; n set<int> Set; n set<pair<long long, long long> > Cur; n int main() { n   int n = getnum(), k = getnum(), ans = 0; n   for (int i = 1; i <= n; i++) A[i] = getnum(); n   for (int i = n; i >= 1; i--) { n     if (store[A[i]] != 0) n       nxt[i] = store[A[i]]; n     else n       nxt[i] = n + 1; n     store[A[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     if (Set.find(A[i]) == Set.end()) { n       ans++; n       if (Set.size() == k) { n         auto it = Cur.end(); n         it--; n         Set.erase(it->second); n         Cur.erase(it); n       } n       Set.insert(A[i]); n       Cur.insert({nxt[i], A[i]}); n       at[A[i]] = i; n     } else { n       Cur.erase({nxt[at[A[i]]], A[i]}); n       Cur.insert({nxt[i], A[i]}); n       at[A[i]] = i; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, ar[N]; n char mark[N] = {}; n int sz[N] = {}; n priority_queue<pair<int, int>, vector<pair<int, int> > > pq; n int main(void) { n   cin.tie(0); n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> ar[i]; n   for (int i = 0; i < n; ++i) { n     if (ar[i] != 0) { n       pq.push(make_pair(ar[i], i)); n     } else { n       sz[i] = min(3, (int)pq.size()); n       int tmp = sz[i]; n       while (tmp--) { n         pair<int, int> x = pq.top(); n         pq.pop(); n         mark[x.second] = 1; n       } n       while (pq.size()) pq.pop(); n     } n   } n   int flag = 0; n   for (int i = 0; i < n; ++i) { n     if (ar[i] != 0) { n       if (mark[i]) { n         switch (flag) { n           case 0: n             cout <<  pushStack n ; n             break; n           case 1: n             cout <<  pushQueue n ; n             break; n           case 2: n             cout <<  pushFront n ; n             break; n         } n         flag = (flag + 1) % 3; n       } else n         cout <<  pushBack n ; n     } else { n       int k = sz[i]; n       cout << k; n       while (k--) { n         flag = (flag - 1 + 3) % 3; n         switch (flag) { n           case 0: n             cout <<   popStack ; n             break; n           case 1: n             cout <<   popQueue ; n             break; n           case 2: n             cout <<   popFront ; n             break; n         } n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e2 + 10; n int ans, mac, n; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   while (ans < n) { n     mac += 5; n     int x = mac; n     while (x % 5 == 0) { n       x /= 5; n       ans++; n     } n   } n   if (ans == n) { n     cout << 5 <<   n ; n     for (int i = mac; i < mac + 5; ++i) { n       cout << i <<    ; n     } n     cout <<   n ; n     return 0; n   } n   cout << 0 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1000000007; n long long q; n long long md[255][255] = {0}; n long long a[500005] = {0}; n int main() { n   long long op, x, y; n   scanf( %lld , &q); n   while (q--) { n     scanf( %lld %lld %lld , &op, &x, &y); n     if (op == 1) { n       for (long long i = 1; i <= 250; i++) md[i][x % i] += y; n       a[x] += y; n     } n     if (op == 2) { n       long long ans = 0; n       if (x > 250) { n         for (long long i = y; i <= 500000; i += x) ans += a[i]; n       } else n         ans = md[x][y]; n       printf( %lld n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, d[22]; n int f[22], g[22], L[22], memF[22]; n void moveG(int n, int a, int b, int c) { n   if (n == 0) return; n   moveG(n - L[n], a, c, b); n   for (int i = 0; i < L[n]; i++) printf( %d %d n , a, c); n   moveG(n - L[n], b, a, c); n } n void moveF(int n, int a, int b, int c) { n   if (n == 0) return; n   if (memF[n] == 0) { n     moveG(n - 1, a, c, b); n     printf( %d %d n , a, c); n     moveG(n - 1, b, a, c); n   } else { n     int k = memF[n]; n     moveG(n - k, a, b, c); n     for (int i = 0; i < k; i++) printf( %d %d n , a, b); n     moveG(n - k, c, b, a); n     for (int i = 0; i < k; i++) printf( %d %d n , b, c); n     moveF(n - k, a, b, c); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &d[i]); n   reverse(d + 1, d + 1 + n); n   for (int i = 1; i <= n; i++) { n     L[i] = 1; n     while (i - L[i] >= 1 && d[i - L[i]] == d[i]) L[i]++; n   } n   for (int i = 1; i <= n; i++) { n     f[i] = 2 * g[i - 1] + 1; n     memF[i] = 0; n     for (int k = 1; k <= L[i]; k++) { n       int tmp = 2 * g[i - k] + f[i - k] + 2 * k; n       if (tmp < f[i]) f[i] = tmp, memF[i] = k; n     } n     g[i] = 2 * g[i - L[i]] + L[i]; n   } n   printf( %d n , f[n]); n   moveF(n, 1, 2, 3); n } n


#include <bits/stdc++.h> n using namespace std; n long long p; n long long base; n char s[20]; n long long a; n long long d; n int main(int argc, const char* argv[]) { n   int T; n   cin >> T; n   while (T--) { n     base = 1989; n     d = 10; n     scanf( %s , s); n     int i; n     for (i = 0, a = 0; s[i + 4] >=  0  && s[i + 4] <=  9 ; i++) n       a = a * 10 + (long long)(s[i + 4] -  0 ); n     for (int j = 2; j <= i; j++) { n       base += d; n       d *= 10; n     } n     for (i = 0; i * d + a < base; i++) n       ; n     cout << i * d + a << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n vector<vector<pair<int, int>>> g; n vector<pair<int, pair<int, int>>> edg; n int cp[100010]; n int find(int x) { return cp[x] = cp[x] == x ? x : find(cp[x]); } n void union_(int x, int y) { cp[find(x)] = find(y); } n int h[100010]; n int anc[100010][18]; n int val[100010][18]; n void dfs_preprocess(int u, int p = -1) { n   anc[u][0] = p; n   if (~p) { n     h[u] = h[p] + 1; n   } n   for (int i = 1; i < 18; ++i) { n     if (~anc[u][i - 1]) { n       anc[u][i] = anc[anc[u][i - 1]][i - 1]; n       val[u][i] = max(val[anc[u][i - 1]][i - 1], val[u][i - 1]); n     } n   } n   for (auto v : g[u]) { n     if (v.second != p) { n       val[v.second][0] = v.first; n       dfs_preprocess(v.second, u); n     } n   } n } n int LCA(int v, int u) { n   if (h[v] < h[u]) swap(u, v); n   int val_ans = 0; n   for (int i = 18 - 1; i >= 0; --i) { n     if (anc[v][i] + 1 && h[anc[v][i]] >= h[u]) { n       val_ans = max(val_ans, val[v][i]); n       v = anc[v][i]; n     } n   } n   if (v == u) return val_ans; n   for (int i = 18 - 1; i >= 0; --i) { n     if (anc[v][i] != anc[u][i]) { n       val_ans = max({val_ans, val[v][i], val[u][i]}); n       v = anc[v][i]; n       u = anc[u][i]; n     } n   } n   val_ans = max({val_ans, val[v][0], val[u][0]}); n   return val_ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cp[i] = i; n   g.assign(n, vector<pair<int, int>>()); n   map<pair<int, int>, int> mp; n   int id = 0; n   for (int i = 0; i < m; ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     u--, v--; n     mp[{u, v}] = id++; n     edg.push_back({w, {u, v}}); n   } n   sort((edg).begin(), (edg).end()); n   vector<int> mst(m, 0); n   memset(anc, -1, sizeof(anc)); n   for (int i = 0; i < m; ++i) { n     int u = edg[i].second.first, v = edg[i].second.second, w = edg[i].first; n     if (find(u) != find(v)) { n       union_(u, v); n       g[u].push_back({w, v}); n       g[v].push_back({w, u}); n       mst[i] = 1; n     } n   } n   dfs_preprocess(0); n   vector<int> ans(m, -1); n   for (int i = 0; i < m; ++i) { n     if (!mst[i]) { n       ans[mp[edg[i].second]] = LCA(edg[i].second.first, edg[i].second.second); n     } n   } n   for (int u : ans) { n     if (u + 1) cout << u <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct NODE { n   char w[4]; n }; n NODE tmp; n vector<NODE> st, stt; n bool use[10]; n int bull, cow; n char ss[6]; n void back(int index) { n   if (index == 4) { n     int i, j, b, c; n     for (i = 0, b = 0, c = 0; i < 4; ++i) n       for (j = 0; j < 4; ++j) n         if (tmp.w[i] == ss[j]) { n           if (i == j) n             b++; n           else n             c++; n         } n     if (b == bull && c == cow) { n       st.push_back(tmp); n     } n   } else { n     int i; n     for (i = 0; i < 10; ++i) { n       if (use[i]) continue; n       tmp.w[index] =  0  + i; n       use[i] = true; n       back(index + 1); n       use[i] = false; n     } n   } n } n int main() { n   int i, k, j, num, m, n, b, c; n   while (scanf( %d , &num) == 1) { n     st.clear(); n     scanf( %s %d %d , ss, &bull, &cow); n     memset(use, 0, sizeof(use)); n     back(0); n     for (i = 2; i <= num; ++i) { n       scanf( %s %d %d , ss, &bull, &cow); n       stt.clear(); n       for (j = 0, k = st.size(); j < k; ++j) { n         for (m = 0, b = 0, c = 0; m < 4; ++m) { n           for (n = 0; n < 4; ++n) { n             if (st[j].w[m] == ss[n]) { n               if (m == n) n                 ++b; n               else n                 ++c; n             } n           } n         } n         if (b == bull && c == cow) stt.push_back(st[j]); n       } n       st.clear(); n       for (j = 0, k = stt.size(); j < k; ++j) st.push_back(stt[j]); n     } n     if (st.size() > 1) n       puts( Need more data ); n     else if (st.size() < 1) n       puts( Incorrect data ); n     else { n       for (i = 0; i < 4; ++i) printf( %c , st[0].w[i]); n       putchar(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t, a, b; n   cin >> t; n   while (t--) { n     cin >> a >> b; n     if (a == b) { n       cout << 0 <<   n ; n     } else if (abs(a - b) <= 10) { n       cout << 1 <<   n ; n     } else if (abs(a - b) % 10 != 0) { n       cout << (abs(b - a) / 10) + 1 <<   n ; n     } else { n       cout << (abs(a - b) / 10) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 100010; n long long MAX = 0; n vector<int> maxs; n vector<int> A[M]; n map<pair<int, int>, int> mep; n map<pair<int, int>, int> tmpmep; n map<int, vector<pair<int, int> > > edges; n int weight[M]; n int parent[M]; n int compsize[M]; n int visited[M]; n int dp[M]; n int f(int first) { n   return parent[first] = parent[first] == first ? first : f(parent[first]); n } n void add(int a, int b) { n   int first = f(a), second = f(b); n   if (first != second) { n     parent[first] = second; n     compsize[second] += compsize[first]; n   } n } n int dfs1(int first) { n   visited[first] = true; n   int sum = 0; n   for (int second : A[first]) n     if (!visited[second]) sum += dfs1(second); n   return sum + compsize[first]; n } n int dfs2(int first, int p, int total) { n   visited[first] = true; n   int sum = compsize[first]; n   for (int second : A[first]) n     if (!visited[second]) sum += dfs2(second, first, total); n   long long trees = (long long)sum * (long long)(total - sum); n   if (trees > MAX) n     MAX = trees, maxs.clear(), n     maxs.push_back(tmpmep[make_pair(min(p, first), max(p, first))]); n   else if (trees == MAX) n     maxs.push_back(tmpmep[make_pair(min(p, first), max(p, first))]); n   return sum; n } n int main() { n   ios_base::sync_with_stdio(false); n   int i, j, k, n; n   scanf( %d , &n); n   for (int _ = 1; _ < n; _++) { n     scanf( %d%d%d , &i, &j, &k); n     mep[make_pair(min(i, j), max(i, j))] = _; n     edges[k].push_back(make_pair(min(i, j), max(i, j))); n     weight[_] = k; n   } n   for (i = 0; i <= n; i++) parent[i] = i, compsize[i] = 1; n   for (auto elm : edges) { n     set<int> nodes; n     tmpmep.clear(); n     for (auto e : elm.second) { n       int first = f(e.first), second = f(e.second); n       nodes.insert(first); n       nodes.insert(second); n       A[first].push_back(second); n       A[second].push_back(first); n       tmpmep[make_pair(min(first, second), max(first, second))] = mep[e]; n     } n     vector<pair<int, int> > roots; n     for (auto first : nodes) n       if (!visited[first]) roots.push_back(make_pair(first, dfs1(first))); n     for (auto first : nodes) visited[first] = false; n     for (auto p : roots) dfs2(p.first, -1, p.second); n     for (auto e : elm.second) add(e.first, e.second); n     for (auto first : nodes) { n       A[first].clear(); n       visited[first] = false; n     } n   } n   sort((maxs).begin(), (maxs).end()); n   printf( %lld %d n , 2 * MAX, (int)maxs.size()); n   for (auto m : maxs) printf( %d  , m); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   vector<vector<int>> g(n); n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   vector<int> color(n); n   vector<int> d(n); n   vector<int> sub(n); n   int iter = 0; n   function<void(int, int, int, int)> dfs_to_color = [&](int v, int p, int c, n                                                         int pr) { n     color[v] = c; n     for (int i : g[v]) { n       if (i == p || color[i] != pr) continue; n       dfs_to_color(i, v, c, pr); n     } n   }; n   function<void(int, int, int)> dfs_on_color = [&](int v, int p, int c) { n     if (~p) n       d[v] = d[p] ^ 1; n     else n       d[v] = 0; n     sub[v] = 1; n     for (int i : g[v]) { n       if (color[i] != c || i == p) continue; n       dfs_on_color(i, v, c); n       sub[v] += sub[i]; n     } n   }; n   vector<pair<int, int>> ret; n   function<void(vector<int>)> solve = [&](vector<int> nodes) { n     int sz = nodes.size(); n     if (sz <= 4) return; n     int root = nodes[0]; n     int c = color[root]; n     dfs_on_color(root, -1, c); n     int pr = -1; n     while (true) { n       int nxt = -1; n       for (int i : g[root]) { n         if (color[i] != c || i == pr) continue; n         if (sub[i] > sz / 2) nxt = i; n       } n       if (nxt == -1) break; n       pr = root; n       root = nxt; n     } n     for (int i : g[root]) { n       if (color[i] != c) continue; n       iter++; n       dfs_to_color(i, root, iter, c); n     } n     map<int, vector<int>> to_color; n     for (int i : nodes) { n       if (i == root) continue; n       to_color[color[i]].push_back(i); n     } n     int pos = -1; n     int cd = 0; n     for (auto it : to_color) { n       int id = it.first; n       vector<int> nxt = it.second; n       solve(nxt); n       for (int i : nxt) color[i] = id; n       dfs_on_color(nxt[0], -1, id); n       if ((int)nxt.size() > cd) { n         cd = nxt.size(); n         pos = id; n       } n     } n     for (auto it : to_color) { n       int id = it.first; n       vector<int> vertices = it.second; n       vector<int> to_root; n       if (id != pos) n         to_root = vertices; n       else { n         vector<int> cnt(2); n         for (int i : vertices) cnt[d[i]]++; n         int chosen = cnt[1] < cnt[0]; n         for (int i : vertices) { n           if (d[i] == chosen) to_root.push_back(i); n         } n       } n       for (int i : to_root) { n         ret.emplace_back(i, root); n       } n     } n   }; n   vector<int> foo(n); n   iota(foo.begin(), foo.end(), 0); n   solve(foo); n   assert((int)ret.size() <= 10 * n); n   cout << ret.size() << endl; n   for (auto i : ret) { n     cout << i.first + 1 <<     << i.second + 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double Pi = acos(-1.0); n const long long MAXN = 1e6 + 5; n long long n, m, t; n struct NODE { n   long long a, b; n } v[MAXN]; n long long cmp1(NODE a, NODE b) { return a.a < b.a; } n long long a[MAXN], b[MAXN]; n long long q[MAXN]; n int main() { n   cin >> t; n   while (t--) { n     cin >> m >> n; n     for (long long i = 1; i <= n; i++) cin >> v[i].a >> v[i].b; n     sort(v + 1, v + 1 + n, cmp1); n     for (long long i = 1; i <= n; i++) n       a[i] = v[i].a, b[i] = v[i].b, q[i] = q[i - 1] + a[i]; n     long long ans = 0; n     for (long long i = 1; i <= n; i++) { n       long long nowb = b[i]; n       long long index = lower_bound(a + 1, a + 1 + n, nowb) - a; n       if (index == n + 1) { n         ans = max(ans, a[i] + (m - 1) * b[i]); n         continue; n       } n       if (index <= i) { n         long long can = n - index + 1; n         if (can >= m) { n           ans = max(ans, q[n] - q[n - m]); n           continue; n         } n         ans = max(ans, q[n] - q[index - 1] + b[i] * (m - can)); n       } else { n         long long can = n - index + 1; n         if (can >= m - 1) { n           ans = max(ans, q[n] - q[n - m + 1] + a[i]); n           continue; n         } n         ans = max(ans, q[n] - q[index] + a[i] + b[i] * (m - can - 1) + n                            max(b[i], a[index])); n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j, k, dances = 0, a[250][2]; n   cin >> n >> m; n   dances = m + n - 1; n   for (i = 0; i < m; i++) { n     a[i][0] = 1; n     a[i][1] = i + 1; n   } n   k = 2; n   for (j = i; j < dances; j++) { n     a[j][0] = k; n     a[j][1] = 1; n     k++; n   } n   cout << dances <<   n ; n   for (i = 0; i < dances; i++) { n     cout << a[i][0] <<     << a[i][1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9 + 100; n const long double eps = 1e-11; n const long double pi = acos(-1.0L); n int myrand() { return rand(); } n unsigned rdtsc() { n   unsigned ans; n   asm( rdtsc  :  =a (ans)); n   return ans; n } n int rnd(int x) { return myrand() % x; } n void precalc() {} n const int maxn = 1e5; n int n; n string str; n char s[maxn]; n int dp[5][maxn]; n bool read() { n   if (scanf( %s , s) < 1) { n     return false; n   } n   str = string(s); n   n = strlen(s); n   return true; n } n void solve() { n   memset(dp, 0, sizeof(dp)); n   dp[2][n - 2] = 1; n   dp[3][n - 3] = 1; n   for (int i = n - 4; i >= 5; i--) { n     for (int j = 2; j <= 3; j++) { n       if (dp[j ^ 1][i + j]) { n         dp[j][i] = 1; n       } n       if (i + j * 2 <= n) { n         string s1 = str.substr(i, j); n         string s2 = str.substr(i + j, j); n         if (s1 != s2 && dp[j][i + j]) { n           dp[j][i] = 1; n         } n       } n     } n   } n   set<string> ans; n   for (int i = 5; i < n; i++) { n     for (int j = 2; j <= 3; j++) { n       if (i + j > n) { n         continue; n       } n       if (i + j == n - 1) { n         continue; n       } n       string cur = str.substr(i, j); n       if (dp[2][i + j] || dp[3][i + j] || n == i + j) { n         ans.insert(cur); n       } n     } n   } n   printf( %d n , ((int)((ans).size()))); n   for (string s : ans) { n     printf( %s n , s.c_str()); n   } n } n int main() { n   srand(rdtsc()); n   precalc(); n   while (true) { n     if (!read()) { n       break; n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class mat { n  public: n   long long a, b, c, d; n }; n mat a; n long long n, k, l, m, step, res; n long long power(long long a, long long b); n mat mult(mat a, mat b); n mat power1(mat a, long long n); n int main() { n   cin >> n >> k >> l >> m; n   step = power(2, n); n   a.a = a.b = a.c = 1; n   a.d = 0; n   a = power1(a, n + 1); n   res = 1; n   while (l > 0) { n     if (k % 2) n       res = (res * ((step + m - a.a) % m)) % m; n     else n       res = (res * a.a) % m; n     k /= 2; n     l--; n   } n   if (k > 0) n     cout << 0; n   else n     cout << res % m; n   return 0; n } n long long power(long long a, long long b) { n   long long res; n   if (b == 0) return 1; n   res = power(a, b / 2) % m; n   res = (res * res) % m; n   if (b % 2) res = (res * a) % m; n   return res; n } n mat mult(mat a, mat b) { n   mat res; n   res.a = (a.a * b.a + a.b * b.c) % m; n   res.b = (a.a * b.b + a.b * b.d) % m; n   res.c = (a.c * b.a + a.d * b.c) % m; n   res.d = (a.c * b.b + a.d * b.d) % m; n   return res; n } n mat power1(mat a, long long n) { n   mat res, a1; n   if (n == 0) { n     res.a = res.d = 1; n     res.b = res.c = 0; n     return res; n   } n   res = power1(a, n / 2); n   res = mult(res, res); n   if (n % 2) { n     a1.a = a1.b = a1.c = 1; n     a1.d = 0; n     res = mult(res, a1); n   } n   return res; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1000000007; n const long long int ll_MAX = 1e15; n long long int fast_expo(long long int x, long long int p) { n   if (p == 0) n     return 1; n   else if (p % 2 == 0) { n     long long int t = fast_expo(x, p / 2) % MOD; n     return (t * t) % MOD; n   } else n     return (x * (fast_expo(x, p - 1)) % MOD) % MOD; n } n long long int invMod(long long int num) { n   return fast_expo(num, MOD - 2) % MOD; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long int t_c; n   t_c = 1; n   for (long long int t_i = 0; t_i < t_c; ++t_i) { n     string str; n     cin >> str; n     long long int n = str.size(); n     long long int mini[27][n], maxi[27][n]; n     memset(mini, -1, sizeof(mini)); n     memset(maxi, -1, sizeof(maxi)); n     for (long long int k = 1; k < 27; ++k) { n       long long int cnt[26]{}, num = 0, j = 0; n       for (long long int i = 0; i < n; ++i) { n         while (j < n && num != k) { n           long long int pos = str[j] -  a ; n           if (cnt[pos] == 0) { n             num++; n           } n           cnt[pos]++; n           j++; n         } n         if (num == k) mini[k][i] = j - 1; n         long long int pos = str[i] -  a ; n         if (cnt[pos] == 1) { n           num--; n         } n         cnt[pos]--; n       } n     } n     for (long long int k = 1; k < 27; ++k) { n       long long int cnt[26]{}, num = 0, j = 0; n       for (long long int i = 0; i < n; ++i) { n         while (j < n && num != k + 1) { n           long long int pos = str[j] -  a ; n           if (cnt[pos] == 0) { n             num++; n           } n           cnt[pos]++; n           j++; n         } n         if (num == k + 1) n           maxi[k][i] = j - 2; n         else if (num == k) n           maxi[k][i] = n - 1; n         long long int pos = str[i] -  a ; n         if (cnt[pos] == 1) { n           num--; n         } n         cnt[pos]--; n       } n     } n     long long int ans[27]{}, num = 0; n     for (long long int k = 1; k < 27; ++k) { n       for (long long int i = 0; i < n; ++i) { n         if (mini[k][i] != -1) ans[k] += maxi[k][i] - mini[k][i] + 1; n       } n       if (ans[k] > 0) { n         num = k; n       } n     } n     cout << num << endl; n     for (long long int i = 1; i <= num; ++i) cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, tot, arr[105], sum[100050][105], a[100050], s[105]; n bool Solved(int x, int y) { n   for (int i = 1; i <= tot; ++i) n     if (sum[y][i] - sum[x - 1][i] < s[i]) return false; n   return true; n } n int main() { n   long long ans; n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   int t = k; n   for (int i = 2; i * i <= t; ++i) n     if (t % i == 0) { n       arr[++tot] = i; n       for (; t % i == 0; t /= i) s[tot]++; n     } n   if (t > 1) arr[++tot] = t, s[tot] = 1; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= tot; ++j) n       for (; a[i] % arr[j] == 0; a[i] /= arr[j]) sum[i][j]++; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= tot; ++j) sum[i][j] += sum[i - 1][j]; n   ans = 0; n   for (int i = 1, L, R, mid; i <= n; ++i) { n     L = i - 1; n     R = n + 1; n     while (L + 1 < R) { n       mid = (L + R) / 2; n       if (Solved(i, mid)) n         R = mid; n       else n         L = mid; n     } n     ans += n - R + 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, m, x, y, it; n   int64_t r, min, max, ser, k; n   std::cin >> n >> m >> k >> x >> y; n   std::vector<std::vector<int64_t>> serg(n); n   if (n == 1) { n     min = k / m; n     max = min + (k % m != 0); n     ser = min + (k % m - y >= 0); n   } else { n     r = k % (2 * m * (n - 1)); n     min = k / (2 * m * (n - 1)); n     for (int i = 0; i < n; i++) { n       serg[i].resize(m); n     } n     for (int i = 0; i < m; i++) { n       serg[0][i] = min; n       serg[n - 1][i] = min; n     } n     for (int i = 1; i < n - 1; i++) { n       for (int j = 0; j < m; j++) { n         serg[i][j] = 2 * min; n       } n     } n     for (int i = 0; r != 0; i++) { n       if (i >= n) { n         it = 2 * n - i - 2; n       } else { n         it = i; n       } n       for (int j = 0; r != 0 && j < m; j++) { n         serg[it][j]++; n         r--; n       } n     } n     ser = serg[x - 1][y - 1]; n     min += 4; n     max = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         max = std::max(max, serg[i][j]); n         min = std::min(min, serg[i][j]); n       } n     } n   } n   std::cout << max <<     << min <<     << ser; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   int n = s.size(); n   vector<int> seq(n + 1, 0); n   vector<int> ind; n   for (int i = 1; i <= n; i++) { n     if (s[i - 1] ==  )  || s[i - 1] ==  # ) { n       seq[i] = seq[i - 1] - 1; n       if (s[i - 1] ==  # ) { n         ind.push_back(i - 1); n       } n     } else { n       seq[i] = seq[i - 1] + 1; n     } n     if (seq[i] < 0) { n       cout << -1 << endl; n       return 0; n     } n   } n   if (seq[n] == 0) { n     for (int i = 0; i < ind.size(); i++) { n       cout << 1 << endl; n     } n   } else { n     seq[ind[ind.size() - 1]] -= seq[n]; n     int val = seq[n]; n     for (int i = ind[ind.size() - 1] + 1; i <= n; i++) { n       if (s[i - 1] ==  )  || s[i - 1] ==  # ) { n         seq[i] = seq[i - 1] - 1; n       } else { n         seq[i] = seq[i - 1] + 1; n       } n       if (seq[i] < 0) { n         cout << -1 << endl; n         return 0; n       } n     } n     for (int i = 0; i < (int)ind.size() - 1; i++) { n       cout << 1 << endl; n     } n     cout << 1 + val << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n bool vis[maxn]; n int n, m, k, p[maxn], a[maxn]; n char s[maxn][maxn]; n void func(int x, int y) { n   --m; n   if (x <= y) { n     s[m][x] = s[m][y] =  / ; n   } else { n     s[m][x] = s[m][y] =     ; n   } n } n int main() { n   scanf( %d , &n); n   m = n + 1, k = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &p[i]); n     for (int j = 1; j <= n; j++) { n       s[i][j] =  . ; n     } n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       int c = 0, v = i; n       while (!vis[v]) { n         a[++c] = v; n         vis[v] = 1; n         v = p[v]; n       } n       if (c <= 1) continue; n       reverse(a + 1, a + c + 1); n       if (k == 0) { n         func(a[1], a[1]); n         k = a[c]; n         for (int i = 2; i <= c; i++) { n           func(a[i], a[i - 1]); n         } n         continue; n       } n       for (int i = 1; i <= c; i++) { n         if (k <= a[i] && a[i] <= a[i == c ? 1 : i + 1]) { n           func(a[i == c ? 1 : i + 1], a[i]); n           s[m][k] =     ; n           for (int j = i + 2; j <= c; j++) { n             func(a[j], a[j - 1]); n           } n           for (int j = (i == c) + 1; j < i; j++) { n             func(a[j], a[j == 1 ? c : j - 1]); n           } n           func(k, a[i == 1 ? c : i - 1]); n           break; n         } else if (k >= a[i] && a[i] >= a[i == c ? 1 : i + 1]) { n           func(a[i == c ? 1 : i + 1], a[i]); n           s[m][k] =  / ; n           for (int j = i + 2; j <= c; j++) { n             func(a[j], a[j - 1]); n           } n           for (int j = 1; j < i; j++) { n             func(a[j], a[j == 1 ? c : j - 1]); n           } n           func(k, a[i == 1 ? c : i - 1]); n           break; n         } n       } n     } n   } n   printf( %d n , k == 0 ? n : n - 1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       putchar(s[i][j]); n     } n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int size(long long a) { n   int c = 0; n   while (a != 0) { n     c++; n     a /= 10; n   } n   return c; n } n int main() { n   long long a, b, c; n   cin >> a >> b; n   long long s = size(b), ns = 1; n   for (int i = 1; i <= s; i++) ns *= 10; n   s = ns; n   while (b != 0) { n     long long f = b % 10; n     b /= 10; n     s /= 10; n     a += s * f; n   } n   cout << a; n   return 0; n } n