#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + (ch ^ 48); n     ch = getchar(); n   } n   return x * f; n } n int n, m, SG[55][55][55][55][2]; n char mp[55][55]; n int dfs(int x1, int y1, int x2, int y2, int type) { n   if (x1 > x2 || y1 > y2) return 0; n   if (SG[x1][y1][x2][y2][type] != -1) return SG[x1][y1][x2][y2][type]; n   bool vis[215]; n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       int x = i + j, y = i - j + m; n       if ((i + j) % 2 == type || x < x1 || x > x2 || y < y1 || y > y2) continue; n       int nxt = 0; n       if (mp[i][j] ==  L ) n         nxt = dfs(x + 1, y1, x2, y2, type) ^ dfs(x1, y1, x - 1, y2, type); n       else if (mp[i][j] ==  R ) n         nxt = dfs(x1, y + 1, x2, y2, type) ^ dfs(x1, y1, x2, y - 1, type); n       else n         nxt = dfs(x + 1, y + 1, x2, y2, type) ^ n               dfs(x1, y1, x - 1, y - 1, type) ^ n               dfs(x + 1, y1, x2, y - 1, type) ^ dfs(x1, y + 1, x - 1, y2, type); n       vis[nxt] = 1; n     } n   } n   int res = 0; n   while (vis[res]) ++res; n   return SG[x1][y1][x2][y2][type] = res; n } n int main() { n   memset(SG, -1, sizeof(SG)); n   n = read(); n   m = read(); n   for (int i = 1; i <= n; i++) scanf( %s , (mp[i] + 1)); n   int ans = (dfs(1, 1, n + m, n + m, 0) ^ dfs(1, 1, n + m, n + m, 1)); n   if (ans) n     puts( WIN ); n   else n     puts( LOSE ); n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long dx[] = {-1, 0, 1, 0}; n long long dy[] = {0, -1, 0, 1}; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> v(n); n   vector<long long> a; n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n     if (v[i] == 0) a.push_back(i); n   } n   for (long long i = 0; i < n; i++) { n     long long k = upper_bound(a.begin(), a.end(), i) - a.begin(); n     long long ans = abs(i - a[k]); n     if (k > 0) { n       ans = min(ans, abs(i - a[k - 1])); n     } n     cout << ans <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n struct Point { n   T x, y; n   Point() {} n   Point(T x_, T y_) : x(x_), y(y_) {} n   using pair = std::pair<T, T>; n   explicit operator pair() const { return pair(x, y); } n   friend bool operator==(const Point& a, const Point& b) { n     return pair(a) == pair(b); n   } n   friend bool operator!=(const Point& a, const Point& b) { n     return pair(a) != pair(b); n   } n   friend bool operator<(const Point& a, const Point& b) { n     return pair(a) < pair(b); n   } n   friend bool operator<=(const Point& a, const Point& b) { n     return pair(a) <= pair(b); n   } n   friend bool operator>(const Point& a, const Point& b) { n     return pair(a) > pair(b); n   } n   friend bool operator>=(const Point& a, const Point& b) { n     return pair(a) >= pair(b); n   } n   friend std::ostream& operator<<(std::ostream& o, const Point& p) { n     return o <<  (  << p.x <<  ,  << p.y <<  ) ; n   } n   friend std::istream& operator>>(std::istream& i, Point& p) { n     return i >> p.x >> p.y; n   } n   Point& operator+=(const Point& p) { n     x += p.x; n     y += p.y; n     return *this; n   } n   Point& operator-=(const Point& p) { n     x -= p.x; n     y -= p.y; n     return *this; n   } n   friend Point operator+(const Point& a, const Point& b) { n     return Point(a) += b; n   } n   friend Point operator-(const Point& a, const Point& b) { n     return Point(a) -= b; n   } n   T cross(const Point& p) const { return x * p.y - y * p.x; } n   T cross(const Point& p, const Point& q) const { n     return (p - *this).cross(q - *this); n   } n }; n using Pt = Point<int>; n const int MAXN = 7000; n int A, B; n int N; n struct City { n   Pt pt; n   int id; n   int deg; n   friend bool operator<(const City& a, const City& b) { return a.pt < b.pt; } n } pts[MAXN]; n int hsz; n int hull[MAXN]; n void solve(int st, int en) { n   if (st == en) return; n   if (pts[st].deg == -1) return solve(st + 1, en); n   if (pts[en].deg == -1) return solve(st, en - 1); n   int len = 0; n   int totdeg = 0; n   for (int i = st; i <= en; i++) { n     if (pts[i].deg == -1) continue; n     len++; n     totdeg += pts[i].deg; n   } n   assert(len); n   assert(totdeg == len - 1); n   assert(len >= 2); n   { n     hsz = 0; n     for (int i = 0; i <= (en - st) * 2; i++) { n       int cur = (i <= (en - st) ? (st + i) : (en + (en - st) - i)); n       if (pts[cur].deg == -1) continue; n       while (hsz >= 2 && hull[hsz - 1] != en) { n         if (pts[hull[hsz - 2]].pt.cross(pts[hull[hsz - 1]].pt, pts[cur].pt) < n             0) { n           break; n         } else { n           hsz--; n         } n       } n       hull[hsz++] = cur; n     } n     hsz--; n     assert(hsz >= 2); n     assert(hull[hsz] == hull[0]); n     for (int ind = 0; ind < hsz; ind++) { n       int a = hull[ind], b = hull[ind + 1]; n       assert(pts[a].deg != -1 && pts[b].deg != -1); n       if (pts[a].deg == 0 && pts[b].deg > 0) { n         cout << pts[b].id <<     << pts[a].id <<   n ; n         pts[b].deg--; n         if (pts[b].deg == 0) { n           pts[b].deg = -1; n         } else { n           pts[a].deg = -1; n         } n         return solve(st, en); n       } n     } n   } n   int pref = 0; n   int lsz = 0; n   for (int i = st; i <= en; i++) { n     if (pts[i].deg == -1) continue; n     int suff = pref + (pts[i].deg - 1); n     lsz++; n     if (lsz > 1 && lsz < len && (pref >= 0) != (suff >= 0)) { n       int ldeg, rdeg; n       if (pts[i].deg > 0) { n         assert(pref < 0 && suff >= 0); n         ldeg = -pref; n         rdeg = suff + 1; n         assert(ldeg + rdeg == pts[i].deg); n       } else { n         ldeg = 0; n         rdeg = 0; n       } n       pts[i].deg = ldeg; n       solve(st, i); n       pts[i].deg = rdeg; n       solve(i, en); n       return; n     } n     pref = suff; n   } n   assert(false); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int T; n   cin >> T; n   while (T--) { n     cin >> A >> B; n     N = A + B; n     for (int i = 0; i < A; i++) { n       pts[i].deg = 0; n       pts[i].id = i + 1; n     } n     for (int i = A; i < A + B; i++) { n       cin >> pts[i].deg; n       assert(pts[i].deg > 0); n       pts[i].id = i - A + 1; n     } n     for (int i = 0; i < N; i++) { n       cin >> pts[i].pt; n     } n     sort(pts, pts + N); n     cout <<  YES  <<   n ; n     solve(0, N - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n const double PI = 3.141592653589793238; n using namespace std; n long long takeTurn(long long n) { n   if (n % 2 == 1) return n - 1; n   if (n % 4 == 0 && n > 4) return n - 1; n   return n / 2; n } n void solve() { n   long long n, res = 0; n   cin >> n; n   while (n > 0) { n     long long t1 = takeTurn(n); n     res += n - t1; n     n = t1; n     n = takeTurn(n); n   } n   cout << res << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   long t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[110][110]; n int main() { n   int n, m, i, j; n   while (~scanf( %d %d , &n, &m)) { n     for (i = 0; i < n; i++) n       for (j = 0; j < m; j++) scanf( %d , &a[i]); n     if (n & 1) { n       cout << n << endl; n       continue; n     } n     int vis; n     for (i = 0; i < m; i++) { n       for (j = 0, vis = 0; j < n; j++) { n         if (a[j][i] != a[n - j - 1][i]) { n           vis = 1; n           break; n         } n       } n       if (vis) break; n     } n     if (vis) n       cout << n << endl; n     else { n       while (1) { n         n /= 2; n         if (n == 1 || (n & 1)) { n           cout << n << endl; n           break; n         } n         for (i = 0; i < m; i++) { n           for (j = 0, vis = 0; j < n; j++) { n             if (a[j][i] != a[n - j - 1][i]) { n               vis = 1; n               break; n             } n           } n           if (vis) break; n         } n         if (vis) { n           cout << n << endl; n           break; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int k = 0; n   int a, b, c; n   string s1, s2, s3; n   cin >> s1 >> s2 >> s3; n   a = s1.size(); n   b = s2.size(); n   c = s3.size(); n   if ((a + b) != c) { n     cout <<  NO ; n     return 0; n   } n   s1 = s1 + s2; n   for (int i = 0; i < c; i++) { n     for (int j = 0; j < c; j++) { n       if (s1[i] == s3[j]) { n         k++; n         s3[j] =  0 ; n         break; n       } n     } n   } n   if (k == c) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n == 2) n     cout << 1 << endl << 1; n   else if (n == 3) n     cout << 2 << endl <<  1 3 ; n   else { n     cout << n << endl; n     for (int i = 2; i <= n; i += 2) cout << i <<    ; n     for (int i = 1; i <= n; i += 2) cout << i <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n int dist(int from, int to, int count) { n   if (from <= to) { n     return to - from; n   } else { n     return dist(from, count - 1, count) + dist(0, to, count) + 1; n   } n } n void output(const std::vector<int64_t>& boxes); n std::vector<int64_t> recover(const std::vector<int64_t>& boxes, int lastBox) { n   std::vector<int64_t> result(boxes.size()); n   int minValue = *std::min_element(boxes.begin(), boxes.end()); n   int index = -1; n   int minDist = -1; n   for (size_t i = 0; i < boxes.size(); ++i) { n     if (boxes[i] == minValue) { n       if (index == -1 || minDist > dist(i, lastBox, boxes.size())) { n         index = i; n         minDist = dist(i, lastBox, boxes.size()); n       } n     } n   } n   int64_t wasBalls = n       boxes[index] * boxes.size() + dist(index, lastBox, boxes.size()); n   for (size_t i = 0; i < boxes.size(); ++i) { n     if (i == index) { n       result[i] = wasBalls; n     } else { n       int dst = dist(index, i, boxes.size()) - 1; n       if (wasBalls >= dst) { n         int64_t rem = wasBalls - dst; n         int64_t add = rem / boxes.size(); n         if (rem % boxes.size() != 0) { n           ++add; n         } n         result[i] = boxes[i] - add; n         assert(result[i] >= 0); n       } else { n         result[i] = boxes[i]; n       } n     } n   } n   return result; n } n void output(const std::vector<int64_t>& boxes) { n   for (size_t i = 0; i < boxes.size(); ++i) { n     cout << boxes[i] <<    ; n   } n   cout <<   n ; n } n void input(std::vector<int64_t>* boxes, int* lastBox) { n   int count; n   cin >> count >> *lastBox; n   --(*lastBox); n   boxes->resize(count); n   for (int i = 0; i < count; ++i) { n     cin >> (*boxes)[i]; n   } n } n void stressTest() { n   int N = 10; n   for (int tc = 0; tc < 1000; ++tc) { n     std::vector<int64_t> a(N); n     for (size_t i = 0; i < a.size(); ++i) { n       if (rand() % 4 == 0) { n         a[i] = 0; n       } else { n         a[i] = rand() % 1000; n       } n     } n     int start = -1; n     while (true) { n       start = rand() % N; n       if (a[start] == 0) { n         continue; n       } n       break; n     } n     int cnt = a[start]; n     int realCnt = cnt; n     a[start] = 0; n     int i = (start + 1) % N; n     for (; cnt > 0; cnt--, i = (i + 1) % N) { n       ++a[i]; n     } n     int end = (i + N - 1) % N; n     std::vector<int64_t> b = recover(a, end); n     assert(b[start] == realCnt); n     b[start] = 0; n     i = (start + 1) % N; n     cnt = realCnt; n     for (; cnt > 0; cnt--, i = (i + 1) % N) { n       ++b[i]; n     } n     if (a != b) { n       cout << end + 1 <<   n ; n       output(a); n       output(b); n       exit(0); n     } n     assert(a == b); n   } n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::vector<int64_t> boxes; n   int lastBox; n   input(&boxes, &lastBox); n   output(recover(boxes, lastBox)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, a, b; n void fn() { n   cin >> a >> b; n   if (a < b) swap(a, b); n   a -= b; n   int ans = a / 5; n   a %= 5; n   if (a == 1 || a == 2) n     ans++; n   else if (a == 3 || a == 4) n     ans += 2; n   cout << ans << endl; n } n int main() { n   cin >> t; n   while (t--) fn(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[300005]; n void input() { n   int i, l, r, x, cur, n, ne; n   set<int> alive; n   set<int>::iterator ite; n   vector<int> xoa; n   scanf( %d %d , &n, &ne); n   for ((i) = (1); (i) <= (n); (i)++) alive.insert(i); n   for ((i) = 0; (i) < (ne); (i)++) { n     scanf( %d %d %d , &l, &r, &x); n     xoa.clear(); n     ite = alive.lower_bound(l); n     while (ite != alive.end()) { n       cur = *ite; n       if (cur > r) break; n       if (cur != x) ans[cur] = x, xoa.push_back(cur); n       ite++; n     } n     for (typeof(xoa.begin()) jte = xoa.begin(); jte != xoa.end(); jte++) n       alive.erase(*jte); n   } n   for ((i) = (1); (i) <= (n); (i)++) printf( %d  , ans[i]); n } n int main() { n   input(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100005; n int a[MAX]; n int main() { n   ios::sync_with_stdio(false); n   int n, k; n   cin >> n >> k; n   n = 2 * n + 1; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 1; i < n - 1 && k; i++) n     if (a[i - 1] + 1 < a[i] && a[i] > a[i + 1] + 1) { n       a[i]--; n       k--; n     } n   for (int i = 0; i < n; i++) cout << a[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long a[n], b[n + 1]; n   vector<pair<int, int>> c; n   for (int i = 0; i < n; i++) cin >> a[i]; n   unordered_map<long long, long long> mp, mp1; n   vector<vector<int>> v; n   v.assign(n + 1, vector<int>()); n   for (int i = 0; i < n; i++) { n     mp[a[i]]++; n     v[n - a[i]].push_back(i + 1); n   } n   for (auto it : mp) { n     c.push_back({it.second / (n - it.first), n - it.first}); n   } n   int x = 0; n   for (int i = 0; i < c.size(); i++) x += (c[i].first) * (c[i].second); n   if (x != n) n     cout <<  Impossible ; n   else { n     int y = 1; n     cout <<  Possible n ; n     for (auto it : c) { n       for (int j = 0; j < it.first; j++) { n         for (int k = 0; k < it.second; k++) { n           x = *v[it.second].rbegin(); n           v[it.second].pop_back(); n           b[x] = y; n         } n         y += 1; n       } n     } n     for (int i = 1; i <= n; i++) cout << b[i] <<    ; n   } n } n


#include <bits/stdc++.h> n int f[105][25][25], g[25][25], n, k, u, v; n std::vector<int> ch[105]; n using ll = long long; n const int mod = 1e9 + 7; n void dfs(int u, int fa) { n   f[u][0][1] = f[u][k][0] = 1; n   for (int v : ch[u]) { n     if (v == fa) continue; n     dfs(v, u); n     std::memcpy(g, f[u], sizeof(f[u])); n     std::memset(f[u], 0, sizeof(f[u])); n     for (int a = 0; a <= k; ++a) n       for (int b = 0; b <= k; ++b) n         for (int c = 0; c <= k; ++c) n           for (int d = 0; d <= k; ++d) { n             int d1 = b, d2 = d; n             if (d1 <= c) d1 = 0; n             if (d2 <= a) d2 = 0; n             int i = std::max(a, c - 1); n             int j = std::max(d1, d2 + (d2 != 0)); n             if (j <= k) n               f[u][i][j] = (f[u][i][j] + (ll)g[a][b] * f[v][c][d] % mod) % mod; n           } n   } n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &u, &v); n     ch[u].push_back(v); n     ch[v].push_back(u); n   } n   dfs(1, 0); n   int ans = 0; n   for (int i = 0; i <= k; ++i) ans = (ans + f[1][i][0]) % mod; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n int a[30][2 * 100000 + 5], cnt[30]; n char s[2 * 100000 + 5], t[2 * 100000 + 5]; n long long max(long long a, long long b) { n   if (a > b) n     return a; n   else n     return b; n } n int main() { n   long long i, j, n, len, m, maxn; n   scanf( %lld , &n); n   scanf( %s , s); n   for (i = 0; i < n; i++) { n     cnt[s[i] -  a ]++; n     a[s[i] -  a ][cnt[s[i] -  a ]] = i; n   } n   scanf( %lld , &m); n   while (m--) { n     memset(cnt, 0, sizeof(cnt)); n     scanf( %s , t); n     len = strlen(t); n     maxn = 0; n     for (i = 0; i < len; i++) { n       maxn = max(maxn, a[t[i] -  a ][cnt[t[i] -  a ] + 1] + 1); n       cnt[t[i] -  a ]++; n     } n     printf( %lld n , maxn); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, a, b, c, d, t, input; n   vector<int> vi; n   for (i = 1; i <= 370; i++) { n     t = i; n     if (t <= 9) { n       vi.push_back(t); n     } else if (t >= 10 && t < 100) { n       a = t % 10; n       t = t / 10; n       b = t; n       vi.push_back(b); n       vi.push_back(a); n     } else if (t >= 100 && t < 1000) { n       c = t % 10; n       t = t / 10; n       b = t % 10; n       t = t / 10; n       a = t; n       vi.push_back(a); n       vi.push_back(b); n       vi.push_back(c); n     } else if (t >= 1000) { n       d = t % 10; n       t /= 10; n       c = t % 10; n       t /= 10; n       b = t % 10; n       t /= 10; n       a = t % 10; n       vi.push_back(a); n       vi.push_back(b); n       vi.push_back(c); n       vi.push_back(d); n     } n   } n   while (cin >> input) { n     cout << vi[input - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class DFS { n   int N_, R_; n   vector<vector<int> > G_; n   vector<int> par_, dep_, dep_sub_; n   void DFS_internal(int v) { n     dep_sub_[v] = 0; n     for (auto u : G_[v]) n       if (par_[u] == -1) { n         par_[u] = v; n         dep_[u] = dep_[v] + 1; n         DFS_internal(u); n         dep_sub_[v] = max(dep_sub_[v], dep_sub_[u] + 1); n       } n   } n  n  public: n   DFS(vector<vector<int> >& G, int R) : N_(G.size()), R_(R), G_(G) { n     par_.resize(N_, -1); n     dep_.resize(N_); n     dep_sub_.resize(N_); n     par_[R_] = R_; n     dep_[R_] = 0; n     DFS_internal(R_); n   } n   int max_dep_id() { n     int ret = -1, max_dep = -1; n     for (int i = 0; i < N_; i++) n       if (max_dep < dep_[i]) { n         max_dep = dep_[i]; n         ret = i; n       } n     return ret; n   } n   int dep(int v) { return dep_[v]; } n   int par(int v) { return par_[v]; } n   int dep_subtree(int v) { return dep_sub_[v]; } n }; n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   int N, K; n   cin >> N >> K; n   vector<vector<int> > G(N); n   for (int i = 0; i < N - 1; i++) { n     int u, v; n     cin >> u >> v; n     G[--u].push_back(--v); n     G[v].push_back(u); n   } n   DFS DFS0(G, 0); n   int R1 = DFS0.max_dep_id(); n   DFS DFS1(G, R1); n   int R2 = DFS1.max_dep_id(); n   DFS DFS2(G, R2); n   int D = DFS1.dep(R2); n   if (K == 2) { n     cout <<  Yes n ; n     for (int i = 0; i < N; i++) n       cout << DFS1.dep(i) % 2 + 1 << ((i == N - 1) ?   n  :    ); n     return 0; n   } n   vector<int> ans(N); n   for (int i = 0; i < N; i++) { n     if (DFS1.dep(i) + DFS2.dep(i) - D == 0) { n       ans[i] = DFS1.dep(i) % K + 1; n       continue; n     } n     int d1 = DFS1.dep_subtree(i) + DFS1.dep(i); n     int d2 = DFS1.dep_subtree(i) + DFS2.dep(i); n     if (min(d1, d2) >= K - 1) { n       cout <<  No n ; n       return 0; n     } n     if (max(d1, d2) < K - 1) { n       ans[i] = 1; n       continue; n     } n     if (d1 > d2) n       ans[i] = DFS1.dep(i) % K + 1; n     else n       ans[i] = (D + K - DFS2.dep(i) % K) % K + 1; n   } n   cout <<  Yes n ; n   for (int i = 0; i < N; i++) cout << ans[i] << ((i == N - 1) ?   n  :    ); n } n


#include <bits/stdc++.h> n #define ll long long  n #define INF INT_MAX n #define pii pair<int,int> n using namespace std; n  n const int maxn=1e3+10; n const int mod=998244353; n int main(){ n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     ll N,K; n     cin>>N>>K; n     vector<vector<ll>> p(maxn); n     vector<ll> s1(maxn,0); n     vector<ll> s2(maxn,0); n     ll tem; n     for(int i=0;i<K;i++){ n         for(int j=0;j<N;j++){ n             cin>>tem; n             p[i].push_back(tem); n             s1[i]+=tem; n             s2[i]+=(tem*tem); n         } n     } n     map<ll,ll> cnt; n     map<ll,ll> cnt2; n     ll tem2; n  n     for(int i=1;i<=6;i++){ n         tem=s1[i]-s1[i-1]; n         tem2=s2[i-1]+s2[i+1]-2*s2[i]; n         if(cnt.find(tem)==cnt.end()){ n             cnt[tem]=0; n         } n         else n             cnt[tem]++; n         if(i!=6){ n             if(cnt2.find(tem2)==cnt2.end()){ n                 cnt2[tem2]=0; n             } n             else n                 cnt2[tem2]++; n         } n     } n     ll d,sq; n     auto it=cnt.begin(); n     if(it->second>=3) n     d=it->first; n     else{ n         it++; n         d=it->first; n     } n     auto it2=cnt2.begin(); n     if(it2->second>=2) n     sq=it2->first; n     else{ n         it2++; n         sq=it2->first; n     } n     //cout<<sq<<  n ; n     ll er; n     for(int i=0;i<K-1;i++){ n         if(s1[i+1]-s1[i]!=d){ n             er=i+1; n             break; n         } n     } n     if(er==1 && s1[2]-s1[1]==d){ n         er=0; n     } n     ll dif,dif2; n     tem=0; n     for(int i=0;i<N;i++){ n         tem+=(p[er][i]*p[er][i]); n     } n     //cout<<tem<<  n ; n     if(er==0) n     dif=s1[er+1]-d-s1[er]; n     else n     dif=s1[er-1]+d-s1[er]; n     //cout<<dif<<  n ; n     ll ans=0; n     for(int i=0;i<N;i++){ n         if(er<=K-3){ n             if(s2[er+2]-2*s2[er+1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){ n                 ans=p[er][i]+dif; n                 break; n             } n         } n         else{ n             if(s2[er-2]-2*s2[er-1]+s2[er]-p[er][i]*p[er][i]+(p[er][i]+dif)*(p[er][i]+dif)==sq){ n                 ans=p[er][i]+dif; n                 break; n             } n         } n     } n     cout<<er<<   <<ans<<  n ; n }


#include <bits/stdc++.h> n using namespace std; n const int N = 5010; n struct T { n   int a, b, i; n   T() {} n   T(int a, int b, int i) : a(a), b(b), i(i) {} n   bool operator<(const T &other) const { return a > other.a; } n }; n const int inf = 1e9; n int n, m, k, dp[N][N], f[N][N]; n T a[N]; n vector<int> ga, gb; n int fsolve(int i, int j) { n   if (f[i][j] != -1) return f[i][j]; n   if (i > n) { n     if (j == k) n       f[i][j] = 0; n     else n       f[i][j] = -inf; n     return f[i][j]; n   } n   f[i][j] = fsolve(i + 1, j); n   if (j < k) f[i][j] = max(f[i][j], fsolve(i + 1, j + 1) + a[i].b); n   if (f[i][j] < 0) f[i][j] = -inf; n   return f[i][j]; n } n int solve(int i, int j) { n   if (dp[i][j] != -1) return dp[i][j]; n   if (i > n) { n     if (j == m) n       dp[i][j] = 0; n     else n       dp[i][j] = -inf; n     return dp[i][j]; n   } n   int p = i - 1 - j; n   if (j == m) { n     dp[i][j] = fsolve(i, p); n     return dp[i][j]; n   } n   dp[i][j] = solve(i + 1, j + 1) + a[i].a; n   if (p != k) dp[i][j] = max(dp[i][j], solve(i + 1, j) + a[i].b); n   if (dp[i][j] < 0) dp[i][j] = -inf; n   return dp[i][j]; n } n void fsolve1(int i, int j) { n   if (i > n) { n     return; n   } n   if (f[i][j] == f[i + 1][j]) n     fsolve1(i + 1, j); n   else { n     gb.push_back(a[i].i); n     fsolve1(i + 1, j + 1); n   } n } n void solve1(int i, int j) { n   if (i > n) { n     return; n   } n   int p = i - 1 - j; n   if (j == m) { n     fsolve1(i, p); n     return; n   } n   if (dp[i][j] == dp[i + 1][j + 1] + a[i].a) { n     ga.push_back(a[i].i); n     solve1(i + 1, j + 1); n   } else { n     gb.push_back(a[i].i); n     solve1(i + 1, j); n   } n } n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) cin >> a[i].a; n   for (int i = 1; i <= n; i++) cin >> a[i].b; n   for (int i = 1; i <= n; i++) a[i].i = i; n   sort(a + 1, a + n + 1); n   memset(f, -1, sizeof(f)); n   memset(dp, -1, sizeof(dp)); n   cout << solve(1, 0) << endl; n   solve1(1, 0); n   for (int i = 0; i < ga.size(); i++) cout << ga[i] <<    ; n   cout << endl; n   for (int i = 0; i < gb.size(); i++) cout << gb[i] <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1001][3] = {0}; n int b[1001] = {0}; n int c[1001] = {0}; n vector<int> a1, a2, a3; n int main() { n   int n, m, i, x, y, z; n   int ans, t = 0; n   scanf( %d%d , &n, &m); n   for (i = 0; i < m; i++) { n     scanf( %d%d%d , &x, &y, &z); n     a[x][0] = y; n     a[x][1] = z; n     b[x]++; n     c[y]++; n   } n   for (i = 1; i <= n; i++) { n     if (b[i] == 1 && c[i] == 0) { n       x = i; n       ans = 1000001; n       do { n         if (a[x][0] > 0) { n           ans = min(ans, a[x][1]); n           x = a[x][0]; n         } else n           break; n       } while (1); n       a1.push_back(i); n       a2.push_back(x); n       a3.push_back(ans); n     } n   } n   printf( %d n , a1.size()); n   for (i = 0; i < a1.size(); i++) printf( %d %d %d n , a1[i], a2[i], a3[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k, i, j, total, cnt; n   cin >> n >> k; n   double r, g, b; n   r = ceil((n * 2.0) / k); n   g = ceil((n * 5.0) / k); n   b = ceil((n * 8.0) / k); n   cout << int(r + g + b) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x6fffffff; n const int MINF = 0x80000000; n const int mod = 1000000007; n const int cons = 100001; n const double pi = 3.141592653589793; n int dy2[2] = {1, 0}; n int dx2[2] = {0, -1}; n int dy1[2] = {0, 1}; n int dx1[2] = {1, 0}; n int n, m; n int main() { n   vector<vector<bool> > M; n   vector<vector<int> > km, lm; n   scanf( %d%d , &n, &m); n   M.resize(n + 1, vector<bool>(m + 1, false)); n   km.resize(n + 1, vector<int>(m + 1, -1)); n   lm.resize(n + 1, vector<int>(m + 1, -1)); n   vector<pair<int, int> > pos[10005]; n   queue<pair<int, int> > qu; n   qu.push(make_pair(1, 1)); n   km[1][1] = 2; n   pos[2].push_back(make_pair(1, 1)); n   while (!qu.empty()) { n     int y = qu.front().first; n     int x = qu.front().second; n     qu.pop(); n     for (int i = 0; i < 2; i++) { n       int ty = y + dy1[i]; n       int tx = x + dx1[i]; n       if (ty < 1 || ty > n || tx < 1 || tx > m) continue; n       if (km[ty][tx] != -1) continue; n       km[ty][tx] = km[y][x] + 1; n       pos[km[ty][tx]].push_back(make_pair(ty, tx)); n       qu.push(make_pair(ty, tx)); n     } n   } n   qu.push(make_pair(1, m)); n   lm[1][m] = 2; n   while (!qu.empty()) { n     int y = qu.front().first; n     int x = qu.front().second; n     qu.pop(); n     for (int i = 0; i < 2; i++) { n       int ty = y + dy2[i]; n       int tx = x + dx2[i]; n       if (ty < 1 || ty > n || tx < 1 || tx > m) continue; n       if (lm[ty][tx] != -1) continue; n       lm[ty][tx] = lm[y][x] + 1; n       qu.push(make_pair(ty, tx)); n     } n   } n   map<int, int> K, L; n   int k; n   scanf( %d , &k); n   for (int i = 1; i <= k; i++) { n     int x; n     scanf( %d , &x); n     K[x]++; n   } n   int l; n   scanf( %d , &l); n   for (int i = k + 1; i <= l + k; i++) { n     int x; n     scanf( %d , &x); n     L[x]++; n   } n   for (int i = n + m; i >= 2; i--) { n     for (int j = 0; j < pos[i].size(); j++) { n       int y = pos[i][j].first; n       int x = pos[i][j].second; n       int lvl = lm[y][x]; n       auto it = K.lower_bound(i); n       auto it2 = L.lower_bound(lvl); n       if (it == K.end() && it2 == L.end()) { n         puts( NO ); n         return 0; n       } else if (it == K.end()) { n         it2->second--; n         if (it2->second == 0) { n           L.erase(it2); n         } n       } else if (it2 == L.end()) { n         it->second--; n         if (it->second == 0) { n           K.erase(it); n         } n       } else { n         it2->second--; n         if (it2->second == 0) { n           L.erase(it2); n         } n       } n     } n   } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long dx[4] = {-1, 0, 1, 0}; n const long long dy[4] = {0, -1, 0, 1}; n const long long dxx[] = {1, 1, 0, -1, -1, -1, 0, 1}; n const long long dyy[] = {0, 1, 1, 1, 0, -1, -1, -1}; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   n ; n   err(++it, args...); n } n long long gcd(long long a, long long b) { n   if (!b) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n long long modexpo(long long x, long long n, long long M) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) n     return modexpo((x * x) % M, n / 2, M); n   else n     return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M; n } n long long bexpo(long long x, long long n) { n   if (n == 0) n     return 1; n   else if (n % 2 == 0) n     return bexpo(x * x, n / 2); n   else n     return x * bexpo(x * x, (n - 1) / 2); n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n const long long mod = 1e9 + 7; n const long long N = 4e5 + 5; n const long long INF = 1e18; n void solve() { n   long long n; n   cin >> n; n   ; n   string second; n   cin >> second; n   vector<long long> a; n   for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n)); n        i += 1 - 2 * ((0) > (n))) n     a.push_back(second[i] -  0 ); n   long long sum = 0; n   for (__typeof(n - 1) k = (0) - ((0) > (n - 1)); n        k != (n - 1) - ((0) > (n - 1)); k += 1 - 2 * ((0) > (n - 1))) { n     sum += a[k]; n     long long c_sum = 0; n     for (__typeof(n) i = (k + 1) - ((k + 1) > (n)); i != (n) - ((k + 1) > (n)); n          i += 1 - 2 * ((k + 1) > (n))) { n       if (a[i] == 0) { n         continue; n       } n       if (c_sum == sum) { n         c_sum = 0; n       } n       c_sum += a[i]; n       if (c_sum > sum) { n         break; n       } n     } n     if (c_sum == sum) { n       cout <<  YES  n            <<   n ; n       ; n       return; n     } n   } n   cout <<  NO  n        <<   n ; n   ; n } n int32_t main() { n   long long t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, x, k, mult = 1; n   cin >> n >> k >> x; n   while (k--) { n     mult *= x; n   } n   vector<long long> pre(n + 1, 0), suf(n + 2, 0), v(n + 1, 0); n   for (long long i = 1; i <= n; i++) { n     cin >> v[i]; n     pre[i] = pre[i - 1] | v[i]; n   } n   for (long long i = n; i >= 1; i--) suf[i] = suf[i + 1] | v[i]; n   long long ans = 0; n   for (long long i = 1; i <= n; i++) n     ans = max(ans, pre[i - 1] | (mult * v[i]) | suf[i + 1]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n int lp[MAXN]; n vector<int> pr; n int ans[MAXN]; n int main() { n   for (int i = 2; i < MAXN; ++i) { n     ans[i] = 0; n     if (lp[i] == 0) { n       lp[i] = i; n       pr.push_back(i); n     } n     for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i] && i * pr[j] < MAXN; n          ++j) n       lp[i * pr[j]] = pr[j]; n   } n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int s; n     cin >> s; n     while (s > 1) { n       int d = lp[s]; n       ans[d]++; n       while (s % d == 0) { n         s /= d; n       } n     } n   } n   int res = 0; n   for (int i = 2; i < MAXN; i++) { n     res = (res > ans[i] ? res : ans[i]); n   } n   cout << (res > 1 ? res : 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v; n   int c; n   for (int i = 0; i < n; i++) { n     cin >> c; n     v.push_back(c); n   } n   if (n == 1) { n     if (v[0] == 1) { n       cout <<  YES ; n       return 0; n     } n   } n   sort(v.begin(), v.end()); n   if (v[0] == 0 && v[1] == 1) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k, x; n long long eval(long long x) { n   long long ret = 0; n   if (x % 4 == 0) { n     return x / 4; n   } else { n     if (x % 4 == 3) { n       x -= 15; n       ret++; n       ret++; n     } else if (x % 4 == 2) { n       x -= 6; n       ret++; n     } else if (x % 4 == 1) { n       x -= 9; n       ret++; n     } n     if (x < 0) n       return -1; n     else n       return ret + x / 4; n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < (n); ++i) { n     cin >> x; n     printf( %lld n , eval(x)); n   } n } n


#include <bits/stdc++.h> n const int N = 1000; n int n, k; n struct point { n   int x, y; n   point operator-(const point &rhs) const { n     return (point){x - rhs.x, y - rhs.y}; n   } n } a[7], b[N]; n bool same_sgn(int x, int y) { return !x || !y || (x > 0) == (y > 0); } n bool collinear(point a, point b) { n   return (long long)a.x * b.y == (long long)a.y * b.x && same_sgn(a.x, b.x) && n          same_sgn(a.y, b.y); n } n bool on_segment(point a, point b, point c) { n   return collinear(a - b, c - b) && collinear(a - c, b - c); n } n std::vector<int> need[N][7]; n bool unable[N][7], shot[N]; n int p[7], id, ans; n bool dfs(int target) { n   if (id == k) return 0; n   int i = p[id++]; n   bool success = 1; n   if (unable[target][i]) return 0; n   for (int nxt : need[target][i]) n     if (!shot[nxt] && !dfs(nxt)) return 0; n   return shot[target] = 1; n } n int main() { n   std::ios::sync_with_stdio(0), std::cin.tie(0); n   std::cin >> k >> n; n   for (int i = 0; i < k; ++i) std::cin >> a[i].x >> a[i].y; n   for (int i = 0; i < n; ++i) std::cin >> b[i].x >> b[i].y; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < k; ++j) n       for (int p = 0; p < n; ++p) n         if (p != i && on_segment(b[p], b[i], a[j])) { n           need[i][j].emplace_back(p); n           if (need[i][j].size() >= k) { n             unable[i][j] = 1; n             break; n           } n         } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < k; ++j) p[j] = j; n     do n       if (dfs((std::memset(shot, id = 0, sizeof shot), i))) { n         ++ans; n         break; n       } n     while (std::next_permutation(p, p + k)); n   } n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   cout << (n / 2) - (n % 2) * n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int a, b, c, m; n   int flag = 0; n   int c1 = 0, c2 = 0, c3 = 0; n   int t; n   cin >> a >> b >> c >> m; n   t = 0; n   for (int i = min(c, m); i <= 2 * c && i <= 2 * m; i++) { n     if ((m <= i && 2 * m >= i) && (c <= i && 2 * c >= i)) { n       t = 1; n       c3 = i; n       break; n     } n   } n   if (t == 0) { n     flag = 1; n   } n   if (flag == 0) { n     t = 0; n     for (int i = b; i <= 2 * b; i++) { n       if ((m <= i) && (b <= i && 2 * b >= i) && i > c3 && (2 * m < i)) { n         t = 1; n         c2 = i; n         break; n       } n     } n     if (t == 0) { n       flag = 1; n     } n   } n   if (flag == 0) { n     t = 0; n     for (int i = a; i <= 2 * a; i++) { n       if ((m <= i) && (a <= i && 2 * a >= i) && i > c2 && (2 * m < i)) { n         t = 1; n         c1 = i; n         break; n       } n     } n     if (t == 0) { n       flag = 1; n     } n   } n   if (flag == 1) { n     cout <<  -1 n ; n   } else { n     cout << c1 <<   n  << c2 <<   n  << c3 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1e5 + 10; n inline int read() { n   int x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f |= ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return f ? -x : x; n } n std::vector<int> vec[N]; n inline int calc(int n, int m) { n   int sum = 0; n   for (int i = 0; i < n - 1; ++i) n     for (int j = 0; j < m - 1; ++j) { n       int x = vec[i][j] + vec[i][j + 1] + vec[i + 1][j] + vec[i + 1][j + 1]; n       sum += x == 3 ? 1 : (x == 4 ? 4 : 0); n     } n   return sum; n } n inline void solve() { n   int n = read(), m = read(), k = read(), flg = 0; n   if (4LL * (n - 1) * (m - 1) < k) return puts( -1 ), void(); n   if (n > m) std::swap(n, m), flg = 1; n   for (int i = 0; i < n; ++i) vec[i].resize(m); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) vec[i][j] = 0; n   if (m < 5) { n     int suc = 0; n     for (int s = 1; s < (1 << n * m); ++s) { n       for (int i = 0; i < n; ++i) n         for (int j = 0; j < m; ++j) vec[i][j] = s >> i * m + j & 1; n       if (calc(n, m) == k) { n         suc = 1; n         break; n       } n     } n     if (!suc) return puts( -1 ), void(); n   } else if (4LL * (n - 1) * (m - 1) == k + 8 && n == 3) { n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < m; ++j) vec[i][j] = 1; n     vec[0][0] = vec[1][0] = vec[2][0] = 0; n   } else { n     int sum = 0, flg = k ? 0 : 1; n     for (int i = 0; i < m; ++i) vec[0][i] = 1; n     for (int i = 1; i < n && !flg; ++i) n       for (int j = 0; j < m && !flg; ++j) { n         int x = j == m - 1 ? 3 : (j ? 4 : 1); n         if (sum + x > k) { n           int w = k - sum; n           if (w == 0) flg = 1; n           if (w == 1) { n             if (j != m - 1) n               vec[i][m - 1] = flg = 1; n             else if (i != n - 1) n               vec[i + 1][0] = flg = 1; n           } n           if (w == 2) { n             if (j <= m - 3) n               vec[i][m - 2] = flg = 1; n             else if (i != n - 1) n               vec[i + 1][1] = flg = 1; n           } n           if (w == 3) { n             if (j <= m - 4) n               vec[i][m - 1] = vec[i][m - 3] = flg = 1; n             else if (i != n - 1 && j <= m - 3) n               vec[i][m - 2] = vec[i + 1][0] = flg = 1; n             else if (i != n - 1 && j <= m - 2) n               vec[i][m - 1] = vec[i + 1][1] = flg = 1; n             else if (i != n - 1) n               vec[i + 1][0] = vec[i + 1][2] = flg = 1; n           } n           if (flg == 0) return puts( -1 ), void(); n         } else n           vec[i][j] = 1, sum += x; n       } n   } n   if (flg) { n     for (int i = 0; i < m; ++i, putchar(  n )) n       for (int j = 0; j < n; ++j) putchar(vec[j][i] ?  *  :  . ); n   } else { n     for (int i = 0; i < n; ++i, putchar(  n )) n       for (int j = 0; j < m; ++j) putchar(vec[i][j] ?  *  :  . ); n   } n } n int main() { n   for (int T = read(); T; putchar(  n ), --T) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 2; n const long long N = 1e6 + 1; n long long n; n set<int> Q; n int main() { n   scanf( %d , &n); n   int ans = 1; n   while (n--) { n     int x; n     scanf( %d , &x); n     while (!Q.insert(x).second) { n       Q.erase(x); n       x++; n     } n   } n   printf( %d n , Q.size()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   while (cin >> a) { n     bool f = false; n     if (a.length() < 3) { n       cout <<  No  << endl; n       continue; n     } n     for (int i = 0; i <= a.length() - 3; i++) { n       b = a.substr(i, 3); n       if (b[0] !=  .  && b[1] !=  .  && b[2] !=  . ) { n         if (b[0] != b[1] && b[1] != b[2] && b[2] != b[0]) { n           f = true; n           break; n         } n       } n       b.clear(); n     } n     if (f) 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 using ll = long long; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   ll n, k; n   cin >> n >> k; n   if (k == 1 || k == n) { n     cout << (3 * n); n   } else { n     cout << min(2 + 3 * (k - 1) + k + 3 + 3 * (n - k - 1), n                 6 + 3 * (n - k - 1) + n - k + 3 * (k - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int h, l; n   scanf( %lld %lld , &h, &l); n   printf( %.9f n , (l * l - h * h + 0.0) / (2 * h)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[110]; n int n, ans, len; n bool arr[110][220][55][2]; n int main() { n   scanf( %s%d , str + 1, &n); n   len = strlen(str + 1); n   arr[0][100][0][0] = true; n   for (int i = 1; str[i]; ++i) n     for (int j = 100 - i; j <= 100 + i; ++j) n       for (int k = 0; k <= i && k <= n; ++k) n         for (int l = 0; l <= 1; ++l) { n           if (str[i] ==  T ) { n             if (arr[i - 1][j][k][l ^ 1]) arr[i][j][k][l] = true; n             if (k > 0 && (arr[i - 1][j + ((l == 0) ? -1 : 1)][k - 1][l])) n               arr[i][j][k][l] = true; n           } else { n             if (arr[i - 1][j + ((l == 0) ? -1 : 1)][k][l]) n               arr[i][j][k][l] = true; n             if (k > 0 && arr[i - 1][j][k - 1][l ^ 1]) arr[i][j][k][l] = true; n           } n         } n   for (int j = 100 - len; j <= 100 + len; ++j) n     for (int k = n; k >= 0; k -= 2) n       for (int l = 0; l <= 1; ++l) n         if (arr[len][j][k][l]) ans = max(ans, abs(100 - j)); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 4010; n const int T = 20010; n int n, p, q, c[N], h[N], t[N], cs[T], cd[T], b[T], rez[T]; n int d[10010][N]; n vector<int> v[T], v2[T], v3[T]; n void sol(int pozs) { n   int pozd = min(T - 1, pozs + 2 * p), mid = pozs + p; n   vector<int>::iterator it; n   int i, j; n   for (i = pozs; i <= mid; ++i) memset(d[i - pozs], 0, sizeof(d[i - pozs])); n   int din[N]; n   memset(din, 0, sizeof(din)); n   for (i = mid - 1; i >= pozs; --i) { n     for (it = v[i].begin(); it != v[i].end(); ++it) n       for (j = N - 1; j >= c[*it]; --j) n         din[j] = max(din[j], din[j - c[*it]] + h[*it]); n     memcpy(d[i - pozs], din, sizeof(din)); n   } n   memset(din, 0, sizeof(din)); n   for (i = mid; i <= pozd; ++i) { n     for (it = v[i].begin(); it != v[i].end(); ++it) n       for (j = N - 1; j >= c[*it]; --j) n         din[j] = max(din[j], din[j - c[*it]] + h[*it]); n     for (it = v2[i - p].begin(); it != v2[i - p].end(); ++it) n       for (j = 0; j <= b[*it]; ++j) n         rez[*it] = max(rez[*it], d[i - p - pozs][j] + din[b[*it] - j]); n   } n } n void sol1() { n   int i, j; n   int din[N]; n   memset(din, 0, sizeof(din)); n   vector<int>::iterator it; n   for (i = 1; i <= p + 1; ++i) { n     for (it = v[i].begin(); it != v[i].end(); ++it) n       for (j = N - 1; j >= c[*it]; --j) n         din[j] = max(din[j], din[j - c[*it]] + h[*it]); n     for (it = v3[i].begin(); it != v3[i].end(); ++it) rez[*it] = din[b[*it]]; n   } n } n int main() { n   int i, j, k; n   cin >> n >> p; n   --p; n   for (i = 1; i <= n; ++i) { n     cin >> c[i] >> h[i] >> t[i]; n     v[t[i]].push_back(i); n   } n   cin >> q; n   for (i = 1; i <= q; ++i) { n     cin >> cd[i] >> b[i]; n     cs[i] = max(1, cd[i] - p); n     if (cs[i] == 1) { n       v3[cd[i]].push_back(i); n       continue; n     } n     v2[cs[i]].push_back(i); n   } n   sol1(); n   for (int t = 0; t + p < T; t += p) sol(t); n   for (i = 1; i <= q; ++i) cout << rez[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long n; n   cin >> n; n   long long a[n]; n   long long maxi = LONG_LONG_MIN, mini = LONG_LONG_MAX; n   map<long long, stack<long long> > ma; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (i < 5) { n       maxi = max(maxi, a[i]); n       mini = min(mini, a[i]); n     } n     ma[a[i]].push(i); n   } n   sort(a, a + n); n   long long dp[n]; n   long long parent[n]; n   dp[0] = a[0]; n   dp[1] = a[1] - a[0]; n   dp[2] = a[2] - a[0]; n   dp[3] = a[3] - a[0]; n   dp[4] = a[4] - a[0]; n   long long ctr = 2; n   memset(parent, -1, sizeof(parent)); n   for (long long i = 5; i < n; i++) { n     long long temp1, temp2, temp3; n     if (i >= 7) { n       temp1 = dp[i - 3] + a[i] - a[i - 2]; n       temp2 = dp[i - 4] + a[i] - a[i - 3]; n       temp3 = dp[i - 5] + a[i] - a[i - 4]; n     } else if (i == 6) { n       temp1 = dp[i - 3] + a[i] - a[i - 2]; n       temp2 = dp[i - 4] + a[i] - a[i - 3]; n       temp3 = LONG_LONG_MAX; n     } else if (i == 5) { n       temp1 = dp[i - 3] + a[i] - a[i - 2]; n       temp2 = LONG_LONG_MAX; n       temp3 = LONG_LONG_MAX; n     } n     if ((temp1 <= temp2) && (temp1 <= temp3)) { n       parent[i] = i - 3; n     } else if ((temp2 <= temp3) && (temp2 <= temp1)) { n       parent[i] = i - 4; n     } else { n       parent[i] = i - 5; n     } n     dp[i] = min(temp1, min(temp2, temp3)); n   } n   vector<long long> res; n   long long x = n - 1; n   while (parent[x] != -1) { n     res.push_back(x); n     x = parent[x]; n   } n   res.push_back(x); n   long long ans[n]; n   long long team[n]; n   ctr = 1; n   long long j = 0; n   reverse(res.begin(), res.end()); n   for (long long i = 0; i < n; i++) { n     team[i] = ctr; n     if (i == res[j]) { n       j++; n       ctr++; n     } n   } n   for (long long i = 0; i < n; i++) { n     ans[ma[a[i]].top()] = team[i]; n     ma[a[i]].pop(); n   } n   cout << dp[n - 1] <<     << ctr - 1 <<   n ; n   for (long long i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n const int mod = 1000000007; n long long f[2005][2005], g[2005][2005]; n int main() { n   for (int n, m; scanf( %d%d , &n, &m) != EOF;) { n     memset(f, 0, sizeof(f)); n     memset(g, 0, sizeof(g)); n     for (int i = 1; i <= n; i++) { n       long long sum = 0; n       for (int j = 2; j <= m; j++) { n         f[i][j] = (g[i - 1][j] + 1) % mod; n         sum = (sum + f[i][j]) % mod; n         g[i][j] = (g[i][j - 1] + sum) % mod; n       } n     } n     long long ans = 0; n     for (int i = 1; i <= n; i++) { n       for (int j = 2; j <= m; j++) { n         ans = ans + (f[i][j] * (g[n - i][j] - f[n - i][j] + 1) % mod) * n                         (m - j + 1) % mod; n         ans = ans % mod; n       } n     } n     printf( %I64d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int _xor(long long int a, long long int b) { return a ^ b; } n long long int _and(long long int a, long long int b) { return a & b; } n long long int _or(long long int a, long long int b) { return a | b; } n long long int _not(long long int a) { return ~a; } n long long int ai[1000], pi[2005]; n long long int dp[100001]; n int main() { n   long long int b, c = 0, x, y, z, t, i, j, k, l1, l2, m, n, c1 = 0, c2 = 0, q, n                    f = 0, ans = 0; n   string str; n   cin >> str; n   dp[0] = 0; n   for (i = 1; i < str.length(); i++) { n     if (str[i] == str[i - 1]) { n       dp[i] = dp[i - 1] + 1; n     } else n       dp[i] = dp[i - 1]; n   } n   scanf( %lld , &m); n   long long int low, up; n   for (i = 0; i < m; i++) { n     scanf( %lld , &low); n     scanf( %lld , &up); n     up--; n     low--; n     cout << dp[up] - dp[low] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void affiche(int t[], int n) { n   for (int i = 0; i < n; i++) cout << t[i] <<    ; n   cout <<   n ; n } n void afficheV(vector<int> t) { n   for (int i = 0; i < t.size(); i++) cout << t[i] <<    ; n } n vector<vector<int> > adj(50005); n vector<bool> visited(50005, false); n int ans[50005]; n int dp[50005]; n int r1, r2; n void DFS(int node) { n   visited[node] = true; n   for (int i = 0; i < adj[node].size(); i++) { n     int child = adj[node][i]; n     if (!visited[child]) { n       ans[child] = node; n       DFS(child); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n; n   cin >> n >> r1 >> r2; n   memset(dp, -1, sizeof dp); n   for (int i = 1; i < n + 1; i++) { n     if (i == r1) continue; n     int x; n     cin >> x; n     adj[x].push_back(i); n     adj[i].push_back(x); n   } n   DFS(r2); n   for (int i = 1; i < n + 1; i++) { n     if (i == r2) continue; n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n namespace FGF { n int n, m; n const int N = 2e5 + 5; n const double eps = 1e-10; n struct Node { n   double x, t; n } a[N]; n double sum, ans; n bool cmp(Node u, Node v) { return u.t < v.t; } n void work() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %lf , &a[i].x); n   for (int i = 1; i <= n; i++) { n     scanf( %lf , &a[i].t), a[i].t -= m; n     sum += a[i].x * a[i].t; n   } n   sort(a + 1, a + n + 1, cmp); n   if (a[1].t > 0 || a[n].t < 0) { n     puts( 0 ); n     return; n   } n   if (sum > 0) { n     sum = 0; n     for (int i = 1; i <= n; i++) { n       if (sum + a[i].x * a[i].t > 0) { n         ans = ans + sum / (-a[i].t); n         break; n       } else n         ans += a[i].x, sum += a[i].x * a[i].t; n     } n   } else { n     sum = 0; n     for (int i = n; i; i--) { n       if (sum + a[i].x * a[i].t < 0) { n         ans = ans + sum / (-a[i].t); n         break; n       } else n         ans += a[i].x, sum += a[i].x * a[i].t; n     } n   } n   printf( %.12f , ans); n } n }  // namespace FGF n int main() { n   FGF::work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   char c = getchar(); n   long long x = 0; n   bool f = 0; n   for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   if (f) x = -x; n   return x; n } n struct modint { n   long long x; n   modint(long long o = 0) { x = o; } n   modint &operator=(long long o) { return x = o, *this; } n   modint &operator+=(modint o) { n     return x = x + o.x >= 1000000007 ? x + o.x - 1000000007 : x + o.x, *this; n   } n   modint &operator-=(modint o) { n     return x = x - o.x < 0 ? x - o.x + 1000000007 : x - o.x, *this; n   } n   modint &operator*=(modint o) { return x = 1ll * x * o.x % 1000000007, *this; } n   modint &operator^=(long long b) { n     modint a = *this, c = 1; n     for (; b; b >>= 1, a *= a) n       if (b & 1) c *= a; n     return x = c.x, *this; n   } n   modint &operator/=(modint o) { return *this *= o ^= 1000000007 - 2; } n   modint &operator+=(long long o) { n     return x = x + o >= 1000000007 ? x + o - 1000000007 : x + o, *this; n   } n   modint &operator-=(long long o) { n     return x = x - o < 0 ? x - o + 1000000007 : x - o, *this; n   } n   modint &operator*=(long long o) { n     return x = 1ll * x * o % 1000000007, *this; n   } n   modint &operator/=(long long o) { n     return *this *= ((modint(o)) ^= 1000000007 - 2); n   } n   template <class I> n   friend modint operator+(modint a, I b) { n     return a += b; n   } n   template <class I> n   friend modint operator-(modint a, I b) { n     return a -= b; n   } n   template <class I> n   friend modint operator*(modint a, I b) { n     return a *= b; n   } n   template <class I> n   friend modint operator/(modint a, I b) { n     return a /= b; n   } n   friend modint operator^(modint a, long long b) { return a ^= b; } n   friend bool operator==(modint a, long long b) { return a.x == b; } n   friend bool operator!=(modint a, long long b) { return a.x != b; } n   bool operator!() { return !x; } n   modint operator-() { return x ? 1000000007 - x : 0; } n }; n long long n, m, k; n modint x, p[1505], sump[1505], fr[1505][1505], s[1505][1505], tmp[1505][1505]; n modint fac[1000005], iv[1000005]; n void pre(long long n) { n   fac[0] = iv[0] = 1; n   for (register long long i = (1); i <= (n); ++i) n     fac[i] = fac[i - 1] * i, iv[i] = iv[i - 1] / i; n } n inline modint C(long long n, long long m) { return fac[n] * iv[m] * iv[n - m]; } n signed main() { n   n = read(), m = read(), x = read(), x /= read(), k = read(); n   pre(1e6); n   for (register long long i = (0); i <= (min(m, k)); ++i) n     p[i] = C(k, i) * (x ^ i) * ((-x + 1) ^ (k - i)); n   for (register long long i = (1); i <= (m); ++i) n     sump[i] = sump[i - 1] + p[i - 1]; n   fr[0][m] = s[0][m] = 1; n   for (register long long i = (1); i <= (n); ++i) n     for (register long long r = (1); r <= (m); ++r) { n       fr[i][r] = p[m - r] * n                  (sump[r] * (s[i - 1][m] - s[i - 1][m - r]) - tmp[i - 1][r]); n       s[i][r] = s[i][r - 1] + fr[i][r]; n       tmp[i][r] = tmp[i][r - 1] + p[r - 1] * s[i][r - 1]; n     } n   cout << s[n][m].x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<510> reach[510]; n int n, p[510], use[510], i, j, wz[510]; n char s[510]; n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &p[i]), wz[p[i]] = i; n   for (i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     reach[i][i] = 1; n     for (j = 1; j <= n; j++) n       if (s[j] ==  1 ) reach[i][j] = 1; n   } n   for (i = 1; i <= n; i++) n     for (j = 1; j <= n; j++) n       if (reach[j][i]) reach[j] |= reach[i]; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) n       if (!use[j] && reach[i][wz[j]]) break; n     use[j] = 1; n     printf( %d  , j); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, a, flag = 0; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a; n     if (a == 1) flag = 1; n   } n   if (flag == 1) n     cout <<  HARD  << endl; n   else n     cout <<  EASY  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, u, v; n pair<int, vector<int> > P[100011][25]; n vector<int> residents[100011]; n vector<int> adj[100001]; n int parent[100001]; n int L[100001]; n int checker; n vector<int> mergevec(vector<int>& A, vector<int>& B, int sz) { n   vector<int> sol; n   int ap = 0, bp = 0; n   while (sz != 0 && ap != A.size() && bp != B.size()) { n     if (A[ap] < B[bp]) { n       if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--; n       ap++; n     } else { n       if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--; n       bp++; n     } n   } n   while (sz != 0 && ap != A.size()) { n     if (sol.size() == 0 || sol.back() != A[ap]) sol.push_back(A[ap]), sz--; n     ap++; n   } n   while (sz != 0 && bp != B.size()) { n     if (sol.size() == 0 || sol.back() != B[bp]) sol.push_back(B[bp]), sz--; n     bp++; n   } n   return sol; n } n void process() { n   int i, j; n   for (i = 1; i <= n; i++) { n     for (j = 0; j <= 20; j++) { n       P[i][j].first = -1; n     } n   } n   for (i = 1; i <= n; i++) { n     P[i][0].first = parent[i]; n     P[i][0].second = residents[i]; n   } n   for (j = 1; 1 << j < n; j++) { n     for (i = 1; i <= n; i++) { n       if (P[i][j - 1].first != -1) { n         P[i][j].first = P[P[i][j - 1].first][j - 1].first; n         P[i][j].second = mergevec(P[i][j - 1].second, n                                   P[P[i][j - 1].first][j - 1].second, 10); n       } n     } n   } n } n int lca(int p, int q) { n   int tmp, log, i; n   if (L[p] < L[q]) tmp = p, p = q, q = tmp; n   for (log = 1; 1 << log <= L[p]; log++) n     ; n   log--; n   for (i = log; i >= 0; i--) { n     if (L[p] - (1 << i) >= L[q]) { n       p = P[p][i].first; n     } n   } n   if (p == q) return p; n   for (i = log; i >= 0; i--) n     if (P[p][i].first != -1 && P[p][i].first != P[q][i].first) n       p = P[p][i].first, q = P[q][i].first; n   return parent[p]; n } n vector<int> path(int u, int levelpar, int sz) { n   vector<int> sol = residents[u]; n   for (int i = checker; i >= 0; i--) { n     if (P[u][i].first != -1) { n       if (L[P[u][i].first] >= levelpar) { n         sol = mergevec(sol, P[u][i].second, sz); n         u = P[u][i].first; n       } n     } n   } n   return sol; n } n void dfs(int start, int p) { n   parent[start] = p; n   if (p == -1) n     L[start] = 1; n   else n     L[start] = L[p] + 1; n   for (int i = 0; i < adj[start].size(); i++) { n     if (adj[start][i] != p) { n       dfs(adj[start][i], start); n     } n   } n } n int main() { n   int a; n   scanf( %d%d%d , &n, &m, &q); n   checker = min((int)(log2(n) + 3), (int)20); n   for (int i = 0; i < n - 1; i++) { n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   for (int i = 0; i < m; i++) { n     scanf( %d , &u); n     if (residents[u].size() < 10) residents[u].push_back(i + 1); n   } n   for (int i = 1; i <= 100000; i++) n     sort(residents[i].begin(), residents[i].end()); n   dfs(1, -1); n   process(); n   for (int i = 0; i < q; i++) { n     scanf( %d%d%d , &u, &v, &a); n     int lcaa = lca(u, v); n     vector<int> v1 = path(u, L[lcaa], a), v2 = path(v, L[lcaa], a); n     vector<int> sol = mergevec(v1, v2, a); n     sol = mergevec(sol, residents[lcaa], a); n     printf( %d  , (int)sol.size()); n     for (int j = 0; j < sol.size(); j++) { n       printf( %d  , sol[j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n int cnt[maxn], a[maxn], n, q; n signed main() { n   scanf( %d , &q); n   while (q--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) { n       scanf( %d , &a[i]); n       cnt[i] = 0; n     } n     vector<int> res; n     for (int i = 1; cnt[i] < 3; i -= a[i]) n       if ((++cnt[i]) == 2) n         res.push_back(i); n       else if (cnt[i] == 3) n         break; n     printf( %d n , (int)res.size()); n     for (int u : res) printf( %d  , u); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[1003]; n char s[1003]; n int sign[1003]; n int fi[1003]; n int main() { n   int n, m; n   cin >> n >> m; n   getchar(); n   int num = 0; n   int ans = 1001; n   for (int i = 0; i < n; i++) { n     scanf( %c , &c[i]); n   } n   getchar(); n   for (int i = 0; i < m; i++) { n     scanf( %c , &s[i]); n   } n   for (int j = 0; j < m - n + 1; j++) { n     memset(sign, 0, sizeof(sign)); n     num = 0; n     for (int q = 0; q < n; q++) { n       if (s[j + q] != c[q]) { n         sign[num++] = q + 1; n       } n     } n     if (ans > num) { n       ans = num; n       memcpy(fi, sign, sizeof(int) * num); n     } n   } n   printf( %d n , ans); n   for (int i = 0; i < ans; i++) { n     printf( %d  , fi[i]); n   } n   cin >> n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n const int MAXN = 1e5 + 10; n int v[MAXN]; n int lis[MAXN]; n int main() { n   int n; n   scanf( %d , &n); n   for (int a = 0; a < n; ++a) scanf( %d , &v[a]); n   memset(lis, INF, sizeof(lis)); n   for (int a = 0; a < n; ++a) { n     int i = lower_bound(lis, lis + n, v[a]) - lis; n     lis[i] = v[a]; n   } n   int hi = 0; n   for (int a = 0; a < n; ++a) n     if (lis[a] != INF) hi = a; n   printf( %d n , hi + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct road { n   int x, next; n } r[100005 * 2]; n int N, M, D, ans; n int vis[100005], p[100005]; n int down[100005], up[100005]; n int st[100005], w; n void add(int x, int y) { n   r[++w].x = y, r[w].next = st[x]; n   st[x] = w; n } n void Make_Down(int x, int fr) { n   int i, tmp; n   if (vis[x]) n     down[x] = 0; n   else n     down[x] = -0x7ffffff; n   for (i = st[x]; i; i = r[i].next) { n     tmp = r[i].x; n     if (tmp == fr) continue; n     Make_Down(tmp, x); n     down[x] = max(down[x], down[tmp] + 1); n   } n } n void Dfs(int x, int fr) { n   int i, tmp; n   int m1 = 0, m2 = 0; n   if (vis[x]) up[x] = max(up[x], 0); n   if (max(down[x], up[x]) <= D) ans++; n   for (i = st[x]; i; i = r[i].next) { n     tmp = r[i].x; n     if (tmp == fr) continue; n     if (down[m1] <= down[tmp]) n       m2 = m1, m1 = tmp; n     else if (down[m2] <= down[tmp]) n       m2 = tmp; n   } n   for (i = st[x]; i; i = r[i].next) { n     tmp = r[i].x; n     if (tmp == fr) continue; n     if (tmp == m1) n       up[tmp] = max(up[x] + 1, down[m2] + 2); n     else n       up[tmp] = max(up[x] + 1, down[m1] + 2); n     Dfs(tmp, x); n   } n } n int main() { n   int i, j; n   int fr, to; n   scanf( %d %d %d , &N, &M, &D); n   for (i = 1; i <= M; i++) scanf( %d , &p[i]), vis[p[i]] = 1; n   for (i = 1; i < N; i++) { n     scanf( %d %d , &fr, &to); n     add(fr, to), add(to, fr); n   } n   down[0] = up[0] = -0x7ffffff; n   memset(up, 200, sizeof(up)); n   Make_Down(1, 0); n   Dfs(1, 0); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(0); n   int cases, caseno = 0, n, i, j, k, cnt, sum; n   cin >> n >> j >> k; n   for (i = 1; i <= 10000; i++) { n     if (n == 2) { n       cout <<  Final! ; n       return 0; n     } n     if ((j + 1) / 2 == (k + 1) / 2) { n       cout << i; n       return 0; n     } n     j = (j + 1) / 2; n     k = (k + 1) / 2; n     n /= 2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     int n; n     cin >> n; n     int tot = 0; n     vector<int> v; n     for (int i = 1; i < n + 1; i++) { n       if (tot + i > n) { n         v.back() += n - tot; n         break; n       } else { n         tot += i; n         v.push_back(i); n       } n     } n     cout << v.size() <<   n ; n     for (int i = 0; i < v.size(); i++) { n       cout << v[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 29; n int n, m; n int main(void) { n   while (cin >> n >> m && n && m) { n     priority_queue<long long, vector<long long>, greater<long long> > que; n     for (int i = 0; i < n; i++) { n       long long a; n       que.push((cin >> a, a)); n     } n     for (int i = 0; i < m; i++) { n       long long b; n       cin >> b; n       if (!que.empty() && que.top() <= b) que.pop(); n     } n     cout << que.size() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e7 + 7; n const long long mo = 1e9 + 7; n long long n, m, k, p, q, r, mod, i, j, d = 0, ans; n long long wz; n int main() { n   scanf( %lld %lld %lld , &n, &m, &k); n   r = n - 1; n   ans = r * m; n   wz = 1; n   if (ans < k || m > k) n     printf( NO n ); n   else { n     printf( YES n ); n     while (k - r > m - 1) { n       if (d == 0) n         wz = n; n       else n         wz = 1; n       printf( %lld  , wz); n       k -= r; n       d ^= 1; n       m--; n     } n     p = k - m + 1; n     if (m > 0 && p != 0) { n       m--; n       if (d == 0) n         wz = wz + p; n       else n         wz = wz - p; n       printf( %lld  , wz); n       d ^= 1; n     } n     while (m--) { n       if (d == 0) n         wz = wz + 1; n       else n         wz = wz - 1; n       printf( %lld  , wz); n       d ^= 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 9; n long long pow_mod(long long x, long long n) { n   long long res = 1; n   while (n) { n     if (n & 1) res = res * x % mod; n     n >>= 1; n     x = x * x % mod; n   } n   return res; n } n long long inv(long long x) { return pow_mod(x, mod - 2); } n int main() { n   long long n, a, b, k; n   string s; n   while (cin >> n >> a >> b >> k) { n     cin >> s; n     long long ans = 0; n     for (long long i = 0; i < k; i++) { n       if (s[i] ==  + ) n         ans = ((ans + pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod; n       else n         ans = ((ans - pow_mod(a, n - i) * pow_mod(b, i)) % mod + mod) % mod; n     } n     long long m = (n + 1) / k; n     long long q = pow_mod(b, k) * inv(pow_mod(a, k)) % mod; n     if (q == 1) n       ans = ans * m % mod; n     else { n       ans = ans * (1 - pow_mod(q, m)) % mod; n       ans = ans * inv(1 - q) % mod; n     } n     cout << (ans + mod) % mod << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n int find(vector<int>& par, int x) { n   if (x != par[x]) return find(par, par[x]); n   return x; n } n bool same(vector<int>& par, int x, int y) { n   return find(par, x) == find(par, y); n } n void merge(vector<int>& par, vector<int>& sz, int x, int y) { n   int X = find(par, x); n   int Y = find(par, y); n   if (sz[X] < sz[Y]) swap(X, Y); n   par[Y] = X; n   sz[X] += sz[Y]; n   return; n } n int main(int argc, char const* argv[]) { n   cin.sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   vector<int> sz(n); n   vector<int> par(n); n   for (int i = 0; i < n; i++) { n     sz[i] = 1; n     par[i] = i; n   } n   vector<vector<int> > l(m); n   int maxk = -1; n   int ind = -1; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     if (maxk < k) { n       maxk = k; n       ind = i; n     } n     for (int j = 0; j < k; j++) { n       int lng; n       cin >> lng; n       lng--; n       l[lng].push_back(i); n     } n   } n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < l[i].size(); j++) { n       if (!same(par, l[i][0], l[i][j])) { n         merge(par, sz, l[i][0], l[i][j]); n       } n     } n   } n   int ret = 0; n   if (maxk == 0) { n     cout << n; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     if (!same(par, ind, i)) { n       merge(par, sz, ind, i); n       ret++; n     } n   } n   cout << ret; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxn = 200000; n int n; n int a[mxn], b[mxn], first[mxn], ff[mxn]; n vector<int> v[mxn]; n auto cmp = [](int x, int y) { return b[x] > b[y]; }; n priority_queue<int, vector<int>, decltype(cmp)> pq(cmp); n map<int, int> second; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n     a[i]--, b[i]--; n     v[a[i]].push_back(i); n   } n   int p = -1, q = -1; n   for (int i = 0; i < n; i++) { n     for (int j : v[i]) pq.push(j); n     int x = pq.top(); n     pq.pop(); n     first[i] = x, ff[x] = i + 1; n     if (!~p) { n       auto it = second.lower_bound(i); n       if (it != second.end() && it->second >= a[x]) { n         p = first[it->second], q = x; n       } else { n         it = second.insert({b[x], i}).first; n         if (it->second < i) { n           if (next(it) != second.end() && i <= next(it)->second) n             it = second.erase(it); n           while (it != second.begin() && (--it)->second <= i) n             it = second.erase(it); n         } n       } n     } n   } n   cout << (!~p ?  YES  :  NO ) <<   n ; n   for (int i = 0; i < 1 + !!~p; i++) { n     cout << ff[0]; n     for (int i = 1; i < n; i++) cout <<     << ff[i]; n     cout <<   n ; n     if (~p) swap(ff[p], ff[q]); n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 998244353; n const int N = 6000; n std::vector<long long> fact(N), revfact(N); n long long Pow(long long a, long long b) { n   long long rt = 1; n   while (b) { n     if (b & 1) rt = (rt * a) % MOD; n     a = (a * a) % MOD; n     b /= 2; n   } n   return rt; n } n long long C(int n, int k) { n   return (((fact[n] * revfact[k]) % MOD) * revfact[n - k]) % MOD; n } n int main() { n   const int n = 3; n   std::vector<int> a(n); n   for (int i = 0; i < n; i++) std::cin >> a[i]; n   fact[0] = 1; n   for (int i = 1; i < N; i++) { n     fact[i] = (fact[i - 1] * 1LL * i) % MOD; n   } n   for (int i = 0; i < N; i++) { n     revfact[i] = Pow(fact[i], MOD - 2); n     assert((fact[i] * revfact[i]) % MOD == 1); n   } n   long long ans = 1; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       long long cur = 0; n       for (int k = 0; k <= std::min(a[i], a[j]); k++) { n         cur = (cur + (C(a[i], k) * C(a[j], k) % MOD) * fact[k]) % MOD; n       } n       ans = (ans * cur) % MOD; n     } n   } n   std::cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   vector<int> g[n + 1]; n   for (int i = 0; i < n - 1; ++i) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   vector<vector<int>> dp(n + 1, vector<int>(k + 1)); n   int ans = 0; n   function<void(int, int)> dfs; n   dfs = [&](int u, int pre) { n     dp[u][0] = 1; n     for (auto v : g[u]) { n       if (v != pre) { n         dfs(v, u); n         for (int j = 0; j < k; ++j) { n           ans += dp[v][j] * dp[u][k - 1 - j]; n         } n         for (int j = 1; j <= k; ++j) { n           dp[u][j] += dp[v][j - 1]; n         } n       } n     } n   }; n   dfs(1, 0); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool uin(T &a, T b) { n   if (a > b) { n     a = b; n     return true; n   } n   return false; n } n template <class T> n bool uax(T &a, T b) { n   if (a < b) { n     a = b; n     return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   cout.precision(10); n   cout << fixed; n   int N, X, Y; n   cin >> N >> X >> Y; n   for (int i = 0; i < (int)(N); ++i) { n     int A; n     cin >> A; n     long long l = 0, r = 1e18; n     while (r - l > 1) { n       long long m = (l + r) / 2; n       long long hits = m / X + m / Y; n       if (hits >= A) n         r = m; n       else n         l = m; n     } n     if (r % Y == 0 && r % X == 0) n       cout <<  Both n ; n     else if (r % X) n       cout <<  Vanya n ; n     else if (r % Y) n       cout <<  Vova n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1e9 + 7; n using namespace std; n vector<int> par, rnk; n void make_set(int n) { n   par[n] = n; n   rnk[n] = 0; n } n int find_set(int a) { n   if (par[a] == a) return a; n   return par[a] = find_set(par[a]); n } n void union_set(int a, int b) { n   a = find_set(a); n   b = find_set(b); n   if (a == b) return; n   if (rnk[a] > rnk[b]) { n     par[b] = a; n   } else if (rnk[a] < rnk[b]) { n     par[a] = b; n   } else { n     par[b] = a; n     rnk[a]++; n   } n } n void solve() { n   int n, a, b; n   cin >> n >> a >> b; n   par.assign(n, 0); n   rnk.assign(n, 0); n   if (a != 1 && b != 1) { n     cout <<  NO n ; n     return; n   } n   if (a == 1 && b == 1) { n     if (n == 2 || n == 3) { n       cout <<  NO n ; n       return; n     } n     cout <<  YES n ; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         if (abs(i - j) == 1) n           cout <<  1 ; n         else n           cout <<  0 ; n       } n       cout << endl; n     } n     return; n   } n   for (int i = 0; i < n; i++) make_set(i); n   for (int i = 0; i < n - (max(a, b)); i++) { n     union_set(i, i + 1); n   } n   int flag = 0; n   if (a > 1) flag = 1; n   cout <<  YES n ; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (i == j) n         cout <<  0 ; n       else if (flag) { n         if (find_set(i) == find_set(j)) n           cout <<  1 ; n         else n           cout <<  0 ; n       } else { n         if (find_set(i) != find_set(j)) n           cout <<  1 ; n         else n           cout <<  0 ; n       } n     } n     cout << endl; n   } n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 100; n vector<int> v[maxn]; n stack<int> s; n int low[maxn], dfn[maxn], vis[maxn], clk = 0; n int belong[maxn], tot = 0; n vector<int> Ws[maxn]; n void tarjan(int x) { n   s.push(x), vis[x] = 1; n   low[x] = dfn[x] = ++clk; n   for (auto &u : v[x]) { n     if (!dfn[u]) { n       tarjan(u); n       low[x] = min(low[x], low[u]); n     } else if (vis[u]) n       low[x] = min(low[x], dfn[u]); n   } n   if (low[x] == dfn[x]) { n     int u; n     tot++; n     do { n       u = s.top(); n       s.pop(), vis[u] = 0; n       belong[u] = tot, Ws[tot].push_back(u); n     } while (x != u); n   } n } n int n, m, D; n vector<pair<int, int> > usedge[maxn]; n int in[maxn]; n pair<int, int> dp[maxn][55]; n void buildnew() { n   Ws[0].push_back(0), in[belong[1]]++; n   belong[0] = 0, usedge[0].push_back({0, 1}); n   for (int i = 1; i <= n; ++i) { n     for (auto &u : v[i]) { n       if (belong[i] != belong[u]) { n         usedge[belong[i]].push_back({i, u}); n         in[belong[u]]++; n       } n     } n   } n } n char mp[maxn][55]; n void calblock(int x, int time, int bx, int w) { n   time %= D; n   pair<int, int> &ret = dp[x][time]; n   if (ret.first) return; n   ret = {1, w}; n   for (auto &u : v[x]) { n     if (bx != belong[u]) continue; n     calblock(u, time + 1, bx, w); n   } n } n int val[maxn][55], ans[maxn][55]; n int cal(int x, int p) { n   if (val[x][p] != -1) return val[x][p]; n   val[x][p] = 0; n   for (auto &u : Ws[x]) { n     for (int i = 0; i < D; ++i) { n       int ok = (dp[u][i].first && mp[u][i] ==  1  && dp[u][i].second == p); n       val[x][p] += ok; n       if (ok) break; n     } n   } n   return val[x][p]; n } n int dis[maxn]; n void solve(int x) { n   queue<int> q; n   for (int i = 0; i <= tot; ++i) n     if (!in[i]) q.push(i); n   while (q.size()) { n     int p = q.front(); n     q.pop(); n     for (auto &u : usedge[p]) { n       int bx = belong[u.second]; n       for (int i = 0; i < D; ++i) { n         if (dp[u.first][i].first) { n           int tp = (i + 1) % D; n           int go = (dis[u.second] + i + 1) % D; n           calblock(u.second, (i + 1) % D, bx, go); n           tp = dp[u.second][(i + 1) % D].second; n           ans[bx][tp] = n               max(ans[bx][tp], ans[p][dp[u.first][i].second] + cal(bx, tp)); n         } n       } n       in[bx]--; n       if (in[bx] == 0) q.push(bx); n     } n   } n } n void bfs(int x) { n   int p = Ws[x][0]; n   queue<int> q; n   q.push(p); n   dis[p] = 0; n   while (q.size()) { n     int u = q.front(); n     q.pop(); n     for (auto r : v[u]) { n       if (belong[r] != x || (dis[r] != -1)) continue; n       dis[r] = dis[u] + 1; n       q.push(r); n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &D); n   for (int i = 1; i <= m; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     v[x].push_back(y); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %s , mp[i]); n   } n   for (int i = 1; i <= n; ++i) { n     if (!dfn[i]) { n       tarjan(i); n     } n   } n   buildnew(); n   memset(val, -1, sizeof val); n   memset(dis, -1, sizeof dis); n   for (int i = 0; i <= tot; ++i) bfs(i); n   dp[0][D - 1] = {1, D - 1}; n   solve(0); n   int ret = 0; n   for (int i = 1; i <= tot; ++i) { n     for (int j = 1; j <= D; ++j) ret = max(ret, ans[i][j - 1]); n   } n   cout << ret <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int i, a[n]; n     map<int, pair<int, int> > m; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n     } n     int vis[n + 1]; n     memset(vis, -1, sizeof(vis)); n     for (i = 0; i < n; i++) { n       if (m.find(a[i]) == m.end()) { n         pair<int, int> p; n         p.first = i; n         p.second = i + 1; n         m[a[i]] = p; n       } else { n         pair<int, int> p = m[a[i]]; n         p.second = max(p.second, i - p.first); n         p.first = i; n         m[a[i]] = p; n       } n     } n     map<int, pair<int, int> >::iterator it; n     for (it = m.begin(); it != m.end(); it++) { n       pair<int, int> p = it->second; n       int i = p.first; n       int x = max(p.second, n - i); n       if (vis[x] == -1) n         vis[x] = it->first; n       else n         vis[x] = min(vis[x], it->first); n     } n     for (i = 1; i <= n; i++) { n       if (vis[i] == -1) n         cout << vis[i] <<    ; n       else { n         int temp = vis[i]; n         while (i + 1 <= n && (vis[i + 1] == -1 || vis[i + 1] >= temp)) { n           cout << temp <<    ; n           i++; n         } n         cout << temp <<    ; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[300001]; n long long an[300001], dp[300001]; n struct data { n   int x, y, No; n   void scan() { scanf( %d%d , &x, &y); } n   bool operator<(data b) const { n     if (y < b.y) return 0; n     if (y > b.y) return 1; n     int r1 = x % y, r2 = b.x % y; n     if (r1 < r2) return 0; n     if (r1 > r2) return 1; n     return No < b.No; n   } n } d[300001]; n int main() { n   int n, i, j, k, mi, p; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   scanf( %d , &p); n   for (i = 0; i < p; i++) d[i].scan(), d[i].No = i; n   sort(d, d + p); n   for (i = 0; i < p; i += j) { n     int tmp = d[i].x % d[i].y; n     mi = n; n     for (j = 0; i + j < p; j++) { n       if (d[i].y != d[i + j].y || d[i + j].x % d[i].y != tmp) break; n       mi = min(mi, d[i + j].x); n     } n     k = d[i].x + (n - d[i].x) / d[i].y * d[i].y; n     dp[k] = a[k]; n     for (k -= d[i].y; k >= mi; k -= d[i].y) dp[k] = a[k] + dp[k + d[i].y]; n     for (k = 0; k < j; k++) an[d[i + k].No] = dp[d[i + k].x]; n   } n   for (i = 0; i < p; i++) printf( %I64d n , an[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int a[100000], b, c, n, m, x, y, z, s; n int main() { n   cin >> a[0] >> a[1] >> n; n   if (n <= 1) n     cout << a[n]; n   else { n     for (int i = 2; i <= n; i++) { n       a[i] = a[i - 1] + a[i - 2]; n     } n     cout << a[n]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cnt[105]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   long long a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   long long ans = 0; n   while (m--) { n     long long l, r; n     cin >> l >> r; n     l--; n     r--; n     long long sm = 0; n     for (long long i = l; i <= r; i++) sm += a[i]; n     if (sm > 0) ans += sm; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int inf = 1000000000; n const long long int mod = 1000000000 + 7; n inline void IO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } n template <class T> n inline int CHECK(T MASK, int i) { n   return (MASK >> i) & 1; n } n template <class T> n inline T ON(T MASK, int i) { n   return MASK | (T(1) << i); n } n template <class T> n inline T OFF(T MASK, int i) { n   return MASK & (~(T(1) << i)); n } n template <typename T> n inline int CNT(T MASK) { n   if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits) n     return __builtin_popcount(MASK); n   else n     return __builtin_popcountll(MASK); n } n template <class T> n inline int RIGHT(T MASK) { n   return log2(MASK & -MASK); n } n int dx4[] = {0, 0, -1, +1}; n int dy4[] = {+1, -1, 0, 0}; n int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0}; n int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; n inline void I(int& a) { scanf( %d , &a); } n inline void I(long long int& a) { scanf( %I64d , &a); } n inline void I(unsigned long long int& a) { scanf( %I64u , &a); } n inline void I(char* a) { scanf( %s , a); } n char Iarr[2000010]; n inline void I(string& a) { n   scanf( %s , Iarr); n   a = Iarr; n } n template <typename T, typename... Args> n void I(T& a, Args&... args) { n   I(a); n   I(args...); n } n inline void OUT(int a) { printf( %d , a); } n inline void OUT(long long int a) { printf( %I64d , a); } n inline void OUT(const char* a) { printf( %s , a); } n inline void OUT(char* a) { printf( %s , a); } n inline void OUT(bool a) { printf( %d , a); } n inline void OUT(string a) { n   for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end())); n        it != (a.end()) - ((a.begin()) > (a.end())); n        it += 1 - 2 * ((a.begin()) > (a.end()))) n     printf( %c , *it); n } n inline void OUT(unsigned long long int a) { printf( %I64u , a); } n template <typename T, typename... Args> n void OUT(T a, Args... args) { n   OUT(a); n   OUT(   ); n   OUT(args...); n } n template <typename... Args> n void O(Args... args) { n   OUT(args...); n   OUT(  n ); n } n template <typename T1, typename T2> n inline ostream& operator<<(ostream& os, pair<T1, T2> p) { n   os <<  {  << p.first <<  ,   << p.second <<  } ; n   return os; n } n template <typename T> n inline ostream& operator<<(ostream& os, vector<T>& a) { n   os <<  [ ; n   for (int i = 0; i < (int)a.size(); i++) { n     if (i) os <<  ,  ; n     os << a[i]; n   } n   os <<  ] ; n   return os; n } n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a << endl; n   err(++it, args...); n } n const int M = 1000010; n bool dp[500001]; n int main() { n   int n, d; n   I(n, d); n   dp[0] = 1; n   for (int i = 0; i < n; i++) { n     int x; n     I(x); n     for (int j = 500000; j >= 0; j--) { n       if (dp[j]) { n         if (j + x <= 500000) dp[j + x] = 1; n       } n     } n   } n   vector<int> v; n   for (int i = 0; i <= 500000; i++) { n     if (dp[i]) v.push_back(i); n   } n   int in = 0; n   int days = 0; n   while (1) { n     int low = in + 1, high = (int)v.size() - 1; n     if (low > high) break; n     while (low < high) { n       int mid = (low + high + 1) / 2; n       if (v[mid] - v[in] <= d) { n         low = mid; n       } else { n         high = mid - 1; n       } n     } n     if (v[low] - v[in] <= d) { n       days++; n       in = low; n     } else { n       break; n     } n   } n   O(v[in], days); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T in() { n   char ch; n   T n = 0; n   bool ng = false; n   while (1) { n     ch = getchar(); n     if (ch ==  - ) { n       ng = true; n       ch = getchar(); n       break; n     } n     if (ch >=  0  && ch <=  9 ) break; n   } n   while (1) { n     n = n * 10 + (ch -  0 ); n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n   } n   return (ng ? -n : n); n } n template <typename T> n inline T POW(T B, T P) { n   if (P == 0) return 1; n   if (P & 1) n     return B * POW(B, P - 1); n   else n     return (POW(B, P / 2) * POW(B, P / 2)); n } n template <typename T> n inline T Gcd(T a, T b) { n   if (a < 0) return Gcd(-a, b); n   if (b < 0) return Gcd(a, -b); n   return (b == 0) ? a : Gcd(b, a % b); n } n template <typename T> n inline T Lcm(T a, T b) { n   if (a < 0) return Lcm(-a, b); n   if (b < 0) return Lcm(a, -b); n   return a * (b / Gcd(a, b)); n } n long long Bigmod(long long base, long long power, long long MOD) { n   long long ret = 1; n   while (power) { n     if (power & 1) ret = (ret * base) % MOD; n     base = (base * base) % MOD; n     power >>= 1; n   } n   return ret; n } n bool isVowel(char ch) { n   ch = toupper(ch); n   if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E ) n     return true; n   return false; n } n template <typename T> n long long int isLeft(T a, T b, T c) { n   return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y); n } n long long ModInverse(long long number, long long MOD) { n   return Bigmod(number, MOD - 2, MOD); n } n bool isConst(char ch) { n   if (isalpha(ch) && !isVowel(ch)) return true; n   return false; n } n int toInt(string s) { n   int sm; n   stringstream second(s); n   second >> sm; n   return sm; n } n int n; n double a[19][19]; n double dp[19][(1 << 18) + 10]; n int vs[19][(1 << 18) + 10]; n int lm; n double Solve(int w, int m) { n   if (m == lm) { n     if (w == 0) return 1.0; n     return 0.0; n   } n   double &res = dp[w][m]; n   if (vs[w][m]) return res; n   vs[w][m] = 1; n   res = 0.0; n   for (int i = 0; i < n; i++) { n     if ((m & (1 << i)) == 0) { n       double aa = a[w][i] * Solve(w, (m | (1 << i))); n       aa += a[i][w] * Solve(i, (m | (1 << i))); n       res = max(res, aa); n     } n   } n   return res; n } n int main() { n   cin >> n; n   lm = (1 << n) - 1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) cin >> a[i][j]; n   if (n == 1) { n     printf( 1.00 n ); n     return 0; n   } else if (n == 2) { n     printf( %.10lf n , a[0][1]); n     return 0; n   } n   double ans = 0.0; n   for (int j = 0; j < n; j++) { n     for (int i = j + 1; i < n; i++) { n       double aa = a[j][i] * Solve(j, (1 << j) | (1 << i)); n       aa += a[i][j] * Solve(i, (1 << i) | (1 << j)); n       ans = max(aa, ans); n     } n   } n   printf( %.10lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> e[100005]; n int used[100005]; n void bfs(int x) { n   queue<int> q; n   while (!q.empty()) q.pop(); n   q.push(x); n   used[x] = 1; n   while (!q.empty()) { n     int p = q.front(); n     q.pop(); n     for (int i = 0; i < e[p].size(); i++) { n       if (e[p][i]) { n         if (!used[e[p][i]]) { n           if (used[p] == 1) n             used[e[p][i]] = 2; n           else n             used[e[p][i]] = 1; n           q.push(e[p][i]); n         } n       } n     } n   } n } n int main() { n   int n, x, y; n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n - 1; i++) { n       scanf( %d%d , &x, &y); n       e[x].push_back(y); n       e[y].push_back(x); n     } n     memset(used, 0, sizeof(used)); n     bfs(1); n     long long ans1 = 0, ans2 = 0; n     for (int i = 1; i <= n; i++) { n       if (used[i] == 1) n         ans1++; n       else n         ans2++; n     } n     printf( %I64d n , ans2 * ans1 - (n - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   if (a + b <= max(c, d)) n     cout <<  Polycarp ; n   else if (a <= c && b <= d) n     cout <<  Polycarp ; n   else n     cout <<  Vasiliy ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long n, r, l[210000], t[210000], ans, a[110000], b, x, y, c; n int main() { n   scanf( %I64d%I64d , &n, &r); n   for (int i = 1; i <= n; i++) scanf( %I64d , &l[i]); n   for (int i = 1; i <= n; i++) scanf( %I64d , &t[i]); n   for (int i = 1; i <= n; i++) n     if (t[i] < l[i]) { n       printf( -1 n ); n       return 0; n     } n   b = 0; n   c = 0; n   for (int i = 1; i <= n; i++) { n     if (l[i] <= b) { n       b -= l[i]; n       c += l[i]; n     } else { n       l[i] -= b; n       t[i] -= b; n       c += b; n       b = 0; n       x = 2 * l[i] - t[i]; n       if (x > 0) { n         y = (x - 1) / r + 1; n         if (ans + y <= 100000) { n           for (int j = 1; j <= y; j++) a[++ans] = c + t[i] - x + r * (j - 1); n         } else n           ans += y; n         b = (r - x % r) % r; n         c += t[i]; n       } else n         c += 2 * l[i]; n     } n   } n   printf( %I64d n , ans); n   if (ans <= 100000) { n     for (int i = 1; i < ans; i++) printf( %I64d  , a[i]); n     if (ans) printf( %I64d , a[ans]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int s[1005]; n int main() { n   int n, m, h; n   scanf( %d%d%d , &n, &m, &h); n   int sum = 0; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &s[i]); n     sum += s[i]; n   } n   if (sum < n) { n     printf( -1 n ); n     return 0; n   } n   long double ans = 1; n   long double down = sum - 1; n   long double up = sum - s[h]; n   for (int i = 1; i <= n - 1; i++) { n     ans = ans * up / down; n     up--, down--; n   } n   printf( %.20Lf n , 1 - ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   vector<long long> h(n + 5); n   vector<long long> deg(n + 5, 0), a(n + 5, 0); n   for (long long i = 1; i <= n; i++) cin >> h[i]; n   for (long long i = 1; i <= n; i++) cin >> a[i], deg[a[i]]++; n   long long c = -1; n   long long maxi = 0; n   for (long long i = 1; i <= n; i++) { n     if (h[i] == 1) { n       long long x = a[i]; n       long long cnt = 1; n       while (x > 0 && deg[x] == 1) cnt++, x = a[x]; n       if (cnt > maxi) { n         maxi = cnt; n         c = i; n       } n     } n   } n   vector<long long> temp; n   temp.push_back(c); n   c = a[c]; n   while (c > 0 && deg[c] == 1) temp.push_back(c), c = a[c]; n   long long l = (long long)temp.size(); n   cout << l <<   n ; n   for (long long i = l - 1; i >= 0; i--) cout << temp[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int mxs = 2e5 + 7; n int n; n int a[mxs]; n int l[mxs]; n int r[mxs]; n int ans[mxs]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = n; i; i--) { n     l[i] = i; n     while (a[i] <= a[l[i] + 1]) l[i] = l[l[i] + 1]; n   } n   for (int i = 1; i <= n; i++) { n     r[i] = i; n     while (a[i] <= a[r[i] - 1]) r[i] = r[r[i] - 1]; n   } n   for (int i = 1; i <= n; i++) { n     int res = l[i] - r[i] + 1; n     ans[res] = max(ans[res], a[i]); n   } n   for (int i = n; i; i--) ans[i] = max(ans[i], ans[i + 1]); n   for (int i = 1; i <= n; i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:64000000 ) n const int maxn = 200200; n const int inf = 1000000007; n const int mod = 1000000007; n const int dx[4] = {1, -1, 0, 0}; n const int dy[4] = {0, 0, 1, -1}; n double pr[maxn]; n double pw(double x, int k) { n   if (k == 1) return x; n   double ans = pw(x, k / 2); n   ans = ans * ans; n   if (k % 2 == 1) ans = ans * x; n   return ans; n } n int main() { n   int n, m; n   while (scanf( %d%d , &n, &m) == 2) { n     pr[n + 1] = 0; n     double ans = 0; n     for (int i = n; i >= 1; i--) { n       pr[i] = 1 - pw((double)(i - 1) / n, m); n       ans += i * (pr[i] - pr[i + 1]); n     } n     printf( %.10lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> nums; n int mod[100]; n char in[1000010]; n int cnt[100]; n int main() { n   int i, j, k; n   nums.push_back(1); n   nums.push_back(6); n   nums.push_back(8); n   nums.push_back(9); n   sort(nums.begin(), nums.end()); n   do { n     int sum = 0; n     for (i = 0; i < 4; i++) { n       sum *= 10; n       sum += nums[i]; n     } n     mod[sum % 7] = sum; n   } while (next_permutation(nums.begin(), nums.end())); n   int ok = 1; n   int n; n   scanf( %s , in); n   n = strlen(in); n   for (i = 0; i < n; i++) { n     cnt[in[i] -  0 ]++; n   } n   for (i = 0; i < 4; i++) { n     cnt[nums[i]]--; n   } n   int now = 0; n   for (i = 9; i >= 1; i--) { n     while (cnt[i]--) { n       now *= 10; n       now += i; n       now %= 7; n       printf( %d , i); n     } n   } n   now *= 10000; n   now %= 7; n   printf( %d , mod[(7 - now) % 7]); n   while (cnt[i]--) { n     printf( %d , i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n const long long mod = 998244353; n long long a[N]; n long long n, m, k; n long long pw(long long n, long long k) { n   if (!k) return 1; n   long long res = pw(n, k >> 1); n   res = res * res % mod; n   if (k & 1) return res * n % mod; n   return res; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> k; n   for (long long i = 1; i <= m; i++) { n     cin >> a[i]; n   } n   long long ans = 1; n   for (long long i = 1; i <= m; i++) { n     long long num = a[i] - a[i - 1]; n     (ans *= pw(k, 2 * num) + pw(k, num)) %= mod; n     if (ans < 0) ans += mod; n   } n   (ans *= pw(k, n - 2 * a[m])) %= mod; n   (ans *= pw(pw(2, m), mod - 2)) %= mod; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     long long c = a ^ b; n     a = a & c; n     b = b & c; n     cout << a + b <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> a; n int n, j; n string s; n map<long long, int> f; n long long h(string s) { n   long long res = 0; n   for (int i = 0; i < s.length(); i++) res = res * 28 + (s[i] -  a ) + 1; n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     cin >> s; n     a.push_back(s); n   } n   long long j; n   for (int i = n - 1; i >= 0; i--) { n     j = h(a[i]); n     f[j]++; n     if (f[j] == 1) cout << a[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { n   if (a > b) { n     return a; n   } else { n     return b; n   } n } n long long min(long long a, long long b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n vector<string> split(const string& s, char c) { n   vector<string> v; n   stringstream ss(s); n   string x; n   while (getline(ss, x, c)) v.emplace_back(x); n   return move(v); n } n void err(vector<string>::iterator it) {} n template <typename T, typename... Args> n void err(vector<string>::iterator it, T a, Args... args) { n   cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<  ,  ; n   err(++it, args...); n } n template <typename T> n struct number_iterator : std::iterator<random_access_iterator_tag, T> { n   T v; n   number_iterator(T _v) : v(_v) {} n   operator T&() { return v; } n   T operator*() const { return v; } n }; n template <typename T> n struct number_range { n   T b, e; n   number_range(T b, T e) : b(b), e(e) {} n   number_iterator<T> begin() { return b; } n   number_iterator<T> end() { return e; } n }; n template <typename T> n number_range<T> range(T e) { n   return number_range<T>(1, e + 1); n } n template <typename T> n number_range<T> range(T b, T e) { n   return number_range<T>(b, e + 1); n } n long long c(long long len, long long b) { n   long long base = 1, tot = 0; n   for (int i = (1); i <= (len); i++) { n     if (i != b) tot += base; n     base *= 2; n   } n   return tot; n } n long long f(long long d) { n   if (d <= 1) return 0; n   long long res = 0; n   for (int i = (1); i <= (60); i++) { n     for (int j = (1); j <= (i - 1); j++) { n       if (c(i, j) <= d) res++; n     } n   } n   return res; n } n int main() { n   long long a, b; n   cin >> a >> b; n   long long ff = f(b) - f(a - 1); n   cout << ff << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct ilter { n   int job; n   long long ti; n   bool operator<(const ilter &a) const { return a.ti > ti; } n } T[100001]; n int s, c; n long long TIME; n int main() { n   map<int, int> M2; n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> T[i].job; n     M2[T[i].job]++; n   } n   for (int i = 0; i < n; i++) { n     cin >> T[i].ti; n     ; n   } n   s = k - M2.size(); n   if (s == 0) n     return cout << 0, 0; n   else { n     sort(T, T + n); n     for (int i = 0; i < n; i++) { n       if (M2[T[i].job] > 1) { n         TIME += T[i].ti; n         M2[T[i].job]--; n         c++; n       } n       if (c == s) break; n     } n     cout << TIME; n   } n   return 0; n } n


#include <bits/stdc++.h> n const double EPS = 1e-9; n const int MAX_REPS = 2000; n double bx, by, h, r; n void solve(double x, double& y1, double& y2, double& y3) { n   double A1, A2, B1, B2, C1, C2, dy1, dy2, dx, dy; n   dx = -(x - bx); n   dy = ((h - r) - by); n   A1 = -dy; n   B1 = dx; n   C1 = A1 * x + B1 * (h - r); n   y1 = C1 / B1; n   A2 = -B1; n   B2 = A1; n   C2 = B2 * y1; n   dy1 = ((C1 - A1) / B1) - (C1 / B1); n   dy2 = ((C2 - A2) / B2) - (C2 / B2); n   assert(dy1 > 0); n   assert(dy2 < 0); n   A1 = dy1 - dy2; n   B1 = sqrt(1 + dy2 * dy2); n   y2 = y1 + A1 / B1 * (B1 + r) - A1; n   y3 = y1 + A1 / B1 * (B1 - r) - A1; n } n int main(void) { n   int i; n   double yl, yh, frl, tol, frh, toh, mi, bc, bh, bl; n   std::cin >> yl >> yh >> h >> bx >> by >> r; n   frh = 0; n   toh = bx - r / 2; n   for (i = 0; i < MAX_REPS && fabs(frh - toh) >= EPS; ++i) { n     mi = (frh + toh) / 2; n     solve(mi, bc, bh, bl); n     if (bh >= yh) { n       frh = mi; n     } else { n       toh = mi; n     } n   } n   frl = 0; n   tol = bx - r / 2; n   for (i = 0; i < MAX_REPS && fabs(frl - tol) >= EPS; ++i) { n     mi = (frl + tol) / 2; n     solve(mi, bc, bh, bl); n     if (bc - r <= yl) { n       tol = mi; n     } else { n       frl = mi; n     } n   } n   mi = (frl + frh) / 2; n   solve(mi, bc, bh, bl); n   if (bc - r < yl || bh > yh) { n     std::cout <<  -1  << std::endl; n   } else { n     std::cout << (frl + frh) / 2 << std::endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 * 100 * 2 + 10; n long long int a[MAXN]; n long long int b[MAXN]; n long long int p[MAXN]; n long long int d[MAXN]; n long long int mod = 1000 * 1000 * 1000 + 7; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   int n, c; n   cin >> n >> c; n   for (int i = 0; i < n - 1; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     cin >> b[i]; n   } n   cout << 0 <<    ; n   for (int i = 0; i < n - 1; i++) { n     if (i == 0) { n       d[i] = c + b[i]; n       p[i] = a[i]; n     } else { n       d[i] = min(d[i - 1] + b[i], p[i - 1] + b[i] + c); n       p[i] = min(p[i - 1] + a[i], d[i - 1] + a[i]); n     } n     cout << min(d[i], p[i]) <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int l[1000005], n, m; n long long f[5005][5005], g[2][5005], fa[5005], fac[5005], p, sum; n inline int read() { n   int ret = 0; n   char fa = getchar(); n   while (!isdigit(fa)) fa = getchar(); n   while (isdigit(fa)) { n     ret = (ret << 1) + (ret << 3) + fa -  0 ; n     fa = getchar(); n   } n   return ret; n } n inline void Aireen() { n   n = read(); n   m = read(); n   p = (long long)(read()); n   for (int i = 1; i <= n; ++i) l[i] = read(); n   fa[0] = fac[0] = 1ll; n   for (int i = 1, j = m; i < 5005 && j; ++i, --j) { n     fa[i] = fa[i - 1] * (long long)(i) % p; n     fac[i] = fac[i - 1] * (long long)(j) % p; n   } n   f[0][0] = 1ll; n   for (int i = 1; i < 5005; ++i) n     for (int j = min(m, i); j; --j) n       f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] * (long long)(j - 1) % p) % p; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= l[i + 1]; ++j) g[i & 1][j] = 0ll; n     if (i == 1) { n       for (int j = min(l[i], m); j; --j) g[i][j] = fac[j] * f[l[i]][j] % p; n     } else { n       sum = 0ll; n       for (int j = min(l[i - 1], m); j; --j) sum = (sum + g[i & 1 ^ 1][j]) % p; n       for (int j = min(l[i], m); j; --j) { n         g[i & 1][j] = (fac[j] * sum % p - fa[j] * g[i & 1 ^ 1][j] % p + p) % p * n                       f[l[i]][j] % p; n       } n     } n   } n   sum = 0ll; n   for (int j = min(l[n], m); j; --j) sum = (sum + g[n & 1][j]) % p; n   cout << sum << endl; n } n int main() { n   Aireen(); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n