#include <bits/stdc++.h> n using namespace std; n template <typename T> n void maxtt(T& t1, T t2) { n   t1 = max(t1, t2); n } n template <typename T> n void mintt(T& t1, T t2) { n   t1 = min(t1, t2); n } n bool debug = 0; n int n, m, k; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n string direc =  URDL ; n const long long MOD2 = (long long)998244353 * (long long)998244353; n long long ln, lk, lm; n void etp(bool f = 0) { n   puts(f ?  YES  :  NO ); n   exit(0); n } n void addmod(int& x, int y, int mod = 998244353) { n   assert(y >= 0); n   x += y; n   if (x >= mod) x -= mod; n   assert(x >= 0 && x < mod); n } n void et(int x = -1) { n   printf( %d n , x); n   exit(0); n } n long long fastPow(long long x, long long y, int mod = 998244353) { n   long long ans = 1; n   while (y > 0) { n     if (y & 1) ans = (x * ans) % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ans; n } n long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; } n long long rL; n int a[1035], b[1035]; n long long ansl[1035], ansr[1035]; n long long rd(int id, long long x) { n   printf( ? %d %lld n , id, x); n   fflush(stdout); n   scanf( %lld , &lk); n   return lk; n } n void cal(int l, int r, long long L, long long R) { n   if (l == r) { n     ansl[a[l]] = L; n     ansr[a[l]] = R; n     return; n   } n   int m1 = (l + r) / 2; n   long long X = rL / n * m1, m2; n   mt19937 ttrand((int)time(0)); n   for (int p = l, q = r;;) { n     int i = uniform_int_distribution<int>(p, q)(ttrand); n     long long lb = L, rb = R; n     while (lb < rb) { n       long long mb = (lb + rb) / 2; n       if (rd(a[i], mb) < X) n         lb = mb + 1; n       else n         rb = mb; n     } n     int l2 = p, r2 = q; n     vector<int> e; n     for (int j = p; j <= q; ++j) { n       long long y = rd(a[j], lb); n       if (y > X) n         b[l2++] = a[j]; n       else if (y < X) n         b[r2--] = a[j]; n       else n         e.push_back(a[j]); n     } n     for (int(j) = 0; (j) < (int)(e.size()); (j)++) b[l2 + j] = e[j]; n     for (int z = p; z <= q; z++) a[z] = b[z]; n     if (l2 <= m1 && m1 <= r2) { n       m2 = lb; n       break; n     } n     if (l2 < m1) n       p = l2 + 1; n     else n       q = l2 - 1; n   } n   cal(l, m1, L, m2); n   cal(m1 + 1, r, m2, R); n } n void fmain(int tid) { n   scanf( %d%lld , &n, &rL); n   for (int(i) = 1; (i) <= (int)(n); (i)++) a[i] = i; n   cal(1, n, 0, 1e18); n   puts( ! ); n   for (int(i) = 1; (i) <= (int)(n); (i)++) n     printf( %lld %lld n , ansl[i], ansr[i]); n } n int main() { n   int t = 1; n   for (int(i) = 1; (i) <= (int)(t); (i)++) { n     fmain(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n; n   cin >> n >> a >> b; n   cout << min(n - a, b + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T sqr(const T &a) { n   return a * a; n } n template <class T> n inline T middle(const T &a, const T &b) { n   return (a + b) / 2; n } n template <class T> n inline int len(const T &c) { n   return static_cast<int>(c.size()); n } n const long double EPS = 1e-9; n const long double PI = 2 * acos(0.0); n const int N = 100; n struct Item { n   long long r; n   char c; n   Item() {} n   Item(long long rr, char cc) : r(rr), c(cc) {} n   void Read() { scanf( %I64d-%c , &r, &c); } n }; n int ReadLine(int n, vector<Item> &s) { n   Item tmp; n   for (int i = 0; i < n; ++i) { n     tmp.Read(); n     if (!s.empty() && s.back().c == tmp.c) { n       s.back().r += tmp.r; n     } else { n       s.push_back(tmp); n     } n   } n   return len(s); n } n inline bool Check1(const vector<Item> &s, const Item &cur, int n, int j) { n   if (s[j].c != cur.c) { n     return false; n   } n   if (j == 0 || j == n - 1) { n     return s[j].r <= cur.r; n   } n   return s[j].r == cur.r; n } n int main() { n   int n, m; n   scanf( %d%d n , &n, &m); n   vector<Item> t, s; n   n = ReadLine(n, t); n   m = ReadLine(m, s); n   s.push_back(Item(0,  # )); n   s.insert(s.end(), t.begin(), t.end()); n   long long ans = 0; n   vector<int> pi(len(s), 0); n   for (int i = 1; i < len(pi); ++i) { n     Item &cur = s[i]; n     int j = pi[i - 1]; n     while (j && !Check1(s, cur, m, j)) { n       j = pi[j - 1]; n     } n     if (Check1(s, cur, m, j)) { n       ++j; n     } n     if (j == m) { n       if (m > 1) { n         ++ans; n       } else { n         assert(cur.c == s[0].c); n         long long val = cur.r - s[0].r + 1; n         ans += val; n       } n       --j; n       if (j) { n         j = pi[j - 1]; n       } n       if (Check1(s, cur, m, j)) { n         ++j; n       } n     } n     pi[i] = j; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, b, c, D, e; n int cs[200020]; n int all[200020], A[4], AA[4]; n int i, x, y, z, tmp, tim, m; n int main() { n   cin >> n; n   cin >> a >> b >> c; n   if (a > c) swap(a, c); n   if (a > b) swap(a, b); n   if (b > c) swap(b, c); n   A[1] = a; n   A[2] = b; n   A[3] = c; n   for (i = 1; i <= n; i++) { n     scanf( %d , &D); n     if (D > a + b + c) { n       cout << -1 << endl; n       return 0; n     } n     if (D > b + c) { n       tim++; n       continue; n     } n     m++; n     all[m] = D; n   } n   AA[1] = m; n   AA[2] = m; n   AA[3] = m; n   sort(all + 1, all + m + 1); n   for (i = m; i >= 1; i--) { n     if (all[i] && c < all[i]) { n       if (a + b >= all[i]) n         e = 3; n       else if (a + c >= all[i]) n         e = 2; n       else n         e = 1; n       AA[e] = min(AA[e], i - 1); n       while (AA[e] >= 0 && all[AA[e]] == 0 || all[AA[e]] > A[e]) AA[e]--; n       tim++; n       all[AA[e]] = 0; n       all[i] = 0; n     } n   } n   n = 0; n   for (i = 1; i <= m; i++) n     if (all[i]) { n       n++; n       cs[n] = all[i]; n     } n   if (n == 0) { n     cout << tim << endl; n     return 0; n   } n   int l = 1; n   int r = n - 1; n   int ress = n; n   while (l <= r) { n     m = (l + r) / 2; n     int k = n - m; n     if (a + b < cs[k]) { n       l = m + 1; n       continue; n     } n     int ja = 0; n     for (ja = 1; ja <= k; ja++) n       if (cs[ja] > a) break; n     ja--; n     int jb = 0; n     for (jb = 1; jb <= k; jb++) n       if (cs[jb] > b) break; n     jb--; n     while (jb - ja < ja) ja--; n     if (max(ja, jb - ja) + k - jb <= m) { n       ress = m; n       r = m - 1; n     } else n       l = m + 1; n   } n   cout << ress + tim << endl; n } n


#include <bits/stdc++.h> n template <class C, class E> n inline bool contains(const C &container, const E &element) { n   return container.find(element) != container.end(); n } n template <class T> n inline void checkmin(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n inline void checkmax(T &a, T b) { n   if (b > a) a = b; n } n using namespace std; n map<int, bool> res; n enum Type { XOR, AND, IN, NOT, OR }; n struct Gate { n   Type _type; n   int _index; n   bool _bOriVal; n   int _c[2]; n }; n vector<Gate> gates; n bool Eval(int index) { n   Gate &g = gates[index]; n   bool bRes; n   switch (g._type) { n     case OR: { n       bool b1 = Eval(g._c[0]); n       bool b2 = Eval(g._c[1]); n       bRes = b1 || b2; n     } break; n     case AND: { n       bool b1 = Eval(g._c[0]); n       bool b2 = Eval(g._c[1]); n       bRes = b1 && b2; n     } break; n     case NOT: n       bRes = !Eval(g._c[0]); n       break; n     case XOR: n       bRes = Eval(g._c[0]) != Eval(g._c[1]); n       break; n     case IN: n       bRes = g._bOriVal; n       break; n   } n   g._bOriVal = bRes; n   return bRes; n } n void Solve(int index, bool resObt[2]) { n   Gate &g = gates[index]; n   switch (g._type) { n     case OR: { n       for (int i = 0; i < 2; ++i) { n         int askedSubGate = g._c[i]; n         int otherSubGate = g._c[1 - i]; n         bool otherSubVal = gates[otherSubGate]._bOriVal; n         bool rr[2]; n         rr[false] = resObt[otherSubVal || false]; n         rr[true] = resObt[otherSubVal || true]; n         Solve(askedSubGate, rr); n       } n       break; n     } n     case AND: n       for (int i = 0; i < 2; ++i) { n         int askedSubGate = g._c[i]; n         int otherSubGate = g._c[1 - i]; n         bool otherSubVal = gates[otherSubGate]._bOriVal; n         bool rr[2]; n         rr[false] = resObt[otherSubVal && false]; n         rr[true] = resObt[otherSubVal && true]; n         Solve(askedSubGate, rr); n       } n       break; n     case NOT: { n       bool rr[2]; n       rr[0] = resObt[1]; n       rr[1] = resObt[0]; n       Solve(g._c[0], rr); n       break; n     } n     case XOR: { n       for (int i = 0; i < 2; ++i) { n         int askedSubGate = g._c[i]; n         int otherSubGate = g._c[1 - i]; n         bool otherSubVal = gates[otherSubGate]._bOriVal; n         bool rr[2]; n         rr[false] = resObt[otherSubVal != false]; n         rr[true] = resObt[otherSubVal != true]; n         Solve(askedSubGate, rr); n       } n       break; n     } n     case IN: { n       res[g._index] = resObt[!g._bOriVal]; n       break; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << std::setprecision(15); n   cout << std::fixed; n   int n; n   cin >> n; n   gates.resize(n + 1); n   for (int i = (1), _b = (n); i <= _b; i++) { n     string s; n     cin >> s; n     if (s ==  IN ) { n       gates[i]._type = IN; n       bool val; n       cin >> val; n       gates[i]._bOriVal = val; n       gates[i]._index = i; n     } else if (s ==  AND ) { n       gates[i]._type = AND; n       cin >> gates[i]._c[0] >> gates[i]._c[1]; n     } else if (s ==  OR ) { n       gates[i]._type = OR; n       cin >> gates[i]._c[0] >> gates[i]._c[1]; n     } else if (s ==  XOR ) { n       gates[i]._type = XOR; n       cin >> gates[i]._c[0] >> gates[i]._c[1]; n     } else if (s ==  NOT ) { n       gates[i]._type = NOT; n       cin >> gates[i]._c[0]; n     } n   } n   bool current = Eval(1); n   bool rr[2] = {false, true}; n   Solve(1, rr); n   for (auto &v : res) { n     cout << (v.second ?  1  :  0 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n LL g_l, g_r; n LL gcd(LL a, LL b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n bool input() { n   cin >> g_l >> g_r; n   if (cin.eof()) return false; n   return true; n } n void solve() { n   for (LL i = g_l; i <= g_r; ++i) { n     for (LL j = i + 1; j <= g_r; ++j) { n       for (LL k = j + 1; k <= g_r; ++k) { n         if (gcd(i, k) != 1 && gcd(i, j) == 1 && gcd(j, k) == 1) { n           cout << i <<     << j <<     << k << endl; n           return; n         } n       } n     } n   } n   cout << -1 << endl; n } n int main() { n   while (input()) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100010; n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 3) + (x << 1) + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long n, m, a[N], op, x, y, z; n struct SegmentTree { n   long long l, r, sum, maxn; n } tree[N << 2]; n void pushup(int k) { n   tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum; n   tree[k].maxn = max(tree[k << 1].maxn, tree[k << 1 | 1].maxn); n } n void build(int k, int l, int r) { n   tree[k].l = l, tree[k].r = r; n   if (l == r) { n     tree[k].sum = tree[k].maxn = a[l]; n     return; n   } n   int mid = (l + r) / 2; n   build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r); n   pushup(k); n } n void changemod(int k, int ql, int qr, long long mod) { n   if (tree[k].maxn < mod) return; n   if (ql <= tree[k].l && tree[k].r <= qr && tree[k].l == tree[k].r) { n     tree[k].sum %= mod, tree[k].maxn %= mod; n     return; n   } n   int mid = (tree[k].l + tree[k].r) / 2; n   if (ql <= mid) changemod(k << 1, ql, qr, mod); n   if (mid < qr) changemod(k << 1 | 1, ql, qr, mod); n   pushup(k); n } n void modify(int k, int q, long long v) { n   if (tree[k].l > q || q > tree[k].r) return; n   if (tree[k].l == tree[k].r) { n     tree[k].sum = tree[k].maxn = v; n     return; n   } n   int mid = (tree[k].l + tree[k].r) / 2; n   if (q <= mid) n     modify(k << 1, q, v); n   else n     modify(k << 1 | 1, q, v); n   pushup(k); n } n long long query(int k, int ql, int qr) { n   long long res = 0; n   if (ql <= tree[k].l && tree[k].r <= qr) return tree[k].sum; n   int mid = (tree[k].l + tree[k].r) / 2; n   if (ql <= mid) res += query(k << 1, ql, qr); n   if (mid < qr) res += query(k << 1 | 1, ql, qr); n   return res; n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   build(1, 1, n); n   while (m--) { n     op = read(); n     if (op == 1) { n       x = read(), y = read(); n       printf( %lld n , query(1, x, y)); n     } n     if (op == 2) { n       x = read(), y = read(), z = read(); n       changemod(1, x, y, z); n     } n     if (op == 3) { n       x = read(), y = read(); n       modify(1, x, y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct BipartiteMatcher { n   vector<vector<int>> g; n   vector<int> L, R; n   vector<bool> vis; n   BipartiteMatcher(int n, int m) : g(n), L(n, -1), R(m, -1), vis(n) {} n   void addEdge(int a, int b) { g[a].emplace_back(b); } n   bool match(int x) { n     if (vis[x]) return 0; n     vis[x] = 1; n     for (int v : g[x]) n       if (R[v] == -1) return R[L[x] = v] = x, 1; n     for (int v : g[x]) n       if (match(R[v])) return R[L[x] = v] = x, 1; n     return 0; n   } n   int solve() { n     int cnt = 1; n     while (cnt--) { n       fill(vis.begin(), vis.end(), 0); n       for (int i = 0; i < L.size(); ++i) { n         cnt |= L[i] == -1 and match(i); n       } n     } n     int res = 0; n     for (int i = 0; i < L.size(); ++i) res += L[i] != -1; n     return res; n   } n }; n int solve(int n, int m) { n   BipartiteMatcher BM(n * m, n * m); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       if ((i + j) % 2 == 1) continue; n       for (int k = max(i - 3, 0); k <= min(i + 3, n - 1); ++k) { n         for (int l = max(j - 3, 0); l <= min(j + 3, m - 1); ++l) { n           if ((k + l) % 2 == 0) continue; n           if (abs(i - k) + abs(j - l) == 3) { n             BM.addEdge(i * m + j, k * m + l); n           } n         } n       } n     } n   return 2 * BM.solve(); n } n int main() { n   int n, m; n   cin >> n >> m; n   if (n > m) swap(n, m); n   if (n <= 20 and m <= 20) n     cout << solve(n, m) << endl; n   else if (n == 1) n     cout << 2 * (m / 6 * 3 + max(m % 6 - 3, 0)) << endl; n   else n     cout << (n * 1ll * m) / 2 * 2 << endl; n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x[60002]; n long long v[60002]; n double ans = 1e12; n long long n; n double ma(double a, double b) { n   if (a > b) return a; n   return b; n } n double calc(double xx, double& bd) { n   double time = -1; n   for (int i = 0; i < n; i++) { n     double d = abs(xx - x[i]); n     if (d / v[i] > time) { n       time = d / v[i]; n       bd = x[i]; n     } n   } n   return time; n } n void bs(double s, double e) { n   if (s < e - 0.0000001) { n     double mid = s + (e - s) / 2; n     double xx; n     double x1 = calc(mid, xx); n     if (ans > x1) { n       ans = x1; n     } n     if (xx > mid) n       bs(mid, e); n     else n       bs(s, mid); n   } n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> x[i]; n   for (int i = 0; i < n; i++) cin >> v[i]; n   bs(1, 1000000000); n   cout << fixed << setprecision(10) << ans; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     int a[20005], b[20005]; n     for (int i = 0; i < n; i++) scanf( %d %d , &a[i], &b[i]); n     int num = 1; n     for (int i = 0; i < n; i++) { n       if (num < a[i]) { n         num = a[i]; n       } n       if (num <= b[i]) { n         printf( %d  , num); n         num++; n       } else n         printf( 0  ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long int INFL = 0x3f3f3f3f3f3f3f3fLL; n const int MOD = 1e9 + 7; n const int MAX = 1e5 + 5; n int a[1001]; n int __attribute__((optimize( -O3 ))) main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int ans = 1; n   for (int i = 0; i < n; i++) { n     int l = i, r = i; n     while (l > 0 and a[l] >= a[l - 1]) { n       l--; n     } n     while (r < n - 1 and a[r] >= a[r + 1]) { n       r++; n     } n     ans = max(ans, r - l + 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 522133279; n const int MAXN = 100000; n const int TOTN = 100 + 100; n const long long MOD = 1000000007; n bool _su[MAXN]; n vector<int> su; n vector<int> suc; n int n, k; n void shai() { n   memset((_su), true, sizeof(_su)); n   for (int i = (2); i < (MAXN); i++) { n     if (k <= 1) break; n     if (_su[i] && k % i == 0) { n       su.push_back(i); n       suc.push_back(0); n       while (k && k % i == 0) { n         k /= i; n         suc.back()++; n       } n       for (int j = 2; j * i < MAXN; j++) _su[j * i] = false; n     } n   } n   if (k != 1) { n     su.push_back(k); n     suc.push_back(1); n   } n } n vector<int> fen(int x) { n   vector<int> cnt; n   cnt.resize(su.size()); n   for (int i = (0); i < (su.size()); i++) { n     while (x && x % su[i] == 0) { n       x /= su[i]; n       cnt[i]++; n     } n   } n   return cnt; n } n vector<vector<int> > lis; n bool divisible(vector<int> cnt) { n   bool ok = true; n   for (int i = (0); i < (cnt.size()); i++) { n     if (cnt[i] < suc[i]) { n       ok = false; n       break; n     } n   } n   return ok; n } n vector<int> getCnt(int l, int r) { n   if (l == 0) return lis[r]; n   vector<int> res; n   for (int i = (0); i < (lis[l].size()); i++) { n     res.push_back(lis[r][i] - lis[l - 1][i]); n   } n   return res; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> k; n   shai(); n   for (int i = (0); i < (n); i++) { n     int a; n     cin >> a; n     lis.push_back(fen(a)); n   } n   for (int i = (1); i < (n); i++) { n     for (int j = (0); j < (lis[i].size()); j++) { n       lis[i][j] += lis[i - 1][j]; n     } n   } n   int l = 0, r = 0; n   long long ans = 0; n   while (r < n) { n     while (r < n && !divisible(getCnt(l, r))) r++; n     if (r >= n) break; n     ans += n - r; n     l++; n     if (l > r) r = l; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int p[100000]; n int h[100000]; n int queries[100000][3]; n vector<pair<int, int> > type3[100000]; n vector<int> adj[100000]; n int visited[100000]; n vector<int> who; n int top[100000]; n int ok[100000]; n vector<pair<int, int> > need[100000]; n int which[100000]; n int findSet(int x) { n   if (p[x] == x) return x; n   return p[x] = findSet(p[x]); n } n void mergeSet(int x, int y) { n   int r1 = findSet(x); n   int r2 = findSet(y); n   if (h[r1] > h[r2]) n     p[r2] = r1; n   else if (h[r2] > h[r1]) n     p[r1] = r2; n   else { n     p[r1] = r2; n     h[r2] += 1; n   } n } n bool sameSet(int x, int y) { return findSet(x) == findSet(y); } n void dfs(int x) { n   visited[x] = 1; n   for (int i = 0; i < type3[x].size(); i++) n     if (visited[type3[x][i].first] == 1) ok[type3[x][i].second] = 1; n   for (int i = 0; i < adj[x].size(); i++) n     if (!visited[adj[x][i]]) dfs(adj[x][i]); n   visited[x] = 2; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     top[i] = 1; n     p[i] = i; n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &queries[i][0], &a); n     if (queries[i][0] != 2) scanf( %d , &b); n     queries[i][1] = a - 1; n     queries[i][2] = b - 1; n     if (queries[i][0] == 1) { n       adj[b - 1].push_back(a - 1); n       top[a - 1] = 0; n     } n     if (queries[i][0] == 2) { n       who.push_back(a - 1); n       which[who.size() - 1] = i; n     } n     if (queries[i][0] == 3) { n       type3[who[b - 1]].push_back(make_pair(a - 1, i)); n       need[which[b - 1]].push_back(make_pair(a - 1, i)); n     } n   } n   for (int i = 0; i < n; i++) n     if (top[i]) dfs(i); n   for (int i = 0; i < m; i++) { n     if (queries[i][0] == 1) mergeSet(queries[i][1], queries[i][2]); n     if (queries[i][0] == 2) n       for (int j = 0; j < need[i].size(); j++) n         if (!sameSet(queries[i][1], need[i][j].first)) n           ok[need[i][j].second] = 0; n     if (queries[i][0] == 3) { n       if (ok[i]) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int st[1000010]; n int mod = 1000000007; n vector<vector<int> > g; n int dp[1000010][2]; n int n, m, k; n int a[1000010]; n int main() { n   st[0] = 1; n   for (int i = (1); i < (1000010); ++i) { n     st[i] = st[i - 1] + st[i - 1]; n     if (st[i] >= mod) st[i] -= mod; n   } n   scanf( %d%d%d , &n, &m, &k); n   int max1 = -1; n   int min1 = 2000000000; n   int tot = 0; n   for (int i = (0); i < (m); ++i) { n     int v1, v2; n     scanf( %d%d , &v1, &v2); n     v1--; n     v2--; n     if (((v2 - v1) != 1) && (v2 - v1 != k + 1)) { n       cout << 0 << endl; n       return 0; n     } n     if (v2 - v1 == k + 1) { n       a[v1] = 1; n       max1 = v1; n       min1 = ((min1 < v1) ? (min1) : (v1)); n       tot++; n     } n   } n   if (max1 - min1 > k) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = (1); i < (n); ++i) a[i] += a[i - 1]; n   int res = 1; n   for (int i = (0); i < (n); ++i) { n     int v = i + k + 1; n     if (v >= n) break; n     if (i + k + 1 <= max1) continue; n     if (i > min1) break; n     int last = min(i + k, n - k - 2); n     int sum = a[last] - a[i]; n     int c = a[i]; n     if (i) c -= a[i - 1]; n     if (c) res--; n     if (res < 0) res += mod; n     res += st[last - i - sum]; n     if (res >= mod) res -= mod; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s; n   string c; n   cin >> n >> c; n   s = n; n   string r =   ; n   while (n > 0) { n     if (n % 2 == 0) { n       string y =   ; n       y += c[s - n]; n       y += r; n       r = y; n     } else { n       r += c[s - n]; n     } n     n--; n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int M, N, maxH[100009], d[100009]; n void dfs(int nod) { n   if (nod >= (1 << N)) { n     maxH[nod] = 0; n     return; n   } n   int f1 = nod << 1, f2 = f1 | 1; n   dfs(f1), dfs(f2); n   maxH[nod] = max(maxH[f1] + d[f1], maxH[f2] + d[f2]); n } n int ans = 0; n void solve(int nod) { n   if (nod >= (1 << N)) return; n   int f1 = nod << 1, f2 = f1 | 1; n   if (maxH[f1] + d[f1] < maxH[f2] + d[f2]) swap(f1, f2); n   solve(f1); n   ans += maxH[nod] - (maxH[f2] + d[f2]); n   solve(f2); n } n int main() { n   scanf( %d , &N), M = (1 << (N + 1)) - 1; n   for (int i = 2; i <= M; i++) scanf( %d , &d[i]); n   dfs(1); n   solve(1); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int L, f, b; n int n; n int pos[110]; n map<int, int> lot; n int findpos(int L) { n   map<int, int>::iterator cur, next; n   cur = lot.begin(), next = cur; n   next++; n   for (; next != lot.end(); cur++, next++) { n     int back = cur->first + cur->second, front = next->first; n     if (back + b + L + f <= front) return back + b; n   } n   return -1; n } n int main() { n   scanf( %d%d%d , &L, &b, &f); n   scanf( %d , &n); n   lot.clear(); n   lot.insert(make_pair(-b, 0)); n   lot.insert(make_pair(L + f, 0)); n   for (int i = 0; i < n; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     if (a == 1) { n       int pl = findpos(b); n       pos[i + 1] = pl; n       if (pl >= 0) lot.insert(make_pair(pl, b)); n       printf( %d n , pl); n     } else { n       if (pos[b] < 0) continue; n       lot.erase(pos[b]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1 << 28; n const long long LINF = 1ll << 61; n string B, N; n long long b, pw[10], C; n int main() { n   ios::sync_with_stdio(false); n   cin >> B >> N >> C; n   int it = N.size(); n   for (int i = N.size() - 1; i >= 0; i--) { n     N[i]--; n     if (N[i] <  0 ) n       N[i] =  9 ; n     else n       break; n   } n   b = 0; n   for (int i = 0; i < B.size(); i++) b = (b * 10 + B[i] -  0 ) % C; n   pw[0] = 1; n   for (int i = 1; i < 10; i++) pw[i] = pw[i - 1] * b % C; n   long long ans = 1; n   for (int i = 0; i < N.size(); i++) { n     ans = ans * ans % C; n     long long tmp = ans; n     ans = ans * ans % C; n     ans = ans * ans % C; n     ans = ans * tmp % C; n     ans = ans * pw[N[i] -  0 ] % C; n   } n   ans = ans * (b - 1 + C) % C; n   if (ans == 0) n     cout << C << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, cnt = 1; n   cin >> a >> b; n   int d = a; n   bool flag = true; n   while (d >= cnt) { n     if (flag) { n       a -= cnt; n       flag = false; n       d = b; n     } else { n       b -= cnt; n       flag = true; n       d = a; n     } n     ++cnt; n   } n   if (a < cnt && flag) n     cout <<  Vladik  n          <<   n ; n   else n     cout <<  Valera  n          <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long tripleIndx = n / 3; n     if (!(n % 3)) tripleIndx--; n     stack<long long> st; n     while (tripleIndx--) { n       st.push(tripleIndx % 4ll); n       tripleIndx /= 4; n     } n     long long curA = 1; n     long long curB = 2; n     long long curC = 3; n     long long a[4] = {0, 1, 2, 3}; n     long long b[4] = {0, 2, 3, 1}; n     long long c[4] = {0, 3, 1, 2}; n     while (!st.empty()) { n       long long mod = st.top(); n       st.pop(); n       curA *= 4; n       curA += a[mod]; n       curB *= 4; n       curB += b[mod]; n       curC *= 4; n       curC += c[mod]; n     } n     if (n % 3 == 1) { n       cout << curA <<   n ; n     } else if (n % 3 == 2) { n       cout << curB <<   n ; n     } else { n       cout << curC <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 110; n int a[maxn]; n int main() { n   int n; n   while (cin >> n) { n     int ans = 0; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       if (a[i]) ans++; n     } n     for (int i = 1; i <= n; i++) { n       if (a[i] == 1) { n         if (i == 1) continue; n         if (a[i - 1] && i >= 1) continue; n         if (i >= 2 && a[i - 2]) { n           ans++; n           continue; n         } n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   int n; n   cin >> n; n   for (long long(i) = (0); (i) < (n); (i)++) cin >> a[i]; n   int tmp = n + 1; n   int ans = 0; n   for (int i = n; i >= 1; --i) { n     if (i < tmp) ans++; n     tmp = min(tmp, i - a[i - 1]); n   } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n int cumsum[200005]; n int a[200005]; n int main() n { n  int t; n  scanf( %d ,&t); n  while(t--) n  { n   int n; n   scanf( %d ,&n); n   for(int i=0;i<n;i++) n   { n    scanf( %d ,&a[i]); n   } n   for(int i=0;i<n;i++) n   { n    cumsum[i] = 0; n   } n  n   for(int i=0;i<n;i++) n   { n    if(a[i] == 0) n     continue; n    cumsum[i+1]--; n    cumsum[max(0,i-a[i] + 1)]++; n   } n  n   for(int i=0;i<n;i++) n   { n    if(i != 0) n     cumsum[i]+=cumsum[i-1]; n    if(cumsum[i] == 0) n    { n     printf( 0  ); n    } n    else n    {  n     printf( 1  ); n    } n   } n   printf(  n ); n  } n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n priority_queue<long long, vector<long long>, greater<long long> > q; n int main() { n   long long n; n   while (cin >> n) { n     long long e = 0, o = 0; n     for (long long i = 1; i <= n; i++) { n       long long x; n       cin >> x; n       if (x % 2) n         o++; n       else n         e++; n     } n     long long xx = min(e, o); n     cout << xx + (o - xx) / 3 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int NCARDS = 8; n const int NVALS = 5; n const int NSTATE = 495; n vector<vector<int> > states; n map<vector<int>, int> mp; n void genstates(vector<int> &v, int at, int rem) { n   if (at >= ((int)(v).size())) { n     if (rem == 0) { n       int id = ((int)(states).size()); n       states.push_back(v); n       mp[v] = id; n     } n     return; n   } n   for (v[at] = 0; v[at] <= rem; ++v[at]) genstates(v, at + 1, rem - v[at]); n } n int nxt[NSTATE][NVALS][NVALS]; n vector<int> adj[NSTATE][NSTATE]; n vector<int> radj[NSTATE][NSTATE]; n int deg[NSTATE][NSTATE]; n int dp[NSTATE][NSTATE]; n int q[NSTATE * NSTATE], qhead, qtail; n void precalc() { n   states.clear(); n   mp.clear(); n   vector<int> state(NVALS, 0); n   genstates(state, 0, NCARDS); n   for (int i = (0); i < (((int)(states).size())); ++i) n     for (int a = (0); a < (NVALS); ++a) n       for (int b = (0); b < (NVALS); ++b) { n         if (states[i][a] == 0) { n           nxt[i][a][b] = -1; n           continue; n         } n         vector<int> tmp = states[i]; n         tmp[a]--; n         tmp[b]++; n         assert(mp.count(tmp)); n         nxt[i][a][b] = mp[tmp]; n       } n   for (int i = (0); i < (((int)(states).size())); ++i) n     for (int j = (0); j < (((int)(states).size())); ++j) { n       for (int a = (0); a < (NVALS); ++a) n         for (int b = (0); b < (NVALS); ++b) n           if (a * b != 0 && states[i][a] != 0 && states[j][b] != 0) { n             int c = (a + b) % NVALS; n             int ni = j, nj = nxt[i][a][c]; n             assert(nj != -1); n             adj[i][j].push_back(ni * NSTATE + nj); n           } n       sort(adj[i][j].begin(), adj[i][j].end()); n       adj[i][j].erase(unique(adj[i][j].begin(), adj[i][j].end()), n                       adj[i][j].end()); n       for (int k = (0); k < (((int)(adj[i][j]).size())); ++k) { n         int ii = adj[i][j][k] / NSTATE, jj = adj[i][j][k] % NSTATE; n         radj[ii][jj].push_back(i * NSTATE + j); n       } n     } n   int winid = ((int)(states).size()) - 1; n   for (int i = (0); i < (((int)(states).size())); ++i) n     for (int j = (0); j < (((int)(states).size())); ++j) n       dp[i][j] = 0, deg[i][j] = ((int)(adj[i][j]).size()); n   qhead = qtail = 0; n   for (int i = (0); i < (((int)(states).size())); ++i) n     dp[i][winid] = -1, q[qhead++] = i * NSTATE + winid; n   while (qtail < qhead) { n     int i = q[qtail] / NSTATE, j = q[qtail] % NSTATE; n     ++qtail; n     for (int k = (0); k < (((int)(radj[i][j]).size())); ++k) { n       int ii = radj[i][j][k] / NSTATE, jj = radj[i][j][k] % NSTATE; n       if (dp[ii][jj] != 0) continue; n       if (dp[i][j] == -1) { n         dp[ii][jj] = 1; n         q[qhead++] = ii * NSTATE + jj; n         continue; n       } n       if (--deg[ii][jj] == 0) { n         dp[ii][jj] = -1; n         q[qhead++] = ii * NSTATE + jj; n         continue; n       } n     } n   } n } n int fst; n int a[NCARDS], b[NCARDS]; n void run() { n   int nq; n   scanf( %d , &nq); n   for (int qi = (0); qi < (nq); ++qi) { n     scanf( %d , &fst); n     for (int i = (0); i < (NCARDS); ++i) scanf( %d , &a[i]); n     for (int i = (0); i < (NCARDS); ++i) scanf( %d , &b[i]); n     vector<int> acnt(NVALS, 0), bcnt(NVALS, 0); n     for (int i = (0); i < (NCARDS); ++i) acnt[a[i]]++, bcnt[b[i]]++; n     assert(mp.count(acnt) && mp.count(bcnt)); n     int aid = mp[acnt], bid = mp[bcnt]; n     int ans = fst == 0 ? dp[aid][bid] : -dp[bid][aid]; n     printf( %s n , ans > 0 ?  Alice  : ans < 0 ?  Bob  :  Deal ); n   } n } n int main() { n   precalc(); n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> S; n vector<int> ack; n int pop[1100100]; n int kol[1100100]; n int k[1234]; n char c[1234]; n const int INF = 1000000000; n int parse(int a) { n   if (a == INF) return -INF; n   return a; n } n int main() { n   int n, m; n   scanf( %d , &n); n   for (int i = (0); i <= (int(n) - 1); ++i) { n     int s; n     scanf( %d , &s); n     S.push_back(s); n   } n   sort(S.begin(), S.end()); n   scanf( %d , &m); n   for (int i = (0); i <= (int(m) - 1); ++i) { n     ack.push_back(S.back()); n     S.pop_back(); n   } n   for (int i = (0); i <= (int(m) - 1); ++i) { n     scanf(  %c%d , &c[i], &k[i]); n   } n   for (int q = m - 1; q >= 0; q--) { n     for (int i = (0); i <= (int(1 << m) - 1); ++i) pop[i] = kol[i]; n     int mn = 1; n     if (k[q] == 2) mn *= -1; n     for (int i = (0); i <= (int(1 << m) - 1); ++i) { n       kol[i] = -INF; n       for (int j = (0); j <= (int(m) - 1); ++j) n         if ((i & (1 << j)) != 0) { n           int x = ack[j]; n           if (c[q] ==  b ) x = 0; n           kol[i] = n               mn * max(mn * (pop[i ^ (1 << j)] + mn * x), parse(kol[i] * mn)); n         } n     } n   } n   printf( %d n , kol[(1 << m) - 1]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int ans = 0; n   int n, a = 0, b; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> b; n     a += b; n   } n   int m, c, d; n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> c >> d; n     if (ans == 0) { n       if (a >= c && a <= d) ans = a; n       if (c > a) ans = c; n     } n   } n   if (ans != 0) n     cout << ans; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 20000; n struct node { n   int flow; n   int ff[5]; n   int ru; n } mat[maxn]; n int n, m; n int kk[500]; n int now; n int getup(int id) { n   int ret = -1; n   int k = id - m; n   while (k >= 1) { n     if (mat[k].flow != -1) { n       ret = k; n       break; n     } n     k -= m; n   } n   return ret; n } n int getright(int id) { n   int ret = -1; n   int k = id; n   while (k % m != 0) { n     k = k + 1; n     if (mat[k].flow != -1) { n       ret = k; n       break; n     } n   } n   return ret; n } n int getdown(int id) { n   int ret = -1; n   int k = id + m; n   while (k <= n * m) { n     if (mat[k].flow != -1) { n       ret = k; n       break; n     } n     k += m; n   } n   return ret; n } n int getleft(int id) { n   int ret = -1; n   int k = id; n   while (k % m != 1) { n     k--; n     if (mat[k].flow != -1) { n       ret = k; n       break; n     } n   } n   return ret; n } n int fl[maxn][5]; n int ans; n int cnt; n int solve(int id) { n   int ret = 0; n   int k = id; n   int ne; n   int u, d, r, l; n   while (k != -1) { n     ret++; n     ne = mat[k].ff[mat[k].flow]; n     u = mat[k].ff[1]; n     d = mat[k].ff[3]; n     r = mat[k].ff[2]; n     l = mat[k].ff[4]; n     if (u != -1) { n       mat[u].ff[3] = d; n     } n     if (d != -1) { n       mat[d].ff[1] = u; n     } n     if (r != -1) { n       mat[r].ff[4] = l; n     } n     if (l != -1) { n       mat[l].ff[2] = r; n     } n     k = ne; n   } n   return ret; n } n int main() { n   kk[ U ] = 1; n   kk[ R ] = 2; n   kk[ D ] = 3; n   kk[ L ] = 4; n   kk[ . ] = -1; n   now = 0; n   cin >> n >> m; n   string s; n   for (int i = 1; i <= n; i++) { n     cin >> s; n     for (int j = 0; j < m; j++) { n       mat[++now].flow = kk[s[j]]; n     } n   } n   for (int i = 1; i <= now; i++) { n     if (mat[i].flow == -1) continue; n     if (n != 1) fl[i][1] = getup(i); n     if (m != 1) fl[i][2] = getright(i); n     if (n != 1) fl[i][3] = getdown(i); n     if (m != 1) fl[i][4] = getleft(i); n     if (m == 1) { n       fl[i][2] = fl[i][4] = -1; n     } n     if (n == 1) { n       fl[i][1] = fl[i][3] = -1; n     } n   } n   for (int i = 1; i <= now; i++) { n     int ne = fl[i][mat[i].flow]; n     if (ne != -1) { n       int nne = fl[ne][mat[ne].flow]; n       if (nne != i) n         ; n       mat[ne].ru = 1; n     } n   } n   ans = 0; n   for (int i = 1; i <= now; i++) { n     if (mat[i].flow == -1) continue; n     for (int i1 = 1; i1 <= now; i1++) { n       for (int j = 1; j <= 4; j++) { n         mat[i1].ff[j] = fl[i1][j]; n       } n     } n     int z = solve(i); n     if (z > ans) { n       ans = z; n       cnt = 1; n     } else if (z == ans) { n       cnt++; n     } n   } n   cout << ans <<     << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 100, MOD = 1e9 + 9, INF = 1e15, SQ = 370, LOG = 30; n int n, m, x, y, x2, y2, z, t, now, l, r; n int ans, dp[4][4 * N]; n bool lazy[4 * N]; n string s; n void bld(int b, int e, int pos) { n   if (b == e - 1) { n     if (s[b] ==  7 ) { n       dp[3][pos]++; n     } else { n       dp[2][pos]++; n     } n     dp[0][pos] = dp[1][pos] = 1; n     return; n   } n   int lch = pos << 1, rch = lch + 1, mid = e + b >> 1; n   bld(b, mid, lch); n   bld(mid, e, rch); n   dp[3][pos] = dp[3][lch] + dp[3][rch]; n   dp[2][pos] = dp[2][lch] + dp[2][rch]; n   dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]); n   dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]); n } n void shift(int pos, int lch, int rch) { n   lazy[lch] = !lazy[lch]; n   lazy[rch] = !lazy[rch]; n   lazy[pos] = false; n   swap(dp[0][lch], dp[1][lch]); n   swap(dp[2][lch], dp[3][lch]); n   swap(dp[0][rch], dp[1][rch]); n   swap(dp[2][rch], dp[3][rch]); n } n void upd(int b, int e, int pos) { n   if (b >= y || e <= x) return; n   if (x <= b && e <= y) { n     lazy[pos] = !lazy[pos]; n     swap(dp[0][pos], dp[1][pos]); n     swap(dp[2][pos], dp[3][pos]); n     return; n   } n   int lch = pos << 1, rch = lch + 1, mid = e + b >> 1; n   if (lazy[pos]) shift(pos, lch, rch); n   upd(b, mid, lch); n   upd(mid, e, rch); n   dp[3][pos] = dp[3][lch] + dp[3][rch]; n   dp[2][pos] = dp[2][lch] + dp[2][rch]; n   dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]); n   dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m >> s; n   bld(0, n, 1); n   while (m--) { n     cin >> s; n     if (s ==  count ) { n       cout << dp[0][1] <<   n ; n     } else { n       cin >> x >> y; n       x--; n       upd(0, n, 1); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n std::vector<std::string> alph; n class IAlphabet { n  public: n   virtual int encode(char symbol) = 0; n   virtual char decode(int code) = 0; n   virtual int size() = 0; n }; n class alphabet_eng : public IAlphabet { n  public: n   virtual int encode(char symbol); n   virtual char decode(int code); n   virtual int size() { return 26; }; n }; n int alphabet_eng::encode(char symbol) { n   if ((symbol < 97) || (symbol >= 123)) n     return -1; n   else n     return (symbol - 97); n } n char alphabet_eng::decode(int code) { n   if ((code < 0) || (code >= 26)) n     return 0; n   else n     return (code + 97); n } n class VocabularyTrie { n  public: n   VocabularyTrie(IAlphabet& alphabet); n   VocabularyTrie(VocabularyTrie& parent); n   void Fill(); n   int GetSize(); n   bool m_end_of_word; n   IAlphabet& m_alphabet; n   int winner; n   int loser; n   std::vector<std::unique_ptr<VocabularyTrie>> m_children; n   VocabularyTrie* m_parent; n }; n std::set<std::pair<int, VocabularyTrie*>> proce; n VocabularyTrie::VocabularyTrie(IAlphabet& alphabet) n     : m_end_of_word(false), n       m_children(alphabet.size()), n       m_parent(nullptr), n       m_alphabet(alphabet) { n   winner = 2; n } n VocabularyTrie::VocabularyTrie(VocabularyTrie& parent) n     : m_end_of_word(false), n       m_children(parent.GetSize()), n       m_parent(&parent), n       m_alphabet(parent.m_alphabet) {} n int VocabularyTrie::GetSize() { return m_alphabet.size(); } n void VocabularyTrie::Fill() { n   for (int i = 0; i < alph.size(); i++) { n     std::string word; n     word = alph[i]; n     VocabularyTrie* trie_ptr = this; n     for (int letter = 0; letter < word.length(); letter++) { n       int curr_letter_code = m_alphabet.encode(word[letter]); n       if (trie_ptr->m_children[curr_letter_code] == nullptr) { n         trie_ptr->m_children[curr_letter_code].reset( n             new VocabularyTrie(*trie_ptr)); n       } n       trie_ptr = trie_ptr->m_children[curr_letter_code].get(); n     } n     trie_ptr->m_end_of_word = true; n     proce.insert(std::make_pair(word.length(), trie_ptr)); n   } n } n int main() { n   int m, n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     std::string x; n     cin >> x; n     alph.push_back(x); n   } n   alphabet_eng alphabet; n   VocabularyTrie nn(alphabet); n   nn.Fill(); n   while (proce.size() >= 1) { n     auto h = proce.end(); n     h--; n     int x = h->first; n     VocabularyTrie* y = h->second; n     proce.erase(std::make_pair(x, y)); n     int winner = 2; n     int loser = 1; n     for (int i = 0; i < 26; i++) { n       if (y->m_children[i] != nullptr) loser = 2; n     } n     if (y == nullptr) continue; n     for (int i = 0; i < 26; i++) { n       if ((y->m_children[i] != nullptr) && (y->m_children[i]->winner == 2)) n         winner = 1; n       if ((y->m_children[i] != nullptr) && (y->m_children[i]->loser == 2)) n         loser = 1; n     } n     y->winner = winner; n     y->loser = loser; n     if (x > 0) proce.insert(std::make_pair(x - 1, y->m_parent)); n   } n   int whowins = 1; n   int u = nn.winner; n   int v = nn.loser; n   if (u == 2) n     whowins = 2; n   else { n     if (v == 1) n       whowins = 1; n     else n       whowins = 2 - (k % 2); n   } n   if (whowins == 2) n     cout <<  Second ; n   else n     cout <<  First ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:36777216 ) n using namespace std; n const int inf = 1 << 30; n const long long Inf = 1LL << 62; n const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0}; n const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0}; n const double eps = 1e-9; n const double pi = 3.1415926535897932384626433832795; n template <class T> n inline bool eq(const T &a, const T &b) { n   return fabs(a - b) < eps; n } n template <class T> n inline bool deg2(const T &n) { n   return (n & (n - 1)) == 0; n } n template <class T> n inline void chmax(T &a, const T &b) { n   a = max(a, b); n } n inline int intRand(int l, int r) { n   return ((rand() << 16) | rand()) % (r - l + 1) + l; n } n inline long long llRand(long long l, long long r) { n   return (((1ll * rand()) << 48) | ((1ll * rand()) << 32) | (rand() << 16) | n           rand()) % n              (r - l + 1) + n          l; n } n int i, n, len, j; n string s, pr; n int main() { n   ios_base::sync_with_stdio(false); n   srand(time(NULL)); n   cin >> n; n   cin >> pr; n   len = (int)pr.size(); n   for (i = 1; i < n; i++) { n     cin >> s; n     for (j = 0; j < len; j++) n       if (s[j] != pr[j]) break; n     len = j; n     pr = s; n   } n   cout << len; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n using namespace std; n int n; n int main() { n   cin >> n; n   int k1 = 0; n   int x = n; n   while (x % 10 != 0) { n     x++; n     k1++; n   } n   int k2 = 0; n   while (n % 10 != 0) { n     n--; n     k2++; n   } n   if (k1 > k2) n     cout << n; n   else n     cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int p[20000000 / 5], cnt; n bool flag[20000000]; n void prepare() { n   flag[1] = 1; n   for (int i = 2; i <= m; i++) { n     if (!flag[i]) { n       p[cnt++] = i; n     } n     for (int j = 0; j < cnt && i * p[j] <= m; j++) { n       flag[i * p[j]] = 1; n       if (i % p[j] == 0) break; n     } n   } n } n int main() { n   cin >> n; n   if (n == 2) { n     puts( 1 1 ); n     return 0; n   } n   m = n * (n + 1) / 2; n   prepare(); n   for (int i = 1; i <= n; i++) n     if (!flag[i] && !flag[m - i]) { n       for (int j = 1; j <= n; j++) { n         printf( %d  , j == i ? 1 : 2); n       } n       puts(  ); n       return 0; n     } n   for (int i = 4; i <= n; i++) n     if (!flag[i] && !flag[m - 3 - i]) { n       for (int j = 1; j <= n; j++) printf( %d  , j == 3 ? 2 : j == i ? 3 : 1); n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct ww { n   long double x, y; n } a[100010]; n int i, j, k, n, m, xx, yy; n long double LU[100010], RU[100010], LD[100010], RD[100010]; n inline bool judge(long double len) { n   int i, j; n   j = 0; n   for (i = 1; i <= n; i++) { n     for (; a[j + 1].x + len < a[i].x; j++) n       ; n     if (max(LU[j], RU[i + 1]) - min(LD[j], RD[i + 1]) <= len) return 1; n   } n   return 0; n } n inline bool cc1(const ww &a, const ww &b) { return a.x < b.x; } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &xx, &yy); n     a[i].x = yy - xx, a[i].y = xx + yy; n   } n   sort(a + 1, a + n + 1, cc1); n   LD[0] = RD[n + 1] = 1e10; n   LU[0] = RU[n + 1] = -1e10; n   for (i = 1; i <= n; i++) n     LD[i] = min(LD[i - 1], a[i].y), LU[i] = max(LU[i - 1], a[i].y); n   for (i = n; i; i--) n     RD[i] = min(RD[i + 1], a[i].y), RU[i] = max(RU[i + 1], a[i].y); n   long double l = 0, r = 1e10, mid; n   for (; l + 1e-7 < r;) { n     mid = (l + r) / 2; n     if (judge(mid)) n       r = mid; n     else n       l = mid; n   } n   double an = r; n   printf( %.10lf n , an / 2); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353; n template <typename T> n struct modular { n   constexpr modular() : val(0) {} n   constexpr modular(const modular<T>& _m) : val(_m.val) {} n   template <typename U> n   constexpr modular(const U& _r = U()) { n     val = -MOD <= _r && _r < MOD ? _r : _r % MOD; n     if (val < 0) { n       val += MOD; n     } n   } n   const T operator()() { return val; } n   template <typename U> n   explicit operator U() const { n     return static_cast<U>(val); n   } n   modular<T>& operator+=(const modular<T>& _m) { n     if ((val += _m.val) >= MOD) { n       val -= MOD; n     } n     return *this; n   } n   modular<T>& operator-=(const modular<T>& _m) { n     if ((val -= _m.val) < 0) { n       val += MOD; n     } n     return *this; n   } n   modular<T>& operator*=(const modular<T>& _m) { n     val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val)) n               .val; n     return *this; n   } n   modular<T>& operator/=(const modular<T>& _m) { n     T a = _m.val, b = MOD, u = 0, v = 1; n     while (a != 0) { n       T q = b / a; n       b -= q * a; n       swap(a, b); n       u -= q * v; n       swap(u, v); n     } n     return *this *= u; n   } n   modular<T>& operator=(const modular<T>& _m) { n     val = _m.val; n     return *this; n   } n   template <typename U> n   modular<T>& operator+=(const U& _r) { n     return *this += modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator-=(const U& _r) { n     return *this -= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator*=(const U& _r) { n     return *this *= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator/=(const U& _r) { n     return *this /= modular<T>(_r); n   } n   template <typename U> n   modular<T>& operator=(const U& _r) { n     val = modular<T>(_r).val; n     return *this; n   } n   modular<T> operator-() { return modular<T>(-val); } n   template <typename U> n   friend bool operator==(const modular<U>&, const modular<U>&); n   friend std::istream& operator>>(std::istream& os, modular<T>& _m) { n     os >> _m.val; n     _m *= 1; n     return os; n   } n   friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) { n     return os << _m.val; n   } n   template <typename U> n   modular<T> exp(U e) { n     modular<T> res = 1; n     modular<T> b = val; n     if (e < 0) { n       b = 1 / b; n       e *= -1; n     } n     for (; e; e >>= 1) { n       if (e & 1) { n         res *= b; n       } n       b *= b; n     } n     return res; n   } n  n  private: n   T val; n }; n template <typename T> n inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T, typename U> n inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) += _rhs; n } n template <typename T> n inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T, typename U> n inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) -= _rhs; n } n template <typename T> n inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T, typename U> n inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) *= _rhs; n } n template <typename T> n inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T, typename U> n inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) /= _rhs; n } n template <typename T> n inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) { n   return _lhs.val == _rhs.val; n } n template <typename T, typename U> n inline bool operator==(const modular<T>& _lhs, const U& _rhs) { n   return _lhs == modular<T>(_rhs); n } n template <typename T, typename U> n inline bool operator==(const U& _lhs, const modular<T>& _rhs) { n   return modular<T>(_lhs) == _rhs; n } n template <typename T> n inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const modular<T>& _lhs, const U& _rhs) { n   return !(_lhs == _rhs); n } n template <typename T, typename U> n inline bool operator!=(const U& _lhs, const modular<T>& _rhs) { n   return !(_lhs == _rhs); n } n const int N = 3003; n modular<int> dp[N][N]; n void solve() { n   memset(dp, 0, sizeof dp); n   int n, m; n   cin >> n >> m; n   vector<int> a(n); n   vector<int> w(n); n   for (auto& x : a) { n     cin >> x; n   } n   int H = 0, T = 0; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     w[i] = x; n     if (a[i]) n       H += x; n     else n       T += x; n   } n   int tot = H + T; n   dp[0][0] = 1; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j <= i; j++) { n       if (i - j <= T) { n         dp[i + 1][j] += dp[i][j] * (T - (i - j)) / (tot + j - (i - j)); n         dp[i + 1][j + 1] += dp[i][j] * (H + j) / (tot + j - (i - j)); n       } n     } n   } n   modular<int> ad = 0; n   modular<int> mi = 0; n   for (int j = 0; j <= m; j++) { n     ad += dp[m][j] * j; n     mi += dp[m][j] * (m - j); n   } n   vector<modular<int> > res(n); n   for (int i = 0; i < n; i++) { n     if (a[i]) { n       res[i] = w[i] + ad * w[i] / H; n     } else { n       res[i] = w[i] - mi * w[i] / T; n     } n   } n   for (auto& x : res) { n     cout << x <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long double epsilon = 1e-9; n string minus1(const string& str) { n   string str1(str); n   for (int i = str.size() - 1; i >= 0; i--) { n     if (str1[i] !=  0 ) { n       str1[i]--; n       break; n     } else n       str1[i] =  9 ; n   } n   return str1; n } n long long rem(const string& str, long long c) { n   long long temp = 0; n   for (int i = 0; i < str.size(); i++) { n     temp = (temp * 10LL + (long long)(str[i] -  0 )) % c; n   } n   return temp; n } n long long phi(long long c) { n   long long res = 1; n   for (long long i = 2; i * i <= c; i++) { n     if (c % i == 0) { n       c /= i; n       res *= (i - 1); n       while (c % i == 0) { n         c /= i; n         res *= i; n       } n     } n   } n   if (c > 1) res *= c - 1; n   return res; n } n long long rem2(const string& str, long long c) { n   long long temp = 0; n   long long t2; n   for (int i = 0; i < str.size(); i++) { n     t2 = (temp * 10LL + (long long)(str[i] -  0 )); n     temp = t2 % c + t2 / c; n   } n   return temp; n } n long long powe(long long a, long long p, long long c) { n   long long res = 1; n   long long mul = a; n   while (p > 0) { n     if (p & 1) { n       res = (res * mul) % c; n     } n     mul = (mul * mul) % c; n     p >>= 1; n   } n   return res; n } n long long bruteForce(string B, string N, long long c) { n   stringstream ss; n   ss << B <<     << N; n   long long b, n; n   ss >> b >> n; n   long long res = (b - 1) % c; n   for (int i = 1; i < n; i++) res = (res * b) % c; n   if (res == 0) res = c; n   return res; n } n long long nod(long long a, long long b) { n   if (a < b) swap(a, b); n   long long x; n   while (b) { n     x = a % b; n     a = b; n     b = x; n   } n   return a; n } n bool isPow(long long i, long long j) { n   if (j == 1) return false; n   while (i % j == 0) i /= j; n   return i == 1; n } n void fail() { n   long long nd; n   for (int i = 2; i < 10000; i++) { n     for (int j = 1; j < i; j++) { n       nd = nod(i, j); n       if (isPow(i, nd)) continue; n       if (powe(j, phi(i) + 1, i) != j) { n         cerr <<  Failed with:   << i <<     << j << endl; n         return; n       } n     } n   } n } n int main() { n   string n, b; n   long long c; n   long long e; n   int o = 1; n   while (cin >> b >> n >> c) { n     long long a = rem(minus1(b), c); n     long long b2 = rem(b, c); n     n = minus1(n); n     long long mat[10]; n     for (int i = 0; i < 10; i++) mat[i] = 1LL; n     long long ge, ye; n     int idx; n     for (int i = n.size() - 1; i >= 0; i--) { n       idx = n[i] -  0 ; n       mat[idx] = (mat[idx] * b2) % c; n       ge = (b2 * b2) % c; n       ye = (ge * ge) % c; n       ye = (ye * ye) % c; n       b2 = (ye * ge) % c; n     } n     long long re = 1; n     for (int i = 0; i < 10; i++) { n       for (int j = 0; j < i; j++) re = (re * mat[i]) % c; n     } n     long long q = (a * re) % c; n     if (q == 0) q = c; n     cout << q << endl; n     o++; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void umax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void umin(T &a, T b) { n   if (a > b) a = b; n } n template <class T> n inline T abs(T a) { n   return a > 0 ? a : -a; n } n template <class T> n inline T gcd(T a, T b) { n   return __gcd(a, b); n } n template <class T> n inline T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n const int inf = 1e9 + 143; n const long long longinf = 1e18 + 143; n inline int read() { n   int x; n   scanf(  %d , &x); n   return x; n } n const int N = 1e5 + 100; n const int MAX = 1e4 + 100; n int n; n long long x[N]; n int c[N]; n set<pair<int, int> > reach; n bool taken[N]; n int sz = 0; n long long a[N]; n priority_queue<pair<long long, int> > q; n long long dist[MAX]; n bool used[MAX]; n void rebuild() { n   sort(a, a + sz); n   sz = unique(a, a + sz) - a; n   int mod = a[0]; n   dist[0] = 0; n   used[0] = 0; n   for (int i = 1; i < mod; i++) { n     dist[i] = longinf; n     used[i] = 0; n   } n   q.push(make_pair(0ll, 0)); n   while (!q.empty()) { n     int u = q.top().second; n     long long len = -q.top().first; n     q.pop(); n     if (dist[u] < len) continue; n     for (int i = 1; i < sz; i++) { n       int v = (u + a[i]) % mod; n       long long c = a[i]; n       if (dist[v] > dist[u] + c) { n         dist[v] = dist[u] + c; n         q.push(make_pair(-dist[v], v)); n       } n     } n   } n   reach.clear(); n   for (int i = 0; i < n; i++) { n     if (taken[i]) continue; n     if (dist[x[i] % mod] <= x[i]) { n       reach.insert(make_pair(-c[i], i)); n     } n   } n } n int main() { n   long long h; n   cin >> h; n   n = read(); n   int m = read(); n   a[sz++] = read(); n   for (int i = 0; i < n; i++) { n     scanf(  %I64d , x + i); n     --x[i]; n     c[i] = read(); n   } n   rebuild(); n   while (m--) { n     int op = read(); n     if (op == 1) { n       long long x; n       scanf(  %I64d , &x); n       a[sz++] = x; n       rebuild(); n     } else if (op == 2) { n       int id = read() - 1; n       int y = read(); n       if (reach.find(make_pair(-c[id], id)) != reach.end()) { n         reach.erase(make_pair(-c[id], id)); n         c[id] -= y; n         reach.insert(make_pair(-c[id], id)); n       } else { n         c[id] -= y; n       } n     } else if (op == 3) { n       if (!reach.size()) { n         puts( 0 ); n       } else { n         printf( %d n , -reach.begin()->first); n         taken[reach.begin()->second] = true; n         reach.erase(reach.begin()); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 1e5 + 5; n int f[mx]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int>> v; n   for (int i = 3; 2 * i <= n; i += 2) { n     if (f[i] == 0) { n       int c = 0; n       for (int j = i; j <= n; j += i) c += !f[j]; n       for (int j = i, l = -1; j <= n; j += i) { n         if ((c & 1) && j == 2 * i) continue; n         if (!f[j]) { n           if (l == -1) n             l = j; n           else { n             v.push_back({l, j}); n             l = -1; n           } n         } n         f[j] = 1; n       } n     } n   } n   for (int j = 2, l = -1; j <= n; j += 2) { n     if (!f[j]) { n       if (l == -1) n         l = j; n       else { n         v.push_back({l, j}); n         l = -1; n       } n     } n   } n   cout << v.size() <<   n ; n   for (auto x : v) cout << x.first <<     << x.second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int n, act; n int t[MAXN]; n int last[MAXN], len[MAXN]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i < MAXN; ++i) len[i] = -1; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &t[i]); n     act = t[i]; n     if (len[act] == -1) { n       len[act] = 0; n     } else if (len[act] >= 0) { n       if (len[act] == 0) n         len[act] = i - last[act]; n       else if (i - last[act] != len[act]) n         len[act] = -2; n     } n     last[act] = i; n   } n   int counter = 0; n   for (int i = 1; i < MAXN; ++i) n     if (len[i] >= 0) ++counter; n   printf( %d n , counter); n   for (int i = 1; i < MAXN; ++i) { n     if (len[i] >= 0) { n       printf( %d %d n , i, len[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MaxN = 300005; n const long long int mod = 1e9 + 7; n const float pi = 3.1415926535897932384626433832795028; n long long int mcd(long long int a, long long int b) { n   if (a == 0) return b; n   return mcd(b % a, a); n } n int arr[MaxN]; n void solve() { n   int N, i, j, p, q; n   cin >> N; n   for (i = 1; i <= N; i++) { n     cin >> arr[i]; n   } n   p = 0, q = N + 1; n   for (i = 1; i <= N; i++) { n     if (arr[i] >= i - 1) { n       p = i; n     } else n       break; n   } n   for (i = N; i > 0; i--) { n     if (arr[i] >= N - i) { n       q = i; n     } else n       break; n   } n   if (p >= q) n     cout <<  Yes n ; n   else n     cout <<  No n ; n } n int main() { n   long long int t, i; n   cin >> t; n   for (i = 1; i <= t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int out = 0, fh = 1; n   char jp = getchar(); n   while ((jp >  9  || jp <  0 ) && jp !=  - ) jp = getchar(); n   if (jp ==  - ) fh = -1, jp = getchar(); n   while (jp >=  0  && jp <=  9 ) out = out * 10 + jp -  0 , jp = getchar(); n   return out * fh; n } n void print(int x) { n   if (x >= 10) print(x / 10); n   putchar( 0  + x % 10); n } n void write(int x, char c) { n   if (x < 0) putchar( - ), x = -x; n   print(x); n   putchar(c); n } n int phi(int x) { n   int res = x; n   for (int i = 2; i * i <= x; ++i) n     if (x % i == 0) { n       res /= i, res *= i - 1; n       while (x % i == 0) x /= i; n     } n   if (x > 1) res /= x, res *= x - 1; n   return res; n } n int mul(int a, int b, int Mod) { n   long long pr = 1LL * a * b; n   if (pr < Mod) return pr; n   return pr % Mod + Mod; n } n int fpow(int a, int b, int Mod) { n   int res = 1; n   while (b) { n     if (b & 1) res = mul(res, a, Mod); n     a = mul(a, a, Mod); n     b >>= 1; n   } n   return res; n } n int f(int x, int Mod) { n   if (x < Mod) return x; n   return x % Mod + Mod; n } n const int N = 1e5 + 10; n int n, m, q, Mod[N], k = 0, a[N]; n int query(int l, int r, int p) { n   if (l == r || p == k) return f(a[l], Mod[p]); n   int base = a[l], expo = query(l + 1, r, p + 1); n   return fpow(base, expo, Mod[p]); n } n signed main() { n   n = read(), m = read(); n   while (1) { n     Mod[++k] = m; n     if (m == 1) break; n     m = phi(m); n   } n   for (int i = 1; i <= n; ++i) a[i] = read(); n   q = read(); n   for (int i = 1; i <= q; ++i) { n     int l = read(), r = read(); n     int ans = query(l, r, 1) % Mod[1]; n     write(ans,   n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[101000], n, h[101000], p[101000]; n pair<int, int> w[101000]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &t[i]); n     w[i].first = t[i]; n     w[i].second = i; n   } n   sort(w, w + n); n   for (int i = n - 1; i >= 0; i--) { n     h[i] = ((long long)h[i + 1] * 1337 + t[i]) % 1000000009; n   } n   p[0] = 1; n   for (int i = 1; i <= n; i++) p[i] = (long long)p[i - 1] * 1337 % 1000000009; n   vector<pair<int, int> > s; n   for (int i = 0; i < n; i++) { n     int j = i + 1; n     while (j < n && w[j].first == w[i].first) { n       int len = w[j].second - w[i].second, start = w[i].second; n       long long tmp = h[start] - (long long)h[start + len] * p[len]; n       tmp -= h[start + len] - (long long)h[start + 2 * len] * p[len]; n       if (tmp % 1000000009 == 0) s.push_back(pair<int, int>(len, start)); n       j++; n     } n   } n   sort(s.begin(), s.end()); n   int first = 0; n   for (int i = 0; i < s.size(); i++) n     if (s[i].second >= first) { n       first = s[i].second + s[i].first; n     } n   printf( %d n , n - first); n   for (int i = first; i < n; i++) printf( %d%c , t[i], i + 1 < n ?     :   n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n const int inf = 1e9; n const int mod = 1e9 + 7; n const long long INF = 1e18; n long long a00, a01, a10, a11, cnt0, cnt1, cnt01, cnt10, ins = 0, t = -1; n long long p[N]; n void get() { n   for (int i = 1; i <= ins; ++i) { n     cout << 1; n   } n   if (t == -1) { n     for (int i = 0; i < cnt0; ++i) { n       cout << 0; n     } n   } else { n     ins++; n     for (int i = 0; i < cnt0 - t; ++i) { n       cout << 0; n     } n     cout << 1; n     for (int i = cnt0 - t; i < cnt0; ++i) { n       cout << 0; n     } n   } n   for (int i = ins + 1; i <= cnt1; ++i) { n     cout << 1; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   for (long long a = 1; a * (a - 1) / 2 < 1e11 + 1000; ++a) { n     p[a] = a * (a - 1) / 2; n   } n   cin >> a00 >> a01 >> a10 >> a11; n   if (!a00 && !a01 && !a10 && !a11) { n     return cout << 0, 0; n   } n   for (int i = 1; i < N; ++i) { n     if (p[i] > a00) { n       return cout <<  Impossible , 0; n     } n     if (a00 == p[i]) { n       cnt0 = i; n       break; n     } n   } n   for (int i = 1; i < N; ++i) { n     if (p[i] > a11) { n       return cout <<  Impossible , 0; n     } n     if (a11 == p[i]) { n       cnt1 = i; n       break; n     } n   } n   if (!a01 && !a10) { n     if (!a00) { n       for (int i = 0; i < cnt1; ++i) { n         cout << 1; n       } n       return 0; n     } n     if (!a11) { n       for (int i = 0; i < cnt0; ++i) { n         cout << 0; n       } n       return 0; n     } n   } n   if (cnt0 * cnt1 != a01 + a10) { n     return cout <<  Impossible , 0; n   } n   cnt01 = cnt0 * cnt1; n   cnt10 = 0; n   for (int i = 1; i <= cnt1; ++i) { n     if (cnt01 - cnt0 >= a01) { n       cnt01 -= cnt0; n       cnt10 += cnt0; n       ++ins; n     } else { n       t = cnt01 - a01; n       cnt01 -= t; n       cnt10 += t; n     } n     if (cnt01 == a01 && cnt10 == a10) { n       get(); n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n long long a[maxn], suf[maxn]; n int main() { n   long long n, ans = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = n; i >= 1; i--) suf[i] = gcd(suf[i + 1], a[i]); n   for (int i = 1; i <= n; i++) ans = gcd(ans, lcm(a[i], suf[i + 1])); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n const int MAXN = 5 * 1e5 + 1, MODM = 1e9 + 7; n int n; n vector<int> g[MAXN]; n int sz[MAXN]; n int pr[MAXN]; n int ans[MAXN]; n int m1, m2; n int now; n int root = -1; n void dfs(int v, int p = -1) { n   sz[v] = 1; n   pr[v] = p; n   for (auto to : g[v]) { n     if (to != p) { n       dfs(to, v); n       sz[v] += sz[to]; n     } n   } n } n void dfs2(int v, int p = -1) { n   int k = m1; n   if (sz[now] == m1) k = m2; n   ans[v] |= (n - sz[v] - k <= (n / 2)); n   ans[v] |= (n - sz[now] <= (n / 2)); n   for (auto it : g[v]) n     if (it != p) dfs2(it, v); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   dfs(1); n   for (int v = 1; v <= n; v++) { n     int cnt = 0; n     for (auto to : g[v]) n       if (to != pr[v]) cnt += (sz[to] <= (n / 2)); n     if (v != 1) cnt += (n - sz[v] <= (n / 2)); n     ans[v] = (cnt == g[v].size()); n     if (ans[v]) root = v; n   } n   if (root == -1) { n     for (int i = 0; i < n; i++) cout << 0 <<    ; n     return 0; n   } n   fill(sz, sz + MAXN, 0); n   dfs(root); n   for (auto it : g[root]) { n     if (sz[it] > m1) { n       m2 = m1; n       m1 = sz[it]; n     } else n       m2 = max(m2, sz[it]); n   } n   for (auto it : g[root]) { n     now = it; n     dfs2(it, root); n   } n   for (int i = 0; i < n; i++) cout << ans[i + 1] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e5; n const long double PI = acos(-1.0); n char d[MAX]; n int l[MAX]; n int w[MAX]; n int pos; n int main() { n   long long n; n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   long long i; n   for (i = 0; i < n; i++) cin >> d[i]; n   for (i = 0; i < n; i++) cin >> l[i]; n   while (w[pos] == 0) { n     w[pos] = 1; n     if (d[pos] ==  > ) n       pos += l[pos]; n     else n       pos -= l[pos]; n     if (pos < 0 || pos >= n) { n       cout <<  FINITE  n            <<   n ; n       return 0; n     } n   } n   cout <<  INFINITE  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < k; i++) { n     if (n % 10 > 0) { n       n--; n     } else n       n /= 10; n   } n   cout << n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100100]; n int main() { n   int n, m; n   scanf( %d %d %s , &n, &m, s); n   long long ans = 0, cnt = 1, num = 0; n   for (int i = 1; s[i]; i++) { n     cnt += s[i] != s[i - 1]; n   } n   ans += cnt * n * (m - 1); n   cnt = 1; n   for (int i = 1; s[i]; i++) { n     if (s[i] != s[i - 1] && (cnt == 1 || s[i] == s[i - 2])) { n       cnt++; n     } else { n       num += cnt * (cnt - 1) / 2; n       if (cnt != 1) i--; n       cnt = 1; n     } n   } n   num += cnt * (cnt - 1) / 2; n   cout << ans - num << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <class A, class B> n ostream& operator<<(ostream& out, const pair<A, B>& a) { n   return out <<  (  << a.first <<  ,   << a.second <<  ) ; n } n template <class A> n ostream& operator<<(ostream& out, const vector<A>& v) { n   out <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) out <<  ,  ; n     out << v[i]; n   } n   return out <<  ] ; n } n void solve() { n   long long n, x; n   cin >> n >> x; n   int a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long sum = 0; n   for (int i = 0; i < n; i++) sum += a[i]; n   if (sum % x != 0) n     cout << n <<   n ; n   else { n     long long res = -1; n     long long s = 0; n     for (int i = 0; i < n; i++) { n       s += a[i]; n       sum -= a[i]; n       if (s % x != 0) res = max(res, (long long)i + 1); n       if (sum % x != 0) res = max(res, n - i - 1); n     } n     cout << res <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int q = 1; n   cin >> q; n   for (int kase = 1; kase <= q; kase++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s, e; n long long x[5001]; n long long a[5001]; n long long b[5001]; n long long c[5001]; n long long d[5001]; n long long pd[5001][5001]; n long long func(int at, int comp, int left, int right) { n   if (comp <= 0 && at != 0) return 0x3f3f3f3f3f3f3f3fll; n   if (at == n) return ((comp == 1) ? 0 : 0x3f3f3f3f3f3f3f3fll); n   if (pd[at][comp] != -1) return pd[at][comp]; n   long long ans = 0x3f3f3f3f3f3f3f3fll; n   int onlycomp = (comp - left - right); n   if (at != s && at != e) { n     ans = func(at + 1, comp + 1, left, right) - 2 * x[at] + d[at] + b[at]; n     if (left) { n       ans = min(ans, func(at + 1, comp, left, right) + a[at] + d[at]); n       if (onlycomp) n         ans = min(ans, func(at + 1, comp - 1, left, right) + a[at] + c[at] + n                            2 * x[at]); n     } n     if (right) { n       ans = min(ans, func(at + 1, comp, left, right) + c[at] + b[at]); n       if (onlycomp) n         ans = min(ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] + n                            2 * x[at]); n     } n     if (onlycomp) { n       ans = min( n           ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] + 2 * x[at]); n       ans = min(ans, func(at + 1, comp, left, right) + b[at] + c[at]); n       ans = min(ans, func(at + 1, comp, left, right) + a[at] + d[at]); n     } n     if (at == n - 1 && comp == 2) n       ans = min( n           ans, func(at + 1, comp - 1, left, right) + c[at] + a[at] + 2 * x[at]); n   } else if (at == s) { n     ans = func(at + 1, comp + 1, 1, right) - x[at] + d[at]; n     if (onlycomp) ans = min(ans, func(at + 1, comp, 1, right) + x[at] + c[at]); n     if (at == n - 1 && comp == 1) n       ans = min(ans, func(at + 1, comp, 1, right) + c[at] + x[at]); n   } else { n     ans = func(at + 1, comp + 1, left, 1) - x[at] + b[at]; n     if (onlycomp) ans = min(ans, func(at + 1, comp, left, 1) + x[at] + a[at]); n     if (at == n - 1 && comp == 1) n       ans = min(ans, func(at + 1, comp, left, 1) + a[at] + x[at]); n   } n   return pd[at][comp] = ans; n } n int main() { n   scanf( %d %d %d , &n, &s, &e); n   s--; n   e--; n   for (int i = 0; i < n; i++) scanf( %lld , &x[i]); n   for (int i = 0; i < n; i++) scanf( %lld , &a[i]); n   for (int i = 0; i < n; i++) scanf( %lld , &b[i]); n   for (int i = 0; i < n; i++) scanf( %lld , &c[i]); n   for (int i = 0; i < n; i++) scanf( %lld , &d[i]); n   memset(pd, -1, sizeof pd); n   printf( %lld n , func(0, 0, 0, 0)); 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   if (m % 2 != 0) { n     cout << (m + 1) / 2; n   } else { n     cout << (n - m + 2) / 2; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 1005; n int a[MAXN]; n int cnt[MAXN]; n int main() { n   int n, k; n   while (scanf( %d%d , &n, &k) + 1) { n     memset(cnt, 0, sizeof(cnt)); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         if ((j - i) * k == a[j] - a[i]) { n           cnt[i]++; n         } n       } n     } n     int mm = 0; n     int p = 0; n     for (int i = 1; i <= n; i++) { n       if (cnt[i] > mm && a[i] - (i - 1) * k > 0) { n         mm = cnt[i]; n         p = i; n       } n     } n     printf( %d n , n - mm); n     for (int i = 1; i <= n; i++) { n       if ((i - p) * k != a[i] - a[p]) { n         if (a[i] - a[p] > (i - p) * k) { n           printf( - %d %d n , i, a[i] - a[p] - (i - p) * k); n         } else { n           printf( + %d %d n , i, (i - p) * k - a[i] + a[p]); n         } n       } n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n map<long long, pair<long long, long long>> ChthollyTree; n map<long long, pair<long long, long long>>::iterator split( n     long long p, map<long long, pair<long long, long long>>::iterator *pre) { n   map<long long, pair<long long, long long>>::iterator pos = n       ChthollyTree.lower_bound(p); n   if (pos->first == p) return pos; n   pos--; n   if (pos->second.first < p) return ChthollyTree.end(); n   long long left = pos->first, right = pos->second.first; n   long long value = pos->second.second; n   if (pre && *pre == pos) { n     ChthollyTree.erase(pos); n     *pre = ChthollyTree.insert(make_pair(left, make_pair(p - 1, value))).first; n   } else { n     ChthollyTree.erase(pos); n     ChthollyTree[left] = make_pair(p - 1, value); n   } n   return ChthollyTree.insert(make_pair(p, make_pair(right, value))).first; n } n void add(long long l, long long r, long long diff) { n   map<long long, pair<long long, long long>>::iterator s = split(l, NULL), n                                                        e = split(r + 1, &s); n   while (s != e) { n     s->second.second += diff; n     s++; n   } n } n void assign(long long l, long long r, long long x) { n   map<long long, pair<long long, long long>>::iterator s = split(l, NULL), n                                                        e = split(r + 1, &s); n   map<long long, pair<long long, long long>>::iterator tmp; n   while (s != e) { n     tmp = s; n     s++; n     ChthollyTree.erase(tmp); n   } n   ChthollyTree[l] = make_pair(r, x); n } n long long kSmallest(long long l, long long r, long long k) { n   map<long long, pair<long long, long long>>::iterator s = split(l, NULL), n                                                        e = split(r + 1, &s); n   vector<pair<long long, long long>> buff; n   while (s != e) { n     buff.push_back(make_pair(s->second.second, s->second.first - s->first + 1)); n     s++; n   } n   sort(buff.begin(), buff.end()); n   unsigned int length = buff.size(); n   for (unsigned int i = 0; i < length; i++) { n     k -= buff[i].second; n     if (k <= 0) return buff[i].first; n   } n   return -1; n } n long long fastPowMod(long long base, long long p, long long mod) { n   long long ret = 1; n   base %= mod; n   do { n     if (p & 1) ret = ret * base % mod; n     base = base * base % mod; n   } while (p >>= 1); n   return ret; n } n long long intervalPowSum(long long l, long long r, long long p, long long mod) { n   map<long long, pair<long long, long long>>::iterator s = split(l, NULL), n                                                        e = split(r + 1, &s); n   long long ret = 0; n   while (s != e) { n     ret = (ret + fastPowMod(s->second.second, p, mod) % mod * n                      (s->second.first - s->first + 1)) % n           mod; n     s++; n   } n   return ret; n } n inline long long rnd(long long &seed) { n   long long ret = seed; n   seed = (seed * 7 + 13) % 1000000007; n   return ret; n } n inline void swap(long long &a, long long &b) { n   long long t = a; n   a = b; n   b = t; n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m, seed, v; n   long long op, l, r, x, y; n   cin >> n >> m >> seed >> v; n   for (long long i = 1; i <= n; i++) { n     ChthollyTree[i] = make_pair(i, rnd(seed) % v + 1); n   } n   for (long long i = 0; i < m; i++) { n     op = rnd(seed) % 4 + 1; n     l = rnd(seed) % n + 1; n     r = rnd(seed) % n + 1; n     if (l > r) swap(l, r); n     if (op == 3) n       x = (rnd(seed) % (r - l + 1)) + 1; n     else n       x = rnd(seed) % v + 1; n     if (op == 4) y = rnd(seed) % v + 1; n     switch (op) { n       case 1: n         add(l, r, x); n         break; n       case 2: n         assign(l, r, x); n         break; n       case 3: n         cout << kSmallest(l, r, x) <<   n ; n         break; n       case 4: n         cout << intervalPowSum(l, r, x, y) <<   n ; n         break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int ans = 6; n   for (int i = 4; i <= n; i++) { n     ans += (i - 1) * i; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int kbo[1001]; n int main() { n   int s, k, i; n   scanf( %d%d , &s, &k); n   kbo[0] = 0; n   kbo[1] = 1; n   kbo[2] = 1; n   for (i = 3;; i++) { n     if (i - k - 1 > 0) n       kbo[i] = 2 * kbo[i - 1] - kbo[i - k - 1]; n     else n       kbo[i] = 2 * kbo[i - 1]; n     if (kbo[i] > s) break; n   } n   for (int j = 0; j < i; ++j) { n   } n   int res[100], cnt = 0; n   while (s > 0) { n     i--; n     if (s - kbo[i] >= 0) { n       s -= kbo[i]; n       res[cnt++] = kbo[i]; n     } n   } n   if (cnt == 1) n     printf( 2 n0 %d , res[0]); n   else { n     printf( %d n , cnt); n     for (int j = 0; j < cnt; j++) printf( %d  , res[j]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10, K = 105, MOD = 998244353; n int p[N][K], dp[N][K], a[N], ans[N] = {1}; n int n, k, len; n int sum(int l, int r, int x) { n   l = max(l, 1); n   r = min(r, n); n   return p[r][x] - p[l - 1][x]; n } n int main() { n   cin >> n >> k >> len; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == -1) a[i]++; n     p[i][a[i]]++; n     for (int j = 0; j <= k; j++) { n       p[i][j] += p[i - 1][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= k; j++) { n       if (a[i] == 0 || a[i] == j) { n         dp[i][j] = ans[i - 1]; n         if (sum(i - len + 1, i, j) + sum(i - len + 1, i, 0) == len) { n           dp[i][j] -= ans[i - len] - dp[i - len][j]; n           if (dp[i][j] < 0) dp[i][j] += MOD; n           if (dp[i][j] >= MOD) dp[i][j] -= MOD; n         } n       } n     } n     for (int j = 1; j <= k; j++) { n       ans[i] += dp[i][j]; n       if (ans[i] >= MOD) ans[i] -= MOD; n     } n   } n   cout << ans[n] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAXN = 200011; n long long a[MAXN], v[MAXN]; n int main() { n   long long ii, tt, i, j, k, m, n, d, md, maxt, mx, t, ct, oct, res1, res2, sum, n       osum, L, R, M; n   cin >> tt; n   for (ii = 0; ii < tt; ii++) { n     cin >> n >> m >> maxt; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       v[i] = a[i]; n     } n     sort(v, v + n); n     mx = 0; n     md = 1; n     L = 0; n     R = n; n     while (L + 1 < R) { n       M = (L + R) / 2; n       d = v[M]; n       osum = 0; n       sum = 0; n       oct = 0; n       ct = 0; n       t = 0; n       for (i = 0; i < n; i++) { n         if (a[i] <= d) { n           sum += a[i]; n           osum += a[i]; n           ct++; n           if (osum > maxt) break; n           oct++; n           if (ct == m) { n             ct = 0; n             osum += sum; n             sum = 0; n             if (osum > maxt) break; n           } n         } n       } n       if (oct >= mx) { n         mx = oct; n         md = d; n       } n       if (osum <= maxt) { n         L = M; n       } else { n         R = M; n       } n     } n     d = v[L]; n     osum = 0; n     sum = 0; n     oct = 0; n     ct = 0; n     t = 0; n     for (i = 0; i < n; i++) { n       if (a[i] <= d) { n         sum += a[i]; n         osum += a[i]; n         ct++; n         if (osum > maxt) break; n         oct++; n         if (ct == m) { n           ct = 0; n           osum += sum; n           sum = 0; n           if (osum > maxt) break; n         } n       } n     } n     if (oct >= mx) { n       mx = oct; n       md = d; n     } n     md = min(md, maxt); n     cout << mx <<     << md << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int max(long long int a, long long int b) { n   if (a > b) n     return a; n   else n     return b; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   return (a * b) / gcd(a, b); n } n bool isPowerOfTwo(long long int n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n bool comp(const pair<long long int, bool>& a, n           const pair<long long int, bool>& b) { n   if (a.second != b.second) { n     return a.first < b.first; n   } n   return false; n } n void solve() { n   long long int n, k; n   cin >> n >> k; n   long long int arr[n][n]; n   for (long long int i = 0; i < n; i++) n     for (long long int j = 0; j < n; j++) arr[i][j] = 0; n   long long int x = ceil(k * 1.0 / (n * 1.0)); n   bool f = 0; n   for (long long int l = 1; l <= x && k; l++) { n     for (long long int i = 0; i < n && k; i++) { n       for (long long int j = 0; j < n && k; j++) { n         if (i + j == n + l - 2 || i + j == l - 2) arr[i][j] = 1, k--; n       } n     } n   } n   long long int ans = 0, rma = 0, rmi = INT_MAX, cma = 0, cmi = INT_MAX; n   for (long long int i = 0; i < n; i++) { n     long long int c = 0; n     for (long long int j = 0; j < n; j++) n       if (arr[i][j]) c++; n     rma = max(rma, c); n     rmi = min(rmi, c); n   } n   for (long long int i = 0; i < n; i++) { n     long long int c = 0; n     for (long long int j = 0; j < n; j++) n       if (arr[j][i]) c++; n     cma = max(cma, c); n     cmi = min(cmi, c); n   } n   ans = (pow(rma - rmi, 2) + pow(cma - cmi, 2)); n   cout << ans << endl; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < n; j++) cout << arr[i][j]; n     cout <<   n ; n   } n } n void solve1() { n   long long int n; n   cin >> n; n   if (n & 1) n     cout <<  NO n ; n   else { n     n /= 2; n     if (n & 1) n       cout <<  NO n ; n     else n       cout <<  YES n ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const int NINF = INT_MIN; n const long long INF_LL = LLONG_MAX; n const long long NINF_LL = LLONG_MIN; n const double PI = acos(-1.0); n const int MOD = 1e9 + 7; n int main() { n   long long n, m; n   cin >> n >> m; n   long long ans = n * n; n   int nr = 0, nc = 0; n   vector<bool> r(n, false), c(n, false); n   while (m--) { n     int y, x; n     cin >> y >> x; n     --x, --y; n     bool ds = false; n     if (!r[y] and !c[x]) { n       --ans; n       ds = true; n     } n     if (!r[y]) { n       ans -= (n - nc - ds); n     } n     if (!c[x]) { n       ans -= (n - nr - ds); n     } n     if (!r[y]) { n       nr++; n       r[y] = true; n     } n     if (!c[x]) { n       nc++; n       c[x] = true; n     } n     cout << ans; n     if (m) cout <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T abs(T x) { n   return x > 0 ? x : -x; n } n int n; n int m; n int l[100], v[100][100], t[100][100], q[200]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %d , &l[i]); n     for (int j = 0; j < l[i]; j++) { n       scanf( %d%d , &v[i][j], &t[i][j]); n       if (j > 0) t[i][j] += t[i][j - 1]; n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       int k = 0; n       q[k++] = 0; n       for (int p = 0; p < l[i]; p++) q[k++] = t[i][p]; n       for (int p = 0; p < l[j]; p++) q[k++] = t[j][p]; n       sort(q, q + k); n       int a = 0, b = 0, ls = 0, x = 0, y = 0; n       for (int p = 1; p < k; p++) { n         int d = q[p] - q[p - 1]; n         while (a + 1 < l[i] && t[i][a] < q[p]) a++; n         while (b + 1 < l[j] && t[j][b] < q[p]) b++; n         x += v[i][a] * d; n         y += v[j][b] * d; n         int cs = int(x > y) - int(x < y); n         if (ls == 0) n           ls = cs; n         else if (cs != 0 && ls != cs) { n           ls = cs; n           ans++; n         } n         if (x == m || y == m) break; n       } n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _Tp> n inline _Tp read(_Tp& x) { n   char c11 = getchar(), ob = 0; n   x = 0; n   while (c11 ^  -  && !isdigit(c11)) c11 = getchar(); n   if (c11 ==  - ) ob = 1, c11 = getchar(); n   while (isdigit(c11)) x = x * 10 + c11 -  0 , c11 = getchar(); n   if (ob) x = -x; n   return x; n } n const int N = 201000; n const long long inf = 0x3f3f3f3f3f3f3f3f; n struct Edge { n   int v, nxt, w; n } a[N << 1]; n int head[N], is[N], st[N], vis[N]; n long long f[N], pre[N]; n long long gl[N], gr[N], hl[N], hr[N], hhl[N], hhr[N], ggl[N], ggr[N]; n int n, m, _, top; n long long Ans; n void get_cir(int x, int las) { n   if (vis[x]) { n     int p = top; n     while (st[p] ^ x) --p; n     for (register int i = p; i <= top; ++i) is[st[i - p + 1] = st[i]] = 1; n     st[0] = -1; n     top -= p - 1; n     return; n   } n   vis[st[++top] = x] = 1; n   for (int i = head[x]; i && ~st[0]; i = a[i].nxt) n     if (a[i].v ^ las) get_cir(a[i].v, x); n   if (~st[0]) vis[st[top--]] = 0; n } n void dfs(int x, int las) { n   long long sec = 0ll; n   for (int i = head[x]; i; i = a[i].nxt) n     if (!is[a[i].v] && a[i].v ^ las) { n       dfs(a[i].v, x); n       f[a[i].v] += a[i].w; n       if (f[a[i].v] >= f[x]) n         sec = f[x], f[x] = f[a[i].v]; n       else if (f[a[i].v] > sec) n         sec = f[a[i].v]; n     } n   Ans = max(Ans, f[x] + sec); n } n inline long long G(int x) { return x ? f[st[x]] - pre[x] : -inf; } n inline long long H(int x) { return x ? f[st[x]] + pre[x] : -inf; } n void work() { n   st[0] = st[top]; n   for (register int x = 1; x <= top; ++x) { n     for (register int i = head[st[x - 1]]; i; i = a[i].nxt) n       if (a[i].v == st[x]) { n         pre[x] = pre[x - 1] + a[i].w; n         break; n       } n     dfs(st[x], 0); n   } n   for (register int i = 1; i <= top; ++i) { n     gl[i] = gl[i - 1], ggl[i] = ggl[i - 1]; n     hl[i] = hl[i - 1], hhl[i] = hhl[i - 1]; n     if (G(i) > G(gl[i])) n       ggl[i] = gl[i], gl[i] = i; n     else if (G(i) > G(ggl[i])) n       ggl[i] = i; n     if (H(i) > H(hl[i])) n       hhl[i] = hl[i], hl[i] = i; n     else if (H(i) > H(hhl[i])) n       hhl[i] = i; n   } n   for (register int i = top; i; --i) { n     gr[i] = gr[i + 1], ggr[i] = ggr[i + 1]; n     hr[i] = hr[i + 1], hhr[i] = hhr[i + 1]; n     if (G(i) > G(gr[i])) n       ggr[i] = gr[i], gr[i] = i; n     else if (G(i) > G(ggr[i])) n       ggr[i] = i; n     if (H(i) > H(hr[i])) n       hhr[i] = hr[i], hr[i] = i; n     else if (H(i) > H(hhr[i])) n       hhr[i] = i; n   } n   long long ans; n   if (hl[top] != gl[top]) n     ans = G(gl[top]) + H(hl[top]); n   else n     ans = max(G(ggl[top]) + H(hl[top]), G(gl[top]) + H(hhl[top])); n   for (register int i = 1; i < top; ++i) { n     long long val = pre[top] + H(hl[i]) + G(gr[i + 1]); n     long long tmp; n     if (gl[i] ^ hl[i]) n       tmp = G(gl[i]) + H(hl[i]); n     else n       tmp = max(G(ggl[i]) + H(hl[i]), G(gl[i]) + H(hhl[i])); n     val = max(val, tmp); n     ++i; n     if (gr[i] ^ hr[i]) n       tmp = G(gr[i]) + H(hr[i]); n     else n       tmp = max(G(ggr[i]) + H(hr[i]), G(gr[i]) + H(hhr[i])); n     val = max(val, tmp); n     --i; n     ans = min(ans, val); n   } n   cout << max(ans, Ans) << endl; n } n void init(); n void work(); n int main() { n   init(); n   work(); n   return 0; n } n void init() { n   read(n); n   int u, v, w; n   for (register int i = 1; i <= n; ++i) { n     read(u), read(v), read(w); n     a[++_].v = v, a[_].w = w, a[_].nxt = head[u], head[u] = _; n     a[++_].v = u, a[_].w = w, a[_].nxt = head[v], head[v] = _; n   } n   get_cir(1, 1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, x, a, b; n     cin >> n >> x >> a >> b; n     if (abs(a - b) + x >= n) n       cout << n - 1 << endl; n     else { n       cout << abs(a - b) + x << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) n     x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return x * f; n } n int n, a[710]; n bool flag[710][710], f[710][710][2]; n int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } n int main() { n   const char LL[] =  %lld n ; n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (gcd(a[i], a[j]) > 1) flag[i][j] = 1; n   for (int i = 1; i <= n + 1; i++) f[i][i - 1][0] = f[i][i - 1][1] = 1; n   for (int k = 1; k <= n; k++) n     for (int i = 1; i <= n - k + 1; i++) { n       int j = i + k - 1; n       for (int d = i; d <= j; d++) n         if (f[i][d - 1][1] && f[d + 1][j][0]) { n           if (flag[i - 1][d]) f[i][j][0] = 1; n           if (flag[j + 1][d]) f[i][j][1] = 1; n         } n     } n   for (int i = 1; i <= n; i++) n     if (f[1][i - 1][1] && f[i + 1][n][0]) { n       cout <<  Yes ; n       return 0; n     } n   cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2 * 1e5 + 5; n double sum; n int i, j, l, o, n, k, a[maxn]; n int main() { n   scanf( %d %d , &n, &k); n   for (int j = 1; j <= n; j++) scanf( %d , &a[j]); n   for (i = 1; i <= n; i++) { n     if (i <= k) { n       if (n - k + 1 >= i) n         sum += 1.0 * i * a[i]; n       else { n         l = i + k - 1 - n; n         l = i - l; n         sum += 1.0 * l * a[i]; n       } n     } else { n       if (n - k + 1 >= i) n         sum += 1.0 * k * a[i]; n       else { n         sum += 1.0 * (n - i + 1) * a[i]; n       } n     } n   } n   sum /= (n - k + 1); n   printf( %.10lf n , sum); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long int LINF = 0x3f3f3f3f3f3f3f3fll; n const long double pi = acos(-1); n const int MOD = 1e9 + 7; n const int N = 310; n int l[N], c[N]; n map<long long int, int> mapa; n int mdc(int a, int b) { n   if (b == 0) return a; n   return mdc(b, a % b); n } n bool add(int x, int custo) { n   if (mapa.count(x)) { n     if (mapa[x] > custo) { n       mapa[x] = custo; n       return true; n     } n     return false; n   } else { n     mapa[x] = custo; n     return true; n   } n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &l[i]); n   for (int i = 0; i < n; i++) scanf( %d , &c[i]); n   set<int> q; n   for (int i = 0; i < n; i++) { n     add(l[i], c[i]); n     q.insert(l[i]); n   } n   for (int i = 0; i < 100000; i++) { n     if (q.size() == 0) break; n     int x = *q.begin(); n     q.erase(q.begin()); n     for (int j = 0; j < n; j++) { n       int valnovo = mdc(x, l[j]); n       int custonovo = c[j] + mapa[x]; n       if (add(valnovo, custonovo)) q.insert(valnovo); n     } n   } n   if (mapa.count(1)) { n     printf( %d n , mapa[1]); n   } else { n     int coco = -1; n     printf( %d n , coco); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct node { n   int u, v, w; n   friend bool operator<(node a, node b) { return a.w > b.w; } n } itm[200005]; n int fa[200005]; n int gf(int x) { n   if (x != fa[x]) return fa[x] = gf(fa[x]); n   return fa[x]; n } n int main() { n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 1; i <= n; i++) fa[i] = i; n     priority_queue<node> q; n     for (int i = 0; i < m; i++) { n       scanf( %d%d%d , &itm[i].u, &itm[i].v, &itm[i].w); n       q.push(itm[i]); n     } n     int cnt = 0, ans = 0; n     while (!q.empty() && cnt < (n - 1)) { n       node sta = q.top(); n       q.pop(); n       queue<node> q1, q2; n       q1.push(sta); n       while (!q.empty() && q.top().w == sta.w) { n         q1.push(q.top()); n         q.pop(); n       } n       while (!q1.empty()) { n         node cur = q1.front(); n         q1.pop(); n         int f1 = gf(cur.u); n         int f2 = gf(cur.v); n         if (f1 != f2) q2.push(cur); n       } n       if (!q2.empty()) { n         node cur = q2.front(); n         q2.pop(); n         int f1 = gf(cur.u); n         int f2 = gf(cur.v); n         fa[f1] = f2; n         cnt++; n         while (!q2.empty()) { n           node tp = q2.front(); n           q2.pop(); n           f1 = gf(tp.u); n           f2 = gf(tp.v); n           if (f1 == f2) n             ans++; n           else n             fa[f1] = f2, cnt++; n         } n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 2e5 + 100; n int a[M], b[M]; n int n, x, y; n int di[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n bool check(int xx, int yy) { n   if (xx < 1 || xx > x || yy < 1 || yy > y) return 0; n   return 1; n } n bool bfs() { n   queue<int> q; n   int l = 0; n   q.push(a[l]); n   l++; n   while (q.size()) { n     if (l == n) return 1; n     int ans = q.front(); n     int y1, x1; n     if (ans % y == 0) { n       y1 = y; n       x1 = ans / y; n     } else { n       y1 = ans % y; n       x1 = ans / y + 1; n     } n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int nx = x1 + di[i][0], ny = y1 + di[i][1]; n       int res = (nx - 1) * y + ny; n       if (check(nx, ny) && res == a[l]) { n         q.push(a[l]); n         l++; n         break; n       } n     } n   } n   if (l == n + 1) n     return 1; n   else n     return 0; n } n int main() { n   while (~scanf( %d , &n)) { n     int mac = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       mac = max(a[i], mac); n     } n     int l = 0; n     bool f = 1; n     for (int i = 0; i < n - 1; i++) { n       if (l == 0 && abs(a[i] - a[i + 1]) > 1) l = abs(a[i] - a[i + 1]); n       if (l && abs(a[i] - a[i + 1]) > 1) n         if (l != abs(a[i] - a[i + 1])) { n           f = 0; n           break; n         } n     } n     if (!f) n       printf( NO n ); n     else { n       if (l == 0) { n         x = 1; n         y = mac; n       } else { n         y = l; n         x = mac / l + 1; n       } n       bool tt = bfs(); n       if (tt) { n         printf( YES n ); n         printf( %d %d n , x, y); n       } else n         printf( NO n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, i, j, ans, sum1, sum2; n long long x[100000], y[100000]; n int main() { n   scanf( %I64d , &n); n   sum1 = 0; n   sum2 = 0; n   ans = 0; n   for (i = 0; i < n; i++) { n     scanf( %I64d %I64d , &x[i], &y[i]); n     ans += (n * (x[i] * x[i] + y[i] * y[i])); n     sum1 += x[i]; n     sum2 += y[i]; n   } n   ans -= (sum1 * sum1); n   ans -= (sum2 * sum2); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   int arr[n][n]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) scanf( %d , &arr[i][j]); n   int q; n   scanf( %d , &q); n   int res = 0; n   for (int k = 0; k < n; k++) { n     res += arr[k][k]; n     res %= 2; n   } n   for (int p = 0; p < q; p++) { n     int t; n     scanf( %d , &t); n     switch (t) { n       case 1: { n         int k; n         scanf( %d , &k); n         res = 1 - res; n       } break; n       case 2: { n         int k; n         scanf( %d , &k); n         k--; n         res = 1 - res; n       } break; n       case 3: { n         printf( %d , res); n       } break; n     } n   } n   return 0; n } n