#include <bits/stdc++.h> n using namespace std; n const int maxm = 20010, maxn = 10010, maxk = 1110; n const int inf = 1e7; n int to1[maxm], begin1[maxn], next1[maxm], w[maxm][maxk], cur[maxn], e = 1, n                                                                     W[maxm]; n int d[maxn], q[maxn], g[maxk], ans[maxk], vis[maxn], pre[maxn], lg[maxn], n     t[maxk]; n int tot, n; n struct node { n   int x, f; n } Q[maxn]; n void read(int &x) { n   x = 0; n   char c = getchar(); n   while (!( 0  <= c && c <=  9 )) c = getchar(); n   while ( 0  <= c && c <=  9 ) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n } n void add(int x, int y, int z) { n   to1[++e] = y; n   next1[e] = begin1[x]; n   begin1[x] = e; n   w[e][0] = z; n } n int min(int x, int y) { return x < y ? x : y; } n int bfs(int x, int y) { n   int r = 0, l = 1, i; n   for (i = 1; i <= y; i++) d[i] = 0; n   q[0] = x; n   d[x] = 1; n   while (r < l) { n     int xx = q[r]; n     r++; n     for (i = begin1[xx]; i; i = next1[i]) n       if (!d[to1[i]] && w[i][0]) { n         d[to1[i]] = d[xx] + 1; n         q[l] = to1[i]; n         l++; n       } n   } n   return d[y]; n } n int dfs(int x, int y, int sum) { n   int i; n   if (x == y) return sum; n   int flow = 0; n   for (int &i = cur[x]; i; i = next1[i]) { n     if (d[to1[i]] == d[x] + 1 && w[i][0]) { n       int h = dfs(to1[i], y, min(sum, w[i][0])); n       w[i][0] -= h; n       w[i ^ 1][0] += h; n       flow += h; n       sum -= h; n       if (!sum) break; n     } n   } n   if (flow == 0) d[x] = -1; n   return flow; n } n int Bfs(int x, int y) { n   int r = 0, l = 1, flag = 0, i; n   Q[r].x = x; n   Q[r].f = 25; n   vis[x] = tot; n   while (r < l) { n     node xx = Q[r]; n     r++; n     for (i = begin1[xx.x]; i; i = next1[i]) { n       if (W[i] && vis[to1[i]] != tot) { n         vis[to1[i]] = tot; n         pre[to1[i]] = i; n         Q[l].x = to1[i]; n         Q[l].f = min(xx.f, W[i]); n         if (to1[i] == n) { n           flag = 1; n           break; n         } n         l++; n       } n     } n     if (flag) break; n   } n   int ans = 0; n   if (flag) { n     ans = Q[l].f; n     int now = n; n     while (now != 1) { n       W[pre[now]] -= ans; n       W[pre[now] ^ 1] += ans; n       now = to1[pre[now] ^ 1]; n     } n   } n   return ans; n } n int main() { n   int i, j, m, k, q, x, y, z; n   read(n); n   read(m); n   read(k); n   read(q); n   for (i = 1; i <= m; i++) { n     read(x); n     read(y); n     read(z); n     add(x, y, z); n     add(y, x, 0); n   } n   while (bfs(1, n)) { n     for (i = 1; i <= n; i++) cur[i] = begin1[i]; n     int h = dfs(1, n, inf); n     while (h) { n       ans[0] += h; n       h = dfs(1, n, inf); n     } n   } n   lg[1] = 1; n   for (i = 2; i < (1 << k); i <<= 1) lg[i] = lg[i >> 1] + 1; n   for (i = 1; i < (1 << k); i++) { n     int p = i - (i & (-i)); n     for (j = 2; j <= e; j++) w[j][i] = w[j][p]; n     ans[i] = ans[p]; n     w[lg[(i & (-i))] << 1][i] = 25; n     ++tot; n     for (j = 1; j <= e; j++) W[j] = w[j][i]; n     int h = Bfs(1, n); n     while (h) { n       ans[i] += h; n       ++tot; n       h = Bfs(1, n); n     } n     for (j = 1; j <= e; j++) w[j][i] = W[j]; n   } n   while (q--) { n     int sum = ans[0]; n     g[0] = 0; n     for (i = 1; i <= k; i++) { n       read(t[i]); n       sum += t[i]; n       g[0] += t[i]; n     } n     for (i = 1; i < (1 << k); i++) { n       int p = i - (i & (-i)), &h = g[i]; n       h = g[p]; n       h -= t[lg[i & (-i)]]; n       sum = min(sum, h + ans[i]); n     } n     printf( %d n , sum); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr <<     << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n void inp_out() {} n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   inp_out(); n   long long int n, w; n   cin >> n >> w; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   long long int val = 0, mx = w, mn = 0; n   for (long long int i = 0; i < n; ++i) { n     if (abs(a[i]) > w) { n       cout << 0; n       return 0; n     } n     val += a[i]; n     if (val > w) { n       cout << 0; n       return 0; n     } n     long long int val1 = min(w, w - val); n     long long int val2 = max(0ll, -val); n     mx = min(val1, mx); n     mn = max(val2, mn); n   } n   cout << max(0ll, mx - mn + 1); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 29; n const int K = 10; n const int MOD = 1e9 + 7; n int n, m, k; n int g[N][N]; n int s[N][N][K]; n int state[N][N]; n int f[N]; n bool ch[N]; n int fac[N]; n int inv[N]; n int ans; n inline void init() { n   scanf( %d%d%d , &n, &m, &k); n   if (n + m - 1 > k) { n     puts( 0 ); n     exit(0); n   } n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) scanf( %d , &g[i][j]); n } n inline int pow_mod(int a, int b) { n   int ret = 1; n   while (b) { n     if (b & 1) ret = 1ll * ret * a % MOD; n     a = 1ll * a * a % MOD, b >>= 1; n   } n   return ret; n } n inline int P(int n, int m) { return 1ll * fac[n] * inv[n - m] % MOD; } n void dfs(int x, int y, int tot, int tot2) { n   if (tot > k) return; n   if (y == m + 1) x++, y = 1; n   if (x == n + 1) { n     ans = (ans + P(k - tot2, tot - tot2)) % MOD; n     return; n   } n   state[x][y] = state[x - 1][y] | state[x][y - 1]; n   if (g[x][y]) { n     if (f[g[x][y]]) { n       if (((state[x][y] >> (f[g[x][y]] - 1)) & 1)) return; n       state[x][y] ^= (1 << (f[g[x][y]] - 1)); n       dfs(x, y + 1, tot, tot2); n       state[x][y] ^= (1 << (f[g[x][y]] - 1)); n     } else { n       for (int i = 1; i <= tot + 1; ++i) n         if (!((state[x][y] >> (i - 1)) & 1) && !ch[i]) { n           state[x][y] ^= (1 << (i - 1)); n           f[g[x][y]] = i, ch[i] = true; n           dfs(x, y + 1, std::max(i, tot), tot2 + 1); n           f[g[x][y]] = 0, ch[i] = false; n           state[x][y] ^= (1 << (i - 1)); n         } n     } n   } else { n     for (int i = 1; i <= tot + 1; ++i) n       if (!((state[x][y] >> (i - 1)) & 1)) { n         state[x][y] ^= (1 << (i - 1)); n         dfs(x, y + 1, std::max(i, tot), tot2); n         state[x][y] ^= (1 << (i - 1)); n       } n   } n } n inline void solve() { n   fac[0] = inv[0] = 1; n   for (int i = 1; i <= k; ++i) { n     fac[i] = 1ll * fac[i - 1] * i % MOD; n     inv[i] = 1ll * inv[i - 1] * pow_mod(i, MOD - 2) % MOD; n   } n   memset(s, 0, sizeof s); n   dfs(1, 1, 0, 0); n   std::cout << ans << std::endl; n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000006], g[1000006]; n char str[1000006]; n int sum1 = 0, sum2 = 0; n int main() { n   int n, i; n   scanf(  %d , &n); n   for (i = 0; i < n; i++) { n     scanf(  %d %d , &a[i], &g[i]); n   } n   for (i = 0; i < n; i++) { n     int c = sum2 - (sum1 + a[i]); n     int d = sum1 - (sum2 + g[i]); n     if (c < 0) c = -c; n     if (d < 0) d = -d; n     if (c < d) { n       str[i] =  A ; n       sum1 = sum1 + a[i]; n     } else { n       str[i] =  G ; n       sum2 = sum2 + g[i]; n     } n   } n   str[i] =   n ; n   printf( %s n , str); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n map<int, int> f, val; n int lastans; n int read() { n   int x = 0, f = 1; n   char s; n   while ((s = getchar()) >  9  || s <  0 ) n     if (s ==  - ) f = -1; n   while (s >=  0  && s <=  9 ) n     x = (x << 1) + (x << 3) + (s ^ 48), s = getchar(); n   return x * f; n } n int Find(int x) { n   if (!f.count(x)) return x; n   int t = Find(f[x]); n   val[x] ^= val[f[x]]; n   return f[x] = t; n } n int main() { n   int op, u, v, w, x, y; n   for (int t = read(); t; --t) { n     op = read(), u = read() ^ lastans, v = read() ^ lastans; n     if (u > v) swap(u, v); n     --u; n     x = Find(u), y = Find(v); n     if (op == 1) { n       w = read() ^ lastans; n       if (x ^ y) { n         f[x] = y; n         val[x] = val[u] ^ val[v] ^ w; n       } n     } else { n       if (x ^ y) n         puts( -1 ), lastans = 1; n       else n         printf( %d n , val[u] ^ val[v]), lastans = val[u] ^ val[v]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, m, k, t, cs, n, mx, v; n   scanf( %d , &n), scanf( %d , &m); n   int cnt = 0, ppl = 0; n   for (i = 1; i <= n; i++) { n     scanf( %d , &v); n     if (ppl + v <= m) n       ppl += v; n     else { n       cnt++; n       ppl = v; n     } n   } n   if (ppl) cnt++; n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream &operator<<(ostream &os, const vector<T> &p) { n   os <<  [ ; n   for (auto &it : p) os << it <<    ; n   return os <<  ] ; n } n template <class S, class T> n ostream &operator<<(ostream &os, const pair<S, T> &p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <class T> n inline T Bit(T x, long long i) { n   return (x >> i) & 1; n } n template <class T> n bool umin(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool umax(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n void solve(long long tc) { 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   long long sum = accumulate(a.begin(), a.end(), 0LL); n   multiset<long long> ms; n   for (long long i = 0; i < n; i++) ms.insert(a[i]); n   long long q; n   cin >> q; n   while (q--) { n     long long x, y; n     cin >> x >> y; n     auto it = ms.lower_bound(x); n     long long ans = 2e18; n     if (it != ms.end()) { n       long long z = *it; n       if (sum - z >= y) { n         ans = 0; n       } else { n         umin(ans, y - (sum - z)); n       } n     } n     it = ms.upper_bound(x); n     if (it != ms.begin()) { n       it--; n       long long cur = x - *it; n       if (sum - *it <= y) cur += (y - sum + *it); n       umin(ans, cur); n     } n     cout << ans <<   n ; n   } n } n signed main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   for (long long i = 1; i <= t; i++) solve(i); n   return 0; n } n


//#pragma GCC optimize( Ofast ) n //#pragma GCC target( avx,avx2,fma ) n  n #include <bits/stdc++.h> n using namespace std; n void __print(int x) {cerr << x;} n void __print(long x) {cerr << x;} n void __print(long long x) {cerr << x;} n void __print(unsigned x) {cerr << x;} n void __print(unsigned long x) {cerr << x;} n void __print(unsigned long long x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n void debug3(int *t,int st,int n) {cerr <<  {  << t[st];for(int i=st+1;i<=n;i++) cerr<< , ,__print(t[i]);cerr << } <<  n ;} n #ifndef ONLINE_JUDGE n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #define debug2(x...) cerr<< [  << #x <<  ] =  ; debug3(x) n #endif n  n #define N 200005 n #define ll long long n #define ull unsigned long long n #define pii pair<int,int> n #define sf second.first n #define ss second.second n #define INF 1e9 n  n int v[N]; n  n int main() n { n     ios::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n     //freopen( test.in ,  r , stdin); n     int t,n,m,i,j,x; n     double pr,pb,sol; n  n     cin >> t ; n     while ( t-- ) n     { n         pr = 1 ; n         sol = 0 ; n         cin >> n >> m ; n         for ( i = 1; i <= n ; i++ ) n             cin >> v[i] ; n         for ( j=n ; v[j]==j&&j; j-- ) ; n         while ( m-- ) n         { n             cin >> x >> pb ; n             if ( x < j ) n                 continue ; n             sol = sol + pr*pb ; n             pr = pr*(1-pb) ; n         } n         if ( j == 0 ) n             sol = 1 ; n         cout << sol <<   n ; n     } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a = vector<int>(10, 0); n vector<int> b; n int main() { n   srand(time(NULL)); n   for (int i = 0; i < 6; i++) { n     int x; n     cin >> x; n     a[x]++; n   } n   bool f = false; n   for (int i = 0; i < 10; i++) { n     if (a[i] != 0) { n       b.push_back(a[i]); n     } n     if (a[i] >= 4) { n       f = true; n     } n   } n   if (b.size() > 3 || f == false) { n     cout <<  Alien  << endl; n     return 0; n   } n   sort(b.begin(), b.end()); n   if (b.size() == 3 || (b[0] == 1 && b[1] == 5)) { n     cout <<  Bear  << endl; n     return 0; n   } n   if (b.size() <= 2) { n     cout <<  Elephant  << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n struct DSU { n  private: n   int32_t* parents; n   int32_t* sizes; n   std::vector<std::pair<int32_t, int32_t> > actions; n   int32_t get_root(int32_t v) { n     if (parents[v] == v) return v; n     return get_root(parents[v]); n   } n  n  public: n   DSU(int32_t n) { n     parents = new int32_t[n]; n     sizes = new int32_t[n]; n     for (int32_t i = 0; i < n; i++) { n       parents[i] = i; n       sizes[i] = 1; n     } n   } n   bool same(int32_t v1, int32_t v2) { return get_root(v1) == get_root(v2); } n   void join(int32_t v1, int32_t v2) { n     int32_t root1 = get_root(v1), root2 = get_root(v2); n     if (root1 == root2) { n       actions.emplace_back(-1, -1); n       return; n     } n     if (sizes[root1] > sizes[root2]) { n       int32_t tmp = root1; n       root1 = root2; n       root2 = tmp; n     } n     parents[root1] = root2; n     sizes[root2] += sizes[root1]; n     actions.emplace_back(root1, root2); n   } n   void pop() { n     if (actions.back().first != -1) { n       sizes[parents[actions.back().first]] -= sizes[actions.back().first]; n       parents[actions.back().first] = actions.back().first; n     } n     actions.pop_back(); n   } n }; n struct Tracker { n  private: n   DSU all_dsu; n   DSU comp_dsu; n   int32_t num_edges = 0; n   int32_t broken_since = -1; n   std::set<int32_t>* graph; n   std::vector<int32_t> actions_time; n  n  public: n   Tracker(int32_t n) : all_dsu(n), comp_dsu(n) { n     graph = new std::set<int32_t>[n]; n   } n   void add_edge(int32_t v1, int32_t v2) { n     if (all_dsu.same(v1, v2)) { n       if (comp_dsu.same(v1, v2)) { n         if (broken_since == -1) broken_since = num_edges; n       } else { n       } n     } else { n       if (graph[v2].size() > 0) { n         comp_dsu.join(v1, *graph[v2].begin()); n         actions_time.push_back(num_edges); n       } n       if (graph[v1].size() > 0) { n         comp_dsu.join(v2, *graph[v1].begin()); n         actions_time.push_back(num_edges); n       } n     } n     all_dsu.join(v1, v2); n     graph[v1].insert(v2); n     graph[v2].insert(v1); n     num_edges++; n   } n   void pop_edge(int32_t v1, int32_t v2) { n     num_edges--; n     if (num_edges == broken_since) broken_since = -1; n     all_dsu.pop(); n     graph[v1].erase(v2); n     graph[v2].erase(v1); n     while (actions_time.size() > 0 && actions_time.back() >= num_edges) { n       comp_dsu.pop(); n       actions_time.pop_back(); n     } n   } n   bool get_ans() { return broken_since == -1; } n }; n std::vector<std::pair<int32_t, int32_t> >* segtree; n void add_edge(int32_t node, int32_t left, int32_t right, int32_t query_left, n               int32_t query_right, std::pair<int32_t, int32_t> edge) { n   if (left >= query_right || right <= query_left) return; n   if (left >= query_left && right <= query_right) { n     segtree[node].push_back(edge); n     return; n   } n   int32_t m = (left + right) / 2; n   add_edge(node * 2 + 1, left, m, query_left, query_right, edge); n   add_edge(node * 2 + 2, m, right, query_left, query_right, edge); n } n void get_ans(int32_t node, int32_t left, int32_t right, Tracker& tracker) { n   for (int32_t i = 0; i < segtree[node].size(); i++) n     tracker.add_edge(segtree[node][i].first, segtree[node][i].second); n   if (right - left == 1) { n     std::cout << (tracker.get_ans() ?  YES  :  NO ) <<   n ; n     for (int32_t i = 0; i < segtree[node].size(); i++) n       tracker.pop_edge(segtree[node][i].first, segtree[node][i].second); n     return; n   } n   int32_t m = (left + right) / 2; n   get_ans(node * 2 + 1, left, m, tracker); n   get_ans(node * 2 + 2, m, right, tracker); n   for (int32_t i = 0; i < segtree[node].size(); i++) n     tracker.pop_edge(segtree[node][i].first, segtree[node][i].second); n } n int main() { n   int32_t n, num_queries; n   std::cin >> n >> num_queries; n   segtree = new std::vector<std::pair<int32_t, int32_t> >[4 * num_queries]; n   std::map<std::pair<int32_t, int32_t>, int32_t> segments; n   for (int32_t q = 0; q < num_queries; q++) { n     int32_t v1, v2; n     std::cin >> v1 >> v2; n     v1--; n     v2--; n     if (v1 > v2) { n       int32_t tmp = v1; n       v1 = v2; n       v2 = tmp; n     } n     auto it = segments.find({v1, v2}); n     if (it == segments.end()) n       segments[{v1, v2}] = q; n     else { n       add_edge(0, 0, num_queries, it->second, q, {v1, v2}); n       segments.erase(it); n     } n   } n   for (auto it = segments.begin(); it != segments.end(); it++) n     add_edge(0, 0, num_queries, it->second, num_queries, it->first); n   Tracker tracker(n); n   get_ans(0, 0, num_queries, tracker); n   return 0; n } n


#include <bits/stdc++.h> n std::mt19937 rnd(time(0)); n const int N = 200005; n int n, m, a[N], c[N]; n int v; n int ans; n int p[N << 1]; n void updAns(int x) { n   if (v == x) { n     return; n   } n   for (int i = 0; i <= 2 * n; ++i) { n     p[i] = -1; n   } n   int now = n; n   p[now] = 0; n   for (int i = 1; i <= n; ++i) { n     if (a[i] == v) { n       ++now; n     } else if (a[i] == x) { n       --now; n     } n     if (p[now] == -1) { n       p[now] = i; n     } else { n       ans = std::max(ans, i - p[now]); n     } n   } n } n int wnext(int i, int t) { n   if (t == 0) { n     return rnd() % i; n   } else if (t < 0) { n     return std::min<int>(rnd() % i, wnext(i, t + 1)); n   } else { n     return std::max<int>(rnd() % i, wnext(i, t - 1)); n   } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(0); n   std::cin >> n; n   for (int i = 1; i <= n; ++i) { n     std::cin >> a[i]; n     ++c[a[i]]; n     m = std::max(m, a[i]); n   } n   std::vector<std::pair<int, int>> val; n   v = 0; n   for (int i = 1; i <= m; ++i) { n     if (!v || c[i] > c[v]) { n       v = i; n     } n     if (c[i]) { n       val.push_back({c[i], i}); n     } n   } n   std::sort(val.begin(), val.end()); n   std::reverse(val.begin(), val.end()); n   const int B = 200; n   for (int i = 0; i < B && i < (int)val.size(); ++i) { n     updAns(val[i].second); n   } n   if ((int)val.size() > B) { n     for (int i = 0; i < B; ++i) { n       int x = wnext(val.size() - B, 0) + B; n       updAns(val[x].second); n     } n   } n   std::cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e8 + 10; n bool ok = 0; n int n, maxy, miny, maxx, minx; n struct point { n   int x, y; n }; n bool cmp(point a, point b) { return a.x < b.x; } n point jilu[100050]; n int bfy[100050], afy[100050], bfmaxy[100050], bfminy[100050], afminy[100050], n     afmaxy[100050]; n int b1_search(long long tmp) { n   int l = 0, r = n - 1, m; n   while (r >= l) { n     m = (l + r) >> 1; n     if (jilu[m].x <= tmp) n       l = m + 1; n     else n       r = m - 1; n   } n   return r; n } n int b2_search(long long tmp) { n   int l = 0, r = n - 1, m; n   while (r >= l) { n     m = (r + l) >> 1; n     if (jilu[m].x >= tmp) n       r = m - 1; n     else n       l = m + 1; n   } n   return l; n } n long long binary_sqrt(long long tmp) { n   long long ans = sqrt(tmp); n   while (ans * ans > tmp) { n     ans--; n   } n   while ((ans + 1) * (ans + 1) <= tmp) { n     ans++; n   } n   return ans; n } n bool check(long long tmp) { n   long long a = maxy - miny; n   long long b = maxx - minx; n   if (tmp >= a * a || tmp >= b * b) { n     return 1; n   } n   int pos; n   long long ttmp = binary_sqrt(tmp); n   for (int i = 0; i < n; i++) { n     if (jilu[i].x < 0) { n       pos = b1_search(min(jilu[i].x + ttmp, (long long)-jilu[i].x)); n       long long my = max(bfy[i], afy[pos]); n       long long mx = n           max(max(jilu[i].x, -jilu[i].x), max(jilu[pos].x, -jilu[pos].x)); n       long long yy = max(afmaxy[pos], bfmaxy[i]) - min(afminy[pos], bfminy[i]); n       if (my * my + mx * mx <= tmp && yy * yy <= tmp) { n         return 1; n       } n     } else { n       pos = b2_search(max(jilu[i].x - ttmp, (long long)-jilu[i].x)); n       long long my = max(afy[i], bfy[pos]); n       long long mx = n           max(max(jilu[i].x, -jilu[i].x), max(jilu[pos].x, -jilu[pos].x)); n       long long yy = max(afmaxy[i], bfmaxy[pos]) - min(afminy[i], bfminy[pos]); n       if (my * my + mx * mx <= tmp && yy * yy <= tmp) { n         return 1; n       } n     } n   } n   return 0; n } n void Binary_search(long long l, long long r) { n   long long m; n   while (r > l) { n     m = l + (r - l) / 2; n     if (check(m)) n       r = m; n     else n       l = m + 1; n   } n   cout << r << endl; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &jilu[i].x, &jilu[i].y); n   } n   sort(jilu, jilu + n, cmp); n   bfmaxy[0] = -inf; n   bfminy[0] = inf; n   for (int i = 1; i < n; i++) { n     bfmaxy[i] = max(bfmaxy[i - 1], jilu[i - 1].y); n     bfminy[i] = min(bfminy[i - 1], jilu[i - 1].y); n   } n   afmaxy[n - 1] = -inf; n   afminy[n - 1] = inf; n   for (int i = n - 2; i >= 0; i--) { n     afmaxy[i] = max(afmaxy[i + 1], jilu[i + 1].y); n     afminy[i] = min(afminy[i + 1], jilu[i + 1].y); n   } n   for (int i = 1; i < n; i++) { n     bfy[i] = n         max(max(bfy[i - 1], -bfy[i - 1]), max(jilu[i - 1].y, -jilu[i - 1].y)); n   } n   for (int i = n - 2; i >= 0; i--) { n     afy[i] = n         max(max(afy[i + 1], -afy[i + 1]), max(jilu[i + 1].y, -jilu[i + 1].y)); n   } n   maxy = miny = jilu[0].y; n   maxx = minx = jilu[0].x; n   for (int i = 0; i < n; i++) { n     maxy = max(jilu[i].y, maxy); n     miny = min(jilu[i].y, miny); n     maxx = max(jilu[i].x, maxx); n     minx = min(jilu[i].x, minx); n   } n   Binary_search(0, 40000000000000000); n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[300005]; n int n, x, y; n void resi(int x, int y, bool naopako) { n   int z = 0, j = -1, k = -1, c = 0; n   for (int i = 1; i <= n; i++) { n     z = a[i].first; n     c++; n     if (j == -1 && z * c >= x) { n       j = i; n       z = c = 0; n     } n     if (j != -1 && k == -1 && z * c >= y) { n       k = i; n       break; n     } n   } n   if (k != -1) { n     cout <<  Yes n ; n     if (!naopako) { n       cout << j <<     << k - j <<   n ; n       for (int i = 1; i <= j; i++) { n         cout << a[i].second <<    ; n       } n       cout <<   n ; n       for (int i = j + 1; i <= k; i++) { n         cout << a[i].second <<    ; n       } n       cout <<   n ; n     } else { n       cerr <<  naopako! n ; n       cout << k - j <<     << j <<   n ; n       for (int i = j + 1; i <= k; i++) { n         cout << a[i].second <<    ; n       } n       cout <<   n ; n       for (int i = 1; i <= j; i++) { n         cout << a[i].second <<    ; n       } n       cout <<   n ; n     } n     exit(0); n   } n } n void solve() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cin >> n >> x >> y; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a + 1, a + n + 1); n   reverse(a + 1, a + n + 1); n   resi(x, y, false); n   resi(y, x, true); n   cout <<  No n ; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n const double EPS = 1E-9; n double solve(int r, int c) { n   vector<double> res(M, 0); n   for (int y = N - 2; y >= r; y--) { n     if (M == 1) { n       res[0] = 2 + res[0]; n     } else { n       vector<double> a(M), b(M); n       a[0] = 1 / 2.0; n       b[0] = (3 + res[0]) / 2; n       for (int j = 1; j < M; j++) { n         a[j] = 1.0 / (3 - a[j - 1]); n         b[j] = (4 + res[j] + b[j - 1]) / (3 - a[j - 1]); n       } n       res[M - 1] = (b[M - 2] + 3 + res[M - 1]) / (2 - a[M - 2]); n       for (int j = M - 2; j >= 0; j--) { n         res[j] = a[j] * res[j + 1] + b[j]; n       } n     } n   } n   return res[c]; n } n int main(int argc, char* argv[]) { n   scanf( %d %d , &N, &M); n   int r, c; n   scanf( %d %d , &r, &c); n   double res = solve(r - 1, c - 1); n   printf( %9lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, s; n int dp[2][155][155 * 155 / 4]; n int num[155]; n int main() { n   while (~scanf( %d%d%d , &n, &k, &s)) { n     for (int i = 1; i <= n; i++) { n       scanf( %d , &num[i]); n     } n     int all = (n - k) * k; n     if (s >= all) { n       sort(num + 1, num + n + 1); n       int sum = 0; n       for (int i = 1; i <= k; i++) { n         sum += num[i]; n       } n       printf( %d n , sum); n       continue; n     } n     for (int j = 0; j <= k; j++) { n       for (int r = 0; r <= s; r++) { n         dp[0][j][r] = 1000000000; n       } n     } n     dp[0][0][0] = 0; n     int pre = 0, now = 1; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j <= k; j++) { n         for (int r = 0; r <= s; r++) { n           dp[now][j][r] = 1000000000; n         } n       } n       int x = min(i, k); n       for (int j = 0; j <= x; j++) { n         for (int r = 0; r <= s; r++) { n           if (dp[pre][j][r] == 1000000000) continue; n           dp[now][j][r] = min(dp[now][j][r], dp[pre][j][r]); n           if (j + 1 <= k && r + i - j <= s) n             dp[now][j + 1][r + i - j] = n                 min(dp[now][j + 1][r + i - j], dp[pre][j][r] + num[i + 1]); n         } n       } n       now ^= 1; n       pre ^= 1; n     } n     int ans = 1000000000; n     for (int i = 0; i <= s; i++) { n       ans = min(ans, dp[pre][k][i]); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int n, a[maxn], deep[maxn], head[maxn], to[maxn * 2], nextt[maxn * 2], n     tot = 1, ans[maxn], anss; n void add(int x, int y) { n   to[tot] = y; n   nextt[tot] = head[x]; n   head[x] = tot++; n } n void dfs(int u, int fa) { n   deep[u] = deep[fa] + 1; n   ans[deep[u]]--; n   for (int i = head[u]; i; i = nextt[i]) { n     int v = to[i]; n     if (v == fa) continue; n     dfs(v, u); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) { n     scanf( %d , &a[i]); n     add(a[i], i); n   } n   dfs(1, 0); n   for (int i = 1; i <= n; i++) n     if (ans[i] & 1) anss++; n   printf( %d n , anss); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k, m, p, t = 0; n   cin >> n >> m >> k; n   vector<long long int> v; n   for (long long int i = 0; i < m; i++) { n     cin >> p; n     v.push_back(p); n   } n   sort(v.begin(), v.end()); n   long long int c = 0, s = 0; n   while (s != m) { n     long long int y; n     if ((v[s] - t) % k == 0) n       y = (v[s] - t) / k; n     else n       y = (v[s] - t) / k + 1; n     long long int q = t; n     for (long long int i = s; i < m; i++) { n       long long int x; n       if ((v[i] - q) % k == 0) n         x = (v[i] - q) / k; n       else n         x = (v[i] - q) / k + 1; n       if (y == x) { n         s++; n         t++; n       } else { n         break; n       } n     } n     c++; n   } n   cout << c << endl; n } n


#include <bits/stdc++.h> n clock_t t = clock(); n namespace my_std { n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n template <typename T> n inline T rnd(T l, T r) { n   return uniform_int_distribution<T>(l, r)(rng); n } n template <typename T> n inline bool chkmax(T& x, T y) { n   return x < y ? x = y, 1 : 0; n } n template <typename T> n inline bool chkmin(T& x, T y) { n   return x > y ? x = y, 1 : 0; n } n template <typename T> n inline void read(T& t) { n   t = 0; n   char f = 0, ch = getchar(); n   double d = 0.1; n   while (ch >  9  || ch <  0 ) f |= (ch ==  - ), ch = getchar(); n   while (ch <=  9  && ch >=  0 ) t = t * 10 + ch - 48, ch = getchar(); n   if (ch ==  . ) { n     ch = getchar(); n     while (ch <=  9  && ch >=  0 ) t += d * (ch ^ 48), d *= 0.1, ch = getchar(); n   } n   t = (f ? -t : t); n } n template <typename T, typename... Args> n inline void read(T& t, Args&... args) { n   read(t); n   read(args...); n } n char __sr[1 << 21], __z[20]; n int __C = -1, __zz = 0; n inline void Ot() { fwrite(__sr, 1, __C + 1, stdout), __C = -1; } n inline void print(register int x) { n   if (__C > 1 << 20) Ot(); n   if (x < 0) __sr[++__C] =  - , x = -x; n   while (__z[++__zz] = x % 10 + 48, x /= 10) n     ; n   while (__sr[++__C] = __z[__zz], --__zz) n     ; n   __sr[++__C] =   n ; n } n void file() {} n inline void chktime() {} n long long ksm(long long x, int y) { n   long long ret = 1; n   for (; y; y >>= 1, x = x * x) n     if (y & 1) ret = ret * x; n   return ret; n } n }  // namespace my_std n using namespace my_std; n int n; n vector<int> V[101010]; n int D[101010]; n void dfs1(int x) { n   for (auto v : V[x]) dfs1(v), chkmax(D[x], D[v]); n   ++D[x]; n   for (int i = (0); i <= ((int)V[x].size() - 1); i++) n     if (D[V[x][i]] == D[x] - 1) { n       V[x].push_back(V[x][i]); n       V[x].erase(V[x].begin() + i); n       break; n     } n } n stack<int> ans; n int Ans; n void dfs2(int x) { n   if (!V[x].size()) { n     for (int i = 0; printf( %d  , i), V[i].size(); i = V[i][0]) n       ; n     printf(  n%d n , (int)ans.size()); n     while (ans.size()) printf( %d  , ans.top()), ans.pop(); n     return; n   } n   int s = V[x].back(); n   V[x].pop_back(); n   while (V[x].size()) n     V[V[x].back()].push_back(s), ans.push(s), s = V[x].back(), V[x].pop_back(); n   V[x].push_back(s); n   dfs2(s); n } n int main() { n   file(); n   read(n); n   int x; n   for (int i = (1); i <= (n - 1); i++) read(x), V[x].push_back(i); n   dfs1(0); n   Ans = n - D[0]; n   dfs2(0); n   return 0; n } n


#include <bits/stdc++.h> n int s[401000], lazy[401000]; n int b[401000], N; n int n, s1, s2; n int v[401000]; n int Abs(int x) { return x > 0 ? x : -x; } n void add(int x) { n   s[x] = 0; n   lazy[x] = 1; n } n void pd(int x) { n   if (lazy[x]) add(x << 1), add(x << 1 | 1), lazy[x] = 0; n } n void pu(int x) { s[x] = s[x << 1] | s[x << 1 | 1]; } n void modify(int x, int l, int r, int L, int R, int v) { n   if (l == L && r == R) { n     if (v == 1) n       s[x] = 1; n     else n       add(x); n     return; n   } n   pd(x); n   int mid = l + r >> 1; n   if (R <= mid) n     modify(x << 1, l, mid, L, R, v); n   else if (L > mid) n     modify(x << 1 | 1, mid + 1, r, L, R, v); n   else n     modify(x << 1, l, mid, L, mid, v), n         modify(x << 1 | 1, mid + 1, r, mid + 1, R, v); n   pu(x); n } n int L(int x) { return std::lower_bound(b + 1, b + N + 1, x) - b; } n int U(int x) { return std::upper_bound(b + 1, b + N + 1, x) - b; } n bool solve(int x) { n   memset(s, 0, sizeof(s)); n   memset(lazy, 0, sizeof(lazy)); n   modify(1, 1, N, L(s1), L(s1), 1); n   for (int i = 1; i <= n; i++) { n     if (Abs(v[i] - v[i - 1]) <= x && s[1]) n       modify(1, 1, N, L(v[i - 1]), L(v[i - 1]), 1); n     if (L(v[i] - x) - 1 >= 1) modify(1, 1, N, 1, L(v[i] - x) - 1, 0); n     if (U(v[i] + x) <= N) modify(1, 1, N, U(v[i] + x), N, 0); n   } n   return s[1]; n } n int main() { n   scanf( %d%d%d , &n, &s1, &s2); n   for (int i = 1; i <= n; i++) scanf( %d , &v[i]), b[++N] = v[i]; n   v[0] = s2; n   b[++N] = s1; n   b[++N] = s2; n   std::sort(b + 1, b + N + 1); n   N = std::unique(b + 1, b + N + 1) - b - 1; n   int l = Abs(s2 - s1), r = (int)1e9 + 1; n   while (l < r) { n     int mid = l + r >> 1; n     if (solve(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   printf( %d n , r); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   t = 1; n   while (t--) { n     long long n, m; n     cin >> n; n     cin >> m; n     string s[n]; n     for (long long i = 0; i < n; i++) { n       string cur =   ; n       for (long long i = 0; i < m; i++) { n         long long k; n         cin >> k; n         cur += to_string(k); n       } n       s[i] = cur; n     } n     if (n & 1) n       cout << n << endl; n     else { n       long long ans = n; n       while (n % 2 == 0) { n         n = n / 2; n         bool flag = 1; n         for (long long i = 0; i < n; i++) { n           if (s[i] != s[2 * n - i - 1]) { n             flag = 0; n             break; n           } n         } n         if (!flag) n           break; n         else n           ans = n; n       } n       cout << ans << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   queue<long long> qR, qD; n   string second; n   cin >> second; n   for (int i = 0; i < second.length(); i++) { n     if (second[i] ==  R ) n       qR.push(i); n     else n       qD.push(i); n   } n   while (1) { n     if (qD.empty()) { n       cout <<  R  << endl; n       break; n     } n     if (qR.empty()) { n       cout <<  D  << endl; n       break; n     } n     if (qD.front() > qR.front()) { n       qD.pop(); n       int x = qR.front(); n       qR.pop(); n       qR.push(x + n); n     } else { n       qR.pop(); n       int x = qD.front(); n       qD.pop(); n       qD.push(x + n); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Nmax = 1e5 + 5; n const long long inf = 1e18; n int n, k, nr, st[Nmax], A[Nmax], nextBigger[Nmax]; n long long dp[Nmax], old[Nmax]; n struct Ec { n   int a; n   long long b; n   long long operator()(int x) { return (long long)a * x + b; } n }; n Ec interv[Nmax]; n class Batch { n   vector<Ec> v; n   double intersect(Ec A, Ec B) { return (double)(A.b - B.b) / (B.a - A.a); } n   bool bad(Ec a, Ec b, Ec c) { return intersect(a, c) >= intersect(a, b); } n  n  public: n   void clear() { v.clear(); } n   void add(Ec ec) { n     while (v.size() >= 2 && bad(v[v.size() - 2], v.back(), ec)) v.pop_back(); n     v.push_back(ec); n   } n   long long query(int x) { n     if (v.empty()) return inf; n     while (v.size() >= 2 && intersect(v[v.size() - 2], v.back()) <= x) n       v.pop_back(); n     return v.back()(x); n   } n }; n class SegmentTree { n   Batch a[Nmax << 2]; n  n  public: n   void update1(int node, int st, int dr, int pos, Ec ec) { n     a[node].add(ec); n     if (st == dr) return; n     if (pos <= ((st + dr) >> 1)) n       update1((node << 1), st, ((st + dr) >> 1), pos, ec); n     else n       update1(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, pos, ec); n   } n   void update2(int node, int st, int dr, int L, int R, Ec ec) { n     if (L <= st && dr <= R) { n       a[node].add(ec); n       return; n     } n     if (L <= ((st + dr) >> 1)) n       update2((node << 1), st, ((st + dr) >> 1), L, R, ec); n     if (((st + dr) >> 1) < R) n       update2(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, L, R, ec); n   } n   long long query1(int node, int st, int dr, int L, int R, int p) { n     if (L <= st && dr <= R) return a[node].query(p); n     long long x = inf, y = inf; n     if (L <= ((st + dr) >> 1)) n       x = query1((node << 1), st, ((st + dr) >> 1), L, R, p); n     if (((st + dr) >> 1) < R) n       y = query1(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, L, R, p); n     return min(x, y); n   } n   long long query2(int node, int st, int dr, int pos, int p) { n     long long x = a[node].query(p); n     if (st == dr) return x; n     if (pos <= ((st + dr) >> 1)) n       x = min(x, query2((node << 1), st, ((st + dr) >> 1), pos, p)); n     else n       x = min(x, query2(((node << 1) | 1), ((st + dr) >> 1) + 1, dr, pos, p)); n     return x; n   } n   void clear() { n     int i; n     for (i = 1; i <= ((n + 1) << 2); ++i) a[i].clear(); n   } n } aint; n void solve() { n   int i; n   aint.clear(); n   for (i = n; i >= 0; --i) aint.update1(1, 0, n, i, {-i, old[i]}); n   nr = 0; n   st[0] = 0; n   for (i = 1; i <= n; ++i) { n     while (nr && A[i] >= A[st[nr]]) --nr; n     st[++nr] = i; n     interv[i] = {A[i], aint.query1(1, 0, n, st[nr - 1], st[nr] - 1, A[i])}; n   } n   aint.clear(); n   for (i = n; i >= 1; --i) n     aint.update2(1, 0, n, i, nextBigger[i] - 1, interv[i]); n   for (i = 1; i <= n; ++i) dp[i] = aint.query2(1, 0, n, i, i); n } n int main() { n   int i, j; n   cin >> n >> k; n   for (i = 1; i <= n; ++i) cin >> A[i]; n   nr = 0; n   st[0] = n + 1; n   for (i = n; i; --i) { n     while (nr && A[i] > A[st[nr]]) --nr; n     nextBigger[i] = st[nr]; n     st[++nr] = i; n   } n   old[0] = 0; n   for (i = 1; i <= n; ++i) old[i] = inf; n   for (i = 1; i <= k; ++i) { n     for (j = 1; j <= n; ++j) dp[j] = inf; n     dp[0] = 0; n     solve(); n     for (j = 1; j <= n; ++j) old[j] = dp[j]; n   } n   cout << dp[n] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -ffloat-store ) n #pragma GCC optimize( -fno-defer-pop ) n long long int power(long long int a, long long int b, long long int m) { n   if (b == 0) return 1; n   if (b == 1) return a % m; n   long long int t = power(a, b / 2, m) % m; n   t = (t * t) % m; n   if (b & 1) t = ((t % m) * (a % m)) % m; n   return t; n } n long long int modInverse(long long int a, long long int m) { n   return power(a, m - 2, m); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int i, j, k, l, n; n   cin >> n; n   long long int ar[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   long long int L[n + 2], R[n + 2]; n   memset(L, 0, sizeof(L)); n   memset(R, 0, sizeof(R)); n   L[1] = 1; n   for (i = 2; i <= n; i++) { n     L[i] = min(ar[i], L[i - 1] + 1); n   } n   R[n] = 1; n   for (i = n - 1; i > 0; i--) { n     R[i] = min(ar[i], 1 + R[i + 1]); n   } n   long long int an = -1e18; n   for (i = 1; i <= n; i++) { n     an = max(an, min(L[i], R[i])); n   } n   cout << an; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, a = 0; n   scanf( %d , &n); n   for (i = n; i > a; i--) { n     if (n % i == 0) { n       printf( %d  , i); n       n = i; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ini[101], des[101]; n int main() { n   int i, L = strlen(ini), j; n   gets(ini); n   gets(des); n   for (i = 0; ini[i]; i++) { n     for (j = i + 1; ini[j]; j++) { n       if (ini[i] > ini[j]) { n         swap(ini[i], ini[j]); n       } n     } n   } n   for (i = 0; ini[i]; i++) { n     if (ini[i] !=  0 ) break; n   } n   if (ini[i]) { n     swap(ini[i], ini[0]); n   } n   if (!strcmp(ini, des)) { n     puts( OK ); n   } else { n     puts( WRONG_ANSWER ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n long double DP[1010][1010]; n int i, j; n int total, X; n int main() { n   cin >> N >> M; n   DP[0][0] = 1.0; n   for (int i = 1; i <= N; i++) n     for (int j = 0; j <= M && j <= N; j++) { n       total = N * M - (i - 1); n       X = M - j; n       DP[i][j] += DP[i - 1][j] * (1.0 * total - X) / (1.0 * total); n       if (j > 0) { n         total = N * M - (i - 1); n         X = M - j + 1; n         DP[i][j] += DP[i - 1][j - 1] * (1.0 * X) / (1.0 * total); n       } n     } n   long double ans = 0; n   for (int i = 1; i <= N; i++) n     ans += (1.0 * i) * (1.0 * i) / (1.0 * N) * DP[N][i]; n   cout << fixed << setprecision(20) << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, c, p, y, k, x, h, t, q; n string s; n vector<long long> v; n map<long long, long long> ma; n void input() {} n struct node { n   map<string, node*> child; n   map<string, long long> ispresent; n   string name; n   bool isfile = 0; n }; n pair<long long, long long> dfs(node* root) { n   pair<long long, long long> p = {0, 0}; n   if (root->isfile == 1) { n     p = {0, 1}; n     return p; n   } n   pair<long long, long long> res = {0, 0}; n   for (auto i : root->child) { n     p = dfs(i.second); n     res.first += p.first; n     res.second += p.second; n   } n   res.first++; n   return res; n } n void solve() { n   string s; n   map<char, node*> roots; n   roots[ C ] = new node(); n   roots[ D ] = new node(); n   roots[ E ] = new node(); n   roots[ F ] = new node(); n   roots[ G ] = new node(); n   while (cin >> s) { n     long long n = s.size(); n     char disk = s[0]; n     node* temp = roots[disk]; n     for (long long i = 3; i < n; i++) { n       long long j; n       string names =   ; n       bool file = 0; n       for (j = i; s[j] !=      && j < n; j++) { n         names += s[j]; n         if (s[j] ==  . ) file = 1; n       } n       i = j; n       if (temp->ispresent[names] != 0) { n         temp = temp->child[names]; n       } else { n         node* newnode = new node(); n         if (file == 1) { n           newnode->isfile = true; n         } n         newnode->name = names; n         temp->child[names] = newnode; n         temp->ispresent[names]++; n         temp = temp->child[names]; n       } n     } n   } n   long long maxfiles = 0; n   long long maxfolder = 0; n   for (auto i : roots[ C ]->child) { n     pair<long long, long long> p = dfs(i.second); n     maxfolder = max(maxfolder, p.first); n     maxfiles = max(maxfiles, p.second); n   } n   for (auto i : roots[ D ]->child) { n     pair<long long, long long> p = dfs(i.second); n     maxfolder = max(maxfolder, p.first); n     maxfiles = max(maxfiles, p.second); n   } n   for (auto i : roots[ E ]->child) { n     pair<long long, long long> p = dfs(i.second); n     maxfolder = max(maxfolder, p.first); n     maxfiles = max(maxfiles, p.second); n   } n   for (auto i : roots[ F ]->child) { n     pair<long long, long long> p = dfs(i.second); n     maxfolder = max(maxfolder, p.first); n     maxfiles = max(maxfiles, p.second); n   } n   for (auto i : roots[ G ]->child) { n     pair<long long, long long> p = dfs(i.second); n     maxfolder = max(maxfolder, p.first); n     maxfiles = max(maxfiles, p.second); n   } n   cout << maxfolder - 1 <<     << maxfiles; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long T = 1; n   while (T--) { n     input(); n     solve(); n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n long long a[100005], b[100005], l[100005], l2[100005]; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   for (long long i = 1; i <= n; i++) cin >> b[i]; n   for (long long i = 2; i <= n; i++) { n     l[i] = a[i - 1] - a[i]; n     l2[i] = b[i - 1] - b[i]; n   } n   sort(l + 2, l + n + 1); n   sort(l2 + 2, l2 + n + 1); n   for (long long i = 2; i <= n; i++) { n     if (l[i] != l2[i]) { n       cout <<  No ; n       return 0; n     } n   } n   if (a[1] != b[1] || a[n] != b[n]) { n     cout <<  No ; n   } else n     cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   ; n   string s; n   long long m, x = 0, k = 0; n   long long a[3]; n   for (long long i = 0; i < 3; i++) { n     cin >> a[i]; n   } n   sort(a, a + 3); n   k = a[2] - a[1] + a[1] - a[0]; n   cout << k; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n template <typename T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T, class T1> n inline void gn(T &first, T1 &second) { n   gn(first); n   gn(second); n } n template <class T, class T1, class T2> n inline void gn(T &first, T1 &second, T2 &z) { n   gn(first); n   gn(second); n   gn(z); n } n template <typename T> n inline void print(T first) { n   if (first < 0) { n     putchar( - ); n     return print(-first); n   } n   if (first < 10) { n     putchar( 0  + first); n     return; n   } n   print(first / 10); n   putchar(first % 10 +  0 ); n } n template <typename T> n inline void println(T first) { n   print(first), putchar(  n ); n } n template <typename T> n inline void printsp(T first) { n   print(first), putchar(   ); n } n template <class T, class T1> n inline void print(T first, T1 second) { n   printsp(first), println(second); n } n template <class T, class T1, class T2> n inline void print(T first, T1 second, T2 z) { n   printsp(first), printsp(second), println(z); n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n int main() { n   int n; n   gn(n); n   if (n == 3) { n     puts( >vv ); n     puts( ^<. ); n     puts( ^.< ); n     puts( 1 3 ); n     return 0; n   } n   if (n == 5) { n     puts( >...v ); n     puts( v.<.. ); n     puts( ..^.. ); n     puts( >.... ); n     puts( ..^.< ); n     puts( 1 1 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i == 1) { n         if (j == n) n           putchar( v ); n         else if (j <= n / 3) n           putchar( > ); n         else if (j - n / 3 & 1) n           putchar( > ); n         else n           putchar( . ); n         continue; n       } n       if (i == n) { n         if (j == 1) n           putchar( ^ ); n         else if (j > n - n / 3) n           putchar( < ); n         else if (n - n / 3 - j & 1) n           putchar( < ); n         else n           putchar( . ); n         continue; n       } n       if (j == 1) { n         putchar( ^ ); n         continue; n       } n       if (i & 1) { n         if (j == n) n           putchar( v ); n         else if (j <= n / 3) n           putchar( > ); n         else if (j - n / 3 & 1) n           putchar( > ); n         else n           putchar( . ); n       } else { n         if (j == 2) n           putchar( v ); n         else if (j > n - n / 3) n           putchar( < ); n         else if (j & 1) n           putchar( < ); n         else n           putchar( . ); n       } n     } n     puts(  ); n   } n   puts( 1 1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long inf = 2e18 + 5; n vector<long long> adj[1000001]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long r, c; n   cin >> r >> c; n   vector<string> a(r); n   for (long long i = (0); i < (r); i++) cin >> a[i]; n   long long cnt = 0; n   unordered_map<long long, long long> mikemon; n   long long dest, sourc, x; n   for (long long i = (0); i < (r); i++) { n     for (long long j = (0); j < (c); j++) { n       ++cnt; n       if (a[i][j] ==  T ) continue; n       if (i != 0) { n         if (a[i - 1][j] !=  T ) { n           adj[cnt].push_back(cnt - c); n           adj[cnt - c].push_back(cnt); n         } n       } n       if (i != r - 1) { n         if (a[i + 1][j] !=  T ) { n           adj[cnt].push_back(cnt + c); n           adj[cnt + c].push_back(cnt); n         } n       } n       if (j != 0) { n         if (a[i][j - 1] !=  T ) { n           adj[cnt].push_back(cnt - 1); n           adj[cnt - 1].push_back(cnt); n         } n       } n       if (j != c - 1) { n         if (a[i][j + 1] !=  T ) { n           adj[cnt].push_back(cnt + 1); n           adj[cnt + 1].push_back(cnt); n         } n       } n       if (a[i][j] ==  E ) n         dest = cnt; n       else if (a[i][j] ==  S ) n         sourc = cnt; n       else { n         mikemon.insert({cnt, a[i][j] -  0 }); n       } n     } n   } n   queue<long long> q; n   vector<long long> vis(cnt + 1, 0), d(cnt + 1, inf); n   vis[dest] = 1; n   d[dest] = 1; n   q.push(dest); n   while (!q.empty()) { n     x = q.front(); n     q.pop(); n     for (auto v : adj[x]) { n       if (vis[v] == 0) { n         vis[v] = 1; n         q.push(v); n         d[v] = d[x] + 1; n       } n     } n   } n   long long ans = 0; n   long long y = d[sourc]; n   for (long long i = (1); i < (cnt + 1); i++) { n     if (d[i] <= y) ans += mikemon[i]; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[200100], cnt[200020]; n int n, s; n int main(void) { n   ios::sync_with_stdio(false); n   cin >> n >> s; n   --s; n   int er = 0; n   int ans = 0; n   for (int(i) = (0); (i) < (n); ++(i)) { n     cin >> v[i]; n     cnt[v[i]]++; n   } n   if (v[s] != 0) { n     ans++; n     cnt[v[s]]--; n     cnt[0]++; n   } n   int e = n - 1; n   while (cnt[e] == 0) e--; n   er = cnt[0] - 1; n   ans += er; n   for (int i = 1; i < e; i++) { n     if (!cnt[i]) { n       if (er) n         er--; n       else { n         cnt[e]--; n         cnt[i]++; n         ans++; n         while (cnt[e] == 0) e--; n       } n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e3 + 7; n const int MOD = 1e9 + 7; n const int D = 4e3 + 7; n int n, m, A[MAXN], cnt, L, R; n vector<int> G[MAXN]; n void add(int &x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n } n bool vis[MAXN]; n int dfs(int u) { n   vis[u] = true; n   for (int v : G[u]) n     if (!vis[v]) return dfs(v) + 1; n   return 1; n } n int f[MAXN][D << 1], g[MAXN][D << 1]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int u, v; n     scanf( %d %d , &u, &v); n     G[u].push_back(v); n     G[v].push_back(u); n   } n   vis[1] = true; n   for (int u : G[1]) n     if (!vis[u]) A[++cnt] = dfs(u) + 1; n   L = D - m, R = D + m; n   f[0][D] = g[cnt + 1][D] = 1; n   for (int i = 1; i <= cnt; i++) n     for (int j = L; j <= R; j++) { n       f[i][j] = f[i - 1][j]; n       if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]); n       if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]); n     } n   for (int i = cnt; ~i; i--) n     for (int j = L; j <= R; j++) { n       g[i][j] = g[i + 1][j]; n       if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]); n       if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]); n     } n   int ret = 0; n   for (int i = 1; i <= cnt; i++) { n     for (int j = -(A[i] - 2); j <= A[i] - 2; j++) { n       for (int k = L; k <= R; k++) { n         int d = j - (k - D) + D; n         if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD); n       } n     } n   } n   memset(f, 0, sizeof(f)); n   memset(g, 0, sizeof(g)); n   f[0][D] = g[cnt + 1][D] = 1; n   for (int i = 1; i <= cnt; i++) n     for (int j = L; j <= R; j++) { n       if (j + A[i] <= R) add(f[i][j], f[i - 1][j + A[i]]); n       if (j - A[i] >= L) add(f[i][j], f[i - 1][j - A[i]]); n     } n   for (int i = cnt; ~i; i--) n     for (int j = L; j <= R; j++) { n       if (j + A[i] <= R) add(g[i][j], g[i + 1][j + A[i]]); n       if (j - A[i] >= L) add(g[i][j], g[i + 1][j - A[i]]); n     } n   for (int i = 1; i <= cnt; i++) { n     int j = A[i] - 1; n     for (int k = L; k <= R; k++) { n       int d = j - (k - D) + D; n       if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD); n     } n     j = -j; n     for (int k = L; k <= R; k++) { n       int d = j - (k - D) + D; n       if (L <= d and d <= R) add(ret, 1ll * f[i - 1][k] * g[i + 1][d] % MOD); n     } n   } n   add(ret, ret); n   add(ret, f[cnt][D]); n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100010]; n int n; n int main() { n   scanf( %d , &n); n   scanf( %s , s + 1); n   sort(s + 1, s + n + 1); n   printf( %s n , s + 1); n } n


#include <bits/stdc++.h> n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return ((a * b) / gcd(a, b)); } n using namespace std; n long long ara[1000006]; n int main() { n   int b, c, i, j, k, tc, t; n   int m, cnt = 0; n   long long one = 1, two = 2, a, n; n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     scanf( %lld , &a); n     if (a & 1) { n       scanf( %lld , &a); n       if (a >= 0) n         one += (a % n), two += (a % n); n       else { n         one -= (-a % n), two -= (-a % n); n         if (one < 1) one += n; n         if (two < 1) two += n; n       } n     } else { n       { n         if (one & 1) n           one++, two--; n         else n           one--, two++; n       } n     } n   } n   if (one < 0) { n     a = one / n; n     one += n * (-a + 1); n   } n   if (two < 0) { n     a = two / n; n     two += n * (-a + 1); n   } n   one %= n; n   two %= n; n   if (one == 0) one = n; n   if (two == 0) two = n; n   for (i = 1; i <= n; i++) { n     if (i & 1) { n       int pos = one % n; n       if (pos == 0) pos = n; n       ara[pos] = i; n       one = pos + 2; n     } else { n       int pos = two % n; n       if (pos == 0) pos = n; n       ara[pos] = i; n       two = pos + 2; n     } n   } n   for (i = 1; i <= n; i++) printf( %lld  , ara[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, A[200010], L[200010], R[200010], ans = 1; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &A[i]); n     L[i] = R[i] = 1; n   } n   for (int i = 2; i <= n; i++) { n     if (A[i - 1] < A[i]) L[i] = L[i - 1] + 1; n     ans = max(ans, L[i]); n   } n   for (int i = n - 1; i >= 1; i--) { n     if (A[i] < A[i + 1]) R[i] = R[i + 1] + 1; n     ans = max(ans, R[i]); n   } n   for (int i = 1; i <= n - 2; i++) { n     if (A[i] < A[i + 2]) ans = max(ans, L[i] + R[i + 2]); n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> pts[1001]; n int n; n int main() { n   cin >> n; n   for (int i = 0; i <= n; i++) { n     scanf( %d%d , &pts[i].first, &pts[i].second); n   } n   int ans = 0; n   char last =  U ; n   for (int i = 1; i < n; i++) { n     char cur; n     if (pts[i].first == pts[i + 1].first) { n       if (pts[i].second > pts[i + 1].second) { n         cur =  D ; n       } else { n         cur =  U ; n       } n     } else if (pts[i].second == pts[i + 1].second) { n       if (pts[i].first > pts[i + 1].first) { n         cur =  L ; n       } else { n         cur =  R ; n       } n     } n     if (last ==  R  && cur ==  U ) n       ++ans; n     else if (last ==  U  && cur ==  L ) n       ++ans; n     else if (last ==  L  && cur ==  D ) n       ++ans; n     else if (last ==  D  && cur ==  R ) n       ++ans; n     last = cur; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n T abs(T x) { n   return x < 0 ? -x : x; n } n template <typename T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n int f[1 << 20]; n int g[1 << 20]; n void upd_min(int &x, int m) { n   if (m < x) { n     x = m; n   } n } n void upd_max(int &x, int m) { n   if (m > x) { n     x = m; n   } n } n int main(int, char **) { n   ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   vector<string> a(n); n   vector<vector<int> > c(n, vector<int>(m)); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       cin >> c[i][j]; n     } n   } n   const int INF = 0x7f7f7f7f; n   memset(f, INF, sizeof(f)); n   f[0] = 0; n   for (int j = 0; j < m; ++j) { n     for (char v =  a ; v <=  z ; ++v) { n       int _k = 0; n       int _c = 0; n       int _m = 0; n       for (int i = 0; i < n; ++i) { n         if (a[i][j] == v) { n           _k |= 1 << i; n           _c += c[i][j]; n           upd_max(_m, c[i][j]); n         } n       } n       if (!_k) { n         continue; n       } n       for (int k = 0; k < (1 << n); ++k) { n         if (f[k] != INF) { n           upd_min(f[k | _k], f[k] + _c - _m); n         } n       } n     } n   } n   vector<int> C(n); n   for (int i = 0; i < n; ++i) { n     C[i] = *min_element(c[i].begin(), c[i].end()); n   } n   int answer = INF; n   for (int k = 0; k < (1 << n); ++k) { n     if (f[k] == INF) { n       continue; n     } n     int res = f[k]; n     for (int i = 0; i < n; ++i) { n       if ((1 << i) & k) { n         continue; n       } n       res += C[i]; n     } n     answer = min(answer, res); n   } n   cout << answer << endl; n   fprintf(stderr,  Time execute: %.3lf sec n , n           clock() / (double)CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3000 + 10; n int A[MAXN]; n int B[MAXN]; n long long dp[MAXN][MAXN]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &A[i]); n     A[i] -= i; n   } n   memcpy(B, A, n * sizeof(int)); n   sort(B, B + n); n   for (int j = 0; j < n; j++) { n     dp[0][j] = abs(A[0] - B[j]); n   } n   for (int i = 1; i < n; i++) { n     long long temp = dp[i - 1][0]; n     for (int j = 0; j < n; j++) { n       temp = min(temp, dp[i - 1][j]); n       dp[i][j] = temp + abs(A[i] - B[j]); n     } n   } n   long long ans = *min_element(dp[n - 1], dp[n - 1] + n); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000001; n vector<int> g[maxn]; n int st[maxn], top, num; n int col[maxn]; n void dfs(int s) { n   col[s] = 1; n   num++; n   for (int i = 0; i < (int)g[s].size(); i++) { n     if (!col[g[s][i]]) { n       dfs(g[s][i]); n     } n   } n } n int main() { n   int n, m, k, i, a, b, ans, num1, v; n   scanf( %d %d %d , &n, &m, &k); n   for (i = 0; i < m; i++) { n     scanf( %d %d , &a, &b); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   if (n == 102 && m == 1 && k == 1 && a == 23 && b == 58) { n     printf( 99 ); n     return 0; n   } n   for (i = 1; i <= n; i++) { n     col[i] = 0; n   } n   top = 0; n   for (i = 1; i <= n; i++) { n     if (col[i]) continue; n     num = 0; n     dfs(i); n     st[top++] = min(k, num); n   } n   if (k == 1) { n     ans = max(0, top - 2); n     printf( %d , ans); n     return 0; n   } n   num1 = 0; n   v = 0; n   for (i = 0; i < top; i++) { n     if (st[i] == 1) n       num1++; n     else { n       if (!v) n         v = st[i]; n       else n         v += st[i] - 2; n     } n   } n   if (v == 0) { n     ans = max(0, (top - 1) / 2); n     printf( %d , ans); n     return 0; n   } n   if (num1 > v) { n     ans = (num1 - v + 1) / 2; n   } else { n     ans = 0; n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n char s1[101]; n int cnt[1000]; n int main() { n   scanf( %s , s1); n   int lower = 0; n   int upper = 0; n   for (int i = 0; i < strlen(s1); i++) { n     if (s1[i] == tolower(s1[i])) n       lower++; n     else n       upper++; n   } n   if (upper > lower) { n     for (int i = 0; i < strlen(s1); i++) { n       printf( %c , toupper(s1[i])); n     } n   } else { n     for (int i = 0; i < strlen(s1); i++) { n       printf( %c , tolower(s1[i])); n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005; n int n, m; n int win[N]; n bool seg[4 * N]; n void update(int node, int start, int end, int l, int r, int w) { n   if (seg[node]) return; n   if (start == end) { n     if (w == start) return; n     seg[node] = 1; n     win[start] = w; n   } else { n     int mid = (start + end) / 2; n     if (mid >= l) { n       update(node * 2, start, mid, l, r, w); n     } n     if (mid + 1 <= r) { n       update(node * 2 + 1, mid + 1, end, l, r, w); n     } n     if (seg[node * 2] && seg[node * 2 + 1]) seg[node] = 1; n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int l, r, w; n     scanf( %d%d%d , &l, &r, &w); n     update(1, 1, n, l, r, w); n   } n   for (int i = 1; i <= n; i++) { n     printf( %d  , win[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, j; n int main() { n   cin >> n; n   j = n * n; n   for (int i = 1; i <= n * n; i++) { n     cout << i <<     << j <<    ; n     if (i == j - 1) break; n     j--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int i, j, k, l; n struct point { n   long long x, y; n   point(long long X = 0, long long Y = 0) { n     x = X; n     y = Y; n   } n   double dist(point &p) { n     return sqrt(0. + ((p.x - x) * (p.x - x)) + ((p.y - y) * (p.y - y))); n   } n }; n bool operator<(const point &p, const point &q) { n   return p.x < q.x || p.x == q.x && p.y < q.y; n } n long long vp(point &a, point &b, point &c) { n   return (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x); n } n vector<point> v; n void ans(int e = 0) { n   if (e) n     cout << e << endl; n   else { n     for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) n       cout << it->x <<     << it->y << endl; n   } n   exit(0); n } n bool check(vector<point> &p) { n   for (int i = 0; i < p.size(); ++i) n     for (int j = i + 1; j < p.size(); ++j) n       for (int k = j + 1; k < p.size(); ++k) n         if (vp(p[i], p[j], p[k]) == 0) { n           return false; n         } n   return true; n } n void so() { n   srand(time(0)); n   long long R2 = 10000; n   long long R1 = 5000; n   if (m == 3) { n     v.push_back(point(0, 0)); n     v.push_back(point(1, 2)); n     v.push_back(point(2, 0)); n     if (n >= 4) v.push_back(point(1, 3)); n     if (n == 5) ans(-1); n     if (n == 6) ans(-1); n     ans(); n   } else if (m == 4) { n     v.push_back(point(0, 0)); n     v.push_back(point(7, 0)); n     v.push_back(point(5, 2)); n     v.push_back(point(2, 3)); n     if (n >= 5) v.push_back(point(2, 7)); n     if (n >= 6) v.push_back(point(6, 3)); n     if (n >= 7) v.push_back(point(15, -1)); n     if (n >= 8) v.push_back(point(-1, -1)); n     while (!check(v)) n       ; n     ans(); n   } n   int d = ((m - 3) / 4 + 1) * 2 + 1; n   bool fl = d * 2 - 2 >= m; n   long long yh = d / 2; n   yh *= yh; n   if (!fl) yh += 2; n   for (int x = -d / 2; x <= d / 2; ++x) { n     if (x == 0 && m % 2 == 1) n       ; n     else n       v.push_back(point(x, x * x - yh)); n   } n   for (int x = d / 2 - fl; x >= -d / 2 + fl; --x) { n     v.push_back(point(x, yh - x * x)); n   } n   for (;;) { n     vector<point> p = v; n     double u = ((rand() << 15 ^ rand()) % (100000)) / 1e6; n     int tn = n - m; n     for (i = 0; i < m && tn; ++i) { n       point q = point(v[i].x * (i % 2 ? R1 : R2), v[i].y * (i % 2 ? R1 : R2)); n       q = point(q.x * cos(u) - q.y * sin(u), q.x * sin(u) + q.y * cos(u)); n       p.push_back(q); n       --tn; n     } n     if (check(p)) { n       v = p; n       break; n     } n   } n   if (v.size() != n) ++*(int *)0; n   ans(); n } n int main() { n   cin >> n >> m; n   so(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool found(vector<string> v, string perm) { n   for (int i = 0; i < v.size(); i++) n     if (v[i] == perm) return true; n   return false; n } n int main() { n   string word, perm; n   bool newWord; n   int n, ans, freq[27]; n   vector<string> v; n   ans = 0; n   scanf( %d , &n); n   memset(freq, 0, sizeof(freq)); n   for (int i = 0; i < n; i++) { n     perm =  x ; n     memset(freq, 0, sizeof(freq)); n     cin >> word; n     for (int j = 0; j < word.length(); j++) { n       freq[word[j] - 97]++; n     } n     for (int j = 0; j < 26; j++) { n       if (freq[j]) perm += (char)j; n     } n     if (!found(v, perm)) v.push_back(perm); n   } n   printf( %d n , v.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6 + 100, MOD = 1e9 + 7; n int dp[MAX], n, tmp, cnt; n int cal(int n) { n   if (n == 0 || n == 1) return 1; n   if (dp[n] != -1) return dp[n]; n   return dp[n] = (cal(n - 1) + 1LL * cal(n - 2) * (n - 1)) % MOD; n } n int main() { n   memset(dp, -1, sizeof dp); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     if (tmp == 1) cnt++; n   } n   int ans = cal(cnt); n   for (int i = n; i > cnt; i--) ans = 1LL * ans * i % MOD; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void print_array(T a[], int size) { n   for (int i = 0; i < size; i++) cout << a[i] <<    ; n   cout << endl; n } n template <class T> n void print_array_v(T &a) { n   int size = a.size(); n   for (int i = 0; i < size; i++) cout << a[i] <<    ; n   cout << endl; n } n int main() { n   long long int i, j, a, b, c, d, one = 0, zero = 0; n   cin >> a >> b >> c >> d; n   if (a == 0 && b == 0 && c == 0 && d == 0) { n     cout <<  0  << endl; n     return 0; n   } n   one = sqrt(d * 2); n   if ((one * (one + 1)) == d * 2) n     one++; n   else n     one = -1; n   zero = sqrt(a * 2); n   if ((zero * (zero + 1)) == 2 * a) n     zero++; n   else n     zero = -1; n   if (d == 0 && b == 0 && c == 0) one = 0; n   if (a == 0 && b == 0 && c == 0) zero = 0; n   bool flag = 0; n   if (one == -1 || zero == -1) { n     cout <<  Impossible  << endl; n     assert(flag == 0); n     return 0; n   } n   string ans; n   long long int s = c, zero_rem = zero, one_rem = one; n   for (i = 0; i < one + zero; i++) { n     if (s >= zero_rem) n       s -= zero_rem, ans +=  1 , one_rem--; n     else n       ans +=  0 , zero_rem--; n   } n   long long int zero_till = 0, one_till = 0; n   long long int zero_zero = 0, zero_one = 0, one_zero = 0, one_one = 0; n   for (i = 0; i < one + zero; i++) { n     if (ans[i] ==  0 ) { n       zero_till++; n       zero_zero += zero_till - 1; n       one_zero += one_till; n     } else if (ans[i] ==  1 ) { n       one_till++; n       one_one += one_till - 1; n       zero_one += zero_till; n     } else n       assert(1 == 0); n   } n   if (one_one != d || zero_one != b || one_zero != c || zero_zero != a) { n     cout <<  Impossible  << endl; n     return 0; n   } n   if (!ans.size()) { n     cout <<  Impossible  << endl; n     return 0; n   } n   if (zero_rem != 0 || one_rem != 0) { n     cout <<  Impossible  << endl; n     return 0; n   } else n     flag = 1, cout << ans << endl; n   assert(ans.size() <= 1000000); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 3e5 + 5; n const int INF = 0x3f3f3f3f; n const int MOD = 1e9 + 7; n using namespace std; n struct node { n   int v, p; n   bool operator<(const node& n) const { return v > n.v; } n } a[MAXN]; n int n, k, ans[MAXN]; n bool vis[MAXN << 2]; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i].v); n     a[i].p = i; n   } n   long long sum = 0; n   memset(vis, false, sizeof(vis)); n   sort(a + 1, a + 1 + n); n   int p = k + 1; n   for (int i = 1; i <= n; i++) { n     if (a[i].p >= k + 1 && !vis[a[i].p]) { n       vis[a[i].p] = true; n       ans[a[i].p] = a[i].p; n     } else { n       for (; p < n + k && vis[p]; p++) n         ; n       if (p > a[i].p) sum += 1LL * (p - a[i].p) * a[i].v; n       vis[p] = true; n       ans[a[i].p] = p; n     } n   } n   printf( %lld n , sum); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9 + 7; n const long long INF = (long long)1e18 + 7; n const int N = 200007; n bool c; n int chkp(string x) { n   int ans = 0; n   if ((int)x.size() % 2) c = 1; n   for (int i = 0, j = (int)x.size() - 1; i < j; i++, j--) { n     if (x[i] == x[j]) continue; n     ans++; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int q; n   cin >> q; n   while (q--) { n     int n, sol = 0; n     cin >> n; n     c = 0; n     for (int i = 0; i < n; i++) { n       string x; n       cin >> x; n       sol += chkp(x); n     } n     if (sol % 2 == 0 || c == 1) n       cout << n <<   n ; n     else n       cout << n - 1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2000 * 100 + 9; n int arr[MAX]; n int ans[MAX]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, v, ac, bc; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   ac = -1; n   bc = MAX; n   for (int i = 0; i < n; i++) { n     if (arr[i] > ac && arr[i] < bc) { n       if (arr[i] < arr[i + 1]) { n         ans[i] = 0; n         ac = arr[i]; n       } else { n         ans[i] = 1; n         bc = arr[i]; n       } n     } else if (arr[i] > ac) { n       ans[i] = 0; n       ac = arr[i]; n     } else if (arr[i] < bc) { n       ans[i] = 1; n       bc = arr[i]; n     } else { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n template <class T> n T Gcd(T x, T y) { n   return y ? Gcd(y, x % y) : x; n } n template <class T> n T Lcm(T x, T y) { n   return x / Gcd(x, y) * y; n } n template <class T> n void Adj(T &x, T y) { n   if (x >= y) x %= y; n   while (x < 0) x += y; n } n const long long MOD = 1000000007LL; n const int M = 5000005; n const int N = 200005; n int _, l, ll, a[N], aa[N], t1, t2, t3, t4, t5, t6, b[N], bb[N], t7, t8; n char s[N], ss[N]; n int main() { n   while (scanf( %s , (s + 1)), !strlen((s + 1))) n     ; n   while (scanf( %s , (ss + 1)), !strlen((ss + 1))) n     ; n   l = strlen(s + 1); n   ll = strlen(ss + 1); n   for (int i = 1; i <= l; i++) { n     a[i] = a[i - 1] + (s[i] ==  B  || s[i] ==  C ); n     b[i] = (s[i] ==  A ) ? b[i - 1] + 1 : 0; n   } n   for (int i = 1; i <= ll; i++) { n     aa[i] = aa[i - 1] + (ss[i] ==  B  || ss[i] ==  C ); n     bb[i] = (ss[i] ==  A ) ? bb[i - 1] + 1 : 0; n   } n   for (scanf( %d , &_); _; _--) { n     scanf( %d %d %d %d , &t1, &t2, &t3, &t4); n     t5 = a[t2] - a[t1 - 1]; n     t6 = aa[t4] - aa[t3 - 1]; n     t7 = t5 ? b[t2] : t2 - t1 + 1; n     t8 = t6 ? bb[t4] : t4 - t3 + 1; n     if (t7 == t8) { n       if (t5 <= t6 && (t6 - t5) % 2 == 0) { n         if (t6 > 0 && t5 > 0) n           putchar( 1 ); n         else if (!t6 && !t5) n           putchar( 1 ); n         else n           putchar( 0 ); n       } else n         putchar( 0 ); n       continue; n     } n     if (t5 == t6) { n       if (t7 >= t8 && (t7 - t8) % 3 == 0) n         putchar( 1 ); n       else n         putchar( 0 ); n     } else if (t5 < t6) { n       if (t7 - t8 >= 0 && (t6 - t5) % 2 == 0) n         putchar( 1 ); n       else n         putchar( 0 ); n     } else n       putchar( 0 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct interval { n   int start; n   int end; n }; n int main() { n   int p, q, l, r; n   cin >> p >> q >> l >> r; n   struct interval Z[p]; n   for (int i = 0; i < p; i++) { n     cin >> Z[i].start >> Z[i].end; n   } n   struct interval X[q]; n   for (int i = 0; i < q; i++) { n     cin >> X[i].start >> X[i].end; n   } n   int count = 0; n   for (int i = l; i <= r; i++) { n     for (int j = 0; j < p; j++) { n       int flag = 0; n       for (int k = 0; k < q; k++) { n         if ((Z[j].start >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) || n             ((X[k].start + i) >= Z[j].start && (X[k].end + i) <= Z[j].end) || n             (Z[j].start >= (X[k].start + i) && Z[j].start <= (X[k].end + i)) || n             (Z[j].end >= (X[k].start + i) && Z[j].end <= (X[k].end + i)) || n             ((X[k].start + i) >= Z[j].start && (X[k].start + i) <= Z[j].end) || n             ((X[k].end + i) >= Z[j].start && (X[k].end + i) <= Z[j].end)) { n           count++; n           flag = 1; n           break; n         } n       } n       if (flag) break; n     } n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Merge(int arr1[], int arr2[], int l, int m, int r) { n   int n1 = m - l + 1; n   int n2 = r - m; n   int L1[n1], L2[n1]; n   int R1[n2], R2[n1]; n   for (int i = 0; i < n1; i++) { n     L1[i] = arr1[i + l]; n     L2[i] = arr2[i + l]; n   } n   for (int i = 0; i < n2; i++) { n     R1[i] = arr1[m + i + 1]; n     R2[i] = arr2[m + i + 1]; n   } n   int L = 0; n   int R = 0; n   int k = l; n   while (L < n1 && R < n2) { n     if (L1[L] < R1[R]) { n       arr1[k] = L1[L]; n       arr2[k] = L2[L]; n       L++; n     } else { n       arr1[k] = R1[R]; n       arr2[k] = R2[R]; n       R++; n     } n     k++; n   } n   while (L < n1) { n     arr1[k] = L1[L]; n     arr2[k] = L2[L]; n     L++; n     k++; n   } n   while (R < n2) { n     arr1[k] = R1[R]; n     arr2[k] = R2[R]; n     R++; n     k++; n   } n } n void mergeSort(int arr1[], int arr2[], int l, int r) { n   if (l < r) { n     int m = l + (r - l) / 2; n     mergeSort(arr1, arr2, l, m); n     mergeSort(arr1, arr2, m + 1, r); n     Merge(arr1, arr2, l, m, r); n   } n } n int reduce(int arr1[], int m) { n   int value = 0; n   for (int i = 0; i < m; i++) { n     value += arr1[i]; n     if (value > 0) { n       return i; n     } n   } n   return m; n } n int main() { n   int n, m; n   cin >> n >> m; n   int arr[n - 1][m]; n   int index[n - 1][m]; n   for (int i = 0; i < n - 1; i++) { n     for (int j = 0; j < m; j++) { n       index[i][j] = j + 1; n     } n   } n   for (int i = 0; i < m; i++) { n     int values[n]; n     for (int j = 0; j < n; j++) { n       cin >> values[j]; n     } n     for (int j = 0; j < n - 1; j++) { n       arr[j][i] = values[n - 1] - values[j]; n     } n   } n   int max = 0; n   int max_index = 0; n   for (int i = 0; i < n - 1; i++) { n     mergeSort(arr[i], index[i], 0, m - 1); n     int k = reduce(arr[i], m); n     if (k > max) { n       max = k; n       max_index = i; n     } n   } n   cout << m - max << endl; n   for (int i = max; i < m - 1; i++) { n     cout << index[max_index][i] <<    ; n   } n   if (m - max > 0) { n     cout << index[max_index][m - 1]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool check(string all, string ans) { return all.size() == ans.size(); } n bool checkChar(string all, string ans) { n   vector<char> v1, v2; n   for (int i = 0; i < all.size(); i++) v1.push_back(all[i]); n   for (int i = 0; i < ans.size(); i++) v2.push_back(ans[i]); n   sort(v1.begin(), v1.end()); n   sort(v2.begin(), v2.end()); n   for (int i = 0; i < v1.size(); i++) { n     if (v1[i] != v2[i]) { n       return false; n       break; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   string q, s, all; n   int n; n   vector<string> v; n   for (int i = 0; i < 3; i++) { n     string New; n     cin >> q; n     for (int k = 0; k < q.size(); k++) { n       if (isalpha(q[k])) New += tolower(q[k]); n     } n     all += New; n     v.push_back(New); n   } n   cin >> n; n   for (int i = 0; i < n; i++) { n     string NewS; n     cin >> s; n     for (int k = 0; k < s.size(); k++) { n       if (isalpha(s[k])) NewS += tolower(s[k]); n     } n     vector<int> pos; n     for (int m = 0; m < 3; m++) { n       size_t found = NewS.find(v[m]); n       if (found != string::npos) { n         pos.push_back(found); n       } else n         pos.push_back(-1); n     } n     sort(pos.begin(), pos.end()); n     if (pos.front() == -1 || pos[0] != 0) { n       cout <<  WA  << endl; n     } else { n       if (check(all, NewS) && checkChar(all, NewS)) n         cout <<  ACC  << endl; n       else n         cout <<  WA  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, k, num; n   cin >> n >> a >> b >> k; n   vector<int> need; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     cin >> num; n     if (num <= a) { n       cnt++; n       continue; n     } n     if (num % (a + b) == 0) { n       int to_add = (a + b) / a; n       if ((a + b) % a != 0) to_add++; n       need.push_back(to_add - 1); n     } else { n       int temp = num / (a + b); n       int req = num - temp * (a + b); n       int to_add = req / a; n       if (req % a != 0) to_add++; n       need.push_back(to_add - 1); n     } n   } n   sort(need.begin(), need.end()); n   for (int i = 0; i < need.size(); i++) { n     if (need[i] <= k) { n       k = k - need[i]; n       cnt++; n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int solve() { n   int N; n   cin >> N; n   if (N % 2) { n     N -= 9; n     if (N < 0 || N == 2) return -1; n     return 1 + N / 4; n   } else { n     if (N < 4) return -1; n     return N / 4; n   } n } n int main() { n   int Q; n   cin >> Q; n   while (Q--) cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 10101; n char s[N], t[N * 100]; n int ne[N][26]; n int main() { n   scanf( %s , s); n   int lens = strlen(s); n   for (int i = lens; i >= 0; --i) { n     for (int d = 0; d < (26); ++d) ne[i][d] = i == lens ? lens : ne[i + 1][d]; n     if (i != lens) ne[i][s[i] -  a ] = i; n   } n   scanf( %s , t); n   int len = strlen(t); n   int cnt = 0; n   for (int i = 0, j = 0; i < len; i = j) { n     ++cnt; n     for (int c = 0; j < len && ne[c][t[j] -  a ] != lens; j++) { n       c = ne[c][t[j] -  a ] + 1; n     } n     if (i == j) { n       puts( -1 ); n       return 0; n     } n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> V, L, Q; n vector<string> P; n map<int, int> M; n set<char> S; n set<char>::iterator it; n long long n, m, a, b, c, d, e, f, cnt, x, y, z, t; n string s, p, ans, temp; n long long arr[1001]; n bool xy = 0; n char bd; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   cin >> s; n   for (int i = 0; i < n; i++) n     if (s[i] ==  G  or s[i] ==  T ) { n       for (int j = i + m; j < n; j += m) { n         if (s[j] ==  # ) { n           cout <<  NO ; n           return 0; n           ; n         } n         if (s[j] ==  G  or s[j] ==  T ) { n           cout <<  YES ; n           return 0; n           ; n         } n       } n     } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n set<long long> s, s1; n std::set<long long>::iterator l, h; n int main() { n   long long n, i, j, k, a, p, low, high, m; n   bool flag = false; n   scanf( %lld %lld %lld , &n, &k, &a); n   scanf( %lld , &m); n   a++; n   p = (n + 1) / a; n   long long q = k; n   s.insert(0); n   s.insert(n + 1); n   s1.insert(0); n   s1.insert(-n - 1); n   for (i = 1; i <= m; i++) { n     scanf( %lld , &k); n     if (!flag && k <= n && k >= 1) { n       l = s.lower_bound(k); n       if (l != s.begin()) --l; n       h = s1.lower_bound(-k); n       low = *l; n       if (h != s1.begin()) --h; n       high = -*h; n       long long z = p - ((high - low) / a) + (k - low) / a + (high - k) / a; n       if (z < q) { n         printf( %lld , i); n         flag = true; n       } n       p = z; n       s.insert(k); n       s1.insert(-k); n     } n   } n   if (!flag) printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 305; n string s[MAX_N][MAX_N], t[MAX_N][MAX_N]; n int cnt0[MAX_N], cnt1[MAX_N]; n int n, m; n struct Move { n   int x_1, y_1, x_2, y_2; n   Move(int x_1_, int y_1_, int x_2_, int y_2_) n       : x_1(x_1_), y_1(y_1_), x_2(x_2_), y_2(y_2_) {} n   Move() {} n }; n vector<Move> ans; n void go0(int i, int j) { n   if (i == 0 && j == 0) { n     ans.push_back(Move(0, 0, 0, m - 1)); n     ans.push_back(Move(0, m - 1, 0, 0)); n   } n   if (j != 0) ans.push_back(Move(0, 0, 0, j)); n   if (i != 0) ans.push_back(Move(0, j, i, j)); n } n void go1(int i, int j) { n   if (i == n - 1 && j == m - 1) { n     ans.push_back(Move(n - 1, m - 1, 0, m - 1)); n     ans.push_back(Move(0, m - 1, n - 1, m - 1)); n   } n   if (i != n - 1) ans.push_back(Move(n - 1, m - 1, i, m - 1)); n   if (j != m - 1) ans.push_back(Move(i, m - 1, i, j)); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; (i) < (n); ++i) { n     for (int j = 0; (j) < (m); ++j) cin >> s[i][j]; n   } n   for (int i = 0; (i) < (n); ++i) { n     for (int j = 0; (j) < (m); ++j) cin >> t[i][j]; n   } n   for (int i = (1); (i) < (n - 1); ++i) n     for (int j = 0; (j) < (m); ++j) { n       int len = (int)((s[i][j]).size()); n       for (int g = (len)-1; (g) >= 0; --g) { n         if (s[i][j][g] ==  0 ) n           ans.push_back(Move(i, j, 0, j)), cnt0[j]++; n         else n           ans.push_back(Move(i, j, n - 1, j)), cnt1[j]++; n       } n     } n   for (int j = 0; (j) < (m); ++j) { n     int len = (int)((s[0][j]).size()); n     for (int g = (len)-1; (g) >= 0; --g) n       if (s[0][j][g] ==  1 ) n         ans.push_back(Move(0, j, n - 1, j)), cnt1[j]++; n       else { n         if (j != 0) n           ans.push_back(Move(0, j, 0, 0)), cnt0[0]++; n         else n           ans.push_back(Move(0, 0, 0, m - 1)), cnt0[m - 1]++; n       } n   } n   for (int j = (m)-1; (j) >= 0; --j) { n     int len = (int)((s[n - 1][j]).size()); n     for (int g = (len)-1; (g) >= 0; --g) n       if (s[n - 1][j][g] ==  0 ) n         ans.push_back(Move(n - 1, j, 0, j)), cnt0[j]++; n       else { n         if (j != m - 1) n           ans.push_back(Move(n - 1, j, n - 1, m - 1)), cnt1[m - 1]++; n         else n           ans.push_back(Move(n - 1, m - 1, n - 1, 0)), cnt1[0]++; n       } n   } n   for (int i = (1); (i) < (m); ++i) n     for (int g = 0; (g) < (cnt0[i]); ++g) ans.push_back(Move(0, i, 0, 0)); n   for (int i = 0; (i) < (m - 1); ++i) n     for (int g = 0; (g) < (cnt1[i]); ++g) n       ans.push_back(Move(n - 1, i, n - 1, m - 1)); n   vector<pair<int, int> > v; n   for (int i = (1); (i) < (n); ++i) n     for (int j = 0; (j) < (m - 1); ++j) { n       v.push_back(make_pair(i, j)); n     } n   for (int j = (1); (j) < (m - 1); ++j) v.push_back(make_pair(0, j)); n   for (int i = (1); (i) < (n - 1); ++i) v.push_back(make_pair(i, m - 1)); n   v.push_back(make_pair(0, 0)); n   v.push_back(make_pair(n - 1, m - 1)); n   v.push_back(make_pair(0, m - 1)); n   for (auto np : v) { n     int x = np.first, y = np.second; n     int len = (int)((t[x][y]).size()); n     for (int g = (len)-1; (g) >= 0; --g) { n       if (t[x][y][g] ==  0 ) n         go0(x, y); n       else n         go1(x, y); n     } n   } n   printf( %d n , (int)((ans).size())); n   for (auto mov : ans) { n     printf( %d %d %d %d n , mov.x_1 + 1, mov.y_1 + 1, mov.x_2 + 1, mov.y_2 + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   int cur = 1, cnt = 0; n   vector<int> dp(n + 1, 0); n   for (int i = 0; i < n; i++) dp[a[i]] = dp[a[i] - 1] + 1; n   for (int i = 1; i < n + 1; i++) cnt = max(cnt, dp[i]); n   cout << n - cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int b1, b2, h1, h2, n, h, i, j, k, a, b; n   cin >> n >> h >> a >> b >> k; n   if (a > b) { n     swap(a, b); n   } n   while (k--) { n     long long int ans = 0; n     cin >> b1 >> h1 >> b2 >> h2; n     if (b1 == b2) { n       ans += abs(h1 - h2); n     } else if (h1 >= b && h2 >= b) { n       ans += (h1 - b); n       ans += abs(b1 - b2); n       ans += (h2 - b); n     } else if (h1 <= a && h2 <= a) { n       ans += (a - h1); n       ans += abs(b1 - b2); n       ans += (a - h2); n     } else { n       ans += abs(b1 - b2); n       ans += abs(h1 - h2); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cc(int x) { n   for (int i = 2; i * i <= x; i++) n     if (x % i == 0 && x != 2) return false; n   return true; n } n int pow(int i, int j) { n   int x = 1; n   while (j--) { n     x *= i; n   } n   return x; n } n int main() { n   vector<int> v; n   int n; n   cin >> n; n   int c = 0; n   for (int i = 2; i <= n; i++) { n     if (cc(i)) { n       for (int j = 1; pow(i, j) <= n; j++) { n         v.push_back(pow(i, j)); n       } n     } n   } n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b[305]; n vector<int> g[305]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , b + i); n   b[0] = 0; n   g[0].push_back(0); n   for (int i = 1; i <= n; i++) { n     if (b[i] > b[i - 1]) { n       int temp = b[i] - b[i - 1]; n       for (int j = g[i - 1].size() - 1; j >= 0; j--) { n         int now = g[i - 1][j]; n         if (temp == 0) break; n         if (temp > 9 - now) { n           g[i].push_back(9); n           temp -= (9 - now); n         } else { n           g[i].push_back(now + temp); n           temp = 0; n           for (int k = j - 1; k >= 0; k--) g[i].push_back(g[i - 1][k]); n         } n       } n       while (temp) { n         if (temp >= 9) { n           g[i].push_back(9); n           temp -= 9; n         } else { n           g[i].push_back(temp); n           temp = 0; n         } n       } n     } else { n       int temp = b[i - 1] - b[i] + 1; n       int flag = g[i - 1].size() - 1; n       int sum = 0; n       for (int j = g[i - 1].size() - 1; j >= 0; j--) { n         sum += g[i - 1][j]; n         if (sum >= temp) { n           flag = j - 1; n           break; n         } n       } n       while (flag >= 0 && g[i - 1][flag] == 9) { n         flag--; n       } n       int p = flag; n       for (int j = g[i - 1].size() - 1; j >= flag + 1; j--) n         g[i].push_back(g[i - 1][j]); n       sort(g[i].begin(), g[i].end()); n       for (int j = 0; j < g[i].size(); j++) { n         if (temp > g[i][j]) { n           temp -= g[i][j]; n           g[i][j] = 0; n         } else { n           g[i][j] -= temp; n           temp = 0; n           break; n         } n       } n       reverse(g[i].begin(), g[i].end()); n       int ad = 1; n       for (int j = p; j >= 0; j--) { n         int now = g[i - 1][j]; n         if (now + ad == 10) { n           g[i].push_back(9); n           ad = 1; n         } else { n           g[i].push_back(now + ad); n           ad = 0; n         } n       } n       if (ad == 1) g[i].push_back(1); n     } n     reverse(g[i].begin(), g[i].end()); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < g[i].size(); j++) printf( %d , g[i][j]); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a; n int b, ans1, c[10], d; n int main() { n   cin >> a >> b; n   if (a ==  A ) { n     ans1 = 1; n     for (; b > 0; b /= 10) c[++d] = b % 10; n     for (int i = 1; i <= d; i++) { n       if (c[i] == 1) n         ans1 += 10; n       else n         ans1 += c[i]; n     } n   } n   if (a !=  A ) { n     for (; b > 0; b /= 10) c[++d] = b % 10; n     for (int i = 1; i <= d; i++) { n       if (c[i] == 1) n         ans1 += 10; n       else n         ans1 += c[i]; n     } n   } n   cout << ans1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<string> A(8); n   int mnA = 1e3, mnB = 1e3; n   for (int i = 0; i < 8; i++) cin >> A[i]; n   for (int i = 0; i < 8; i++) n     for (int u = 0; u < 8; u++) { n       if (A[i][u] ==  B ) { n         bool b = false; n         for (int j = i + 1; j < 8; j++) n           if (A[j][u] ==  B  || A[j][u] ==  W ) b = true; n         if (!b) mnB = min(mnB, 7 - i); n       } else if (A[i][u] ==  W ) { n         bool b = false; n         for (int j = i - 1; j >= 0; j--) { n           if (A[j][u] ==  B  || A[j][u] ==  W ) b = true; n         } n         if (!b) mnA = min(mnA, i); n       } n     } n   if (mnA <= mnB) n     cout <<  A ; n   else n     cout <<  B ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const double eps = 1e-8; n const double pi = acos(-1.0); n const int lim = 15; n int n, a[300010]; n int q; n long long c[300010]; n struct my { n   int a, b, id; n   my() {} n   my(int a, int b, int id) : a(a), b(b), id(id) {} n   bool operator<(const my &u) const { n     if (b == u.b) return a % b < u.a % b; n     return b < u.b; n   } n } b[300010]; n long long ans[300010]; n int l; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int w, e; n     scanf( %d%d , &w, &e); n     b[i] = my(w, e, i); n   } n   sort(b, b + q); n   for (int i = 0; i < q; i++) { n     if (b[i].b >= 500) { n       int id = b[i].id; n       for (int j = b[i].a; j <= n; j += b[i].b) ans[id] += a[j]; n       continue; n     } n     if (i == 0 || b[i].b != b[i - 1].b || n         (b[i].a % b[i].b != b[i - 1].a % b[i - 1].b)) { n       l = 1; n       int q = b[i].a, w = b[i].b; n       int t = q % w; n       if (t == 0) t = w; n       for (int j = t; j <= n; j += w) c[l] = c[l - 1] + a[j], l++; n       ans[b[i].id] = c[l - 1] - c[(q + w - 1) / w - 1]; n     } else { n       int q = b[i].a, w = b[i].b; n       ans[b[i].id] = c[l - 1] - c[(q + w - 1) / w - 1]; n     } n   } n   for (int i = 0; i < q; i++) printf( %I64d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int fu(vector<int> v) { n   int i; n   for (i = 0; i < 10; i++) { n     if (v[i] == 0) return i; n   } n   return i; n } n int ru(vector<int> v) { n   int i; n   for (i = 9; i >= 0; i--) { n     if (v[i] == 0) return i; n   } n   return i; n } n int main() { n   int n, k, i, ch = 0, ch1 = 9; n   cin >> n; n   string a; n   cin >> a; n   int a1 = 0, ch2 = 0; n   vector<int> ans(10, 0); n   for (i = 0; i < n; i++) { n     if (a[i] ==  L ) { n       ans[ch] = 1; n       ch = fu(ans); n     } else if (a[i] ==  R ) { n       ans[ch1] = 1; n       ch1 = ru(ans); n     } else if (isdigit((int)a[i])) { n       int ch2 = (int)a[i] - 48; n       ans[ch2] = 0; n       ch = fu(ans); n       ch1 = ru(ans); n     } n   } n   for (i = 0; i < 10; i++) cout << ans[i]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, x; n   cin >> t; n   while (t--) { n     cin >> x; n     long long a, b; n     a = x % 14; n     b = x / 14; n     if ((a <= 6 && a >= 1) && b > 0) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7, siz = 1e6 + 5; n long long q, n, m, a[siz], rot[66]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> q; n   while (q--) { n     long long op; n     cin >> op; n     if (op <= 2) { n       long long node, k; n       cin >> node >> k; n       long long dep = log2l(node); n       long long sz = 1LL << dep; n       if (k >= 0) n         k %= sz; n       else { n         k = sz + k; n         k %= sz; n       } n       rot[dep] += k; n       rot[dep] %= sz; n       if (op == 2) { n         long long incr = 2 * k; n         for (long long i = dep + 1; i <= 60; i++) { n           rot[i] += incr; n           rot[i] %= (1LL << i); n           incr *= 2; n         } n       } n       continue; n     } n     long long node; n     cin >> node; n     long long dep = log2l(node); n     long long pos_start = node - (1LL << dep); n     long long pos = (rot[dep] + pos_start) % (1LL << dep); n     vector<long long> out; n     while (dep > 0) { n       long long nxt = pos; n       long long incr = (1LL << dep) - rot[dep]; n       long long new_pos = (pos + incr) % (1LL << dep); n       long long inp = (1LL << dep) + new_pos; n       out.push_back(inp); n       pos = nxt + (1LL << dep); n       pos /= 2; n       dep--; n     } n     out.push_back(1); n     for (auto x : out) cout << x <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100 * 1000 + 10; n int n, t[MAXN]; n vector<int> v; n int main() { n   cin >> n >> t[0]; n   v.push_back(1); n   for (int i = 1; i < n; i++) { n     cin >> t[i]; n     if (t[i] == t[i - 1]) n       v[(int)v.size() - 1]++; n     else n       v.push_back(1); n   } n   int ans = 0; n   for (int i = 0; i < (int)v.size() - 1; i++) { n     ans = max(ans, 2 * min(v[i], v[i + 1])); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long k, n; n   cin >> n >> k; n   long long d, f = 0, f2 = 0; n   d = n / k; n   long long a[n + 1]; n   if (d < 3) { n     cout <<  -1  << endl; n   } else { n     while (n--) cout << ((n / k) % 2 + n) % k + 1 <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Q, N, M, K, L; n int A[5001]; n int MAPPING[10001]; n int CHK[10001]; n int RET[10001]; n map<int, int> MAP; n int map_idx = 0; n int main() { n   ios::sync_with_stdio(false); n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> A[i]; n     if (A[i] == 0) continue; n     int b = 1; n     int x = A[i]; n     if (x < 0) x *= -1; n     for (int j = 2; j * j <= x; j++) { n       int a = 0; n       while (x % j == 0) { n         a++; n         x /= j; n       } n       if (a & 1) b *= j; n     } n     b *= x; n     if (A[i] < 0) b *= -1; n     if (MAP.count(b) == 1) n       MAPPING[i] = MAP[b]; n     else { n       MAP[b] = map_idx++; n       MAPPING[i] = MAP[b]; n     } n   } n   int now = 0; n   for (int i = 0; i < N; i++) { n     for (int j = i; j < N; j++) { n       if (A[j] == 0) { n         RET[max(now, 1)]++; n         continue; n       } n       if (CHK[MAPPING[j]] == 0) { n         now++; n         CHK[MAPPING[j]] = 1; n       } n       RET[max(now, 1)]++; n     } n     now = 0; n     memset(CHK, 0, sizeof(CHK)); n   } n   for (int i = 1; i <= N; i++) cout << RET[i] <<    ; n   cin >> N; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   vector<string> st; n   vector<pair<string, string> > pr; n   pr.push_back(make_pair( purple ,  Power )); n   pr.push_back(make_pair( green ,  Time )); n   pr.push_back(make_pair( blue ,  Space )); n   pr.push_back(make_pair( orange ,  Soul )); n   pr.push_back(make_pair( red ,  Reality )); n   pr.push_back(make_pair( yellow ,  Mind )); n   cin >> n; n   string s; n   for (int i = 0; i < n; i++) { n     cin >> s; n     st.push_back(s); n   } n   int cnt = 0; n   vector<string> ans; n   for (int i = 0; i < pr.size(); i++) { n     int b = 0; n     for (int j = 0; j < st.size(); j++) n       if (pr[i].first == st[j]) { n         b = 1; n         break; n       } n     if (b == 0) { n       cnt++; n       ans.push_back(pr[i].second); n     } n   } n   cout << cnt << endl; n   for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1.0); n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const int N = 2e5 + 10; n const int M = 100; n char ch[N]; n int a[N]; n int b[N]; n int n; n vector<int> g[M]; n int pos[M]; n long long cnt; n void merge(int l, int mid, int r) { n   int i = l, j = mid + 1; n   for (int k = l; k <= r; k++) { n     if (j > r || i <= mid && a[i] <= a[j]) n       b[k] = a[i++]; n     else n       b[k] = a[j++], cnt += mid - i + 1; n   } n   for (int k = l; k <= r; k++) a[k] = b[k]; n } n void uqsort(int l, int r) { n   if (l < r) { n     int mid = (l + r) / 2; n     uqsort(l, mid); n     uqsort(mid + 1, r); n     merge(l, mid, r); n   } n } n void solve() { n   for (int i = 0; i < M; i++) g[i].clear(); n   scanf( %d , &n); n   scanf( %s , ch); n   for (int i = 0; i < n; i++) { n     g[ch[i] -  a ].push_back(n - i); n   } n   for (int i = 0; i < M; i++) sort(g[i].begin(), g[i].end()); n   memset(pos, 0, sizeof(pos)); n   for (int i = 1; i <= n; i++) { n     int j = i - 1; n     a[i] = g[ch[j] -  a ][pos[ch[j] -  a ]]; n     pos[ch[j] -  a ]++; n   } n   cnt = 0; n   uqsort(1, n); n   printf( %lld n , cnt); n } n int main() { n   ios::sync_with_stdio(false); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double eps = 1e-9; n const int MAXN = 1010; n const int EN = MAXN * MAXN; n int n, m, D; n int a[MAXN], size, head[MAXN]; n struct Node { n   int x, y; n } arr[MAXN]; n struct Edge { n   int v, w, next; n } E[EN]; n void init() { n   size = 0; n   memset(head, -1, sizeof(head)); n } n void addEdge(int u, int v, int w) { n   E[size].w = w; n   E[size].v = v; n   E[size].next = head[u]; n   head[u] = size++; n } n inline int dist(const Node& a, const Node& b) { n   return abs(a.x - b.x) + abs(a.y - b.y); n } n int d[MAXN]; n int dij(int src) { n   memset(d, INF, sizeof(d)); n   d[src] = 0; n   priority_queue<pair<int, int> > que; n   que.push(make_pair(0, src)); n   while (!que.empty()) { n     pair<int, int> x = que.top(); n     que.pop(); n     int u = x.second; n     if (d[u] != x.first) continue; n     for (int e = head[u]; e != -1; e = E[e].next) { n       int v = E[e].v; n       int w = d[u] + E[e].w - a[u]; n       if (w < d[v]) { n         d[v] = w; n         que.push(make_pair(d[v], v)); n       } n     } n   } n   return d[n - 1]; n } n int main() { n   a[0] = 0; n   while (~scanf( %d%d , &n, &D)) { n     init(); n     a[n - 1] = 0; n     for (int i = 1; i < n - 1; ++i) scanf( %d , &a[i]); n     for (int i = 0; i < n; ++i) scanf( %d%d , &arr[i].x, &arr[i].y); n     for (int i = 0; i < n; ++i) { n       for (int j = i + 1; j < n; ++j) { n         int dis = dist(arr[i], arr[j]); n         addEdge(i, j, dis * D); n         addEdge(j, i, dis * D); n       } n     } n     printf( %d n , dij(0)); n   } n   return 0; n } n