#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long int n, i, j, x, in = 0; n   string s; n   vector<pair<string, long long int>> v; n   priority_queue<long long int, vector<long long int>, greater<long long int>> n       pq; n   cin >> n; n   long long int mn = 1000000000000000000LL, dummy = -1; n   for (i = 1; i <= n; i++) { n     cin >> s; n     if (s ==  insert ) { n       cin >> x; n       v.push_back(make_pair(s, x)); n       pq.push(x); n     } else if (s ==  getMin ) { n       cin >> x; n       if (pq.size() != 0) n         mn = pq.top(); n       else n         mn = -1; n       if (x != mn) { n         if (x > mn) { n           while (x > mn && pq.size() != 0) { n             mn = pq.top(); n             if (mn >= x) break; n             pq.pop(); n             v.push_back(make_pair( removeMin , -1)); n           } n           if (x == mn && pq.size() != 0) { n             v.push_back(make_pair(s, x)); n           } else if ((mn > x && pq.size() != 0) || pq.size() == 0) { n             v.push_back(make_pair( insert , x)); n             pq.push(x); n             v.push_back(make_pair(s, x)); n           } n         } else { n           v.push_back(make_pair( insert , x)); n           pq.push(x); n           v.push_back(make_pair(s, x)); n         } n       } else { n         v.push_back(make_pair(s, x)); n       } n     } else if (s ==  removeMin ) { n       if (pq.size() != 0) n         pq.pop(); n       else { n         v.push_back(make_pair( insert , 0)); n       } n       v.push_back(make_pair(s, -1)); n     } n   } n   cout << v.size() << endl; n   for (i = 0; i < v.size(); i++) { n     cout << v[i].first <<    ; n     if (v[i].first !=  removeMin ) n       cout << v[i].second << endl; n     else n       cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MOD = 1e9 + 7; n const int MAXN = 2e5 + 17; n const int magic = (1 << 7); n using namespace std; n struct p { n   long double x, y; n   p(long double x, long double y) : x(x), y(y) {} n   p() {} n   long double len() const { return sqrt(x * x + y * y); } n }; n p operator-(const p &a, const p &b) { return p(a.x - b.x, a.y - b.y); } n string s; n bool solve(int l, int r) { n   int q = 0; n   map<char, int> c; n   int num = 0; n   for (int i = l; i <= r; i++) { n     if (s[i] ==  ? ) n       q++; n     else n       c[s[i]]++; n   } n   if (c.size() + q >= 26) { n     for (int i = l; i <= r; i++) { n       if (s[i] ==  ? ) n         for (int x = int( A ); x <= int( Z ); x++) { n           if (c[char(x)] == 0) { n             s[i] = char(x), c[char(x)]++; n             break; n           } n         } n     } n     return true; n   } n   return false; n } n int main() { n   if (1) { n     ios_base::sync_with_stdio(false); n     cin.tie(nullptr); n     cout.tie(nullptr); n   } n   long long n; n   cin >> n; n   long long cur = 2; n   for (long long i = 1; i <= n; i++) { n     cout << (i * (i + 1) * (i + 1) - cur / i) <<   n ; n     cur = i * (i + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int N = 1e5 + 19; n long long A[N], day[N]; n signed main() { n   long long n, m, d; n   set<pair<long long, int> > S; n   n = read(); n   m = read(); n   d = read(); n   for (int i = 1; i <= n; ++i) { n     long long x; n     x = read(); n     S.insert(pair<long long, int>(x, i)); n   } n   int now = 0; n   while (S.size()) { n     ++now; n     pair<long long, int> tmp = *S.begin(); n     long long s = tmp.first; n     day[tmp.second] = now; n     S.erase(S.begin()); n     for (auto iter = S.lower_bound(pair<long long, int>(s + d + 1, 0)); n          iter != S.end(); n          iter = S.lower_bound(pair<long long, int>(s + d + 1, 0))) { n       day[iter->second] = now; n       s = iter->first; n       S.erase(iter); n     } n   } n   printf( %d n , now); n   for (int i = 1; i <= n; ++i) printf( %I64d  , day[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const int INF = 1e6; n namespace IO { n const int MAXSIZE = 1 << 20; n char buf[MAXSIZE], *p1, *p2; n inline int gc() { n   return (p1 == p2 && n                   (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) n               ? EOF n               : *p1++); n } n inline int rd() { n   int x = 0, f = 1; n   char c = gc(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = gc(); n   } n   while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc(); n   return x * f; n } n inline char getc() { n   char c = gc(); n   while (!isgraph(c)) { n     c = gc(); n   } n   return c; n } n char pbuf[MAXSIZE], *pp = pbuf; n inline void push(const char &c) { n   if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf; n   *pp++ = c; n } n inline void flush() { fwrite(pbuf, 1, pp - pbuf, stdout), pp = pbuf; } n inline void write(int x) { n   static int sta[35]; n   int top = 0; n   do { n     sta[top++] = x % 10, x /= 10; n   } while (x); n   while (top) push(sta[--top] +  0 ); n } n }  // namespace IO n int main() { n   int n, m; n   n = IO::rd(); n   m = IO::rd(); n   vector<char> a(n * m); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) a[((i)*m + (j))] = IO::getc(); n   vector<int> dp(n * m, INF); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       if (a[((i)*m + (j))] !=  X ) n         dp[((i)*m + (j))] = 0; n       else { n         if (i && j) n           dp[((i)*m + (j))] = n               min(dp[((i - 1) * m + (j - 1))], n                   min(dp[((i - 1) * m + (j))], dp[((i)*m + (j - 1))])) + n               1; n         else n           dp[((i)*m + (j))] = 1; n       } n     } n   int l = 0, r = min(n, m); n   auto dp2 = dp; n   while (l < r) { n     int mid = (l + r + 1) / 2; n     int ok = 1; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) { n         if (dp[((i)*m + (j))] < mid) dp[((i)*m + (j))] = 0; n       } n     for (int i = n - 1; i >= 0; i--) n       for (int j = m - 1; j >= 0; j--) { n         if (i != n - 1) n           dp[((i)*m + (j))] = n               max(dp[((i)*m + (j))], dp[((i + 1) * m + (j))] - 1); n         if (j != m - 1) n           dp[((i)*m + (j))] = max(dp[((i)*m + (j))], dp[((i)*m + (j + 1))] - 1); n         if (i != n - 1 && j != m - 1) n           dp[((i)*m + (j))] = n               max(dp[((i)*m + (j))], dp[((i + 1) * m + (j + 1))] - 1); n         if (dp[((i)*m + (j))] == 0 && a[((i)*m + (j))] ==  X ) { n           ok = 0; n           goto zml; n         } n       } n   zml: n     if (ok) { n       l = mid; n     } else { n       r = mid - 1; n     } n     dp = dp2; n   } n   int ans = l; n   IO::write((ans - 1) / 2); n   int a1 = (ans - 1) / 2; n   int a2 = ans / 2; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       a[((i)*m + (j))] =  . ; n       if (dp[((i)*m + (j))] >= ans) { n         a[((i - a1) * m + (j - a1))] =  X ; n         a[((i - a1) * m + (j - a2))] =  X ; n         a[((i - a2) * m + (j - a1))] =  X ; n         a[((i - a2) * m + (j - a2))] =  X ; n       } n     } n   IO::push(  n ); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) IO::push(a[((i)*m + (j))]); n     IO::push(  n ); n   } n   IO::flush(); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, ans, a[2000010], a0[2000010]; n struct Node { n   long long MaxL, MaxR, Max; n }; n Node tree[2000010]; n long long Sign(long long x) { n   if (x > 0) { n     return 1; n   } n   if (x == 0) { n     return 0; n   } n   return -1; n } n void Merge(long long idx, long long l, long long r) { n   if (l == r) { n     return; n   } n   long long mid = (l + r) / 2; n   tree[idx].Max = max(tree[idx * 2 + 1].Max, tree[idx * 2 + 2].Max); n   if (!a[mid] or !a[mid + 1] or Sign(a[mid]) < Sign(a[mid + 1])) { n     tree[idx].MaxL = tree[idx * 2 + 1].MaxL; n     tree[idx].MaxR = tree[idx * 2 + 2].MaxR; n   } else { n     tree[idx].Max = n         max(tree[idx].Max, tree[idx * 2 + 1].MaxR + tree[idx * 2 + 2].MaxL); n     if (tree[idx * 2 + 1].MaxL == mid - l + 1) { n       tree[idx].MaxL = tree[idx * 2 + 1].MaxL + tree[idx * 2 + 2].MaxL; n     } else { n       tree[idx].MaxL = tree[idx * 2 + 1].MaxL; n     } n     if (tree[idx * 2 + 2].MaxR == r - mid) { n       tree[idx].MaxR = tree[idx * 2 + 2].MaxR + tree[idx * 2 + 1].MaxR; n     } else { n       tree[idx].MaxR = tree[idx * 2 + 2].MaxR; n     } n   } n } n void Init(long long idx, long long l, long long r) { n   if (l == r) { n     if (a[l]) { n       tree[idx] = {1, 1, 1}; n     } else { n       tree[idx] = {0, 0, 0}; n     } n     return; n   } n   long long mid = (l + r) / 2; n   Init(idx * 2 + 1, l, mid); n   Init(idx * 2 + 2, mid + 1, r); n   Merge(idx, l, r); n } n void Update(long long idx, long long x, long long val, long long l, n             long long r) { n   if (l == r) { n     a[l] += val; n     if (a[l]) { n       tree[idx] = {1, 1, 1}; n     } else { n       tree[idx] = {0, 0, 0}; n     } n     return; n   } n   long long mid = (l + r) / 2; n   if (x <= mid) { n     Update(idx * 2 + 1, x, val, l, mid); n   } else { n     Update(idx * 2 + 2, x, val, mid + 1, r); n   } n   Merge(idx, l, r); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   cin >> n; n   for (long long i = 0; i < n; ++i) { n     cin >> a0[i]; n   } n   for (long long i = 0; i < n - 1; ++i) { n     a[i] = a0[i + 1] - a0[i]; n   } n   if (n > 1) { n     Init(0, 0, n - 2); n   } n   cin >> m; n   for (long long i = 0; i < m; ++i) { n     long long l, r, x; n     cin >> l >> r >> x; n     if (n == 1) { n       cout <<  1 n ; n       continue; n     } n     if (l >= 2) { n       Update(0, l - 2, x, 0, n - 2); n     } n     if (r < n) { n       Update(0, r - 1, -x, 0, n - 2); n     } n     cout << tree[0].Max + 1 <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mm = 1e6 + 1; n const int mx = 1 << 20; n const int N = 3e5 + 10; n int a[N], b[N]; n int seg_t[mx * 2 + 10], tag[mx * 2 + 10]; n void up(int o) { seg_t[o] = max(seg_t[o << 1], seg_t[o << 1 | 1]); } n void down(int o) { n   if (tag[o] == 0) { n     return; n   } n   seg_t[o << 1] += tag[o]; n   tag[o << 1] += tag[o]; n   seg_t[o << 1 | 1] += tag[o]; n   tag[o << 1 | 1] += tag[o]; n   tag[o] = 0; n } n void update(int o, int l, int r, int ql, int qr, int v) { n   if (ql <= l && r <= qr) { n     seg_t[o] += v; n     tag[o] += v; n     return; n   } n   down(o); n   int mid = (l + r) / 2; n   if (mid >= ql) update(o << 1, l, mid, ql, qr, v); n   if (mid < qr) update(o << 1 | 1, mid + 1, r, ql, qr, v); n   up(o); n } n int query(int o, int l, int r) { n   if (seg_t[o] <= 0) return -1; n   if (l == r) return l; n   down(o); n   int mid = (l + r) / 2; n   if (seg_t[o << 1 | 1] > 0) { n     return query(o << 1 | 1, mid + 1, r); n   } n   return query(o << 1, l, mid); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     update(1, 1, mm, 1, a[i], 1); n   } n   for (int i = 0; i < m; i++) { n     cin >> b[i]; n     update(1, 1, mm, 1, b[i], -1); n   } n   int q; n   cin >> q; n   while (q--) { n     int opt, x, y; n     cin >> opt >> x >> y; n     --x; n     if (opt == 1 && a[x] != y) { n       update(1, 1, mm, 1, a[x], -1); n       a[x] = y; n       update(1, 1, mm, 1, a[x], 1); n     } else if (opt == 2 && b[x] != y) { n       update(1, 1, mm, 1, b[x], 1); n       b[x] = y; n       update(1, 1, mm, 1, b[x], -1); n     } n     cout << query(1, 1, mm) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long int x1, y1; n   cin >> x1 >> y1; n   long long int x2, y2; n   cin >> x2 >> y2; n   int n; n   cin >> n; n   int ans = 0; n   for (int i = 0; n > i; i++) { n     long long int a, b, c; n     cin >> a >> b >> c; n     long long int res1 = a * x1 + b * y1 + c; n     long long int res2 = a * x2 + b * y2 + c; n     if ((res1 < 0 && res2 > 0) || (res1 > 0 && res2 < 0)) { n       ans++; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long N; n long long F[20][10][10] = {{{0}}}; n int to[20][10][10] = {{{0}}}; n long long Ans[20][10] = {{0}}; n void done() { n   for (int i = 0; i <= 9; i++) { n     for (int j = 0; j <= 9; j++) { n       int x = max(i, j); n       if (i == 0 || i < x) { n         F[1][i][j] = 0; n         to[1][i][j] = i; n         continue; n       } n       F[1][i][j] = F[1][i - x][j] + 1; n       to[1][i][j] = to[1][i - x][j]; n     } n   } n   for (int l = 2; l <= 18; l++) { n     for (int i = 0; i <= 9; i++) n       for (int j = 0; j <= 9; j++) { n         long long cost = 0; n         int cnt = i; n         for (int x = 9; x >= 1; x--) { n           cost += F[l - 1][cnt][max(x, j)]; n           cnt = to[l - 1][cnt][max(x, j)]; n           cost++; n           cnt = 10 + cnt - max(max(j, x), cnt); n         } n         cost += F[l - 1][cnt][j]; n         cnt = to[l - 1][cnt][j]; n         F[l][i][j] = cost; n         to[l][i][j] = cnt; n       } n   } n   long long Ans = 0; n   int Len = 0; n   long long Cnt = N; n   for (; Cnt > 0; Cnt /= 10, Len++) n     ; n   int remains = N % 10; n   N /= 10; n   for (int i = 1; i <= Len - 1; i++) { n     int Need = N % 10; n     N /= 10; n     int Max = 0; n     for (Cnt = N; Cnt > 0; Cnt /= 10) Max = max((long long)Max, Cnt % 10); n     for (; Need >= 0; Need--) { n       Ans += F[i][remains][max(Max, Need)]; n       remains = to[i][remains][max(Max, Need)]; n       if (Need > 0 || N > 0) { n         Ans++; n         remains = remains + 10 - max(max(Max, Need), remains); n       } n     } n     N--; n   } n   cout << Ans << endl; n   return; n } n int main() { n   cin >> N; n   if (N <= 9) n     cout << (N > 0) << endl; n   else n     done(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int testcases; n   cin >> testcases; n   while (testcases--) { n     long long int n, m; n     cin >> n >> m; n     char a[n][m]; n     for (long long int(i) = 0; (i) < (n); (i)++) { n       for (long long int(j) = 0; (j) < (m); (j)++) cin >> a[i][j]; n     } n     long long int cnt = 0; n     for (long long int j = 0; j < m - 1; j++) { n       if (a[n - 1][j] ==  D ) cnt++; n     } n     for (long long int(i) = 0; (i) < (n - 1); (i)++) { n       if (a[i][m - 1] ==  R ) cnt++; n     } n     cout << cnt <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {-1, 1, 0, 0, 1, -1, 1, -1}; n int dy[] = {0, -0, -1, 1, 1, -1, -1, 1}; n void run() {} n int fixMod(int a, int b) { return ((a % b) + b) % b; } n long long gcd(long long a, long long b) { n   return (b == 0 ? abs(a) : gcd(b, a % b)); n } n void fast() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int n, m; n vector<vector<char>> grid; n bool flag = 0; n pair<int, int> per[1510][1510]; n bool vis[1510][1510]; n int stx, sty; n bool dfs(int x, int y) { n   int xm = (x + n * 2000) % n; n   int ym = (y + m * 2000) % m; n   if (grid[xm][ym] ==  # ) return 0; n   if (vis[xm][ym]) { n     return per[xm][ym] != make_pair(x, y); n   } n   vis[xm][ym] = 1; n   per[xm][ym] = {x, y}; n   bool ret = 0; n   for (int i = 0; i < 4; i++) { n     ret |= dfs(x + dx[i], y + dy[i]); n   } n   return ret; n } n int main() { n   run(); n   fast(); n   cin >> n >> m; n   grid.resize(n); n   for (int i = 0; i < n; i++) { n     grid[i].resize(m); n     for (int j = 0; j < m; j++) { n       cin >> grid[i][j]; n       if (grid[i][j] ==  S ) stx = i, sty = j; n     } n   } n   if (dfs(stx, sty)) n     cout <<  YES  n          <<   n ; n   else n     cout <<  NO  n          <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   double x, y, r; n }; n double dis(node a, node b) { n   double dx = a.x - b.x, dy = a.y - b.y; n   return sqrt(dx * dx + dy * dy); n } n double R, d; n node origin = {0, 0}; n bool check(node a) { n   double distance = dis(a, origin); n   if (distance - a.r >= R - d && distance + a.r <= R) return true; n   return false; n } n int main() { n   scanf( %lf%lf , &R, &d); n   int k, ans = 0; n   scanf( %d , &k); n   while (k--) { n     node now; n     scanf( %lf%lf%lf , &now.x, &now.y, &now.r); n     if (check(now)) ans++; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[200200], w[200200], dp[3030][3030], ep[3030][3030], X, Y, Z, n     ans[200200], Inv[2 * 3030 + 5]; n const int mod = 998244353; n int expmod(int x, int n) { n   int rlt = 1; n   while (n) { n     if (n & 1) rlt = 1ll * rlt * x % mod; n     x = 1ll * x * x % mod, n >>= 1; n   } n   return rlt; n } n inline int inv(int x) { return expmod(x, mod - 2); } n inline void add(int &x, long long y) { x = (x + y) % mod; } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &w[i]); n   for (int i = 1; i <= n; i++) { n     if (a[i]) n       X += w[i]; n     else n       Y += w[i]; n   } n   Z = X + Y; n   dp[0][0] = 1; n   for (int i = -3030; i <= 3030; i++) Inv[i + 3030] = inv(i + Z); n   for (int i = 0; i <= m; i++) { n     for (int j = 0; j <= m - i; j++) { n       int s = 0; n       if (i) { n         add(dp[i][j], n             1ll * dp[i - 1][j] * (i - 1 + X) % mod * Inv[i - 1 - j + 3030]); n         add(ep[i][j], n             1ll * ep[i - 1][j] * (i - 1 + X) % mod * Inv[i - 1 - j + 3030]); n         add(s, 1ll * dp[i - 1][j] * Inv[i - 1 - j + 3030]); n         add(s, 1ll * ep[i - 1][j] * Inv[i - 1 - j + 3030]); n       } n       if (j) { n         add(dp[i][j], n             1ll * dp[i][j - 1] * (Y - j) % mod * Inv[i - j + 1 + 3030]); n         add(ep[i][j], n             1ll * ep[i][j - 1] * (Y - j) % mod * Inv[i - j + 1 + 3030]); n         add(s, 1ll * dp[i][j - 1] * Inv[i - j + 1 + 3030]); n         add(s, 1ll * ep[i][j - 1] * Inv[i - j + 1 + 3030]); n       } n       add(ep[i][j], s); n     } n   } n   int L = 0, R = 0; n   for (int i = 0; i <= m; i++) add(L, dp[i][m - i]), add(R, ep[i][m - i]); n   for (int k = 1; k <= n; k++) { n     printf( %d n , (1ll * w[k] * (L + a[k] * R) % mod + mod) % mod); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300050; n const int M = 2 * N; n char s[M]; n int tot, sa[M], id[M], fwid[N], bwid[N]; n vector<pair<pair<int, int>, int> > tmp; n void BuildSuffixArray() { n   int i, j, cnt; n   s[++tot] =  a  + 26; n   for (i = 1; i <= tot; i++) id[i] = s[i] -  a ; n   for (j = 0; j < 20; j++) { n     tmp.clear(); n     for (i = 1; i <= tot; i++) n       tmp.push_back(make_pair(make_pair(id[i], id[i + (1 << j)]), i)); n     sort(tmp.begin(), tmp.end()); n     cnt = 0; n     for (i = 0; i < tmp.size(); i++) { n       id[tmp[i].second] = cnt; n       cnt += (tmp[i].first != tmp[i + 1].first); n     } n     if (cnt == tot) break; n   } n   for (i = 1; i <= tot; i++) id[i]++; n   for (i = 1; i <= tot; i++) sa[id[i]] = i; n } n int max(int a, int b) { return a > b ? a : b; } n int min(int a, int b) { return a > b ? b : a; } n int lcp[M]; n void BuildLCPArray() { n   int i, k = 0, j; n   for (i = 1; i <= tot; i++) { n     if (id[i] == tot) continue; n     j = sa[id[i] + 1]; n     while (max(i, j) + k <= tot && s[i + k] == s[j + k]) k++; n     lcp[id[i]] = k; n     if (k > 0) k--; n   } n } n int logs[M]; n void Preprocess() { n   for (int i = 2; i < M; i++) logs[i] = logs[i >> 1] + 1; n } n int rmq[M][21]; n void BuildSparseTable() { n   int i, j; n   for (i = 1; i <= tot; i++) rmq[i][0] = lcp[i]; n   for (j = 1; j < 21; j++) { n     for (i = 1; i <= tot - (1 << j) + 1; i++) { n       rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << j - 1)][j - 1]); n     } n   } n } n void Swap(int &a, int &b) { n   a ^= b; n   b ^= a; n   a ^= b; n } n int RMQ(int l, int r) { n   l = id[l]; n   r = id[r]; n   if (l > r) Swap(l, r); n   if (l == r) return tot - sa[l] + 1; n   r--; n   int k = logs[r - l + 1]; n   return min(rmq[l][k], rmq[r - (1 << k) + 1][k]); n } n int sz[N], dep[N], par[N][19]; n vector<int> E[N]; n void DFS(int u, int p) { n   dep[u] = dep[p] + 1; n   sz[u] = 1; n   par[u][0] = p; n   int i; n   for (i = 1; i < 19; i++) par[u][i] = par[par[u][i - 1]][i - 1]; n   for (i = 0; i < E[u].size(); i++) { n     int v = E[u][i]; n     if (v != p) DFS(v, u), sz[u] += sz[v]; n   } n } n int LCA(int u, int v) { n   if (dep[u] < dep[v]) return LCA(v, u); n   int i; n   for (i = 18; ~i; i--) n     if (dep[par[u][i]] >= dep[v]) u = par[u][i]; n   for (i = 18; ~i; i--) n     if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i]; n   return v == u ? v : par[v][0]; n } n int Chain[N]; n vector<int> Head, Tail[N]; n void HLD(int u, int p) { n   if (!Chain[u]) { n     Chain[u] = Head.size(); n     Head.push_back(u); n   } n   Tail[Chain[u]].push_back(u); n   int i, HC = 0; n   for (i = 0; i < E[u].size(); i++) { n     int v = E[u][i]; n     if (v != p && sz[v] > sz[HC]) HC = v; n   } n   if (HC) { n     Chain[HC] = Chain[u]; n     HLD(HC, u); n     for (i = 0; i < E[u].size(); i++) { n       int v = E[u][i]; n       if (v != p && v != HC) HLD(v, u); n     } n   } n } n char ch[N]; n void BuildString() { n   int i, j; n   for (i = 1; i < Head.size(); i++) { n     for (j = Tail[i].size() - 1; ~j; j--) { n       int v = Tail[i][j]; n       fwid[v] = ++tot; n       s[tot] = ch[v]; n     } n     for (j = 0; j < Tail[i].size(); j++) { n       int v = Tail[i][j]; n       bwid[v] = ++tot; n       s[tot] = ch[v]; n     } n   } n } n vector<pair<int, int> > Take(int u, int v) { n   vector<pair<int, int> > ret, tmp; n   int lca = LCA(u, v), i; n   while (Chain[u] != Chain[lca]) { n     ret.push_back(make_pair(fwid[u], fwid[Head[Chain[u]]])); n     u = par[Head[Chain[u]]][0]; n   } n   while (Chain[v] != Chain[lca]) { n     tmp.push_back(make_pair(bwid[Head[Chain[v]]], bwid[v])); n     v = par[Head[Chain[v]]][0]; n   } n   if (v != lca) n     ret.push_back(make_pair(bwid[lca], bwid[v])); n   else n     ret.push_back(make_pair(fwid[u], fwid[lca])); n   for (i = tmp.size() - 1; ~i; i--) ret.push_back(tmp[i]); n   return ret; n } n int main() { n   Head.push_back(69 & -69); n   int n, q, i, j, u, v, a, b, c, d, k; n   scanf( %i , &n); n   scanf( %s , ch + 1); n   for (i = 1; i < n; i++) n     scanf( %i %i , &u, &v), E[u].push_back(v), E[v].push_back(u); n   DFS(1, 0); n   HLD(1, 0); n   BuildString(); n   BuildSuffixArray(); n   BuildLCPArray(); n   Preprocess(); n   BuildSparseTable(); n   scanf( %i , &q); n   while (q--) { n     scanf( %i %i %i %i , &a, &b, &c, &d); n     if (ch[a] != ch[c]) { n       printf( 0 n ); n       continue; n     } n     vector<pair<int, int> > tmp1, tmp2; n     tmp1 = Take(a, b); n     tmp2 = Take(c, d); n     i = 0; n     j = 0; n     int ans = 0; n     while (i < tmp1.size() && j < tmp2.size()) { n       int sol = RMQ(tmp1[i].first, tmp2[j].first); n       sol = min(sol, tmp1[i].second - tmp1[i].first + 1); n       sol = min(sol, tmp2[j].second - tmp2[j].first + 1); n       ans += sol; n       tmp1[i].first += sol; n       tmp2[j].first += sol; n       bool ok = 0; n       if (tmp1[i].first > tmp1[i].second) i++, ok = 1; n       if (tmp2[j].first > tmp2[j].second) j++, ok = 1; n       if (!ok) break; n     } n     printf( %i n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int nMAX = 100000 + 5; n const int NMAX = 2 * nMAX; n int n, m; n string S, T; n int Q; n int N; n string str; n const int MOD[] = {1000000000 + 7, 1000000000 + 9}; n struct Hash { n   int h[sizeof(MOD) / sizeof(int)]; n   Hash() { n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) h[i] = 0; n   } n   Hash(int v0, int v1) { h[0] = v0, h[1] = v1; } n   Hash operator+(const Hash &hs) const { n     Hash res; n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) { n       res.h[i] = h[i] + hs.h[i]; n       if (res.h[i] >= MOD[i]) res.h[i] -= MOD[i]; n     } n     return res; n   } n   Hash operator-(const Hash &hs) const { n     Hash res; n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) { n       res.h[i] = h[i] - hs.h[i]; n       if (res.h[i] < 0) res.h[i] += MOD[i]; n     } n     return res; n   } n   Hash operator*(const Hash &hs) const { n     Hash res; n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) n       res.h[i] = (1LL * h[i] * hs.h[i]) % MOD[i]; n     return res; n   } n   bool operator==(const Hash &hs) const { n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) n       if (h[i] != hs.h[i]) return false; n     return true; n   } n   bool operator!=(const Hash &hs) const { n     for (int i = 0; i < sizeof(MOD) / sizeof(int); ++i) n       if (h[i] != hs.h[i]) return true; n     return false; n   } n }; n const Hash C = {666013, 666017}; n Hash powC[NMAX]; n Hash sPart[NMAX]; n void precomputeHashes() { n   powC[0] = Hash(1, 1); n   for (int i = 1; i <= N; ++i) powC[i] = powC[i - 1] * C; n   for (int i = 1; i <= N; ++i) n     sPart[i] = sPart[i - 1] * C + Hash(str[i], str[i]); n } n Hash getHashS(int l, int r) { n   Hash hr = sPart[r]; n   Hash hl = sPart[l - 1]; n   return hr - hl * powC[r - l + 1]; n } n Hash getHashT(int l, int r) { n   Hash hr = sPart[r + n + 1]; n   Hash hl = sPart[l - 1 + n + 1]; n   return hr - hl * powC[r - l + 1]; n } n bool lcp(int l, int r) { n   int st = 1; n   int dr = min(N - l + 1, N - r + 1); n   int ans = 0; n   while (st <= dr) { n     int mid = (st + dr) >> 1; n     if (getHashS(l, l + mid - 1) == getHashS(r, r + mid - 1)) { n       ans = mid; n       st = mid + 1; n     } else n       dr = mid - 1; n   } n   return str[l + ans] < str[r + ans]; n } n int lcpSS(int l, int r) { return lcp(l, r); } n int lcpST(int l, int r) { return lcp(l, r + n + 1); } n int lcpTS(int l, int r) { return lcp(l + n + 1, r); } n int lcpTT(int l, int r) { return lcp(l + n + 1, r + n + 1); } n bool cmpPlacement(const int &_a, const int &_b) { n   int a = _a + 1, b = _b + 1; n   bool rev = false; n   if (b < a) { n     swap(a, b); n     rev = true; n   } n   if (b <= a + m) { n     if (getHashT(1, b - a) != getHashS(a, b - 1)) n       return lcpTS(1, a) ^ rev; n     else if (getHashT(b - a + 1, m) != getHashT(1, a + m - b)) n       return lcpTT(b - a + 1, 1) ^ rev; n     else if (getHashS(a, b - 1) != getHashT(a + m - b + 1, m)) { n       return lcpST(a, a + m - b + 1) ^ rev; n     } n   } else { n     if (getHashT(1, m) != getHashS(a, a + m - 1)) n       return lcpTS(1, a) ^ rev; n     else if (getHashS(a, b - m - 1) != getHashS(a + m, b - 1)) { n       return lcpSS(a, a + m) ^ rev; n     } else if (getHashS(b - m, b - 1) != getHashT(1, m)) n       return lcpST(b - m, 1) ^ rev; n   } n   return false; n } n string ins(string a, string b, int pos) { n   a.insert(pos, b); n   return a; n } n int ord[NMAX]; n int inv[NMAX]; n int logar2[NMAX]; n void precLogar2() { n   for (int i = 2; i <= N; ++i) logar2[i] = 1 + logar2[i >> 1]; n } n const int RAD = 150; n struct RMQ { n   vector<int> v; n   int dims; n   int **dp; n   void destroy() { n     v.clear(); n     for (int i = 0; i <= dims; ++i) delete dp[i]; n     delete dp; n     dims = 0; n   } n   void computeDp() { n     dims = logar2[v.size()]; n     if ((1 << dims) < v.size()) ++dims; n     dp = new int *[dims + 1]; n     for (int i = 0; i <= dims; ++i) { n       dp[i] = new int[v.size()]; n     } n     for (int i = 0; i < v.size(); ++i) dp[0][i] = v[i]; n     for (int i = 1; i <= dims; ++i) n       for (int j = 0; j + (1 << i) - 1 < v.size(); ++j) n         if (inv[dp[i - 1][j]] < inv[dp[i - 1][j + (1 << (i - 1))]]) n           dp[i][j] = dp[i - 1][j]; n         else n           dp[i][j] = dp[i - 1][j + (1 << (i - 1))]; n   } n   int query(int a, int b) { n     if (b < a) return n + 1; n     int y = logar2[b - a + 1]; n     if (inv[dp[y][a]] < inv[dp[y][b - (1 << y) + 1]]) return dp[y][a]; n     return dp[y][b - (1 << y) + 1]; n   } n } all; n RMQ rmqs[RAD + 5]; n struct Query { n   int l, r, x, y; n   int pos; n }; n vector<Query> queries[RAD + 5]; n int anss[NMAX]; n int main() { n   ios_base ::sync_with_stdio(false); n   cin >> S >> T >> Q; n   n = S.size(); n   m = T.size(); n   str =  #  + S +  #  + T; n   N = str.size() - 1; n   str +=  # ; n   precomputeHashes(); n   for (int i = 0; i <= n; ++i) ord[i] = i; n   stable_sort(ord, ord + n + 1, cmpPlacement); n   for (int i = 0; i <= n; ++i) inv[ord[i]] = i; n   inv[n + 1] = n + 2; n   precLogar2(); n   all.v.resize(n + 1); n   for (int i = 0; i <= n; ++i) { n     all.v[i] = i; n   } n   all.computeDp(); n   for (int i = 1; i <= Q; ++i) { n     int l, r, k, x, y; n     cin >> l >> r >> k >> x >> y; n     int ans = n + 1; n     if (k > RAD) { n       if (x <= l % k && l % k <= y) { n         ans = all.query(l, min(r, l + y - l % k)); n         l += y - l % k + 1; n       } n       l += (k + x - l % k) % k; n       while (l <= r) { n         int aux = all.query(l, min(r, l + y - x)); n         if (inv[aux] < inv[ans]) ans = aux; n         l += k; n       } n       if (ans == n + 1) n         anss[i] = -1; n       else n         anss[i] = ans; n     } else { n       queries[k].push_back({l, r, x, y, i}); n     } n   } n   for (int k = 1; k <= RAD; ++k) { n     for (int i = 0; i <= n; ++i) rmqs[i % k].v.push_back(i); n     for (int res = 0; res < k; ++res) rmqs[res].computeDp(); n     for (auto it : queries[k]) { n       int x = it.x; n       int y = it.y; n       int l = it.l; n       int r = it.r; n       int pos = it.pos; n       int ans = n + 1; n       for (int res = x; res <= y && res <= r; ++res) { n         int a, b; n         b = (r - res) / k; n         if (l - res < 0) n           a = 0; n         else n           a = (l - res + k - 1) / k; n         int qu = rmqs[res].query(a, b); n         if (inv[qu] < inv[ans]) ans = qu; n       } n       if (ans == n + 1) n         anss[pos] = -1; n       else n         anss[pos] = ans; n     } n     for (int res = 0; res < k; ++res) rmqs[res].destroy(); n   } n   for (int i = 1; i <= Q; ++i) cout << anss[i] <<    n [i == Q]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, s; n int a[105]; n double f[105][10005]; n int main() { n   cin >> n >> x; n   for (int i = 1; i <= n; i++) cin >> a[i], s += a[i]; n   f[0][0] = 1; n   for (int i = 1; i <= n; i++) n     for (int j = i; j >= 1; j--) n       for (int k = s; k >= a[i]; k--) n         f[j][k] += f[j - 1][k - a[i]] * j / (n - j + 1); n   double ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= s; j++) n       ans += f[i][j] * (min((n + i) * x, j * 2) / 2.0) / i; n   printf( %.10lf , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 1e6; n using namespace std; n const int maxn = 1e5 + 5; n const int N = 1e6; n const int big = 1e9; n long long int get(long long int a, long long int b, long long int x, n                   long long int y) { n   x--; n   y--; n   long long int temp = (y * (y - 1) - x * (x - 1)) / 2; n   return a * (y - x) + b * temp; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long int a, b, n, i, l, m, t; n   cin >> a >> b >> n; n   for (i = 0; i < n; i++) { n     cin >> l >> t >> m; n     long long int st = l; n     long long int en = 2e6 + 5; n     while (en - st > 1) { n       long long int mid = st + (en - st) / 2; n       if ((a + (mid - 2) * b) <= t && get(a, b, l, mid) <= m * t) n         st = mid; n       else n         en = mid; n     } n     if (st == l) st = 0; n     cout << st - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n queue<pair<int, int> > q; n vector<pair<int, int> > v; n vector<vector<int> > g; n set<pair<int, int> > out; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     v.push_back({x, y}); n     if (x == 1) q.push({i, y}); n   } n   while (!q.empty()) { n     pair<int, int> x = q.front(); n     q.pop(); n     int y = x.second; n     v[y].second ^= x.first; n     v[y].first--; n     out.insert({min(x.first, y), max(x.first, y)}); n     if (v[y].first == 1) { n       q.push({y, v[y].second}); n     } n   } n   cout << out.size() <<   n ; n   for (auto a : out) { n     cout << a.first <<     << a.second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, x, y, i, s = 0, k = 0; n   vector<pair<long long int, long long int> > v; n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     cin >> x >> y; n     v.push_back(make_pair(y, x)); n   } n   sort(v.begin(), v.end()); n   for (i = v.size() - 1; i >= 0; i--) { n     if (n > 0) { n       if (v[i].second >= n) { n         s = s + n * v[i].first; n         n = 0; n       } else { n         s = s + v[i].second * v[i].first; n         n = n - v[i].second; n       } n     } else { n       k = -1; n       cout << s << endl; n       break; n     } n   } n   if (k == 0) cout << s << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int v[100010]; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   int low = 1000000001; n   for (int i = 0; i < n; i++) { n     scanf( %d , &v[i]); n     low = min(low, v[i]); n   } n   long long ans = 0; n   for (int i = 0; i < n && ans != -1; i++) { n     if ((v[i] - low) % k == 0) { n       ans += (v[i] - low) / k; n     } else n       ans = -1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   stack<char> a; n   int count = 0, flag = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  {  || s[i] ==  [  || s[i] ==  <  || s[i] ==  ( ) n       a.push(s[i]); n     else { n       if (a.size() == 0) { n         cout <<  Impossible ; n         return 0; n       } n       if (a.top() ==  (  && s[i] !=  )  || a.top() ==  {  && s[i] !=  }  || n           a.top() ==  [  && s[i] !=  ]  || a.top() ==  <  && s[i] !=  > ) n         count++; n       a.pop(); n     } n   } n   if (a.size() == 0 && flag == 0) n     cout << count; n   else n     cout <<  Impossible ; n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n using ll = long long; n  n #ifdef LOCAL n #define debug(...) {  n     std::cout <<  [  << __FUNCTION__ <<  :  << __LINE__ <<  ]   << #__VA_ARGS__ <<      << __VA_ARGS__ << std::endl;  n     } n #else n #define debug(...) n #endif n  n const long long mod = 1000000007; n #define MOD(x) ((x)%mod) n struct UnionFind { n  vector<int> par; n  vector<int> siz; n  vector<int> val; n  UnionFind(int N) { n   par.resize(N); n   siz.resize(N); n   val.resize(N); n  n   for (int i = 0; i < N; i++) { n    par[i] = i; n    siz[i] = 1; n  n    val[i] = 0; n   } n  } n  int& operator[](const int &x) { n   return val[getParent(x)]; n  } n  int getParent(int x) { n   int t = x; n  n   while (par[x] != x) { n    x = par[x]; n   } n  n   par[t] = x; n   return x; n  } n  int getSize(const int &x) { n   return siz[getParent(x)]; n  } n  bool merge(int x, int y) { n   x = getParent(x); n   y = getParent(y); n  n   if (x == y) { n    return false; n   } n  n   if (val[x] and val[y]) { n    return false; n   } n  n   if (siz[x] > siz[y]) { n    swap(x, y);    // siz[x] is smaller n   } n  n   par[x] = y; n   siz[y] += siz[x]; n   val[y] = val[x] or val[y]; n   return true; n  n  } n  bool connected(const int &x, const int &y) { n   return getParent(x) == getParent(y); n  } n }; n long long power(long long x, long long n) { n  int i = 0; n  long long d = x; n  long long ats = 1; n  n  while (n > 0) { n   if (n & (1ll << i)) { n    n ^= (1ll << i); n    ats *= d; n    ats %= mod; n   } n  n   i++; n   d = (d * d) % mod; n  } n  n  return ats; n } n /*input n 3 2 n 1 1 n 1 2 n 2 2 1 n */ n /*input n 2 3 n 2 1 3 n 2 1 2 n */ n /*input n 3 5 n 2 1 2 n 1 3 n 1 4 n */ n int main() { n  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n  long long n, m; n  cin >> n >> m; n  n  UnionFind par(m); n  n  set<int> imt; n  n  for (int i = 0; i < n; ++i) { n   int k; n   cin >> k; n  n   if (k == 1) { n    int a; n    cin >> a; n    a--; n  n    if (!par[a]) { n     par[a] = true; n     imt.insert(i); n    } n   } n   else if (k == 2) { n    int a, b; n    cin >> a >> b; n    a--, b--; n  n    if (par.merge(a, b)) { n     imt.insert(i); n    } n   } n  } n  n  long long vis = 0; n  n  for (int i = 0; i < m; ++i) { n   if (par.getParent(i) == i) { n    if (par.val[i]) { n     vis += par.siz[i]; n    } n    else { n     vis += par.siz[i] - 1; n    } n   } n  } n  n  cout << power(2, vis) <<     << imt.size() <<   n ; n  n  for (auto &&i : imt) { n   cout << i + 1 <<    ; n  } n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = int(2 * 1e5 + 5); n int dp1[maxn], dp2[maxn], dp3[maxn], n, k, t; n string second; n char chuyen(char c) { n   if (c ==  R ) return  G ; n   if (c ==  G ) return  B ; n   if (c ==  B ) return  R ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> n >> k >> second; n     second =     + second; n     for (int i = 0; i <= second.length(); i++) { n       dp1[i] = dp2[i] = dp3[i] = 0; n     } n     char c =  R ; n     for (int i = 1; i <= second.length() - 1; i++) { n       if (second[i] != c) n         dp1[i] = dp1[i - 1] + 1; n       else n         dp1[i] = dp1[i - 1]; n       c = chuyen(c); n     } n     c =  G ; n     for (int i = 1; i <= second.length() - 1; i++) { n       if (second[i] != c) n         dp2[i] = dp2[i - 1] + 1; n       else n         dp2[i] = dp2[i - 1]; n       c = chuyen(c); n     } n     c =  B ; n     for (int i = 1; i <= second.length() - 1; i++) { n       if (second[i] != c) n         dp3[i] = dp3[i - 1] + 1; n       else n         dp3[i] = dp3[i - 1]; n       c = chuyen(c); n     } n     int res = int(1e9 + 5); n     for (int i = 1; i <= second.length() - k; i++) { n       res = min(res, dp1[i + k - 1] - dp1[i - 1]); n       res = min(res, dp2[i + k - 1] - dp2[i - 1]); n       res = min(res, dp3[i + k - 1] - dp3[i - 1]); n     } n     cout << res <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n int main() { n   int h, w, k, count = 0; n   scanf( %d %d %d , &h, &w, &k); n   for (size_t i = 0; i < k; i++) { n     if (h == 1 && w == 1) { n       count++; n     } else if (h == 1) { n       count += w; n     } else if (w == 1) { n       count += h; n     } else { n       count += (h * 2) + (w - 2) * 2; n     } n     h -= 4; n     w -= 4; n   } n   printf( %d n , count); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int x[2001], y[2001]; n bool sameLine(int i, int j, int k) { n   return (y[i] - y[j]) * (x[k] - x[j]) == (y[k] - y[j]) * (x[i] - x[j]); n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) scanf( %d %d , &x[i], &y[i]); n   long long ans = 0; n   for (int i = 0; i < N; i++) { n     for (int j = i + 1; j < N; j++) { n       for (int k = j + 1; k < N; k++) { n         if (!sameLine(i, j, k)) ans++; n       } n     } n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int f(long long p) { n   int ans = 0; n   while (p) { n     ans += p % 10; n     p /= 10; n   } n   return ans; n } n long long g(long long a) { n   if (a == 0) return 0; n   int digit = 0; n   long long b = a; n   while (b >= 10) { n     digit++; n     b /= 10; n   } n   int b_digit = b; n   long long ans = b * digit; n   for (int i = 0; i < digit; i++) ans *= 10, b *= 10; n   ans *= 9; n   ans /= 2; n   for (int i = 0; i < b_digit; i++) ans += i * (b / b_digit); n   ans += g(a - b) + b_digit * (a - b + 1); n   return ans; n } n int main() { n   long long a; n   scanf( %lld , &a); n   long long l = 1, r = 20000000000000000LL; n   while (l < r) { n     long long mid = (l + r) / 2; n     if (g(mid) >= a) n       r = mid; n     else n       l = mid + 1; n   } n   l = 1; n   long long cur = g(r); n   while (cur != a) { n     if (cur > a) { n       cur -= f(l); n       l++; n     } else { n       cur += f(r + 1); n       r++; n     } n   } n   printf( %lld %lld , l, r); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T euclideanistance(T x1, T x2, T y1, T y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n } n template <class T> n T digitSum(T n) { n   T sum = 0; n   while (n > 0) sum += n % 10, n /= 10; n   return sum; n } n const double INF = 1e+9; n const double EPS = 1e-9; n const double PI = 3.1415926; n const int knightDir[8][2] = {{-2, -1}, {-2, 1}, {-1, 2},  {1, 2}, n                              {2, -1},  {2, 1},  {-1, -2}, {1, -2}}; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, 1, 0, -1}; n int chk(pair<int, int> a, pair<int, int> b) { n   if (a.first == b.first && a.first != b.second && a.second != b.first && n       a.second != b.second) n     return 1; n   if (a.first != b.first && a.first == b.second && a.second != b.first && n       a.second != b.second) n     return 1; n   if (a.first != b.first && a.first != b.second && a.second == b.first && n       a.second != b.second) n     return 1; n   if (a.first != b.first && a.first != b.second && a.second != b.first && n       a.second == b.second) n     return 1; n   return 0; n } n int getIndex(pair<int, int> a, pair<int, int> b) { n   if (a.first == b.first && a.first != b.second && a.second != b.first && n       a.second != b.second) n     return a.first; n   if (a.first != b.first && a.first == b.second && a.second != b.first && n       a.second != b.second) n     return a.first; n   if (a.first != b.first && a.first != b.second && a.second == b.first && n       a.second != b.second) n     return a.second; n   if (a.first != b.first && a.first != b.second && a.second != b.first && n       a.second == b.second) n     return a.second; n } n int main() { n   int n, m, can = 0, all = 0; n   vector<pair<int, int> > a, b; n   scanf( %d%d , &n, &m); n   a.resize(n); n   b.resize(m); n   for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second); n   for (int i = 0; i < m; i++) scanf( %d%d , &b[i].first, &b[i].second); n   vector<int> alls(10); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (chk(a[i], b[j])) { n         vector<int> c1(10); n         vector<int> c2(10); n         for (int k = 0; k < m; k++) { n           if (chk(a[i], b[k])) { n             c1[getIndex(a[i], b[k])] = 1; n           } n         } n         for (int k = 0; k < n; k++) { n           if (chk(a[k], b[j])) { n             c2[getIndex(a[k], b[j])] = 1; n           } n         } n         if (count(c1.begin(), c1.end(), 1) == 1 && n             count(c2.begin(), c2.end(), 1) == 1) n           can++; n         alls[getIndex(a[i], b[j])] = 1; n         all++; n       } n     } n   } n   if (count(alls.begin(), alls.end(), 1) == 1) { n     for (int i = 1; i <= 10; i++) { n       if (alls[i]) { n         printf( %d n , i); n         return 0; n       } n     } n   } n   if (can == all) { n     printf( 0 n ); n     return 0; n   } n   printf( -1 n ); n } n


#include <bits/stdc++.h> n using namespace std; n long long lcis(long long a[], long long n) { n   unordered_map<long long, long long> make_pair; n   long long dp[n], lastIndex; n   memset(dp, 0, sizeof(dp)); n   ; n   long long mx = INT_MIN; n   for (long long i = 0; i < n; i++) { n     if (make_pair.find(a[i] - 1) != make_pair.end()) n       lastIndex = make_pair[a[i] - 1] - 1, dp[i] = 1 + dp[lastIndex]; n     else n       dp[i] = 1; n     make_pair[a[i]] = i + 1; n     mx = max(mx, dp[i]); n   } n   return mx; n } n int main() { n   long long n; n   cin >> n; n   long long arr[n]; n   for (long long i = 0; i < n; i++) cin >> arr[i]; n   long long li = lcis(arr, n); n   cout << n - li << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e16 + 3; n const int mod = 1e9 + 7; n const int lim = 2e5 + 2; n int q, ni; n string str; n void solve() { n   cin >> q; n   while (q--) { n     cin >> ni >> str; n     if (ni > 2) { n       cout <<  YES  n            <<   n ; n       cout << 2 <<   n ; n       cout << str[0] <<    ; n       for (int i = 1; i < ni; i++) cout << str[i]; n       cout <<   n ; n     } else { n       int f = str[0] -  0 ; n       int s = str[1] -  0 ; n       if (f < s) { n         cout <<  YES  n              <<   n ; n         cout << 2 <<   n ; n         cout << str[0] <<     << str[1] <<   n ; n       } else n         cout <<  NO  n              <<   n ; n     } n   } n } n void fastIO() { n   cin.sync_with_stdio(false); n   cin.tie(0); n } n void IO() { n   if (fopen( d:  lmo.in ,  r ) != NULL) { n     freopen( d:  lmo.in ,  r , stdin); n   } else if (fopen( /media/luismo/Pablo s Destruction/lmo.in ,  r ) != NULL) { n     freopen( /media/luismo/Pablo s Destruction/lmo.in ,  r , stdin); n   } n } n int main() { n   IO(); n   fastIO(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n const long long LINF = 2e18; n void inv(bool e); n template <typename T> n void die(T& a); n bool brute, alter; n int cnt_tests = 1; n const int N = (1 << 17) + 1; n int degree[N], xr[N]; n int n; n void inp() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> degree[i] >> xr[i]; n   } n } n set<int> friends[N]; n void solve() { n   for (int i = 0; i < n; i++) { n     friends[degree[i]].insert(i); n   } n   int newbie, parent; n   auto& cur = friends[1]; n   vector<pair<int, int> > ans; n   while (!cur.empty()) { n     newbie = *cur.begin(); n     cur.erase(cur.begin()); n     parent = xr[newbie]; n     friends[degree[parent]].erase(parent); n     friends[degree[parent] - 1].insert(parent); n     degree[parent]--; n     ans.push_back({newbie, parent}); n     xr[parent] ^= newbie; n   } n   cout << ((int)(ans).size()) << endl; n   for (auto x : ans) { n     cout << x.first <<     << x.second << endl; n   } n } n void stress() {} n void naive() {} n void run(); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   if (0) { n     freopen( stack.in ,  r , stdin); n     freopen( stack.out ,  w , stdout); n   } n   brute = false; n   for (int i = 0; (i < cnt_tests); i++) { n     run(); n   } n   cerr << endl <<  Time:   << clock() / 1000.0 <<   ms ; n   return 0; n } n void run() { n   if (!brute) { n     inp(); n   } else { n     stress(); n   } n   solve(); n } n template <typename T> n void die(T& a) { n   cout << a; n   exit(0); n } n void inv(bool e) { n   if (!e) { n     vector<int> a; n     a[-1] += 1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void ga(int N, int *A) { n   for (int i(0); i < N; i++) scanf( %d , A + i); n } n char s[64][64]; n int N, M, x = int(1e9 + 1), X, y = int(1e9 + 1), Y; n int main(void) { n   scanf( %d%d , &N, &M); n   for (int i(0); i < N; i++) scanf( %s , s[i]); n   for (int i(0); i < N; i++) n     for (int j(0); j < M; j++) n       if (s[i][j] == 42) n         x = min(x, i), X = max(X, i), y = min(y, j), Y = max(Y, j); n   for (int k(x); k < X + 1; k++) { n     for (int l(y); l < Y + 1; l++) putchar(s[k][l]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5 + 10; n int mapp[110][110]; n int b[110][110]; n int main() { n   int Cas = 1; n   scanf( %d , &Cas); n   while (Cas--) { n     int n, m; n     scanf( %d%d , &n, &m); n     memset(mapp, 0, sizeof(mapp)); n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) { n         scanf( %d , &mapp[i][j]); n         int flag = (i + j) % 2; n         if (mapp[i][j] % 2 == flag) n           b[i][j] = mapp[i][j]; n         else n           b[i][j] = mapp[i][j] + 1; n       } n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) printf( %d%c , b[i][j], j == m ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mxn = 1e5 + 1; n string s, s1, s2, s3; n char ch[10000][10000]; n int main() { n   long long int n, m, i, z, j, a = 0, ans = 0, k = 0, cnt = 0, b; n   long long int c = 0, x, y, d = 0, sum = 0, mn = INT_MAX, mx = 0; n   string ss, strn; n   char ch; n   cin >> n; n   long long int evn[n + 1], odd[n + 1], e = 0, o = 0; n   long long int ara[n + 2], bra[n + 1], cra[n + 1]; n   map<long long int, long long int> mp; n   set<long long int> st; n   set<long long int>::iterator sit; n   priority_queue<long long int> pq; n   for (i = 1; i <= n; i++) { n     cin >> ara[i]; n   } n   sort(ara + 1, ara + n + 1); n   for (i = n; i > 1; i--) { n     x = abs(ara[i] - ara[i - 1]); n     if (x <= 1) { n       if (!cnt) a = ara[i - 1]; n       if (cnt == 1) b = ara[i - 1]; n       cnt++; n       if (cnt == 2) { n         ans += (a * b); n         cnt = 0; n       } n       --i; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int T = 1000; n const long long MAX = 1000000000000007; n const long long MOD = 100000000; n long long n, m, k; n vector<long long> A[T]; n vector<pair<char, int> > ans; n long long K[T]; n long long N[T]; n int main() { n   cin >> n; n   for (int i = (int)0; i <= (int)n - 1; i++) { n     cin >> N[i]; n   } n   cin >> k; n   for (int i = (int)0; i <= (int)k - 1; i++) { n     cin >> K[i]; n   } n   int j = 0; n   for (int i = (int)0; i <= (int)k - 1; i++) { n     long long sum = 0; n     while (sum < K[i] && j <= n - 1) { n       sum += N[j]; n       A[i].push_back(N[j]); n       j++; n     } n     if (sum != K[i]) { n       cout <<  NO  << endl; n       return 0; n     } n     if (A[i].size() == 1) { n       continue; n     } n     long long ma = 0; n     for (int g = (int)0; g <= (int)A[i].size() - 1; g++) { n       ma = max(ma, A[i][g]); n     } n     bool can = false; n     for (int g = (int)0; g <= (int)A[i].size() - 1; g++) { n       if (A[i][g] == ma) { n         if (g != 0 && A[i][g - 1] < ma || n             g != A[i].size() - 1 && A[i][g + 1] < ma) { n           can = true; n         } n         if (can) { n           while (A[i].size() != 1) { n             if (g != 0 && A[i][g - 1] < ma) { n               ma = ma + A[i][g - 1]; n               A[i][g - 1] = ma; n               ans.push_back(make_pair( L , i + g + 1)); n               A[i].erase(A[i].begin() + g - 1); n               g--; n             } else { n               if (g != A[i].size() - 1 && A[i][g + 1] < ma) { n                 ma = ma + A[i][g + 1]; n                 A[i][g] = ma; n                 ans.push_back(make_pair( R , i + g + 1)); n                 A[i].erase(A[i].begin() + g); n               } n             } n           } n           break; n         } n       } n     } n     if (!can) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   if (j == n) { n     cout <<  YES  << endl; n   } else { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = (int)0; i <= (int)ans.size() - 1; i++) { n     cout << ans[i].second <<     << ans[i].first << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, i, j, k, t, len; n char st[200]; n int main() { n   scanf( %d , &n); n   while (n--) { n     scanf( %s , st); n     len = strlen(st); n     t = 8; n     for (i = 0; i < len; i++) n       if (st[i] !=  : ) { n         t--; n         while (i < len && st[i] !=  : ) i++; n       } n     j = 0; n     for (i = 0; i < len; i++) { n       if (st[i] ==  : ) { n         if (j != i) { n           if (j != 0) printf( : ); n           for (k = 0; k < 4 - i + j; k++) printf( 0 ); n           for (k = j; k < i; k++) printf( %c , st[k]); n         } n         if (st[i + 1] ==  : ) { n           if (j == i) n             printf( 0000 ); n           else n             printf( :0000 ); n           for (k = 1; k < t; k++) printf( :0000 ); n           i++; n         } n         j = i + 1; n       } n     } n     if (st[len - 1] !=  : ) { n       printf( : ); n       for (k = 0; k < 4 - i + j; k++) printf( 0 ); n       for (k = j; k < i; k++) printf( %c , st[k]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Z = (int)1e5 + 111; n const int inf = (int)1e9 + 111; n const long long llinf = (long long)1e18 + 5; n const int MOD = (int)1e9 + 7; n vector<int> ans[Z]; n int a[Z]; n pair<int, int> b[Z]; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     b[i].first = a[i]; n     b[i].second = i; n   } n   int cnt = 0; n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; ++i) { n     if (a[i] == -inf) continue; n     set<int> cur_pos; n     cur_pos.insert(i); n     int pos = lower_bound(b + 1, b + 1 + n, make_pair(a[i], -inf)) - b; n     while (!cur_pos.count(pos)) { n       int x = pos; n       cur_pos.insert(pos); n       pos = lower_bound(b + 1, b + 1 + n, make_pair(a[pos], -inf)) - b; n       a[x] = -inf; n     } n     cnt++; n     for (int to : cur_pos) { n       ans[cnt].push_back(to); n     } n   } n   cout << cnt <<   n ; n   for (int i = 1; i <= cnt; ++i) { n     cout << (int)ans[i].size() <<    ; n     for (int j = 0; j < (int)ans[i].size(); ++j) { n       cout << ans[i][j] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const long long INF = 1e9; n const long long LINF = INF * INF; n const int MAX = 1 << 10; n void go(pair<int, int> s, pair<int, int> f, vector<pair<int, int> >& a) { n   a.push_back(s); n   while (s.first > f.first) { n     s.first--; n     a.push_back(s); n   } n   while (s.first < f.first) { n     s.first++; n     a.push_back(s); n   } n   while (s.second > f.second) { n     s.second--; n     a.push_back(s); n   } n   while (s.second < f.second) { n     s.second++; n     a.push_back(s); n   } n   a.push_back(f); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   vector<pair<int, int> > a(3); n   for (int i = (0); i < (3); ++i) cin >> a[i].first >> a[i].second; n   vector<pair<int, int> > ans1, ans2; n   sort(a.begin(), a.end()); n   go(a[0], a[1], ans1); n   go(a[1], a[2], ans1); n   go(a[0], {a[1].first, a[2].second}, ans2); n   go(a[1], {a[1].first, a[2].second}, ans2); n   go(a[2], {a[1].first, a[2].second}, ans2); n   sort(ans1.begin(), ans1.end()); n   ans1.resize(unique(ans1.begin(), ans1.end()) - ans1.begin()); n   sort(ans2.begin(), ans2.end()); n   ans2.resize(unique(ans2.begin(), ans2.end()) - ans2.begin()); n   vector<pair<int, int> > ans = ans1; n   if ((int)((ans2).size()) < (int)((ans1).size())) ans = ans2; n   sort(ans.begin(), ans.end()); n   ans.resize(unique(ans.begin(), ans.end()) - ans.begin()); n   cout << (int)((ans).size()) << endl; n   for (auto i : ans) cout << i.first <<     << i.second << endl; n   cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, h, j, w; n string s, t, v; n pair<string, int> k; n stack<int> p; n vector<pair<string, int>> a; n int main() { n   cin >> s; n   v = s; n   t = s; n   for (i = 0; i < s.size(); i++) n     if (s[i] ==  (  || s[i] ==  [ ) p.push(i); n   while (!p.empty()) { n     j = p.top(); n     if (s[j] ==  (  && s[j + 1] ==  ) ) n       v[j] =  0 , v[v.find( ) , j)] =  0 , s.erase(j, 2); n     if (s[j] ==  [  && s[j + 1] ==  ] ) n       v[j] =  0 , v[v.find( ] , j)] =  0 , s.erase(j, 2); n     p.pop(); n   } n   for (i = 0; i < v.size(); i++) { n     if (v[i] ==  0 ) { n       k.first += t[i]; n       if (t[i] ==  [ ) k.second++; n     } n     if (v[i] !=  0  && k.first.size() || i == v.size() - 1 && k.first.size()) n       a.push_back(k), k.first.clear(), h = max(h, k.second), k.second = 0; n   } n   if (!h) n     cout << 0; n   else if (!a.size()) n     cout << k.second << endl << k.first; n   else { n     for (i = 0; i < a.size(); i++) n       if (a[i].second == h) { n         cout << h << endl << a[i].first; n         break; n       } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, k, p, x, y; n   cin >> n >> k >> p >> x >> y; n   long long int sum = 0; n   long long int cov = 0; n   for (int i = 0; i < k; i++) { n     long long int kk; n     cin >> kk; n     if (kk < y) cov++; n     sum += kk; n   } n   int used = k; n   int remain; n   if (cov > (n / 2)) { n     cout <<  -1 ; n     return 0; n   } else { n     remain = (n / 2) - cov; n     if (remain > n - k) remain = n - k; n     sum += remain; n     used += remain; n   } n   int finalre = n - used; n   if (sum + finalre * y <= x) { n     for (int i = 0; i < remain; i++) n       cout <<  1  n            <<    ; n     for (int i = 0; i < finalre; i++) cout << y <<    ; n   } else n     cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[2][252], f[252][252], C[252], mod = 1e9 + 7, inv[252]; n int qp(int a, int x) { n   int i = 1; n   for (; x; x >>= 1, a = 1ll * a * a % mod) n     if (x & 1) i = 1ll * i * a % mod; n   return i; n } n int main() { n   int n, m, i, j, k, a; n   scanf( %d%d , &n, &m); n   for (inv[1] = 1, i = 2; i <= n; i++) n     inv[i] = mod - 1ll * mod / i * inv[mod % i] % mod; n   for (i = C[0] = p[0][0] = p[1][0] = 1; i <= n; i++) { n     C[i] = 1ll * C[i - 1] * (n - i + 1) % mod * inv[i] % mod; n     p[0][i] = 1ll * p[0][i - 1] * m % mod; n     p[1][i] = 1ll * p[1][i - 1] * (m - 1) % mod; n   } n   for (i = k = 0, j = 1; i <= n; i++, j *= -1) { n     a = 1ll * p[0][n - i] * p[1][i] % mod - p[1][n]; n     if (a < 0) a += mod; n     if (a >= mod) a -= mod; n     k += 1ll * j * C[i] * qp(a, n) % mod; n     if (k < 0) k += mod; n     if (k >= mod) k -= mod; n   } n   printf( %d , k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[110]; n void in(long long &x, long long &y) { n   scanf( %s , str); n   int len = strlen(str); n   int at; n   for (int i = 0; i < len; i++) n     if (str[i] ==  / ) at = i; n   x = 0; n   for (int i = 0; i < at; i++) x = x * 10 + (str[i] -  0 ); n   y = 0; n   for (int i = at + 1; i < len; i++) y = y * 10 + (str[i] -  0 ); n } n struct Point { n   long long x, y; n   void in() { scanf( %I64d %I64d , &x, &y); } n } p[100010], q[100010]; n bool cmp_y(Point a, Point b) { return a.y > b.y; } n struct Node { n   long long up, down; n   int id; n   bool operator==(Node a) { return up * a.down == down * a.up; } n } e[100010]; n bool cmp(Node a, Node b) { return a.up * b.down < b.up * a.down; } n Point mark[100010]; n int X[100010]; n int Y[100010]; n int totalx, totaly; n int max_value[100010 * 4]; n void pushup(int rt) { n   max_value[rt] = max(max_value[rt << 1], max_value[rt << 1 | 1]); n } n void update(int pos, int s, int l, int r, int rt) { n   if (l == r) { n     max_value[rt] = max(max_value[rt], s); n     return; n   } n   int m = (l + r) / 2; n   if (pos <= m) n     update(pos, s, l, m, rt << 1); n   else n     update(pos, s, m + 1, r, rt << 1 | 1); n   pushup(rt); n } n int query(int L, int R, int l, int r, int rt) { n   if (R == 0) return 0; n   if (L <= l && r <= R) return max_value[rt]; n   int m = (l + r) / 2; n   int tmp = 0; n   if (L <= m) tmp = max(tmp, query(L, R, l, m, rt << 1)); n   if (R > m) tmp = max(tmp, query(L, R, m + 1, r, rt << 1 | 1)); n   return tmp; n } n int pp[100010]; n int qq; n int main() { n   int n; n   scanf( %d , &n); n   long long Ax, Ay, Bx, By; n   in(Ax, Ay); n   in(Bx, By); n   int m = 0; n   for (int i = 0; i < n; i++) { n     p[i].in(); n     if (Ax * p[i].x >= Ay * p[i].y || Bx * p[i].x <= By * p[i].y) continue; n     q[m++] = p[i]; n   } n   if (m == 0 || Ay == 0 || Bx == 0) { n     printf( 0 n ); n     return 0; n   } n   n = m; n   for (int i = 0; i < n; i++) p[i] = q[i]; n   for (int i = 0; i < n; i++) { n     e[i].id = i; n     e[i].up = p[i].y * Ay - p[i].x * Ax; n     e[i].down = Ay; n   } n   sort(e, e + n, cmp); n   totalx = 0; n   X[e[0].id] = ++totalx; n   for (int i = 1; i < n; i++) { n     if (e[i] == e[i - 1]) n       X[e[i].id] = X[e[i - 1].id]; n     else n       X[e[i].id] = ++totalx; n   } n   for (int i = 0; i < n; i++) { n     e[i].id = i; n     e[i].up = p[i].y * By - p[i].x * Bx; n     e[i].down = By; n     if (By == 0) { n       e[i].up = -p[i].x; n       e[i].down = 1; n     } n   } n   sort(e, e + n, cmp); n   totaly = 0; n   Y[e[0].id] = ++totaly; n   for (int i = 1; i < n; i++) { n     if (e[i] == e[i - 1]) n       Y[e[i].id] = Y[e[i - 1].id]; n     else n       Y[e[i].id] = ++totaly; n   } n   for (int i = 0; i < n; i++) mark[i].x = X[i], mark[i].y = Y[i]; n   sort(mark, mark + n, cmp_y); n   memset(max_value, 0, sizeof(max_value)); n   int ans = 0; n   int j = 0; n   for (int i = 0; i < n; i = j) { n     for (j = i; j < n; j++) n       if (mark[i].y != mark[j].y) break; n     for (int k = i; k < j; k++) { n       int tmp = query(1, mark[k].x - 1, 1, n, 1) + 1; n       ans = max(ans, tmp); n       pp[k] = tmp; n     } n     for (int k = i; k < j; k++) update(mark[k].x, pp[k], 1, n, 1); n   } n   printf( %d n , ans); n   return 0; 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   int n; n   int m; n   cin >> n >> m; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   int ans = 0; n   for (int i = 0; i < m; i++) { n     if (a[i] >= 0) break; n     ans += a[i]; n   } n   cout << abs(ans) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct __s { n   __s() { n     if (1) { n       ios_base::Init i; n       cin.sync_with_stdio(0); n       cin.tie(0); n     } n   } n   ~__s() { n     if (!1) n       fprintf(stderr,  Execution time: %.3lf s. n , n               (double)clock() / CLOCKS_PER_SEC); n     long long n; n     cin >> n; n   } n } __S; n long long d[311111]; n long long s[311111]; n long long I[311111]; n bool u[311111]; n bool comp(long long i, long long j) { return d[i] < d[j]; } n int main(void) { n   long long n, k; n   cin >> n >> k; n   long long cnt = 0; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 2 * i; j <= n; j += i) { n       d[j]++; n     } n     cnt += d[i]; n     s[i] = s[i - 1] + d[i]; n   } n   d[1] = 1e18; n   if (cnt < k) { n     cout <<  No  <<   n ; n     return 0; n   } n   for (long long i = 1; i <= n; i++) { n     u[i] = true; n     I[i] = i; n     if (s[i] >= k) { n       n = i; n       cnt = s[i]; n       break; n     } n   } n   sort(I + n / 2 + 1, I + n + 1, comp); n   long long m = n; n   for (long long ii = n; ii >= 1; ii--) { n     long long i = I[ii]; n     if (k <= cnt - d[i]) { n       cnt -= d[i]; n       u[i] = false; n       m--; n     } n   } n   cout <<  Yes  <<   n ; n   cout << m <<   n ; n   for (long long i = 1; i <= n; i++) { n     if (u[i]) cout << i <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> nums; n int liking[7][7]; n bool usable[7]; n int team[7]; n vector<int> members[3]; n int mindifference, maxliking; n int a, b, c; n void teaming(int currteam, int memberno) { n   int i, j, t; n   if (currteam == 2 && memberno == 7) { n     int exp1 = a / members[0].size(), exp2 = b / members[1].size(), n         exp3 = c / members[2].size(); n     int minexp = min(exp1, min(exp2, exp3)); n     int maxexp = max(exp1, max(exp2, exp3)); n     int diff = maxexp - minexp; n     int lliking = 0; n     for (t = 0; t < 3; t++) { n       for (i = 0; i < members[t].size(); i++) { n         for (j = 0; j < 7; j++) { n           if (liking[members[t][i]][j] == 1 && team[j] == t && n               team[members[t][i]] == t) n             lliking++; n         } n       } n     } n     if (diff < mindifference || n         (diff == mindifference && lliking > maxliking)) { n       mindifference = diff; n       maxliking = lliking; n     } n     return; n   } n   if (memberno >= 7) return; n   for (i = 0; i < 7; i++) n     if (usable[i]) { n       usable[i] = false; n       team[i] = currteam; n       members[currteam].push_back(i); n       teaming(currteam, memberno + 1); n       members[currteam].pop_back(); n       if (currteam < 2 && members[currteam].size() > 0) { n         team[i] = currteam + 1; n         members[currteam + 1].push_back(i); n         teaming(currteam + 1, memberno + 1); n         members[currteam + 1].pop_back(); n       } n       team[i] = -1; n       usable[i] = true; n     } n } n int main() { n   int i, j, n; n   nums.insert(make_pair( Anka , 0)); n   nums.insert(make_pair( Chapay , 1)); n   nums.insert(make_pair( Cleo , 2)); n   nums.insert(make_pair( Troll , 3)); n   nums.insert(make_pair( Dracul , 4)); n   nums.insert(make_pair( Snowy , 5)); n   nums.insert(make_pair( Hexadecimal , 6)); n   scanf( %d , &n); n   for (i = 0; i < 7; i++) n     for (j = 0; j < 7; j++) liking[i][j] = 0; n   for (i = 0; i < 7; i++) { n     usable[i] = true; n     team[i] = -1; n   } n   for (i = 0; i < n; i++) { n     char name1[30], tmp[30], name2[30]; n     scanf( %s %s %s , name1, tmp, name2); n     liking[nums[name1]][nums[name2]] = 1; n   } n   scanf( %d %d %d , &a, &b, &c); n   mindifference = 2000000000; n   maxliking = 0; n   teaming(0, 0); n   printf( %d %d , mindifference, maxliking); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 998244353; n int n, m; n int a[66], w[66]; n long long dp[66][66][66]; n int sa, sb, sum; n long long inv[10010]; n void solve1(int x) { n   memset(dp, 0, sizeof(dp)); n   dp[0][0][0] = 1; n   long long zi, mu; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j <= i; ++j) n       for (int k = j; k <= i; ++k) { n         if (!dp[i][j][k]) continue; n         mu = inv[sum + k * 2 - i]; n         zi = (w[x] + j) % mod; n         (dp[i + 1][j + 1][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n         zi = (sa + k - j - w[x] + mod) % mod; n         (dp[i + 1][j][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n         zi = (sb - i + k + mod) % mod; n         (dp[i + 1][j][k] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n       } n   long long r = 0; n   for (int j = 0; j <= m; ++j) n     for (int k = j; k <= m; ++k) { n       if (!dp[m][j][k]) continue; n       r += dp[m][j][k] * (w[x] + j) % mod; n       r %= mod; n     } n   printf( %lld n , r); n   return; n } n void solve2(int x) { n   memset(dp, 0, sizeof(dp)); n   dp[0][0][0] = 1; n   long long zi, mu; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j <= i; ++j) n       for (int k = j; k <= i; ++k) { n         if (!dp[i][j][k]) continue; n         mu = inv[sum - k * 2 + i]; n         zi = (w[x] - j) % mod; n         (dp[i + 1][j + 1][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n         zi = (sb - w[x] - k + j + mod) % mod; n         (dp[i + 1][j][k + 1] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n         zi = (sa + i - k + mod) % mod; n         (dp[i + 1][j][k] += dp[i][j][k] * zi % mod * mu % mod) %= mod; n       } n   long long r = 0; n   for (int j = 0; j <= m; ++j) n     for (int k = j; k <= m; ++k) { n       if (!dp[m][j][k]) continue; n       r += dp[m][j][k] * max(0, w[x] - j) % mod; n       r %= mod; n     } n   printf( %lld n , r); n   return; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &w[i]); n     sa += a[i] * w[i]; n     sb += (a[i] ^ 1) * w[i]; n   } n   sum = sa + sb; n   inv[1] = 1; n   for (int i = 2; i <= 10000; ++i) n     inv[i] = (mod - mod / i) * inv[mod % i] % mod; n   for (int i = 1; i <= n; ++i) n     if (a[i]) n       solve1(i); n     else n       solve2(i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   string str; n   cin >> n >> a >> b >> str; n   if (str[b - 1] == str[a - 1]) n     cout <<  0 n ; n   else n     cout <<  1 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   string a, b; n   cin >> a >> b; n   if (a == b) n     cout << a << endl; n   else n     cout <<  1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> m1; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int n, k, t; n   cin >> n >> k >> t; n   int temp = n * k * t / 100; n   int cnt = 0; n   while (n--) { n     if (temp > 0) { n       if (temp < k) { n         cout << temp <<    ; n         temp = 0; n       } else { n         cout << k <<    ; n         temp -= k; n       } n     } else n       cout << 0 <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e8; n const double EPS = 1e-9; n const long long MOD = (long long)(1e9 + 7); n const long long MAXV = (long long)(5e3 + 10); n const long long MAXE = (long long)(1e5 + 10); n int n, m; n int c[200]; n vector<pair<int, int> > aux; n bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; } n vector<int> L, R; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     c[a]++; n   } n   for (int i = 0; i <= 100; i++) n     if (c[i]) aux.push_back(pair<int, int>(c[i], i)); n   sort(aux.begin(), aux.end(), cmp); n   int r = aux[0].first; n   for (int i = 0; i < aux.size(); i++) n     for (int j = 0; j < aux[i].first; j++) L.push_back(aux[i].second); n   R = L; n   rotate(R.begin(), R.begin() + r, R.end()); n   int cnt = 0; n   for (int i = 0; i < L.size(); i++) n     if (L[i] != R[i]) cnt++; n   cout << cnt <<   n ; n   for (int i = 0; i < L.size(); i++) cout << L[i] <<     << R[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[400100]; n int b[400100]; n int main() { n   int n; n   cin >> n; n   int k = 0; n   for (int i = 1; i <= n; i++) { n     int l; n     cin >> l; n     if (l == 0) { n       k = 1; n     } else { n       if (k == 1) n         a[i - 1] = l; n       else n         a[i] = l; n     } n   } n   k = 0; n   for (int i = 1; i <= n; i++) { n     int l; n     cin >> l; n     if (l == 0) { n       k = 1; n     } else { n       if (k == 1) n         b[i - 1] = l; n       else n         b[i] = l; n     } n   } n   int uk = n; n   int uk1 = 1; n   for (int i = 1; i < n; i++) { n     if (b[i] != a[1]) { n       b[uk] = b[i]; n       uk++; n     } else { n       uk1 = i; n       break; n     } n   } n   for (int i = 1; i < n; i++) { n     if (a[i] != b[uk1]) { n       cout <<  NO ; n       exit(0); n     } n     uk1++; n   } n   cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n double fRand(double fMin, double fMax) { n   double f = (double)rand() / RAND_MAX; n   return fMin + f * (fMax - fMin); n } n template <class T> n T min(T a, T b, T c) { n   return min(a, min(b, c)); n } n template <class T> n T max(T a, T b, T c) { n   return max(a, max(b, c)); n } n struct pt { n   long long x, y; n   int id; n   pt operator+(pt p) { return {x + p.x, y + p.y}; } n   pt operator-(pt p) { return {x - p.x, y - p.y}; } n   pt operator*(long long k) { return {x * k, y * k}; } n   pt operator/(long long k) { return {x / k, y / k}; } n   long long operator*(pt p) { return x * p.y - y * p.x; } n   long long operator%(pt p) { return x * p.x + y * p.y; } n   friend istream& operator>>(istream& is, pt& p) { n     is >> p.x >> p.y; n     return is; n   } n   friend ostream& operator<<(ostream& os, const pt& p) { n     os << p.id <<  -(  << p.x <<  ,   << p.y <<  ) ; n     return os; n   } n }; n long long sq(pt p) { return p.x * p.x + p.y * p.y; } n bool half(pt p) { return (p.y > 0 || (p.y == 0 && p.x < 0)); } n struct cmpPt { n   bool operator()(pt v, pt w) { n     return make_tuple(half(v), 0, sq(v)) < make_tuple(half(w), v * w, sq(w)); n   } n }; n set<pt, cmpPt> s; n pt piv; n set<pt>::iterator nextCir(set<pt>::iterator it, int k = 1) { n   for (int i = 0; i < k; ++i) { n     ++it; n     if (it == s.end()) it = s.begin(); n   } n   return it; n } n set<pt>::iterator prevCir(set<pt>::iterator it, int k = 1) { n   for (int i = 0; i < k; ++i) { n     if (it == s.begin()) it = s.end(); n     --it; n   } n   return it; n } n long long orient(pt a, pt b, pt c) { return (b - a) * (c - a); } n bool half(pt a, pt p) { return a * p >= 0; } n bool crossesRay(pt a, pt p, pt q) { n   return (half(a, q) - half(a, p)) * orient(a, p, q) > 0; n } n bool onSegment(pt p, pt a, pt b) { n   return orient(p, a, b) == 0 && (a - p) % (b - p) <= 0; n } n bool isIn(pt a) { n   if (a.x == 0 && a.y == 0) return true; n   set<pt>::iterator it = s.lower_bound(a); n   if (it == s.end()) it = s.begin(); n   pt q = *it; n   pt p = *prevCir(it); n   return (onSegment(a, p, q) || crossesRay(a, p, q)); n } n void insert(pt a) { n   if (isIn(a)) return; n   set<pt>::iterator it = s.lower_bound(a); n   if (it == s.end()) it = s.begin(); n   while ((int)s.size() > 2 && orient(a, *it, *nextCir(it)) <= 0) { n     it = nextCir(it); n     s.erase(prevCir(it)); n   } n   it = prevCir(it); n   while ((int)s.size() > 2 && orient(a, *it, *prevCir(it)) >= 0) { n     it = prevCir(it); n     s.erase(nextCir(it)); n   } n   s.insert(a); n } n int main() { n   ios::sync_with_stdio(false); n   int q; n   cin >> q; n   pt p, a[3]; n   int type; n   for (int i = (0); i <= (2); ++i) { n     cin >> type >> a[i]; n     piv = piv + a[i]; n     a[i] = a[i] * 3; n   } n   for (int i = (0); i <= (2); ++i) { n     pt p = a[i] - piv; n     p.id = i + 1; n     s.insert(p); n   } n   for (int i = (4); i <= (q); ++i) { n     cin >> type >> p; n     p = p * 3; n     p = p - piv; n     p.id = i; n     if (type == 2) { n       bool ans = isIn(p); n       cout << (ans ?  YES  :  NO ) << endl; n     } else { n       insert(p); n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n long long sqr(long long a) { return a * a; } n int main() { n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   vector<long long> sumx(n, 0ll); n   vector<long long> sumy(m, 0ll); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       long long c; n       cin >> c; n       sumx[i] += c; n       sumy[j] += c; n     } n   } n   vector<long long> ansx(n + 1, 0ll); n   vector<long long> ansy(m + 1, 0ll); n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j < n; j++) { n       ansx[i] += sumx[j] * sqr((2 * j + 1) - 2 * i); n     } n   } n   for (int i = 0; i <= m; i++) { n     for (int j = 0; j < m; j++) { n       ansy[i] += sumy[j] * sqr((2 * j + 1) - 2 * i); n     } n   } n   pair<long long, pair<int, int> > res = n       make_pair((long long)1e18, make_pair(-1, -1)); n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j <= m; j++) { n       res = min(res, make_pair(ansx[i] + ansy[j], make_pair(i, j))); n     } n   } n   cout << 4 * res.first << endl; n   cout << res.second.first <<     << res.second.second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans; n bool pd(int n) { n   for (int i = 2; i <= sqrt(n); i++) n     if (n % i == 0) return false; n   return true; n } n int main() { n   scanf( %d , &n); n   if (pd(n)) n     puts( 1 ); n   else if (n % 2 == 0 || pd(n - 2)) n     puts( 2 ); n   else n     puts( 3 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> ans, adj[200007]; n bool vis[200007]; n int inputorder[200007], relorder[200007]; n bool cmp(int a, int b) { return relorder[a] < relorder[b]; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   int n, x, a, b, i, j; n   cin >> n; n   for (i = 0; i < n - 1; i++) { n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (i = 0; i < n; i++) { n     cin >> inputorder[i]; n     relorder[inputorder[i]] = i; n   } n   for (i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end(), cmp); n   queue<int> q; n   q.push(1); n   memset(vis, false, sizeof(vis)); n   while (!(q.empty())) { n     queue<int> temp; n     while (!(q.empty())) { n       int x = q.front(); n       q.pop(); n       ans.push_back(x); n       vis[x] = true; n       for (j = 0; j < adj[x].size(); j++) n         if (vis[adj[x][j]] == false) temp.push(adj[x][j]); n     } n     q = temp; n   } n   for (i = 0; i < n; i++) n     if (inputorder[i] != ans[i]) { n       cout <<  No ; n       return 0; n     } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int n, sz[N], sum[N]; n int64_t r[N][3], ans; n vector<pair<int, int>> g[N]; n void dfs(int x, int f) { n   sz[x] = 1; n   for (auto &e : g[x]) { n     int y = e.first, w = e.second; n     if (y == f) continue; n     dfs(y, x), sz[x] += sz[y]; n     if (w) sum[y] = sz[y], r[y][2] += r[y][0] + r[y][1], r[y][0] = r[y][1] = 0; n     r[x][0] += r[y][0]; n     r[x][1] += r[y][1]; n     r[x][2] += r[y][2]; n     sum[x] += sum[y]; n   } n   for (auto &e : g[x]) { n     int y = e.first, w = e.second; n     if (y == f) continue; n     ans += sum[y] * (int64_t)(sz[x] - sz[y]) * (sz[x] - sz[y] - 1); n     ans += n         (sz[y] - sum[y]) * (int64_t)(sum[x] - sum[y]) * (sum[x] - sum[y] - 1); n     ans += 2 * r[y][0] * (sum[x] - sum[y]); n     ans += 2 * (r[y][1] + r[y][2]) * (sz[x] - sz[y]); n     r[x][0] += (sz[y] - sum[y]) * (int64_t)(sum[x] - sum[y]); n     r[x][1] += sum[y] * (int64_t)(sz[x] - sz[y]); n   } n   r[x][0] += sum[x]; n   ans += sum[x] * (sum[x] - 1ll); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; ++i) { n     int u, v, w; n     scanf( %d%d%d , &u, &v, &w); n     int ok = 1; n     while (w) { n       if (w % 10 != 7 && w % 10 != 4) ok = 0; n       w /= 10; n     } n     g[u].push_back({v, ok}); n     g[v].push_back({u, ok}); n   } n   dfs(1, 0); n   printf( %lld n , 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   int n, num = 0, dem = 0; n   cin >> n; n   if (n % 2 == 0) { n     num = (n / 2) - 1; n     dem = (n / 2) + 1; n   } else { n     num = n / 2; n     dem = n - num; n   } n   set<int> x, y; n   while (1) { n     int flag1 = -1; n     x.clear(); n     y.clear(); n     if (num == 2) x.insert(num); n     for (int i = 2; i * i <= num; i++) { n       if (num % i == 0) { n         x.insert(i); n         x.insert(num / i); n       } n     } n     for (int i = 2; i * i <= dem; i++) { n       if (dem % i == 0) { n         y.insert(i); n         y.insert(dem / i); n       } n     } n     for (auto i : x) { n       if (y.count(i) == 1) { n         flag1 = 1; n         break; n       } n     } n     if (flag1 == -1) break; n     num--; n     dem++; n   } n   return cout << num <<     << dem <<   n , 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> g[200010]; n int vis[200010], d[200010]; n stack<int> his; n void dfs(int u, int dd) { n   his.push(u); n   d[u] = dd; n   for (int v : g[u]) { n     if (!d[v]) n       dfs(v, dd + 1); n     else if (d[u] - d[v] + 1 >= ceil(sqrt(n))) { n       puts( 2 ); n       printf( %d n , d[u] - d[v] + 1); n       for (int i = d[v] - 1; i < d[u]; ++i) { n         printf( %d  , his.top()); n         his.pop(); n       } n       exit(0); n     } n   } n   if (!vis[u]) n     for (int v : g[u]) vis[v] = 1; n   his.pop(); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0, u, v; i < m; ++i) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1, 1); n   puts( 1 ); n   int visT = 0; n   for (int i = 1; visT < ceil(sqrt(n)); ++i) { n     if (!vis[i]) printf( %d  , i), ++visT; n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n const double EPS = 1e-7; n const int INF = 1000000000; n char buf[100]; n int maxl[2000000]; n int maxr[2000000]; n int minl[2000000]; n int minr[2000000]; n pair<int, int> g[2000000]; n int n; n int X = 0; n void dfs(int, int); n void add_dfs(int x, int mm) { n   if (X > mm) return; n   if (g[x].second == -1) { n     g[x].second = X; n     X++; n     dfs(g[x].second, mm); n   } n   add_dfs(g[x].second, mm); n } n bool OK = true; n void dfs(int x, int mm) { n   if (X > minl[x]) OK = false; n   if (X <= maxl[x]) { n     g[x].first = X; n     X++; n     dfs(g[x].first, maxl[x]); n   } n   if (X > minr[x]) OK = false; n   if (X <= maxr[x]) { n     g[x].second = X; n     X++; n     dfs(g[x].second, maxr[x]); n   } n   add_dfs(x, mm); n } n vector<int> res; n void dfs2(int x) { n   if (g[x].first != -1) dfs2(g[x].first); n   res.push_back(x); n   if (g[x].second != -1) dfs2(g[x].second); n } n int main() { n   int m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     maxl[i] = 0; n     maxr[i] = 0; n     minl[i] = n; n     minr[i] = n; n     g[i] = make_pair(-1, -1); n   } n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--; n     y--; n     scanf( %s , buf); n     if (buf[0] ==  L ) { n       maxl[x] = max(maxl[x], y); n       minl[x] = min(minl[x], y); n     } else { n       maxr[x] = max(maxr[x], y); n       minr[x] = min(minr[x], y); n     } n   } n   X = 1; n   dfs(0, n - 1); n   dfs2(0); n   if (!OK) n     printf( IMPOSSIBLE n ); n   else { n     for (int i = 0; i < res.size(); i++) { n       printf( %d  , res[i] + 1); n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline long long max(long long a, long long b) { return ((a > b) ? a : b); } n inline long long min(long long a, long long b) { return ((a > b) ? b : a); } n inline long long gcd(long long a, long long b) { n   if (b == 0) return a; n   a %= b; n   return gcd(b, a); n } n long long power(long long x, long long y) { n   if (y == 0) return 1; n   long long a = power(x, y / 2); n   if (y % 2 == 0) n     return a * a; n   else n     return x * a * a; n } n long long powermod(long long x, long long ex, long long md) { n   long long ans = 1ll; n   while (ex > 0) { n     if (ex & 1ll) ans = (ans * x) % md; n     ex >>= 1ll; n     x = (x * x) % md; n   } n   return ans; n } n const long long inf = 1e18 + 9; n const long long mod = 1e9 + 7; n const long double PI = acos(-1); n const long double eps = 1e-9; n const long long N = 2e5 + 11; n long long n, t, easy, hard; n long long a[N], b[N], pfx[N], cnteasy[N], cnthard[N]; n vector<pair<long long, long long> > v; n void solve() { n   cin >> n >> t >> easy >> hard; n   for (int i = 0; i < n; i++) cin >> b[i + 1]; n   for (int i = 0; i < n; i++) cin >> a[i + 1]; n   for (int i = 0; i < n; i++) v.push_back(make_pair(a[i + 1], b[i + 1])); n   sort((v).begin(), (v).end()); n   for (int i = 0; i < n; i++) { n     if (v[i].second) n       pfx[i + 1] = pfx[i] + hard; n     else n       pfx[i + 1] = pfx[i] + easy; n     cnthard[i + 1] = cnthard[i] + (v[i].second); n     cnteasy[i + 1] = cnteasy[i] + (!v[i].second); n   } n   if (pfx[n] <= t) { n     cout << n <<   n ; n   } else { n     long long ans = 0; n     for (long long i = 0; i < n; i++) { n       long long t = v[i].first - 1; n       if (t < 0) continue; n       long long val = i; n       long long tym = pfx[i]; n       long long rem = t - tym; n       if (rem >= 0) { n         long long x = min(rem / easy, cnteasy[n] - cnteasy[i]); n         rem -= (x * easy); n         val += x; n         val += min(rem / hard, cnthard[n] - cnthard[i]); n         ans = max(ans, val); n       } n     } n     cout << ans <<   n ; n   } n   for (int i = 0; i < n + 1; i++) n     a[i] = b[i] = pfx[i] = cnteasy[i] = cnthard[i] = 0; n   v.clear(); n   n = t = easy = hard = 0; n } n int main() { n   { n     ios::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n   }; n   cout << fixed << setprecision(20); n   long long NTC = 1; n   cin >> NTC; n   long long PTC = 0; n   while (PTC++ < NTC) { n     solve(); n     cout <<   n ; n   } n   cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int x = 0, y = 0, dp = 0, tmp; n   int sum = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  U ) { n       y++; n       if (x < y) { n         if (dp == 2) sum++; n         dp = 1; n       } n     } n     if (s[i] ==  R ) { n       x++; n       if (x > y) { n         if (dp == 1) sum++; n         dp = 2; n       } n     } n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.1415926536; n const long long INF = 1e18; n const int32_t M = 1e6 + 7; n const int32_t MM = 998244353; n long long a, b, c, d; n void solve() { n   cin >> a >> b >> c >> d; n   double p, q, x; n   p = (double)a / b; n   q = (double)c / d; n   x = (1 - p) * (1 - q); n   x = 1 - x; n   cout << fixed << setprecision(12); n   cout << p / x; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> ans; n int n, r, fr[101][101]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     scanf( %d , &r); n     for (int x, j = 0; j < r; j++) { n       scanf( %d , &x); n       fr[i][x]++; n     } n   } n   for (int i = 1; i <= 100; i++) { n     int c = 0; n     for (int j = 0; j <= 100; j++) { n       c += fr[j][i]; n     } n     if (c == n) { n       ans.push_back(i); n     } n   } n   for (int i = 0; i < ans.size(); i++) { n     printf( %d , ans[i]); n     if (i != ans.size() - 1) putchar(   ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 5; n const int mod = 1e9 + 7; n int a[N], f[N]; n int main() { n   int n; n   int p = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == 0) f[p++] = i; n   } n   int v = 0; n   for (int i = 0; i < n; i++) { n     if (a[i] != 0) { n       a[i] = abs(f[v] - i); n       if (v + 1 < p) a[i] = min(a[i], abs(f[v + 1] - i)); n       if (v - 1 >= 0) a[i] = min(a[i], abs(f[v - 1] - i)); n     } else n       v++; n   } n   printf( %d , a[0]); n   for (int i = 1; i < n; i++) { n     printf(  %d , a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dist[605][605], u, v, a[205], n, Vv, E, m, fix[605], match[605], w, ans, l, n     r, k; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     q; n vector<pair<int, int> > V[605]; n vector<pair<pair<int, int>, int> > ed; n void dijkstra(int cur) { n   for (int i = 1; i <= Vv; i++) dist[cur][i] = 1e7; n   q.push({0, cur}); n   dist[cur][cur] = 0; n   while (q.size()) { n     u = q.top().second; n     int d = q.top().first; n     q.pop(); n     if (d > dist[cur][u]) continue; n     for (int i = 0; i < V[u].size(); i++) { n       v = V[u][i].first; n       if (dist[cur][v] > dist[cur][u] + V[u][i].second) { n         dist[cur][v] = dist[cur][u] + V[u][i].second; n         q.push({dist[cur][v], v}); n       } n     } n   } n } n bool dfs(int u, int T) { n   for (int v = 1; v <= Vv; v++) { n     if (!fix[v] && dist[u][v] <= T) { n       fix[v] = 1; n       if (match[v] == -1 || dfs(match[v], T)) { n         match[v] = u; n         return true; n       } n     } n   } n   return false; n } n bool check(int T) { n   int pas = 0; n   for (k = 1; k <= Vv; k++) { n     match[k] = -1; n   } n   for (k = 1; k <= n; k++) { n     for (int i = 1; i <= Vv; i++) fix[i] = 0; n     if (dfs(a[k], T)) pas++; n   } n   if (pas >= m) return true; n   return false; n } n int main() { n   cin >> Vv >> E >> n >> m; n   for (k = 1; k <= n; k++) { n     cin >> a[k]; n   } n   for (k = 1; k <= E; k++) { n     cin >> u >> v >> w; n     ed.push_back({{u, v}, w}); n     V[u].push_back({v, w}); n     V[v].push_back({u, w}); n   } n   for (k = 1; k <= n; k++) { n     dijkstra(a[k]); n   } n   l = 0; n   r = 1731311; n   ans = -1; n   while (l <= r) { n     int mid = (l + r) / 2; n     if (check(mid)) { n       ans = mid; n       r = mid - 1; n     } else n       l = mid + 1; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[200005], pos[200005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   ; n   long long n; n   cin >> n; n   cout << n <<    ; n   if (n == 1) { n     cout <<  1 ; n     return 0; n   } n   if (n % 2) { n     long long tmp = 1; n     while (tmp < n) { n       cout << tmp <<    ; n       tmp += 2; n     } n     cout << n <<    ; n     while (tmp > 1) { n       cout << tmp - 2 <<    ; n       tmp -= 2; n     } n     tmp = 2; n     while (tmp < n - 1) { n       cout << tmp <<    ; n       tmp += 2; n     } n     cout << n - 1 <<     << n - 1 <<    ; n     while (tmp > 2) { n       cout << tmp - 2 <<    ; n       tmp -= 2; n     } n   } else { n     long long tmp = 2; n     while (tmp < n) { n       cout << tmp <<    ; n       tmp += 2; n     } n     cout << n <<    ; n     while (tmp > 2) { n       cout << tmp - 2 <<    ; n       tmp -= 2; n     } n     tmp = 1; n     while (tmp < n - 1) { n       cout << tmp <<    ; n       tmp += 2; n     } n     cout << n - 1 <<     << n - 1 <<    ; n     while (tmp > 1) { n       cout << tmp - 2 <<    ; n       tmp -= 2; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int n; n   int a[1100]; n   while (scanf( %d , &n) == 1) { n     for (int i = 0; i < n; i++) scanf( %d , a + i); n     int cnt = 1, ans = 0; n     int j = 0; n     if (n <= 2) { n       printf( %d n , ans); n       break; n     } n     if (a[0] > a[1]) n       j = -1; n     else if (a[0] == a[1]) n       j = 0; n     else n       j = 1; n     while (cnt < n - 1) { n       if (j == -1) { n         for (; cnt < n - 1 && a[cnt] > a[cnt + 1]; cnt++) n           ; n         if (cnt == n - 1) break; n         if (a[cnt] > a[cnt + 1]) n           j = -1; n         else if (a[cnt] == a[cnt + 1]) n           j = 0; n         else { n           ans++; n           j = 1; n         } n       } n       if (j == 0) { n         for (; cnt < n - 1 && a[cnt] == a[cnt + 1]; cnt++) n           ; n         if (cnt == n - 1) break; n         if (a[cnt] > a[cnt + 1]) n           j = -1; n         else if (a[cnt] == a[cnt + 1]) n           j = 0; n         else n           j = 1; n       } n       if (j == 1) { n         for (; cnt < n - 1 && a[cnt] < a[cnt + 1]; cnt++) n           ; n         if (cnt == n - 1) break; n         if (a[cnt] > a[cnt + 1]) { n           ans++; n           j = -1; n         } else if (a[cnt] == a[cnt + 1]) n           j = 0; n         else n           j = 1; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<set<int> > g(n + 1); n   map<int, int> co; n   for (int i = 0; i < m; i++) { n     int n1, n2; n     cin >> n1 >> n2; n     g[n1].insert(n2); n     g[n2].insert(n1); n     co[n1]++; n     co[n2]++; n   } n   int minn = 1000000000; n   for (int i = 1; i <= n; i++) { n     set<int>::iterator iter; n     for (iter = g[i].begin(); iter != g[i].end(); iter++) { n       set<int>::iterator iter2; n       for (iter2 = g[*iter].begin(); iter2 != g[*iter].end(); iter2++) { n         if (*iter2 == i) continue; n         if (g[*iter2].count(i)) { n           minn = min(minn, co[*iter] + co[*iter2] + co[i] - 6); n         } n       } n     } n   } n   if (minn == 1000000000) n     cout << -1 << endl; n   else n     cout << minn << endl; n   return 0; n } n


// REMEMBER USING MOD INVERSE WHILE DOING COMBINATORICS n // REMEMBER using int32_t while typecasting size into int n  n #include<bits/stdc++.h> n using namespace std; n #define pb push_back n #define int long long n #define all(x) x.begin(),x.end() n #define nl    n  n #define ok  cout<< OK n  n #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) n #define free freopen( input.txt , r ,stdin);freopen( output.txt , w ,stdout) n #define ff first n #define ss second n typedef pair<int,int> pii; n const long long INF = 1ll << 32; n const long long MAX_N = 3e6 + 5; n const long long MOD = 1e9 + 7; n  n const long long N = 5001; n  n int I; n  n void solve() n { n     int n; n     cin>>n; n     int even = 0 , odd = 0; n     for(int i = 0 ; i<2 * n ; i++) { n         int p; n         cin>>p; n         if(p & 1) odd++; n         else even++; n     } n     cout<<(even == odd ?  Yes  :  No )<<nl; n  n } n  n int32_t main() n { n     ios; n     int Test = 1; n     cin>>Test; n     for(I = 1 ; I<=Test ;  I++) n     { n         solve(); n     } n  n  n  n  n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const double PI = acos(-1.); n const double eps = 1e-10; n const int INF = 0x3f3f3f3f; n const long long INFll = 0x3f3f3f3f3f3f3f3f; n const int MAXN = 1e6 + 5; n const int MX = 123456; n const int inf = 0x3f3f3f3f; n const int MXE = 1e7; n struct MinCost_MaxFlow { n   struct Edge { n     int v, w, nxt; n     int cost; n   } E[MXE]; n   int head[MX], tot, level[MX], pre[MX], d[MX]; n   bool vis[MX]; n   void init() { n     memset(head, -1, sizeof(head)); n     tot = 0; n   } n   void add(int u, int v, int w, int cost) { n     E[tot].v = v; n     E[tot].w = w; n     E[tot].cost = cost; n     E[tot].nxt = head[u]; n     head[u] = tot++; n     E[tot].v = u; n     E[tot].w = 0; n     E[tot].cost = -cost; n     E[tot].nxt = head[v]; n     head[v] = tot++; n   } n   bool spfa(int s, int t) { n     memset(vis, 0, sizeof(vis)); n     memset(d, 0x3f, sizeof(d)); n     memset(pre, -1, sizeof(pre)); n     queue<int> q; n     q.push(s); n     d[s] = 0; n     vis[s] = 1; n     while (!q.empty()) { n       int u = q.front(); n       q.pop(); n       vis[u] = 0; n       for (int i = head[u]; ~i; i = E[i].nxt) { n         int w = E[i].w, v = E[i].v, cost = E[i].cost; n         if (w > 0 && d[v] > d[u] + cost) { n           d[v] = d[u] + cost; n           pre[v] = i; n           if (!vis[v]) { n             q.push(v); n             vis[v] = 1; n           } n         } n       } n     } n     return pre[t] != -1; n   } n   int solve(int s, int t, int &cost) { n     int flow = 0; n     cost = 0; n     while (spfa(s, t)) { n       int minFlow = inf; n       for (int i = pre[t]; ~i; i = pre[E[i ^ 1].v]) n         minFlow = min(minFlow, E[i].w); n       for (int i = pre[t]; ~i; i = pre[E[i ^ 1].v]) { n         cost += minFlow * E[i].cost; n         E[i].w -= minFlow; n         E[i ^ 1].w += minFlow; n       } n       flow += minFlow; n     } n     return flow; n   } n } F; n int a[MAXN]; n int main() { n   int n; n   scanf( %d , &n); n   F.init(); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int st = 0, en = 2 * n + 5; n   int add = en - 1; n   F.add(st, add, 4, 0); n   int magic = 4; n   for (int i = 1; i <= n; i++) { n     F.add(add, i, 1, 0); n     F.add(i + n, en, 1, 0); n     F.add(i, i + n, 1, -1); n     F.add(i, i + n, INF, 0); n     int cnt1 = 0, cnt2 = 0; n     for (int j = i + 1; j <= n; j++) { n       if (abs(a[i] - a[j]) == 1 && cnt1 <= magic) { n         F.add(i + n, j, 1, 0); n         cnt1++; n       } n       if (a[i] % 7 == a[j] % 7 && cnt2 <= magic) { n         F.add(i + n, j, 1, 0); n         cnt2++; n       } n     } n   } n   int flow, cost; n   flow = F.solve(st, en, cost); n   printf( %d n , -cost); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx,avx2,tune=native ) n template <typename T> n using Prior = std::priority_queue<T>; n template <typename T> n using prior = std::priority_queue<T, std::vector<T>, std::greater<T>>; n using namespace std; n void pre() {} n void solve() { n   int n, k; n   cin >> n >> k; n   vector<long long> arr(n); n   for (auto& x : arr) cin >> x; n   vector<vector<long long>> dp(n, vector<long long>(n + 1)); n   for (int j = 1; j <= n; ++j) n     dp[0][j] = dp[0][j - 1] + (bool)(arr[j - 1] == j); n   if (dp[0].back() >= k) return cout << 0 <<   n , void(); n   for (int i = 1; i < n; ++i) { n     for (int j = i + 1; j <= n; ++j) n       dp[i][j] = n           max(dp[i - 1][j - 1], dp[i][j - 1] + (bool)(arr[j - 1] == j - i)); n     if (dp[i].back() >= k) return cout << i <<   n , void(); n   } n   cout << -1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   pre(); n   int _ = 1; n   cin >> _; n   vector<long long> __(_); n   iota(begin(__), end(__), 1); n   for (auto i : __) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long maxi(long long &a, long long b) { n   if (b > a) { n     a = b; n     return 1; n   } n   return 0; n } n inline long long mini(long long &a, long long b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n inline long long maxi(long double &a, long double b) { n   if (b > a) { n     a = b; n     return 1; n   } n   return 0; n } n inline long long mini(long double &a, long double b) { n   if (b < a) { n     a = b; n     return 1; n   } n   return 0; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     string a, b; n     cin >> n >> a >> b; n     vector<long long> ans1, ans2; n     a +=  0 ; n     b +=  0 ; n     for (long long i = 1; i <= n; i++) { n       if (a[i] != a[i - 1]) { n         ans1.push_back(i); n       } n       if (b[i] != b[i - 1]) { n         ans2.push_back(i); n       } n     } n     for (long long i = (long long)ans2.size() - 1; i >= 0; i--) { n       ans1.push_back(ans2[i]); n     } n     cout << (long long)ans1.size() <<   n ; n     for (auto now : ans1) { n       cout << now <<    ; n     } n     cout <<   n ; n   } n } n