#include <bits/stdc++.h> n template <class T> n inline bool chmax(T& a, T b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n inline bool chmin(T& a, T b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n constexpr long long MAX = 5100000; n constexpr long long INF = 1LL << 60; n constexpr int inf = 1000000007; n constexpr long long mod = 998244353LL; n const long double PI = acos((long double)(-1)); n using namespace std; n struct mint { n   long long x; n   mint(long long x = 0) : x((x % mod + mod) % mod) {} n   mint& operator+=(const mint a) { n     if ((x += a.x) >= mod) x -= mod; n     return *this; n   } n   mint& operator-=(const mint a) { n     if ((x += mod - a.x) >= mod) x -= mod; n     return *this; n   } n   mint& operator*=(const mint a) { n     (x *= a.x) %= mod; n     return *this; n   } n   mint operator+(const mint a) const { n     mint res(*this); n     return res += a; n   } n   mint operator-(const mint a) const { n     mint res(*this); n     return res -= a; n   } n   mint operator*(const mint a) const { n     mint res(*this); n     return res *= a; n   } n   mint pow(long long t) const { n     if (!t) return 1; n     mint a = pow(t >> 1); n     a *= a; n     if (t & 1) a *= *this; n     return a; n   } n   mint inv() const { return pow(mod - 2); } n   mint& operator/=(const mint a) { return (*this) *= a.inv(); } n   mint operator/(const mint a) const { n     mint res(*this); n     return res /= a; n   } n }; n mint dp[2][4001]; n void init(int x) { n   for (int i = 0; i <= 4000; i++) dp[x][i] = 0; n } n long long fac[MAX], finv[MAX], inv[MAX]; n void COMinit() { n   fac[0] = fac[1] = 1; n   finv[0] = finv[1] = 1; n   inv[1] = 1; n   for (int i = 2; i < MAX; i++) { n     fac[i] = fac[i - 1] * i % mod; n     inv[i] = mod - inv[mod % i] * (mod / i) % mod; n     finv[i] = finv[i - 1] * inv[i] % mod; n   } n } n mint COM(int n, int k) { n   if (n < k) return 0; n   if (n < 0 || k < 0) return 0; n   return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod); n } n int main() { n   COMinit(); n   long long n, k; n   scanf( %lld %lld , &n, &k); n   vector<long long> h(n); n   for (int i = 0; i < n; i++) scanf( %lld , &h[i]); n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (h[i] != h[(i + 1) % n]) { n       cnt++; n     } n   } n   mint res = 0; n   vector<mint> k2(n + 1); n   k2[0] = 1; n   for (int i = 1; i <= n; i++) k2[i] = k2[i - 1] * (k - 2); n   vector<mint> tw(n + 1); n   tw[0] = 1; n   for (int i = 1; i <= n; i++) tw[i] = tw[i - 1] * 2; n   mint tinv = mint(2).inv(); n   for (int i = 0; i < cnt; i++) { n     int r = cnt - i; n     if (r & 1) n       res += COM(cnt, i) * k2[i] * tw[r - 1]; n     else n       res += COM(cnt, i) * k2[i] * (tw[r] - COM(r, r / 2)) * tinv; n   } n   res *= mint(k).pow(n - cnt); n   cout << res.x <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1000ll * 1000ll * 1000ll; n const long long inf64 = inf * inf; n const double pi = acos(-1.0); n long long Abs(long long a) { return (a >= 0 ? a : -a); } n template <typename T> n inline T Sqr(T a) { n   return a * a; n } n vector<int> par, sz; n bool solve() { n   ios_base::sync_with_stdio(0); n   ifstream fin( run.in ); n   ofstream fout( run.out ); n   int n, a, b; n   cin >> n; n   vector<int> d(n - 1); n   for (int i(0); i < n - 1; i++) cin >> d[i]; n   cin >> a >> b; n   a--, b--; n   long long ans = 0; n   for (int i(a); i < b; i++) ans += d[i]; n   cout << ans <<   n ; n   return true; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 10; n const int inf = 1e9; n int arr[N], pos[N], rMax[N]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %d , arr + i); n     pos[arr[i]] = i; n   } n   fill(rMax, rMax + N, n - 1); n   while (m--) { n     int a, b; n     scanf( %d %d , &a, &b); n     if (pos[a] < pos[b]) { n       rMax[a] = min(pos[b] - 1, rMax[a]); n     } else { n       rMax[b] = min(pos[a] - 1, rMax[b]); n     } n   } n   long long ans = 1; n   for (int i = n - 2; i >= 0; i--) { n     int k = arr[i]; n     int j = arr[i + 1]; n     rMax[k] = min(rMax[k], rMax[j]); n     ans += rMax[k] - i + 1; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void change_stream(char* in, char* out) { n   ifstream fin; n   fin.open(in); n   ofstream fout; n   fout.open(out); n   if (fin && fout) { n     freopen(in,  r , stdin); n     freopen(out,  w , stdout); n   } n } n long long a[500], renum[500]; n void shift(long long i) { n   long long p = a[i]; n   a[i] = a[i + 2]; n   a[i + 2] = a[i + 1]; n   a[i + 1] = p; n   renum[a[i]] = i; n   renum[a[i + 1]] = i + 1; n   renum[a[i + 2]] = i + 2; n } n void solve() { n   long long n; n   cin >> n; n   pair<long long, long long> s[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     s[i] = {a[i], i}; n   } n   sort(s, s + n); n   for (long long i = 0; i < n; i++) { n     renum[i] = s[i].second; n     a[renum[i]] = i; n   } n   long long sdv = 0; n   for (long long i = 0; i < n; i++) n     for (long long j = i + 1; j < n; j++) n       if (a[i] > a[j]) sdv++; n   if (sdv % 2) { n     bool flag = false; n     for (long long i = 0; i < n - 1; i++) n       if (s[i].first == s[i + 1].first) { n         swap(a[s[i].second], a[s[i + 1].second]); n         renum[a[s[i].second]] = s[i].second; n         renum[a[s[i + 1].second]] = s[i + 1].second; n         flag = true; n         break; n       } n     if (!flag) { n       cout <<  -1 n ; n       return; n     } n   } n   vector<long long> ans; n   for (long long i = n - 1; i > 1; i--) { n     while (renum[i] < i) { n       long long l = max(0ll, renum[i] - 1); n       ans.push_back(l); n       shift(l); n     } n   } n   cout << ans.size() <<   n ; n   for (long long i : ans) cout << i + 1 <<    ; n   cout <<   n ; n } n signed main() { n   change_stream( in ,  out ); n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long test_count = 1; n   cin >> test_count; n   while (test_count--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long dist(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   pair<long long, long long> p1, p2; n   cin >> p1.first >> p1.second >> p2.first >> p2.second; n   vector<pair<long long, long long>> v(n); n   for (int i = 0; i < n; ++i) { n     pair<long long, long long> tmp; n     cin >> tmp.first >> tmp.second; n     v[i] = {dist(p1, tmp), dist(p2, tmp)}; n   } n   long long ans = (1LL << 62); n   v.push_back({0, 0}); n   for (int i = 0; i < v.size(); ++i) { n     long long r2 = 0; n     for (int j = 0; j < v.size(); ++j) { n       if (i == j || v[j].first <= v[i].first) n         continue; n       else n         r2 = max(r2, v[j].second); n     } n     ans = min(ans, v[i].first + r2); n   } n   if (n == 1) ans = min(ans, v[0].second); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200010]; n int base; n int n, tmp; n int main() { n   cin >> n; n   cin >> base; n   a[100000]++; n   for (int i = 1; i <= n - 1; i++) { n     cin >> tmp; n     int offset = tmp - base; n     if (abs(offset) > 100000) { n       cout <<  NO  << endl; n       return 0; n     } n     a[offset + 100000]++; n   } n   int ub = 100000, lb = 100000; n   int cnt = n + a[100000]; n   while (a[ub]) { n     cnt -= a[ub]; n     ub++; n   } n   while (a[lb]) { n     cnt -= a[lb]; n     lb--; n   } n   lb++; n   ub--; n   if (cnt != 0) { n     cout <<  NO ; n     return 0; n   } n   for (int i = lb + 1; i <= ub - 1; i++) { n     if (a[i] < 2) { n       cout <<  NO ; n       return 0; n     } n     a[i] -= 2; n   } n   a[lb]--; n   a[ub]--; n   for (int i = lb; i <= ub; i++) { n     if (a[i + 1] < a[i]) { n       cout <<  NO ; n       return 0; n     } n     a[i + 1] -= a[i]; n   } n   cout <<  YES ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n; n int a[maxn]; n int flag = 0; n int flag1 = 0; n int main() { n   n = read(); n   for (int i = 1; i <= n; i++) { n     a[i] = read(); n     if (i <= n - 1 && a[i] == 0) flag1 = 1; n   } n   if (a[n] == 0) flag = 1; n   if (flag) { n     if (flag1 == 0) { n       printf( YES n ); n       for (int i = 1; i <= n - 1; i++) { n         printf( %d-> , a[i]); n       } n       printf( %d n , a[n]); n       return 0; n     } n     int place = 0; n     for (int i = n - 2; i >= 1; i--) { n       if (a[i] == 0) { n         place = i; n         break; n       } n     } n     if (place == 0) { n       printf( NO n ); n       return 0; n     } n     printf( YES n ); n     for (int i = 1; i <= place - 1; i++) { n       printf( %d-> , a[i]); n     } n     printf( (%d-> , a[place]); n     printf( ( ); n     for (int i = place + 1; i <= n - 2; i++) { n       printf( %d-> , a[i]); n     } n     printf( %d , a[n - 1]); n     printf( ))-> ); n     printf( %d n , a[n]); n   } else { n     printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class T2> n inline int chkmax(T &x, const T2 &y) { n   return x < y ? x = y, 1 : 0; n } n template <class T, class T2> n inline int chkmin(T &x, const T2 &y) { n   return x > y ? x = y, 1 : 0; n } n const int MAXN = (1 << 20); n int n, sum = 0; n vector<int> li1; n vector<pair<int, int> > li; n void read() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     if (x == 1) n       li1.push_back(i); n     else n       sum += x - 2, li.push_back({x - 2, i}); n   } n } n vector<pair<int, int> > answer; n void solve() { n   if (sum < ((int)li1.size()) - 2) { n     cout <<  NO  <<   n ; n     return; n   } n   int d = ((int)li.size()) - 1; n   for (int i = 0; i < ((int)li.size()) - 1; i++) n     answer.push_back({li[i].second, li[i + 1].second}); n   if (((int)li1.size()) >= 1) { n     int x = li1.back(); n     li1.pop_back(); n     answer.push_back({x, li[0].second}); n     d++; n   } n   if (((int)li1.size()) >= 1) { n     int x = li1.back(); n     li1.pop_back(); n     answer.push_back({x, li.back().second}); n     d++; n   } n   for (auto &it : li) { n     while (it.first >= 1 && ((int)li1.size())) { n       int x = li1.back(); n       li1.pop_back(); n       answer.push_back({x, it.second}); n       it.first--; n     } n   } n   cout <<  YES  n        <<     << d <<   n ; n   cout << ((int)answer.size()) <<   n ; n   for (auto e : answer) cout << e.first <<     << e.second <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, n, ans, ghor, j, k, flag = 0; n   cin >> n; n   for (i = 0;; i++) { n     ans = (n - 1) / (5 * pow(2, i)); n     if (ans == 0) break; n     n = n - (5 * pow(2, i)); n   } n   ghor = i + 1; n   long long p = pow(2, i); n   long long cnt = 1; n   for (j = 1; j <= 5; j++) { n     for (k = 1; k <= p; k++) { n       if (cnt == n) { n         flag = 1; n         break; n       } n       cnt++; n     } n     if (flag == 1) break; n   } n   switch (j) { n     case 1: n       cout <<  Sheldon  << endl; n       break; n     case 2: n       cout <<  Leonard  << endl; n       break; n     case 3: n       cout <<  Penny  << endl; n       break; n     case 4: n       cout <<  Rajesh  << endl; n       break; n     case 5: n       cout <<  Howard  << endl; n       break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int i, j, n, m; n   cin >> n; n   vector<int> vec(n); n   vector<int> ans; n   int count = 1; n   for (int i = 0; i < n; i++) { n     cin >> vec[i]; n   } n   for (int i = 0; i < n; i++) { n     count = 1; n     for (int j = 0; j < n; j++) { n       if (vec[i] < vec[j]) { n         count++; n       } n     } n     ans.push_back(count); n   } n   for (auto x : ans) { n     if (x > 1) n       cout << x <<    ; n     else n       cout << 1 <<    ; n   } n   cout <<   n ; n } n int32_t main() { n   int T = 1; n   while (T--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int block_size = 320; n const long long mod = 1e9 + 7; n const long long inf = 1e9 + 7; n const long double eps = 1e-9; n const double PI = atan(1) * 4; n template <typename T> n inline int sign(const T &a) { n   if (a < 0) return -1; n   if (a > 0) return 1; n   return 0; n } n string to_string(string s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n template <typename T, typename S> n inline bool upmin(T &a, const S &b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T, typename S> n inline bool upmax(T &a, const S &b) { n   return a < b ? a = b, 1 : 0; n } n template <typename T> n inline void in(T &x) { n   x = 0; n   T f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   x *= f; n } n long long twop(int x) { return 1LL << x; } n template <typename T> n T MOD(T a, T m) { n   a %= m; n   if (a < 0) a += m; n   return a; n } n template <typename T> n T inverse(T a, T m) { n   a = MOD(a, m); n   if (a <= 1) return a; n   return MOD((1 - inverse(m, a) * m) / a, m); n } n template <typename A, typename B> n inline void in(A &x, B &y) { n   in(x); n   in(y); n } n template <typename A, typename B, typename C> n inline void in(A &x, B &y, C &z) { n   in(x); n   in(y); n   in(z); n } n template <typename A, typename B, typename C, typename D> n inline void in(A &x, B &y, C &z, D &d) { n   in(x); n   in(y); n   in(z); n   in(d); n } n template <typename T> n T sqr(T x) { n   return x * x; n } n long long gcd(long long a, long long b) { n   while (b != 0) { n     a %= b; n     swap(a, b); n   } n   return a; n } n long long fast(long long a, long long b, long long mod) { n   long long ans = 1; n   while (b) { n     if (b & 1) { n       b--; n       ans = ans * a % mod; n     } else { n       a = a * a % mod; n       b /= 2; n     } n   } n   return ans % mod; n } n pair<long long, long long> operator-(const pair<long long, long long> &a, n                                      const pair<long long, long long> &b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n long long cp(pair<long long, long long> o, pair<long long, long long> a, n              pair<long long, long long> b) { n   a = a - o; n   b = b - o; n   return a.first * b.second - a.second * b.first; n } n pair<long long, long long> process(pair<long long, long long> diff) { n   long long g = abs(gcd(diff.first, diff.second)); n   diff.first /= g; n   diff.second /= g; n   return diff; n } n template <int maxn, typename NUM> n struct BIT { n   NUM s[maxn]; n   void init() { memset(s, 0, sizeof(s)); } n   BIT() { init(); } n   void update(int a, NUM value) { n     a++; n     while (a < maxn) { n       s[a] += value; n       a += ((a) & (-(a))); n     } n   } n   NUM query(int a) { n     NUM ans = 0; n     a++; n     while (a) { n       ans += s[a]; n       a -= ((a) & (-(a))); n     } n     return ans; n   } n   NUM query(int a, int b) { n     if (b < a) return 0; n     return query(b) - query(a - 1); n   } n }; n BIT<300010, long long> bit; n namespace SOLVE { n vector<vector<pair<long long, long long>>> vec; n bool cmp(const pair<pair<long long, long long>, long long> &a, n          const pair<pair<long long, long long>, long long> &b) { n   return a.first.second < b.first.second; n } n long long ans[300010]; n void main() { n   int n; n   in(n); n   vec.resize(n + 1); n   for (long long i = 1; i < n + 1; i++) { n     int c; n     in(c); n     vector<pair<long long, long long>> v; n     for (long long j = 0; j < c; j++) { n       pair<long long, long long> x; n       in(x.first, x.second); n       v.push_back(x); n     } n     v.push_back(v[0]); n     for (long long j = 1; j < c + 1; j++) { n       vec[i].push_back(process(v[j] - v[j - 1])); n     } n   } n   int q; n   in(q); n   vector<pair<pair<long long, long long>, long long>> query(q); n   for (long long i = 0; i < q; i++) { n     in(query[i].first.first, query[i].first.second); n     query[i].second = i; n   } n   sort(begin(query), end(query), cmp); n   int cur = 0; n   map<pair<long long, long long>, int> occ; n   for (auto q : query) { n     while (cur < q.first.second) { n       ++cur; n       for (auto v : vec[cur]) { n         bit.update(occ[v], -1); n         bit.update(cur, 1); n         occ[v] = cur; n       } n     } n     ans[q.second] = bit.query(q.first.first, q.first.second); n   } n   {}; n   for (long long i = 0; i < q; i++) cout << ans[i] << endl; n } n }  // namespace SOLVE n signed main() { n   int t = 1; n   while (t--) { n     SOLVE::main(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char matrix[2020][2020]; n int dp[2020][2020]; n pair<int, int> p[2020 * 2020]; n int n, m; n int fill(int i, int j) { n   if (i < 0 || j < 0 || i >= n || j >= m) { n     return 0; n   } n   if (dp[i][j] == -1) { n     int start_x = i; n     int start_y = j; n     int count = 0; n     p[count++] = {i, j}; n     if (matrix[i][j] ==  U ) { n       i = i - 1; n     } else if (matrix[i][j] ==  L ) { n       j = j - 1; n     } else if (matrix[i][j] ==  D ) { n       i = i + 1; n     } else { n       j = j + 1; n     } n     while (i != start_x || j != start_y) { n       p[count++] = {i, j}; n       if (matrix[i][j] ==  U ) { n         i = i - 1; n       } else if (matrix[i][j] ==  L ) { n         j = j - 1; n       } else if (matrix[i][j] ==  D ) { n         i = i + 1; n       } else { n         j = j + 1; n       } n     } n     for (int i = 0; i < count; i++) { n       dp[p[i].first][p[i].second] = (-1 * count); n     } n     return 0; n   } n   if (dp[i][j] != 0) { n     return dp[i][j]; n   } n   dp[i][j] = -1; n   int ans = 1; n   if (matrix[i][j] ==  U ) { n     ans += abs(fill(i - 1, j)); n   } else if (matrix[i][j] ==  L ) { n     ans += abs(fill(i, j - 1)); n   } else if (matrix[i][j] ==  D ) { n     ans += abs(fill(i + 1, j)); n   } else { n     ans += abs(fill(i, j + 1)); n   } n   if (dp[i][j] < -1) { n     ans = dp[i][j]; n   } n   return dp[i][j] = ans; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> m; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cin >> matrix[i][j]; n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         dp[i][j] = 0; n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         fill(i, j); n       } n     } n     int ans = dp[0][0]; n     int x = 0; n     int y = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         if (abs(dp[i][j]) > ans) { n           x = i; n           y = j; n           ans = abs(dp[i][j]); n         } n       } n     } n     cout << (x + 1) <<     << (y + 1) <<     << ans << endl; n   } n } n


#include <bits/stdc++.h> n int n, m; n int f[2000010], mx, mn = (int)1e7; n short check(int x) { n   int i; n   for (i = x; i <= mx; i += x) n     if (f[i + x - 1] >= i && f[i + x - 1] - i > m) return 0; n   return 1; n } n int main() { n   int i, x; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d , &x); n     f[x] = x; n     mx = mx > x ? mx : x; n     mn = mn < x ? mn : x; n   } n   mx <<= 1; n   for (i = 1; i <= mx; i++) f[i] = f[i] > f[i - 1] ? f[i] : f[i - 1]; n   mx >>= 1; n   for (i = mn; i > 1; i--) n     if (check(i)) break; n   printf( %d , i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string raspuns; n long long n, x, y; n int read() { n   char c; n   int nr = 0; n   c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   while (c >=  0  && c <=  9 ) { n     nr = nr * 10 + (c -  0 ); n     c = getchar(); n   } n   return nr; n } n int main() { n   n = read(); n   long long sa, sg; n   sa = sg = 0; n   for (long long i = 0; i < n; i++) { n     x = read(); n     y = read(); n     if (sa + x - sg <= 500) { n       sa += x; n       raspuns +=  A ; n     } else if (sg + y - sa <= 500) { n       sg += y; n       raspuns +=  G ; n     } n   } n   if (raspuns !=   0 ) n     cout << raspuns; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   for (; b; a %= b, swap(a, b)) n     ; n   return a; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, x; n     cin >> n >> x; n     int cnt = 0; n     for (int i = 0; i < n - 1; i++) { n       int u, v; n       cin >> u >> v; n       if (u == x || v == x) cnt++; n     } n     if (cnt <= 1) { n       cout <<  Ayush n ; n       continue; n     } n     if (n % 2) n       cout <<  Ashish n ; n     else n       cout <<  Ayush n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1005; n int in[maxn]; n int t1, t2; n struct edge { n   int v, w; n }; n vector<edge> g[maxn]; n void dfs(int u, int fa) { n   if (in[u] == 1) { n     if (!t1) t1 = u; n     t2 = u; n   } n   for (edge e : g[u]) { n     if (e.v == fa) continue; n     dfs(e.v, u); n   } n } n struct Ans { n   int a, b, c; n }; n vector<Ans> ans; n void add(int a, int b, int c) { n   if (a == b || !c) return; n   ans.push_back({a, b, c}); n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n; ++i) { n     int u, v, w; n     cin >> u >> v >> w; n     in[u]++, in[v]++; n     g[u].push_back({v, w}); n     g[v].push_back({u, w}); n   } n   for (int i = 1; i <= n; ++i) n     if (in[i] == 2) { n       cout <<  NO  << endl; n       return 0; n     } n   cout <<  YES  << endl; n   for (int u = 1; u <= n; ++u) { n     for (edge e : g[u]) { n       int v = e.v, w = e.w; n       if (v < u) continue; n       int a1, a2, b1, b2; n       t1 = t2 = 0; n       dfs(u, v); n       a1 = t1, a2 = t2; n       t1 = t2 = 0; n       dfs(v, u); n       b1 = t1, b2 = t2; n       add(a1, b1, w / 2); n       add(a2, b2, w / 2); n       add(a1, a2, -w / 2); n       add(b1, b2, -w / 2); n     } n   } n   cout << ans.size() << endl; n   for (auto p : ans) cout << p.a <<     << p.b <<     << p.c << endl; n } n


#include<bits/stdc++.h> n   n #define lowbit(x) ((x)&(-(x))) n #define DEBUG fprintf(stderr, Running on Line %d in Function %s n ,__LINE__,__FUNCTION__) n #define SZ(x) ((int)x.size()) n #define mkpr std::make_pair n #define pb push_back n   n typedef long long ll; n typedef unsigned int uint; n typedef unsigned long long ull; n typedef std::pair<int,int> pi; n typedef std::pair<ll,ll> pl; n using std::min; n using std::max; n   n const int inf=0x3f3f3f3f,Inf=0x7fffffff; n const ll INF=0x3f3f3f3f3f3f3f3f; n   n std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count()); n template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return !b?a:gcd(b,a%b);} n template <typename _Tp>inline _Tp abs(const _Tp &a){return a>=0?a:-a;} n template <typename _Tp>inline void chmax(_Tp &a,const _Tp &b){a=a<b?b:a;} n template <typename _Tp>inline void chmin(_Tp &a,const _Tp &b){a=a<b?a:b;} n template <typename _Tp>inline void read(_Tp &x) n { n  char ch(getchar());bool f(false);while(!isdigit(ch)) f|=ch==45,ch=getchar(); n  x=ch&15,ch=getchar();while(isdigit(ch)) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar(); n  f&&(x=-x); n } n template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);} n inline int read_str(char *s) n { n  char ch(getchar());while(ch==   ||ch==  r ||ch==  n ) ch=getchar(); n  char *tar=s;*tar++=ch,ch=getchar();while(ch!=   &&ch!=  r &&ch!=  n &&ch!=EOF) *tar++=ch,ch=getchar(); n  return *tar=0,tar-s; n } n   n const int max_len=1<<16,N=max_len+5,mod=998244353; n template<typename _Tp1,typename _Tp2>inline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);} n template<typename _Tp1,typename _Tp2>inline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);} n template<typename _Tp>inline _Tp _sub(_Tp a,const _Tp &b){(a+=mod-b)>=mod&&(a-=mod);return a;} n ll ksm(ll a,ll b=mod-2){ll res=1;while(b){if(b&1)res=res*a%mod;a=a*a%mod,b>>=1;}return res;} n typedef std::vector<int> poly; n void print(const poly &a) n { n  for(auto it:a) printf( %d  ,it); n  printf(  n ); n } n poly operator << (const poly &a,uint b) n { n  poly o(a.size()+b); n  for(uint i=0;i<b;++i) o[i]=0; n  for(uint i=0;i<a.size();++i) o[i+b]=a[i]; n  return o; n } n inline poly operator <<= (poly &a,uint b){return a=a<<b;} n inline poly operator >> (const poly &a,uint b){return b>=a.size()?poly():poly{a.begin()+b,a.end()};} n inline poly operator >>= (poly &a,uint b){return a=b>=a.size()?poly():poly{a.begin()+b,a.end()};} n poly operator += (poly &a,const poly &b) n { n  if(SZ(b)>SZ(a)) a.resize(SZ(b)); n  for(uint i=0;i<b.size();++i) add(a[i],b[i]); n  return a; n } n inline poly operator + (const poly &a,const poly &b){poly tmp(a);tmp+=b;return tmp;} n poly operator -= (poly &a,const poly &b) n { n  if(SZ(b)>SZ(a)) a.resize(SZ(b)); n  for(uint i=0;i<b.size();++i) sub(a[i],b[i]); n  return a; n } n inline poly operator - (const poly &a,const poly &b){poly tmp(a);tmp-=b;return tmp;} n ull Omgs[N]; n int r[N]; n const ull Omg=ksm(3,(mod-1)/max_len); n int getlen(int len) n { n  int limit=1;while(limit<len)limit<<=1; n  for(int i=0;i<limit;++i)r[i]=(r[i>>1]>>1)|(i&1?limit>>1:0); n  return limit; n } n void setup() n { n  Omgs[max_len>>1]=1; n  for(int i=(max_len>>1)+1;i<max_len;++i) Omgs[i]=Omgs[i-1]*Omg%mod; n  for(int i=(max_len>>1)-1;i>0;--i) Omgs[i]=Omgs[i<<1]; n } n void dft(ull *A,int limit) n { n  for(int i=0;i<limit;++i)if(i<r[i])std::swap(A[i],A[r[i]]); n  for(int len=1;len<limit;len<<=1) n  { n   if(len==262144)for(int i=0;i<limit;++i)A[i]%=mod; n   for(int i=0;i<limit;i+=len<<1) n   { n    ull *p=A+i,*q=A+i+len,*w=Omgs+len; n    for(int _=0;_<len;++_,++p,++q,++w){ull tmp=*q**w%mod;*q=*p+mod-tmp,*p+=tmp;} n   } n  } n  for(int i=0;i<limit;++i)A[i]%=mod; n } n void idft(ull *A,int limit) n { n  std::reverse(A+1,A+limit),dft(A,limit); n  ull inv=mod-(mod-1)/limit;for(int i=0;i<limit;++i) A[i]=inv*A[i]%mod; n } n ull _f[N],_g[N]; n poly operator * (const poly &a,const poly &b) n { n  uint len=a.size()+b.size()-1; n  if(a.size()<=64u||b.size()<=64u) n  { n   poly c(len); n   for(uint i=0;i<a.size();++i) for(uint j=0;j<b.size();++j) add(c[i+j],1ull*a[i]*b[j]%mod); n   return c; n  } n  int limit=getlen(len); n  memset(_f,0,limit<<3);for(uint i=0;i<a.size();++i)_f[i]=a[i]; n  memset(_g,0,limit<<3);for(uint i=0;i<b.size();++i)_g[i]=b[i]; n  dft(_f,limit),dft(_g,limit); n  for(int i=0;i<limit;++i)_f[i]=1ULL*_f[i]*_g[i]%mod; n  idft(_f,limit); n  poly ans(len);for(uint i=0;i<len;++i)ans[i]=_f[i]; n  return ans; n } n poly mul(const poly &a,const poly &b,uint len,bool need=true) n { n  if(a.size()<=64u||b.size()<=64u) n  { n   poly c(SZ(a)+SZ(b)-1); n   for(uint i=0;i<a.size();++i) for(uint j=0;j<b.size();++j) add(c[i+j],1ull*a[i]*b[j]%mod); n   return c.resize(len),c; n  } n  int limit=getlen(len); n  memset(_f,0,limit<<3);for(uint i=0;i<a.size();++i)_f[i]=a[i]; n  dft(_f,limit); n  if(need) n  { n   memset(_g,0,limit<<3);for(uint i=0;i<b.size();++i)_g[i]=b[i]; n   dft(_g,limit); n  } n  for(int i=0;i<limit;++i)_f[i]=1ULL*_f[i]*_g[i]%mod; n  idft(_f,limit); n  poly ans(len);for(uint i=0;i<len;++i)ans[i]=_f[i]; n  return ans; n } n inline poly operator *= (poly &a,const poly &b){return a=a*b;} n template<typename _Tp>inline poly operator *= (poly &a,const _Tp &b) n { n  for(auto &&it:a) it=1ll*it*b%mod; n  return a; n } n template<typename _Tp>inline poly operator * (poly a,const _Tp &b){return a*=b;} n template<typename _Tp>inline poly operator * (const _Tp &b,poly a){return a*=b;} n template<typename _Tp>inline poly operator /= (poly &a,const _Tp &b) n { n  ull inv=ksm(b);for(auto &&it:a) it=1ll*it*inv%mod; n  return a; n } n template<typename _Tp>inline poly operator / (poly a,const _Tp &b){return a/=b;} n template<typename _Tp>inline poly operator / (const _Tp &b,poly a){return a/=b;} n   n ll fac[N],ifac[N],inv[N]; n poly getcoef(poly h,ll m,int c) n { n  static int I[N],P[N]; n  int d=SZ(h)-1; n  for(int i=0;i<=d;++i)h[i]=1LL*h[i]*ifac[d-i]%mod*((d-i)&1?mod-ifac[i]:ifac[i])%mod; n  for(int i=0;i<c+d;++i)I[i]=m-d+i; n  P[0]=I[0];for(int i=1;i<c+d;++i)P[i]=1LL*I[i]*P[i-1]%mod; n  ll tp=ksm(P[c+d-1]); n  for(int i=c+d-1;i>=0;--i)P[i]=1LL*tp*(i?P[i-1]:1)%mod,tp=tp*I[i]%mod; n  poly a=mul(poly{P,P+c+d},h,c+d); n  ll cur=1;for(int i=1;i<=d;++i)cur=cur*(m-i)%mod; n  poly ans(c); n  for(int k=0;k<c;++k) cur=cur*(m+k)%mod,ans[k]=cur*a[d+k]%mod,cur=cur*P[k]%mod; n  return ans; n } n int f[N],S; n void init(int n) n { n  S=(int)sqrt(n); n  int cur=0; n  while(1LL*S*S<n)++S; n  while(1LL*S*S>n)--S; n  memset(f,0,(S+1)<<2),f[0]=1; n  for(int i=16;i>=0;--i) n  { n   if(cur) n   { n    poly h={f,f+cur+1},a=getcoef(h,cur+1,cur); n    h.resize(SZ(a)+SZ(h));for(int i=0;i<cur;++i)h[i+cur+1]=a[i]; n    poly b=getcoef(h,1LL*cur*ksm(S)%mod,cur+cur+1); n    cur<<=1;for(int i=0;i<=cur;++i)f[i]=1LL*h[i]*b[i]%mod; n   } n   if((S>>i)&1) n   { n    f[++cur]=1; n    for(int j=0;j<cur;++j)f[j]=1LL*f[j]*(j*S+cur)%mod; n    for(int i=1;i<=cur;++i)f[cur]=1LL*f[cur]*(cur*S+i)%mod; n   } n  } n } n ll getfac(int n) n { n  int i,ans=1; n  for(i=0;(i+1)*S<=n;++i)ans=1LL*ans*f[i]%mod; n  for(int j=i*S+1;j<=n;++j)ans=1LL*ans*j%mod; n  return ans; n } n int a[1005],s; n inline ll getF(int a){return (getfac(s+s-1)*ksm(getfac(s+s-a-1))%mod*ksm(getfac(s))%mod*getfac(s-a)+mod-1)%mod;} n int main() n { n  setup(); n  fac[0]=fac[1]=inv[0]=inv[1]=ifac[0]=ifac[1]=1;for(int i=2;i<N;++i)fac[i]=fac[i-1]*i%mod,inv[i]=inv[mod%i]*(mod-mod/i)%mod,ifac[i]=ifac[i-1]*inv[i]%mod; n  int n;read(n); n  for(int i=1;i<=n;++i)read(a[i]),s+=a[i]; n  init(s+s); n  int ans=mod-getF(s); n  for(int i=1;i<=n;++i)add(ans,getF(a[i])); n  ans=1LL*(mod-2)*s%mod*ksm(s-1)%mod*ans%mod; n  printf( %d n ,ans); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace whatever { n int readu() { n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   int value = ch -  0 ; n   ch = getchar(); n   while (isdigit(ch)) { n     value = value * 10 + ch -  0 ; n     ch = getchar(); n   } n   return value; n } n void writeu(int n) { n   if (n < 10) n     putchar(n +  0 ); n   else { n     writeu(n / 10); n     putchar(n % 10 +  0 ); n   } n } n namespace tree { n vector<int> tree_adj[100001 + 100000]; n int size[100001 + 100000]; n int heavy[100001 + 100000]; n int depth[100001 + 100000]; n int father[100001 + 100000]; n void dfs1(int cur) { n   size[cur] = 1; n   for (auto to : tree_adj[cur]) n     if (to != father[cur]) { n       depth[to] = depth[cur] + 1; n       father[to] = cur; n       dfs1(to); n       size[cur] += size[to]; n       if (size[heavy[cur]] < size[to]) heavy[cur] = to; n     } n } n int top[100001 + 100000]; n void dfs2(int cur) { n   for (auto to : tree_adj[cur]) n     if (to != father[cur]) { n       top[to] = (to == heavy[cur] ? top[cur] : to); n       dfs2(to); n     } n } n int lca(int a, int b) { n   while (top[a] != top[b]) { n     if (depth[top[a]] > depth[top[b]]) n       a = father[top[a]]; n     else n       b = father[top[b]]; n   } n   return (depth[a] < depth[b] ? a : b); n } n }  // namespace tree n namespace graph { n vector<int> adj[100001]; n int dfn[100001]; n int low[100001]; n int dfs_time; n int stack[100001]; n int top; n int bcc_cnt; n void dfs(int cur) { n   dfn[cur] = low[cur] = ++dfs_time; n   stack[top++] = cur; n   for (auto to : adj[cur]) { n     if (!dfn[to]) { n       dfs(to); n       low[cur] = min(low[cur], low[to]); n       if (low[to] == dfn[cur]) { n         ++bcc_cnt; n         do { n           --top; n           tree::tree_adj[stack[top]].push_back(100000 + bcc_cnt); n           tree::tree_adj[100000 + bcc_cnt].push_back(stack[top]); n         } while (stack[top] != to); n         tree::tree_adj[cur].push_back(100000 + bcc_cnt); n         tree::tree_adj[100000 + bcc_cnt].push_back(cur); n       } n     } else n       low[cur] = min(low[cur], dfn[to]); n   } n } n }  // namespace graph n void run() { n   int n = readu(); n   int m = readu(); n   int q = readu(); n   while (--m != -1) { n     int u = readu(); n     int v = readu(); n     graph::adj[u].push_back(v); n     graph::adj[v].push_back(u); n   } n   graph::dfs(1); n   assert(graph::top == 1); n   assert(graph::stack[0] == 1); n   tree::dfs1(1); n   assert(tree::size[1] == graph::bcc_cnt + n); n   tree::dfs2(1); n   while (--q != -1) { n     int a = readu(); n     int b = readu(); n     int l = tree::lca(a, b); n     int dis = tree::depth[a] - tree::depth[l] + tree::depth[b] - tree::depth[l]; n     assert(dis % 2 == 0); n     writeu(dis / 2); n     putchar(  n ); n   } n } n }  // namespace whatever n int main() { whatever::run(); } n


#include <bits/stdc++.h> n using namespace std; n void solve(vector<int> &v, int n, int k) { n   set<int> s; n   for (int i = 0; i < n; i++) s.insert(v[i]); n   if (s.size() >= k) { n     vector<int> res; n     cout <<  YES  << endl; n     for (auto x : s) { n       for (int i = 0; i < n; i++) { n         if (x == v[i]) { n           res.push_back(i + 1); n           break; n         } n       } n     } n     for (int i = 0; i < k; i++) { n       cout << res[i] <<    ; n     } n     cout << endl; n   } else n     cout <<  NO  << endl; n } n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   solve(a, n, k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010; n int n, a[7], cnt[7], t[N]; n void GetData() { n   int i; n   scanf( %d , &n); n   for (i = 0; i < 3; ++i) scanf( %d , &a[i]); n   for (i = 0; i < n; ++i) scanf( %d , &t[i]); n } n void Solve() { n   int i, j, ans, mn; n   bool flag = false; n   sort(a, a + 3); n   sort(t, t + n); n   a[3] = a[0] + a[1]; n   a[4] = a[0] + a[2]; n   a[5] = a[1] + a[2]; n   a[6] = a[3] + a[2]; n   if (t[n - 1] > a[6]) n     ans = -1, mn = 0; n   else { n     if (a[2] > a[3]) { n       swap(a[2], a[3]); n       flag = true; n     } n     memset(cnt, 0, sizeof(cnt)); n     for (i = 0; i < n; ++i) { n       for (j = 0; j < 7; ++j) { n         if (a[j] >= t[i]) { n           cnt[j]++; n           break; n         } n       } n     } n     ans = cnt[6]; n     for (; cnt[5] > 0; ++ans) { n       cnt[5]--; n       if (cnt[0] > 0) cnt[0]--; n     } n     for (; cnt[4] > 0; ++ans) { n       cnt[4]--; n       if (cnt[1] > 0) n         cnt[1]--; n       else if (cnt[0] > 0) n         cnt[0]--; n     } n     if (flag) { n       for (; cnt[3] > 0; ++ans) { n         cnt[3]--; n         if (cnt[0] > 0 && cnt[1] > 0) { n           cnt[0]--; n           cnt[1]--; n         } else if (cnt[0] > 0) { n           if (cnt[0] > 1) n             cnt[0] -= 2; n           else if (cnt[2] > 0) n             cnt[2]--; n           else n             cnt[0]--; n         } else if (cnt[1] > 0) { n           if (cnt[2] > 0) n             cnt[2]--; n           else n             cnt[1]--; n         } else if (cnt[2] > 0) n           cnt[2]--; n       } n     } else { n       for (; cnt[3] > 0; ++ans) { n         cnt[3]--; n         if (cnt[2] > 0) n           cnt[2]--; n         else if (cnt[1] > 0) n           cnt[1]--; n         else if (cnt[0] > 0) n           cnt[0]--; n       } n     } n     mn = n; n     for (i = 0; i <= cnt[2]; ++i) { n       int a, b, c, tmp = i; n       a = cnt[0]; n       b = cnt[1]; n       c = cnt[2]; n       c -= i; n       if (c >= i) n         c -= i; n       else if (b >= i - c) n         b -= i - c, c = 0; n       else { n         if (a >= i - c - b) n           a -= i - c - b; n         else n           a = 0; n         b = c = 0; n       } n       if (c > 0) { n         if (b < c) n           a = max(0, a - c - c + b); n         else n           a = max(0, a - c); n         b = max(0, b - c); n         tmp += c; n       } n       if (b >= a * 2) n         tmp += (b + 1) / 2; n       else n         tmp += (a + b + 2) / 3; n       mn = min(mn, tmp); n     } n   } n   printf( %d n , ans + mn); n } n int main() { n   GetData(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   cin.tie(0); n   cout.tie(0); n   cin.sync_with_stdio(0); n   cout.sync_with_stdio(0); n   long long n; n   cin >> n; n   vector<long long> v(n); n   vector<long long> msuf(n + 1); n   for (long long i = 0; i < n; ++i) cin >> v[i]; n   for (long long i = n - 1; i >= 0; --i) n     msuf[i] = max(v[i] + 1, msuf[i + 1] - 1); n   for (long long i = 1; i < n; ++i) msuf[i] = max(msuf[i], msuf[i - 1]); n   long long second = 0; n   for (long long i = 0; i < n; ++i) second += msuf[i] - v[i] - 1; n   cout << second << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n const long long MOD = 1e9 + 7; n const long long MODD = 1e9 + 1; n const long long MODL = 998244353; n const long long N = 200005; n const long long INF = 1e18; n const long long mx = 1e5 + 1; n long long Power(long long x, long long y) { n   long long r = 1; n   while (y) { n     if (y & 1) r = 1ll * r * x % MOD; n     x = 1ll * x * x % MOD, y >>= 1; n   } n   return r; n } n bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) { n   return (a.second < b.second); n } n bool sortstring(const string& a, const string& b) { return a + b < b + a; } n long long GCD(long long a, long long b) { n   if (b == 0) return a; n   a %= b; n   return GCD(b, a); n } n bool isZero(int i) { return i == 0; } n int ce(int n, int m) { n   int ans = 0; n   if (n % m == 0) n     ans = n / m; n   else n     ans = n / m + 1; n   return ans; n } n int solve(int n) { n   int m, k; n   cin >> m >> k; n   int p = 0; n   int q = 0, qq = 0; n   int r = 0; n   int x = ce(n, m); n   int s = 0; n   if (n % m != 0) { n     for (int i = n - 1; i >= 0; i--) { n       if (i % x == 0 && (n - i) % (n / m) == 0 && n           (i / x + (n - i) / (n / m) == m)) { n         s = i; n         break; n       } n     } n   } n   s = (n - s) / (n / m); n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < m - s; j++) { n       cout << x <<    ; n       r = j * x + p; n       for (int k = 0; k < x; k++) { n         cout << r % n + 1 <<    ; n         q = r % n; n         r++; n       } n       cout <<   n ; n     } n     qq = q; n     for (int j = 0; j < s; j++) { n       cout << n / m <<    ; n       r = q + 1; n       for (int k = 0; k < n / m; k++) { n         cout << r % n + 1 <<    ; n         q = r % n; n         r++; n       } n       cout <<   n ; n     } n     p = qq + 1; n   } n   cout <<   n ; n   return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   int n = 0; n   cin >> t; n   while (t--) { n     cin >> n; n     solve(n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int e = 0; n   int d; n   int a[15], b[15], l[10]; n   for (int f = 0; f < n; f++) cin >> a[f]; n   for (int j = 0; j < m; j++) cin >> b[j]; n   int rr = 0, tt = 0; n   for (int g = 0; g < n; g++) { n     if (a[g] < 0 || a[g] > 9) { n       for (int r = g; r < n; r++) a[r] = a[r + 1]; n       rr++; n     } n   } n   for (int h = 0; h < m; h++) { n     if (b[h] < 0 || b[h] > 9) { n       for (int t = h; t < m; t++) b[t] = b[t + 1]; n       tt++; n     } n   } n   if (n >= 0 && n <= 10 && m >= 0 && m <= 10) { n     for (int c = 0; c < n - rr; c++) { n       for (int d = 0; d < m - tt; d++) { n         if (a[c] == b[d]) { n           l[e] = a[c]; n           e++; n         } n       } n     } n     for (int k = 0; k < e; k++) cout << l[k] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, a; n   cin >> n >> k; n   list<int> lst; n   map<int, bool> vis; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if (lst.size() < k) { n       if (vis.find(a) == vis.end()) { n         lst.push_front(a); n         vis[a] = true; n       } n       continue; n     } n     if (vis.find(a) == vis.end() || vis[a] == false) { n       vis[a] = true; n       vis[lst.back()] = false; n       lst.pop_back(); n       lst.push_front(a); n     } n   } n   cout << lst.size() << endl; n   for (auto it = lst.begin(); it != lst.end(); it++) cout << (*it) <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n } A[10005], B[10005], CA[10005], CB[10005]; n int tim, qim; n node operator+(node a, node b) { return node{a.x + b.x, a.y + b.y}; } n node operator-(node a, node b) { return node{a.x - b.x, a.y - b.y}; } n int operator*(node a, node b) { return a.x * b.x + a.y * b.y; } n int operator/(node a, node b) { return a.x * b.y - a.y * b.x; } n bool operator<(node a, node b) { n   if (a.x == b.x) return a.y > b.y; n   return a.x < b.x; n } n void convex_hull(node p[], node c[], int n, int &tp) { n   sort(p + 1, p + n + 1); n   tp = 0; n   for (int i = 1; i <= n; i++) { n     while (tp > 1 && (c[tp] - p[i]) / (c[tp - 1] - p[i]) >= 0) tp--; n     c[++tp] = p[i]; n   } n   int k = tp--; n   for (int i = n; i >= 1; i--) { n     while (tp > k && (c[tp] - p[i]) / (c[tp - 1] - p[i]) >= 0) tp--; n     c[++tp] = p[i]; n   } n   tp--; n } n bool solve(node a[], node b[], int na, int nb) { n   random_shuffle(a + 1, a + na + 1); n   random_shuffle(b + 1, b + nb + 1); n   for (int i = 1; i <= na; i++) n     for (int j = i + 1, k; j <= na; j++) { n       node pa = a[i], pb = a[j]; n       double lp = -1e100, rp = 1e100, inf = 1e100; n       for (k = 1; k <= na; k++) { n         if (k == i) continue; n         if (k == j) continue; n         int ta = (a[k] - pa) * (a[k] - pb); n         int tb = (pa - a[k]) / (pa - pb); n         assert(tb != 0); n         if (tb == 0) { n           if (ta > 0) n             break; n           else n             continue; n         } n         double r = (double)ta / tb; n         if (tb < 0) n           rp = min(rp, r); n         else if (tb > 0) n           lp = max(lp, r); n         if (lp > rp) break; n       } n       if (k <= na || lp > rp) continue; n       for (k = 1; k <= nb; k++) { n         int ta = (b[k] - pa) * (b[k] - pb); n         int tb = (pa - b[k]) / (pa - pb); n         if (tb == 0) { n           if (ta <= 0) n             break; n           else n             continue; n         } n         double r = (double)ta / tb; n         if (tb > 0) n           rp = min(rp, r); n         else if (tb < 0) n           lp = max(lp, r); n         if (lp >= rp) break; n       } n       if (k > nb && lp < rp) return 1; n     } n   return 0; n } n int main() { n   srand(time(NULL)); n   clock_t st, ed; n   double totaltime; n   st = clock(); n   int n, m, cn, cm, i; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) scanf( %d%d , &A[i].x, &A[i].y); n   for (i = 1; i <= m; i++) scanf( %d%d , &B[i].x, &B[i].y); n   if (n == 1 || m == 1) return puts( YES ), 0; n   convex_hull(A, CA, n, cn); n   convex_hull(B, CB, m, cm); n   if (solve(CA, B, cn, m) || solve(CB, A, cm, n)) n     puts( YES ); n   else n     puts( NO ); n   ed = clock(); n   totaltime = (double)(ed - st) / CLOCKS_PER_SEC; n } n


#include <bits/stdc++.h> n using namespace std; n int ky[8] = {-1, 1, -2, 2, -2, 2, -1, 1}; n int kx[8] = {-2, -2, -1, -1, 1, 1, 2, 2}; n int dy[4] = {-1, 0, 1, 0}; n int dx[4] = {0, 1, 0, -1}; n int ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; n int ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; n const double PI = acos(-1.0); n int n; n int c, p; n int k; n int num; n struct Group { n   int c, p, idx; n }; n Group a[1000]; n Group b[1000]; n pair<int, int> t[1000]; n int ret1, ret2; n int cnt1, cnt2; n set<int> s; n vector<pair<int, int>> pos1, pos2; n int ns; n bool comp1(const Group &x, const Group &y) { n   return x.p > y.p || (x.p == y.p && x.c < y.c); n } n bool comp2(const Group &x, const Group &y) { n   return x.c < y.c || (x.c == y.c && x.p > y.p); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> c >> p; n     a[i].c = c; n     a[i].p = p; n     a[i].idx = i + 1; n     b[i].c = c; n     b[i].p = p; n     b[i].idx = i + 1; n   } n   sort(a, a + n, comp1); n   sort(b, b + n, comp2); n   cin >> k; n   for (int i = 0; i < k; i++) { n     cin >> num; n     t[i].first = num; n     t[i].second = i + 1; n   } n   sort(t, t + k); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < k; j++) { n       if (s.count(j)) continue; n       if (a[i].c <= t[j].first) { n         ret1 += a[i].p; n         cnt1++; n         pos1.push_back({a[i].idx, t[j].second}); n         s.insert(j); n         break; n       } n     } n   } n   s.clear(); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < k; j++) { n       if (s.count(j)) continue; n       if (b[i].c <= t[j].first) { n         ret2 += b[i].p; n         cnt2++; n         pos2.push_back({b[i].idx, t[j].second}); n         s.insert(j); n         break; n       } n     } n   } n   if (ret1 <= ret2) { n     cout << cnt2 <<     << ret2 <<   n ; n     ns = pos2.size(); n     for (int i = 0; i < ns; i++) n       cout << pos2[i].first <<     << pos2[i].second <<   n ; n   } else { n     cout << cnt1 <<     << ret1 <<   n ; n     ns = pos1.size(); n     for (int i = 0; i < ns; i++) n       cout << pos1[i].first <<     << pos1[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int di[] = {0, 0, 1, -1, 1, 1, -1, -1}; n int dj[] = {1, -1, 0, 0, 1, -1, 1, -1}; n inline int calcMedian(vector<int> &vec) { n   if (((int)vec.size()) % 2 == 1) { n     return vec[((int)vec.size()) / 2]; n   } n   return (vec[((int)vec.size()) / 2 - 1] + vec[((int)vec.size()) / 2]) / 2; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long init = 0, ans = 0; n   int n, m; n   cin >> n >> m; n   vector<int> vec(m); n   vector<vector<int> > adj(n); n   for (int i = 0; i < m; ++i) { n     cin >> vec[i]; n     --vec[i]; n     if (i && vec[i] != vec[i - 1]) { n       ans = init += abs(vec[i] - vec[i - 1]); n       adj[vec[i]].push_back(vec[i - 1]); n       adj[vec[i - 1]].push_back(vec[i]); n     } n   } n   for (int i = 0; i < n; ++i) n     if (((int)adj[i].size())) { n       sort(adj[i].begin(), adj[i].end()); n       int median = calcMedian(adj[i]); n       long long tmp = 0; n       for (int j = 0; j < ((int)adj[i].size()); ++j) { n         tmp -= 0LL + abs(adj[i][j] - i); n         tmp += 0LL + abs(adj[i][j] - median); n       } n       if (init + tmp < ans) ans = init + tmp; n     } n   cout << ans <<   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   ; n   string s; n   int flag = 0; n   cin >> s; n   string at =  at , dot =  dot ; n   for (int i = 1; i < s.size() - 3; i++) { n     if (s.substr(i, 2) == at && flag == 0) { n       s.replace(i, 2,  @ ); n       flag = 1; n     } n     if (s.substr(i, 3) == dot) { n       s.replace(i, 3,  . ); n     } n   } n   int j = s.size() - 3; n   if (s.substr(j, 2) == at && flag == 0) s.replace(j, 2,  @ ); n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long int n, max = 0; n   cin >> n; n   map<string, long long int> m; n   string s; n   while (n--) { n     cin >> s; n     m[s]++; n   } n   for (auto it = m.begin(); it != m.end(); it++) { n     if (it->second > max) { n       max = it->second; n       s = it->first; n     } n   } n   cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int maxn = 2 * 1e5; n char s[maxn]; n int n; n int l, r; n int is_pal(int l, int r) { n   for (int i = l; i <= (r + l) / 2; i++) { n     if (s[i] != s[r - (i - l)]) return 0; n   } n   return 1; n } n int main() { n   cin >> (s + 1); n   r = strlen(s + 1); n   while (is_pal(1, r) && r % 2 == 0 && r) { n     r /= 2; n   } n   if (!is_pal(1, r)) { n     cout << 1 << endl; n   } else { n     r = strlen(s + 1); n     for (int i = 1; i <= r / 2; i++) { n       if (!is_pal(1, i)) { n         cout << 2 << endl; n         return 0; n       } n     } n     cout <<  Impossible  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 300010; n int n; n long long w[maxn], ma[maxn][2], ans; n vector<int> a[maxn]; n vector<long long> c[maxn]; n bool visited[maxn]; n void dfs(int u) { n   visited[u] = true; n   for (int i = 0; i < (int)a[u].size(); ++i) { n     int v = a[u][i]; n     if (visited[v]) continue; n     dfs(v); n     long long vC = ma[v][0] - c[u][i]; n     if (vC > ma[u][0]) { n       ma[u][1] = ma[u][0]; n       ma[u][0] = vC; n     } else { n       if (vC > ma[u][1]) { n         ma[u][1] = vC; n       } n     } n   } n   ans = max(ans, ma[u][0] + ma[u][1] + w[u]); n   ma[u][0] += w[u]; n   ma[u][1] += w[u]; n } n int main(int argc, const char* argv[]) { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> w[i]; n   } n   for (int i = 1; i < n; ++i) { n     int u, v, C; n     cin >> u >> v >> C; n     a[u].push_back(v); n     c[u].push_back(C); n     a[v].push_back(u); n     c[v].push_back(C); n   } n   dfs(1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int l, r; n   cin >> l >> r; n   (l == r) ? cout << l : cout << 2; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 9; n int a[N], b[N]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 1; i <= n; i++) cin >> b[i]; n     int ok = 1; n     if (a[1] != b[1]) ok = 0; n     map<int, int> cnt; n     cnt[a[1]]++; n     for (int i = 2; i <= n; i++) { n       if (a[i] < b[i] && cnt[1] == 0) ok = 0; n       if (a[i] > b[i] && cnt[-1] == 0) ok = 0; n       cnt[a[i]] = 1; n     } n     if (ok) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read_file(bool outToFile = true) {} n int A[500 + 9]; n int n, m, b, mod; n int dp[2][500 + 9 + 2][500 + 9 + 1]; n int build() { n   int p = 0; n   for (int c = 0; c <= b; c++) dp[p][0][c] = dp[!p][0][c] = 1; n   for (int c = 0; c <= b; c++) n     for (int r = 1; r <= m; r++) dp[p][r][c] = 0; n   for (int i = n - 1; i >= 0; i--) { n     p = !p; n     for (int r = 1; r <= m; r++) n       for (int c = b; c >= 0; c--) n         if (A[i] + c <= b) n           dp[p][r][c] = (dp[!p][r][c] + dp[p][r - 1][c + A[i]]) % mod; n         else n           dp[p][r][c] = dp[!p][r][c]; n   } n   return dp[p][m][0]; n } n int main() { n   read_file(false); n   while (cin >> n >> m >> b >> mod) { n     for (int i = 0; i < n; i++) cin >> A[i]; n     cout << build() << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } n const int MAXN = 100010; n int fst[MAXN], sec[MAXN]; n int ans[MAXN]; n int N, K; n int cmp(const int &a, const int &b) { return a > b; } n int main() { n   while (scanf( %d%d , &N, &K) != EOF) { n     for (int i = 1; i <= N; i++) scanf( %d , &fst[i]); n     for (int i = 1; i <= N; i++) scanf( %d , &sec[i]); n     sort(fst + 1, fst + 1 + N, cmp); n     sort(sec + 1, sec + 1 + N, cmp); n     int pos = N; n     int cnt = 0, stepl = 1, stepr = N; n     while (cnt < N && stepl <= N && stepr >= 1) { n       if (fst[stepl] + sec[stepr] >= K) { n         ans[cnt++] = fst[stepl] + sec[stepr]; n         stepl++; n         stepr--; n       } else { n         stepr--; n       } n     } n     int tot = 0; n     for (int i = 0; i < N; i++) n       if (ans[i] >= K) tot++; n     printf( 1 %d n , min(tot, pos)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   double a, b, jav = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     jav += b; n   } n   jav /= n; n   cout << jav + 5; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:10000000 ) n using namespace std; n template <class T> n T inline sqr(T x) { n   return x * x; n } n const double pi = 3.1415926535897932384626433832795; n const double eps = 1e-8; n long long ans = 0; n bool f(long long x, long long y, long long n) { n   long long s = x + y; n   long long ch = -n / (x * y) + x + y; n   long long zn = 2; n   long long w = ch / zn; n   if (ch == w * zn) n     if (1 <= w && w < x && w < y) { n       long long k1 = x - w, k2 = y - w, k3 = w; n       if (k3 < k2) return true; n       if (k1 == k2) { n         if (k2 == k3) n           ans++; n         else n           ans += 3; n       } else { n         if (k2 == k3) n           ans += 3; n         else n           ans += 6; n       } n     } n   return false; n } n int main() { n   long long n; n   cin >> n; n   if (n % 3 != 0) { n     cout <<  0 ; n     return 0; n   } n   vector<long long> a, b; n   for (long long i = 1; i * i <= n; i++) n     if (n % i == 0) { n       if (i > 0) a.push_back(i); n       if (i * i != n) b.push_back(n / i); n     } n   for (int i = b.size() - 1; i >= 0; i--) a.push_back(b[i]); n   cerr << a.size() << endl; n   n /= 3; n   int Q = 0; n   for (int i = 0; i < a.size(); i++) n     if (n % a[i] == 0) { n       long long d = n / a[i]; n       int x = lower_bound(a.begin(), a.end(), d) - a.begin(); n       for (int j = x; j >= i; j--) n         if (d % a[j] == 0) { n           if (f(a[i], a[j], n)) break; n         } n     } n   cout << ans; n   return 0; n } n