#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > vec[2102100]; n pair<int, int> tr[2102100]; n int lz[2102100]; n int id[2102100]; n int l[2102100]; n int r[2102200]; n int b[2102100]; n int path[2102100]; n int st[2102100]; n void build(int p, int l, int r) { n   tr[p] = {0, -1}; n   lz[p] = 0; n   if (l == r) { n     return; n   } n   int mid = l + r >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n } n void pushup(int p) { tr[p] = max(tr[p << 1], tr[p << 1 | 1]); } n void pushdown(int p) { n   if (lz[p]) { n     lz[p << 1] = lz[p << 1 | 1] = lz[p]; n     lz[p] = 0; n     tr[p << 1] = tr[p << 1 | 1] = tr[p]; n   } n } n pair<int, int> query(int p, int l, int r, int ll, int rr) { n   if (ll <= l && rr >= r) { n     return tr[p]; n   } n   pushdown(p); n   int mid = l + r >> 1; n   pair<int, int> res = {0, -1}; n   if (ll <= mid) res = max(query(p << 1, l, mid, ll, rr), res); n   if (rr > mid) res = max(query(p << 1 | 1, mid + 1, r, ll, rr), res); n   return res; n } n void update(int p, int l, int r, int ll, int rr, pair<int, int> res) { n   if (ll <= l && rr >= r) { n     tr[p] = res; n     lz[p] = 1; n     return; n   } n   pushdown(p); n   int mid = l + r >> 1; n   if (ll <= mid) update(p << 1, l, mid, ll, rr, res); n   if (rr > mid) update(p << 1 | 1, mid + 1, r, ll, rr, res); n   pushup(p); n } n int main() { n   int n, t; n   cin >> n >> t; n   for (int i = 1; i <= t; i++) { n     cin >> id[i] >> l[i] >> r[i]; n     b[i * 2 - 1] = l[i]; n     b[i * 2] = r[i]; n   } n   sort(b + 1, b + 1 + t * 2); n   int len = unique(b + 1, b + 1 + t * 2) - b - 1; n   build(1, 1, len); n   for (int i = 1; i <= t; i++) { n     l[i] = lower_bound(b + 1, b + 1 + len, l[i]) - b; n     r[i] = lower_bound(b + 1, b + 1 + len, r[i]) - b; n     vec[id[i]].push_back({l[i], r[i]}); n   } n   for (int i = 1; i <= n; i++) { n     pair<int, int> mx = {0, -1}; n     for (auto tt : vec[i]) { n       mx = max(mx, query(1, 1, len, tt.first, tt.second)); n     } n     mx.first++; n     path[i] = mx.second; n     mx.second = i; n     for (auto tt : vec[i]) { n       update(1, 1, len, tt.first, tt.second, mx); n     } n   } n   pair<int, int> ans = query(1, 1, len, 1, len); n   int u = ans.second; n   int aa = n; n   while (u != -1) { n     st[u] = 1; n     aa--; n     u = path[u]; n   } n   cout << aa << endl; n   for (int i = 1; i <= n; i++) { n     if (!st[i]) cout << i <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int MOD = 1000000007; n long long int MOD1 = 998244353; n mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); n unsigned long long power(unsigned long long x, int y, int p) { n   unsigned long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n void solve() { n   long long int n; n   cin >> n; n   long long int res = 1; n   for (int i = 1; i <= n; i++) { n     res = (res * i) % MOD; n   } n   long long int p = power(2, n - 1, MOD); n   res = (res - p + MOD) % MOD; n   cout << res <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long qu(long long a, long long b) { n   cout <<  ?   << a <<     << b << endl; n   fflush(stdout); n   string s; n   cin >> s; n   if (s[0] ==  x ) return 1; n   return 2; n } n int main() { n   string s; n   while (1) { n     cin >> s; n     if (s !=  start ) return 0; n     long long l = 1; n     if (qu(0, 1) == 1) { n       cout <<  ! 1 n ; n       fflush(stdout); n       continue; n     } n     while (qu(2 * l, l) == 1) l = l * 2LL; n     long long r = min((l * 2LL), 1000000000LL); n     l++; n     long long x = l; n     while (l < r) { n       long long mid = (l + r) / 2; n       if (qu(l - 1, mid) == 2) n         l = mid + 1; n       else n         r = mid; n     } n     cout <<  !   << l <<   n ; n     fflush(stdout); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MD = 1000000007; n inline void add(int &a, const int b) { n   a += b; n   if (a >= MD) a %= MD; n } n inline int mul(const int &a, const int &b) { n   long long r = 1ll * a * b; n   if (r >= MD) r %= MD; n   return r; n } n int a[9], n, k; n bool vis[9]; n bool ok(int x) { n   if (x == 1) return 1; n   vis[x] = 1; n   if (!vis[a[x]] && ok(a[x])) return 1; n   return 0; n } n bool check() { n   for (int i = 1; i <= k; ++i) { n     memset(vis, 0, sizeof vis); n     if (!ok(a[i])) return 0; n   } n   return 1; n } n int dfs(int x) { n   if (x == k + 1) { n     if (check()) return 1; n     return 0; n   } n   int ret = 0; n   for (int i = 1; i <= k; ++i) a[x] = i, ret += dfs(x + 1); n   return ret; n } n int main() { n   scanf( %d%d , &n, &k); n   int ans = 1; n   for (int i = k + 1; i <= n; ++i) ans = mul(ans, n - k); n   printf( %d n , mul(ans, dfs(1))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5 + 10; n const int INF = 0x3f3f3f3f; n const int mod = 998244353; n vector<long long> v; n long long dfs(vector<long long> &v, int bit) { n   vector<long long> v0, v1; n   if (bit < 0 || v.size() == 0) return 0; n   for (long long &j : v) { n     if ((j >> bit) & 1) n       v1.push_back(j); n     else n       v0.push_back(j); n   } n   if (v1.size() == 0) return dfs(v0, bit - 1); n   if (v0.size() == 0) return dfs(v1, bit - 1); n   return min(dfs(v0, bit - 1), dfs(v1, bit - 1)) + (1 << bit); n } n int main() { n   int n; n   v.clear(); n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     long long x; n     scanf( %lld , &x); n     v.push_back(x); n   } n   long long ans = dfs(v, 30); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a << endl; n   err(++it, args...); n } n inline int add(int a, int b) { n   a += b; n   return a >= 1000000007 ? a - 1000000007 : a; n } n inline int sub(int a, int b) { n   a -= b; n   return a < 0 ? a + 1000000007 : a; n } n inline int mul(int a, int b) { return (long long int)a * b % 1000000007; } n int Set(int N, int pos) { return N = N | (1 << pos); } n int Reset(int N, int pos) { return N = N & ~(1 << pos); } n bool Cheek(int N, int pos) { return (bool)(N & (1 << pos)); } n int a[1000005], b[1000005], lft[1000005], rgt[1000005], addina[1000005]; n void Solve(int t) { n   int i, j, k, n, ans = 0; n   scanf( %d , &(n)); n   for (__typeof(i) i = 1; i <= n; i++) { n     scanf( %d , &(a[i])); n     addina[a[i]] = i; n   } n   for (__typeof(i) i = 1; i <= n; i++) scanf( %d , &(b[i])); n   for (i = 1; i <= n; i++) { n     int address = addina[b[i]]; n     int needlft = (n - address + i) % n; n     lft[needlft]++; n     int needrgt = (address - i + n) % n; n     rgt[needrgt]++; n   } n   for (i = 0; i <= n; i++) { n     ans = max(ans, lft[i]); n     ans = max(ans, rgt[i]); n   } n   cout << ans << endl; n } n int main() { n   int t, T; n   T = 1; n   for (__typeof(t) t = 1; t <= T; t++) { n     Solve(t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1e-9; n struct Point { n   long long x, y; n   Point() {} n   Point(long long x, long long y) : x(x), y(y) {} n   Point operator-(const Point& a) { return Point(x - a.x, y - a.y); } n   long long operator*(Point a) { return x * a.x + y * a.y; } n   long long operator%(const Point& a) { return x * a.y - y * a.x; } n   long double norm() { return x * x + y * y; } n   long double len() { return sqrt(norm()); } n   void read() { scanf( %lld%lld , &x, &y); } n } A[5], B[5]; n bool operator==(const Point& a, const Point& b) { n   return a.x == b.x && a.y == b.y; n } n long long ccw(Point A, Point B, Point C) { n   long long t = (B - A) % (C - A); n   if (t == 0) return 0; n   if (t < 0) return -1; n   return 1; n } n const long double PI = acos((long double)-1.0); n long double angle(Point a, Point o, Point b) { n   a = a - o; n   b = b - o; n   long double res = acos((a * b) / sqrt(a.norm()) / sqrt(b.norm())); n   while (res < -EPS) res += 2 * PI; n   while (res >= 2 * PI) res -= 2 * PI; n   return res; n } n bool order(Point A, Point B, Point C) { n   return min(A.x, C.x) <= B.x && B.x <= max(A.x, C.x) && min(A.y, C.y) <= B.y && n          B.y <= max(A.y, C.y); n } n bool good(Point A, Point B, Point C) { n   if (ccw(A, B, C)) return false; n   if (!order(A, B, C)) return false; n   long double x = (B - A).len(); n   long double y = (C - B).len(); n   if (x * 4 < y - EPS) return false; n   if (y * 4 < x - EPS) return false; n   return true; n } n bool check() { n   long long t[5]; n   for (long long i = (1), _b = (3); i <= _b; ++i) t[i] = i; n   do { n     for (long long r1 = 0, _a = (2); r1 < _a; ++r1) { n       for (long long r2 = 0, _a = (2); r2 < _a; ++r2) { n         for (long long r3 = 0, _a = (2); r3 < _a; ++r3) { n           if (A[t[1]] == A[t[2]] && ccw(A[t[1]], B[t[1]], B[t[2]]) && n               angle(B[t[1]], A[t[1]], B[t[2]]) < PI / 2.0 + EPS && n               good(A[t[1]], A[t[3]], B[t[1]]) && n               good(A[t[2]], B[t[3]], B[t[2]])) { n             return true; n           } n           swap(A[3], B[3]); n         } n         swap(A[2], B[2]); n       } n       swap(A[1], B[1]); n     } n   } while (next_permutation(t + 1, t + 4)); n   return false; n } n int main() { n   long long ntest; n   scanf( %lld , &ntest); n   while (ntest--) { n     for (long long i = (1), _b = (3); i <= _b; ++i) { n       A[i].read(); n       B[i].read(); n     } n     puts(check() ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100000007; n const double eps = 1e-6; n const long long Inf = 1LL << 62; n const long long mod = 1000000007; n const long long pnum = 5761460; n void err(istream_iterator<string> it) {} n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cout << *it <<   =   << a <<   n ; n   ; n   err(++it, args...); n } n void solve_with_case(int cas) {} n long long maxCalories(vector<vector<long long>> arr, int n, int m) { n   vector<vector<long long>> dp1(1005, vector<long long>(1005, 0)); n   vector<vector<long long>> dp2(1005, vector<long long>(1005, 0)); n   vector<vector<long long>> dp3(1005, vector<long long>(1005, 0)); n   vector<vector<long long>> dp4(1005, vector<long long>(1005, 0)); n   for (int i = (1); i <= (n); i++) { n     for (int j = (1); j <= (m); j++) { n       dp1[i][j] = arr[i][j] + max(dp1[i - 1][j], dp1[i][j - 1]); n     } n   } n   for (int i = (n); i >= (1); i--) { n     for (int j = (m); j >= (1); j--) { n       dp2[i][j] = arr[i][j] + max(dp2[i + 1][j], dp2[i][j + 1]); n     } n   } n   for (int i = (n); i >= (1); i--) { n     for (int j = (1); j <= (m); j++) { n       dp3[i][j] = arr[i][j] + max(dp3[i + 1][j], dp3[i][j - 1]); n     } n   } n   for (int i = (1); i <= (n); i++) { n     for (int j = (m); j >= (1); j--) { n       dp4[i][j] = arr[i][j] + max(dp4[i - 1][j], dp4[i][j + 1]); n     } n   } n   long long ans = 0; n   for (int i = (2); i <= (n - 1); i++) { n     for (int j = (2); j <= (m - 1); j++) { n       long long ans1 = n           dp1[i - 1][j] + dp2[i + 1][j] + dp3[i][j - 1] + dp4[i][j + 1]; n       long long ans2 = n           dp1[i][j - 1] + dp2[i][j + 1] + dp3[i + 1][j] + dp4[i - 1][j]; n       ans = max({ans, ans1, ans2}); n     } n   } n   return ans; n } n void solve_without_case() { n   int n, m; n   cin >> n >> m; n   vector<vector<long long>> arr(1005, vector<long long>(1005, 0)); n   for (int i = (1); i <= (n); i++) { n     for (int j = (1); j <= (m); j++) { n       cin >> arr[i][j]; n     } n   } n   cout << maxCalories(arr, n, m) <<   n ; n   ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   solve_without_case(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1e9 + 7; n double pi = acos(-1.0); n long long powerm(long long x, long long y) { n   long long res = 1; n   while (y) { n     if (y & 1) res = (res * x) % M; n     y = y >> 1; n     x = (x * x) % M; n   } n   return res % M; n } n long long power(long long x, long long y) { n   long long res = 1; n   while (y) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n long long gcd(long long a, long long b) { n   if (b > a) return gcd(b, a); n   if (b == 0) return a; n   return gcd(b, a % b); n } n const int N = 2e5 + 5; n vector<int> adj[N]; n long long a[N]; n bool b[N], c[N]; n vector<pair<int, int> > pp(N); n long long ans; n void dfs(int u, int par, long long mn) { n   if (b[u] == 1 && c[u] == 0) n     pp[u].first++; n   else if (b[u] == 0 && c[u] == 1) n     pp[u].second++; n   a[u] = min(a[u], mn); n   for (auto it : adj[u]) { n     if (it == par) continue; n     dfs(it, u, a[u]); n     pp[u].first += pp[it].first; n     pp[u].second += pp[it].second; n   } n   long long jj = min(pp[u].first, pp[u].second); n   ans += jj * 2 * a[u]; n   pp[u].first -= jj; n   pp[u].second -= jj; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i] >> b[i] >> c[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1, -1, M); n   if (pp[1].first > 0 || pp[1].second > 0) n     cout << -1; n   else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 7e5 + 10; n const int inf = 0x3f3f3f3f; n int n, m, p, q, nx, ny; n long long sum[300][300]; n int dis[300][300]; n int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; n char maze[300][300]; n void bfs(int sx, int sy, long long k) { n   dis[sx][sy] = 0, sum[sx][sy] += k; n   queue<pair<pair<int, int>, int> > q; n   q.push(make_pair(make_pair(sx, sy), k)); n   while (q.empty() == 0) { n     pair<pair<int, int>, int> tmp = q.front(); n     q.pop(); n     for (int i = 0; i < 4; i++) { n       nx = tmp.first.first + dx[i], ny = tmp.first.second + dy[i]; n       if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && maze[nx][ny] !=  *  && n           dis[nx][ny] == inf) { n         dis[nx][ny] = dis[tmp.first.first][tmp.first.second] + 1; n         int res = tmp.second / 2; n         if (res <= 0) { n           break; n         } n         sum[nx][ny] += res; n         q.push(make_pair(make_pair(nx, ny), res)); n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> q >> p; n   memset(sum, 0, sizeof(sum)); n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     cin >> maze[i] + 1; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (maze[i][j] >=  A  && maze[i][j] <=  Z ) { n         memset(dis, inf, sizeof(dis)); n         bfs(i, j, (maze[i][j] -  A  + 1) * q); n       } n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (sum[i][j] > p && maze[i][j] !=  * ) { n         ans++; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool uin(T &a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool uax(T &a, T b) { n   return a < b ? (a = b, true) : false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     vector<vector<int> > occs(n); n     for (int i = 0; i < (int)(n); ++i) { n       int x; n       cin >> x; n       --x; n       occs[x].push_back(i); n     } n     int dif = 0; n     for (int i = 0; i < (int)(n); ++i) n       if (!occs[i].empty()) ++dif; n     int ch = 0, maxch = 0, R = -1; n     for (int i = 0; i < (int)(n); ++i) { n       if (occs[i].empty()) continue; n       if (occs[i][0] > R) n         ++ch, uax(maxch, ch); n       else n         ch = 1; n       R = occs[i].back(); n     } n     cout << dif - maxch <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000 * 100 + 50; n vector<long long> nb[MAXN]; n long long n, m, k, cmp, sz[MAXN]; n bool mrk[MAXN]; n long long pw(long long x, long long y) { n   if (!y) return 1; n   if (y == 1) return x % k; n   long long tmp = pw(x, y / 2); n   if (y % 2) n     return ((tmp * tmp) % k * x) % k; n   else n     return (tmp * tmp) % k; n } n void dfs(int x) { n   if (mrk[x]) return; n   mrk[x] = 1; n   sz[cmp]++; n   for (int i = 0; i < nb[x].size(); i++) dfs(nb[x][i]); n } n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int tmp1, tmp2; n     cin >> tmp1 >> tmp2; n     nb[tmp1 - 1].push_back(tmp2 - 1); n     nb[tmp2 - 1].push_back(tmp1 - 1); n   } n   for (int i = 0; i < n; i++) { n     if (!mrk[i]) { n       dfs(i); n       cmp++; n     } n   } n   if (cmp == 1) { n     cout << 1 % k << endl; n     return 0; n   } n   long long ans = pw(n, cmp - 2) % k; n   for (int i = 0; i < cmp; i++) { n     ans *= sz[i]; n     ans %= k; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n inline void read(T &x) { n   x = 0; n   int f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) { n     f |= ch ==  - ; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   x = f ? -x : x; n   return; n } n int p[100010], siz[100010], find[100010]; n int t, n; n bool flag; n int main() { n   read(t); n   while (t--) { n     read(n); n     flag = true; n     for (int i = 1; i <= n; ++i) read(p[i]); n     for (int i = 2; i <= n; ++i) { n       if (p[i] - p[i - 1] > 1) { n         flag = false; n         break; n       } n     } n     puts(flag ?  Yes  :  No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, INF = 1e9; n const int mx = 1e5 + 5; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, s, k; n   cin >> n >> s; n   if (2 * n > s) n     cout <<  NO  << endl; n   else { n     cout <<  YES  << endl; n     for (int i = 1; i < n; i++) cout << s / n <<    ; n     cout << (s - (s / n) * (n - 1)) << endl; n     cout << 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int days[200][12]; n int v[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n void swap(int &a, int &b) { n   int t = a; n   a = b; n   b = t; n } n struct year { n   int y; n   int m; n   int d; n   bool operator>(year &next) { n     if (this->y > next.y) n       return true; n     else if (this->y < next.y) n       return false; n     if (this->m > next.m) n       return true; n     else if (this->m < next.m) n       return false; n     return this->d > next.d; n   } n   void inc() { n     if (++this->d >= days[this->y][this->m]) { n       this->d = 0; n       if (++this->m >= 12) { n         this->m = 0; n         ++this->y; n       } n     } n   } n }; n int main() { n   for (int i = 0; i < 139; i++) n     for (int j = 0; j < 12; j++) { n       days[i][j] = v[j]; n       if (j == 1 && i % 4 == 0) days[i][1] = 29; n     } n   days[0][1] = 28; n   year y[2]; n   for (int i = 0; i < 2; i++) { n     scanf( %d:%d:%d , &y[i].y, &y[i].m, &y[i].d); n     y[i].y -= 1900; n     y[i].m--; n     y[i].d--; n   } n   year *a, *b; n   if (y[0] > y[1]) { n     a = &y[1]; n     b = &y[0]; n   } else { n     a = &y[0]; n     b = &y[1]; n   } n   int cnt = 0; n   while (a->y != b->y || a->m != b->m || a->d != b->d) { n     a->inc(); n     cnt++; n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[100005], diff[100005], prv[100005]; n bool flag[100005]; n vector<int> a, d; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , arr + i); n     flag[arr[i]] = 1; n   } n   for (int i = 1; i <= n; ++i) { n     if (!flag[arr[i]]) continue; n     if (prv[arr[i]] && !diff[arr[i]]) n       diff[arr[i]] = i - prv[arr[i]]; n     else if (prv[arr[i]] && diff[arr[i]] != i - prv[arr[i]]) n       flag[arr[i]] = 0; n     prv[arr[i]] = i; n   } n   for (int i = 0; i < 100005; ++i) n     if (flag[i]) a.push_back(i), d.push_back(diff[i]); n   printf( %d n , a.size()); n   for (int i = 0; i < a.size(); ++i) printf( %d %d n , a[i], d[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, m; n long long pre[405][405], a[405][405], sum[405]; n long long get(long long a, long long b, long long c) { n   return pre[b][c] - pre[a - 1][c]; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> t; n   while (t--) { n     cin >> n >> m; n     for (long long i = 1; i <= n; i++) { n       for (long long j = 1; j <= m; j++) { n         char f; n         cin >> f; n         a[i][j] = f -  0 ; n         pre[i][j] = pre[i - 1][j] + a[i][j]; n       } n     } n     long long res = 1000000000000000000; n     for (long long l = 1; l <= n - 4; l++) { n       for (long long r = l + 4; r <= n; r++) { n         long long mx = -1000000000000000000; n         for (long long k = 1; k <= 3; k++) n           sum[k] = sum[k - 1] + get(l + 1, r - 1, k) + (2 - a[l][k] - a[r][k]); n         for (long long k = 4; k <= m; k++) { n           sum[k] = sum[k - 1] + get(l + 1, r - 1, k) + (2 - a[l][k] - a[r][k]); n           mx = max(mx, sum[k - 3] - (r - l - 1) + get(l + 1, r - 1, k - 3)); n           res = min(res, sum[k - 1] + (r - l - 1) - get(l + 1, r - 1, k) - mx); n         } n       } n     } n     cout << res <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch - 48, ch = getchar(); n   } n   return x * f; n } n bool vis[1000100]; n int c[100]; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int main() { n   srand(time(0)); n   int n = read(), que = 60; n   int l = 0, r = 1e9, op; n   while (l <= r) { n     int mid = (l + r) / 2; n     que--; n     printf( > %d n , mid); n     fflush(stdout); n     scanf( %d , &op); n     if (op) n       l = mid + 1; n     else n       r = mid - 1; n   } n   int mx = l; n   for (int i = 1; i <= que && i <= n; i++) { n     int p = rand() * rand() % n + 1; n     while (vis[p]) p = rand() * rand() % n + 1; n     vis[p] = 1; n     printf( ? %d n , p); n     fflush(stdout); n     scanf( %d , &c[i]); n   } n   int N = min(que, n); n   sort(c + 1, c + N + 1); n   int g = mx - c[1]; n   for (int i = 2; i <= N; i++) { n     if (c[i] == mx) continue; n     g = gcd(g, mx - c[i]); n     g = gcd(g, c[i] - c[i - 1]); n   } n   printf( ! %d %d n , mx - (n - 1) * g, g); n   fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100002], b[100000]; n int main() { n   int n; n   cin >> n; n   set<pair<int, int> > c; n   c.clear(); n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     pair<int, int> a = make_pair(x, y); n     c.insert(a); n   } n   n = 0; n   set<pair<int, int> >::iterator j; n   for (j = c.begin(); j != c.end(); j++) { n     n++; n     a[n] = (*j).first; n     b[n] = (*j).second; n   } n   int ans = 0, max = -2000000000; n   for (int i = 1; i <= n; i++) { n     if (b[i] < max) ans++; n     if (b[i] > max) max = b[i]; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double x[1010], y[1010]; n bool vis[1010]; n int main() { n   int n, cnt = 0; n   double x0, y0; n   scanf( %d%lf%lf , &n, &x0, &y0); n   for (int i = 0; i < n; i++) { n     scanf( %lf%lf , &x[i], &y[i]); n   } n   for (int i = 0; i < n; i++) { n     double x1 = x[i], y1 = y[i]; n     if (vis[i]) n       continue; n     else n       cnt++; n     vis[i] = 1; n     for (int j = 0; j < n; j++) { n       if (vis[j]) continue; n       if (x1 == x0 && x[j] == x0) n         vis[j] = 1; n       else if (y1 == y0 && y[j] == y0) n         vis[j] = 1; n       else if (fabs((y[j] - y0) / (y1 - y0) - (x[j] - x0) / (x1 - x0)) < 1e-9) n         vis[j] = 1; n     } n   } n   printf( %d n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int arr[2], x; n   cin >> arr[0] >> arr[1] >> x; n   vector<int> v; n   int curr = 1; n   if (x % 2 == 1) { n     v.push_back(curr); n     arr[curr]--; n     curr ^= 1; n     for (int i = 0; i < x; i++) { n       v.push_back(curr); n       arr[curr]--; n       curr ^= 1; n     } n     if (arr[1] > 0) { n       while (arr[1]--) { n         cout <<  1 ; n       } n     } n     for (int i = 0; i < v.size(); i++) cout << v[i]; n     if (arr[0] > 0) { n       while (arr[0]--) cout <<  0 ; n     } n   } else { n     if (arr[0] <= arr[1]) { n       v.push_back(curr); n       arr[curr]--; n       curr ^= 1; n       for (int i = 0; i < x; i++) { n         v.push_back(curr); n         arr[curr]--; n         curr ^= 1; n       } n       if (arr[1] > 0) { n         while (arr[1]--) cout <<  1 ; n       } n       for (int i = 0; i < v.size() - 1; i++) cout << v[i]; n       if (arr[0] > 0) { n         while (arr[0]--) cout <<  0 ; n       } n       cout <<  1 ; n     } else { n       curr = 0; n       v.push_back(curr); n       arr[curr]--; n       curr ^= 1; n       for (int i = 0; i < x; i++) { n         v.push_back(curr); n         arr[curr]--; n         curr ^= 1; n       } n       if (arr[0] > 0) { n         while (arr[0]--) cout <<  0 ; n       } n       for (int i = 0; i < v.size() - 1; i++) cout << v[i]; n       if (arr[1] > 0) { n         while (arr[1]--) cout <<  1 ; n       } n       cout <<  0 ; n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n #define ll long long n #define ld long double n #define pii pair <ll, ll> n #define mp make_pair n  n // const int inf = 1e9 + 111; n const int NMAX = 200111; n const int inf = 1e9 + 7; n const ld eps = 0.00000000001; n const ll mod = 1e9 + 7; n  n constexpr int64_t MOD = 998244353; n  n int main() { n  cin.tie(0); n  cout.tie(0); n  cin.sync_with_stdio(0); n  cout.sync_with_stdio(0); n  cout << setprecision(20) << fixed; n     int t; n     cin >> t; n     for (int i = 0; i < t; ++i) { n         int n, k; n         cin >> n >> k; n         if (k < n) { n             if (n % k == 0) { n                 cout << 1 << endl; n             } else { n                 cout << 2 << endl; n             } n         } else { n             cout << (k + n - 1) / n << endl; n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100050]; n bool vis; n int main() { n   scanf( %s , s + 1); n   int len = strlen(s + 1); n   if (len <= 2) { n     printf( No n ); n     return 0; n   } n   for (int i = 1; i <= len - 2; i++) { n     if (s[i] != s[i + 1] && s[i + 1] != s[i + 2] && s[i] != s[i + 2] && n         s[i] !=  .  && s[i + 1] !=  .  && s[i + 2] !=  . ) { n       vis = 1; n       break; n     } n   } n   if (vis == 1) n     printf( Yes n ); n   else n     printf( No n ); n } n


#include <bits/stdc++.h> n using namespace std; n string s; n long long x; n long long mp[1 << 20]; n vector<long long> vec; n long long trans[1 << 20][10]; n long long dp[1005][12005]; n int main(void) { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   long long n = s.size(); n   s =  #  + s; n   cin >> x; n   if (x == 1) { n     long long ans = 0; n     for (int i = 1; i <= n; i++) { n       if (s[i] ==  1 ) ans++; n     } n     cout << ans << endl; n     return 0; n   } n   long long X = 1 << x; n   for (int i = 0; i < X; i++) { n     mp[i] = -1; n     if (!(i & 1)) continue; n     for (int d = 1; d < x; d++) { n       if (x % d) continue; n       for (int j = 0; j < x; j++) { n         if ((i & (1 << j)) && (i & (1 << (j + d)))) goto pass; n       } n     } n     vec.push_back(i); n     mp[i] = (int)vec.size() - 1; n   pass:; n   } n   long long m = vec.size(); n   for (int i = 0; i < m; i++) { n     for (int j = 1; j <= 9; j++) { n       long long b = vec[i]; n       b <<= j; n       for (int d = 1; d < x; d++) { n         if (x % d) continue; n         if (b & (1 << d)) { n           b %= (1 << d); n           break; n         } n       } n       if (b & (1 << x)) { n         trans[i][j] = -1; n         continue; n       } n       b %= X; n       b |= 1; n       trans[i][j] = mp[b]; n     } n   } n   for (int i = 0; i <= n; i++) { n     for (int j = 0; j < m; j++) { n       dp[i][j] = 1e18; n     } n   } n   dp[0][mp[1]] = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       (dp[i + 1][j]) = min((dp[i + 1][j]), (dp[i][j] + 1)); n       if (trans[j][s[i + 1] -  0 ] != -1) n         (dp[i + 1][trans[j][s[i + 1] -  0 ]]) = n             min((dp[i + 1][trans[j][s[i + 1] -  0 ]]), (dp[i][j])); n     } n   } n   long long ans = 1e18; n   for (int j = 0; j < m; j++) ans = min(ans, dp[n][j]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(0); n   std::cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n), b(2 * n); n     multiset<int> m; n     for (size_t i = 0; i < 2 * n; ++i) m.insert(i + 1); n     for (auto& i : a) { n       cin >> i; n       m.erase(i); n     } n     bool flg = true; n     for (size_t i = 0; i < n; ++i) { n       b[2 * i] = a[i]; n       auto it = upper_bound(m.begin(), m.end(), a[i]); n       if (it == m.end()) { n         flg = false; n         cout << -1 << endl; n         break; n       } n       b[2 * i + 1] = *it; n       m.erase(*it); n     } n     if (!flg) continue; n     for (auto& i : b) cout << i <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n void solve() { n   long long n; n   cin >> n; n   n = 2 * n; n   long double dist, ang; n   ang = (360 * 1.0) / (n * 1.0); n   ang = ang / 2.0; n   long double rad = ang / 180.0; n   rad = rad * pi; n   dist = tan(rad); n   dist = 1.0 / dist; n   cout << fixed << setprecision(10) << dist; n   cout << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long arr[100005], ans[2]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %lld , arr + i); n   } n   for (int sum = 1; sum <= m << 1; sum++) { n     vector<int> vec = {0}; n     for (int i = 0; i < n; i++) { n       vec.push_back(arr[i] % sum); n     } n     vec.push_back(sum - 1); n     sort(vec.begin(), vec.end()); n     for (int i = n + 1, t = 0; i; i--, t ^= 1) { n       int x = max(vec[i - 1], vec[n - t] / 2) + 1, y = min(vec[i], m); n       int a = max(x, sum - y), b = min(y, sum - x); n       if (a <= b) ans[t] += b - a + 1; n     } n   } n   long long x = ((long long)m * m - ans[0] - ans[1]) / 2; n   printf( %lld %lld %lld %lld n , x, x, ans[1], ans[0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int BLOCK = 250; n const int N = 200100; n const int NB = BLOCK * N; n long long ans = 0ll; n int sm[NB + N], pf[N], n, pr[N]; n string s; n int calc(int len, int kol) { return len / kol; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s; n   n = ((int)s.size()); n   pf[0] = 0; n   for (int i = 1; i <= n; i++) pf[i] = pf[i - 1] + (s[i - 1] ==  1  ? 1 : 0); n   for (int k = 1; k < BLOCK; k++) { n     for (int i = 0; i <= n; i++) sm[k * pf[i] - i + N] = 0; n     for (int i = 0; i <= n; i++) { n       int cv = k * pf[i] - i + N; n       ans += sm[cv]; n       sm[cv]++; n     } n   } n   pr[0] = -1; n   for (int i = 1; i <= n; i++) { n     pr[i] = pr[i - 1]; n     if (s[i - 1] ==  1 ) pr[i] = i; n   } n   for (int r = 1; r <= n; r++) { n     int i = r; n     for (int it = 1; it <= 2 * BLOCK; it++) { n       int nw = pr[i]; n       if (nw < 0) break; n       i = nw - 1; n       int l = max(0, pr[i]); n       int cans = calc(r - l, it) - calc(r - i - 1, it); n       int mn = (r - i) / it + bool((r - i) % it > 0); n       int mx = (r - l) / it; n       mx = min(mx, BLOCK - 1); n       cans -= max(0, mx - mn + 1); n       ans += cans; n     } n   } n   cout << ans; n   return 0; n } n


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


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


#include <bits/stdc++.h> n inline long long read() { n   long long x = 0, f = 1; n   char c = getchar(); n   for (; c >  9  || c <  0 ; c = getchar()) { n     if (c ==  - ) f = -1; n   } n   for (; c >=  0  && c <=  9 ; c = getchar()) { n     x = x * 10 + c -  0 ; n   } n   return x * f; n } n int dp[200005]; n int a[85], r[85]; n inline void work() { n   int n = read(), m = read(); n   dp[m + 1] = 0; n   for (int i = 1; i <= n; i++) a[i] = read(), r[i] = read(); n   for (int i = m; i; i--) { n     dp[i] = dp[i + 1] + 1; n     for (int j = 1; j <= n; j++) { n       if (a[j] >= i) { n         if (a[j] - r[j] <= i) { n           dp[i] = std::min(dp[i], dp[std::min(m + 1, a[j] + r[j] + 1)]); n         } else { n           dp[i] = std::min( n               dp[i], a[j] - r[j] - i + dp[std::min(m + 1, 2 * a[j] - i + 1)]); n         } n       } else { n         if (a[j] + r[j] >= i) { n           dp[i] = std::min(dp[i], dp[std::min(m + 1, a[j] + r[j] + 1)]); n         } n       } n     } n   } n   printf( %d n , dp[1]); n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10, INF = 1e9; n struct event { n   int pos, start, end, val, t, i; n   event(int a, int b, int c, int d, int e, int f) n       : pos(a), start(b), end(c), val(d), t(e), i(f){}; n }; n bool comp(event a, event b) { n   if (a.pos != b.pos) n     return a.pos < b.pos; n   else n     return a.t < b.t; n } n vector<event> vx, vy; n bool ok[MAXN]; n int minx[MAXN], miny[MAXN]; n int seg[4 * MAXN]; n void clear(int i, int ini, int fim) { n   seg[i] = 0; n   if (ini == fim) n     return; n   else { n     int mid = (ini + fim) / 2; n     clear(i * 2, ini, mid); n     clear(i * 2 + 1, mid + 1, fim); n   } n } n void update(int i, int ini, int fim, int pos, int val) { n   if (pos < ini || pos > fim) n     return; n   else { n     if (ini == fim) n       seg[i] = val; n     else { n       int mid = (ini + fim) / 2; n       update(i * 2, ini, mid, pos, val); n       update(i * 2 + 1, mid + 1, fim, pos, val); n       seg[i] = min(seg[i * 2], seg[i * 2 + 1]); n     } n   } n } n int query(int i, int ini, int fim, int p, int q) { n   if (ini >= p && fim <= q) return seg[i]; n   if (q < ini || p > fim) n     return INF; n   else { n     int mid = (ini + fim) / 2; n     return min(query(i * 2, ini, mid, p, q), n                query(i * 2 + 1, mid + 1, fim, p, q)); n   } n } n void print(int i, int ini, int fim) { n   printf( i %d ini %d fim %d seg %d n , i, ini, fim, seg[i]); n   if (ini != fim) { n     int mid = (ini + fim) / 2; n     print(i * 2, ini, mid); n     print(i * 2 + 1, mid + 1, fim); n   } n } n int main() { n   int n, m, p, q; n   scanf( %d %d %d %d , &n, &m, &p, &q); n   for (int i = 0, a, b; i < p; i++) { n     scanf( %d %d , &a, &b); n     vx.push_back(event(a, 0, 0, b, 1, i)); n     vy.push_back(event(b, 0, 0, a, 1, i)); n   } n   for (int i = 0, a, b, c, d; i < q; i++) { n     scanf( %d %d %d %d , &a, &b, &c, &d); n     vx.push_back(event(c, b, d, 0, 2, i)); n     vy.push_back(event(d, a, c, 0, 2, i)); n     minx[i] = a; n     miny[i] = b; n   } n   sort(vx.begin(), vx.end(), comp); n   sort(vy.begin(), vy.end(), comp); n   clear(1, 1, max(m, n)); n   for (int i = 0; i < vx.size(); i++) { n     if (vx[i].t == 1) { n       update(1, 1, m, vx[i].val, vx[i].pos); n     } else { n       if (query(1, 1, m, vx[i].start, vx[i].end) >= minx[vx[i].i]) n         ok[vx[i].i] = 1; n     } n   } n   clear(1, 1, max(m, n)); n   for (int i = 0; i < vy.size(); i++) { n     if (vy[i].t == 1) { n       update(1, 1, n, vy[i].val, vy[i].pos); n     } else { n       if (query(1, 1, n, vy[i].start, vy[i].end) >= miny[vy[i].i]) n         ok[vy[i].i] = 1; n     } n   } n   for (int i = 0; i < q; i++) { n     if (ok[i]) n       printf( YES n ); n     else n       printf( NO n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int i = 0; n   for (i = 0; i < s.length(); i++) { n     if (s[i] ==  0 ) break; n   } n   if (i < s.length() - 1) n     s = s.substr(0, i) + s.substr(i + 1); n   else n     s = s.substr(0, s.length() - 1); n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-6; n int n, ans; n double a[2000]; n struct Line { n   double x, y, vx, vy; n   void read() { n     double t1, t2; n     scanf( %lf%lf%lf%lf%lf%lf , &t1, &x, &y, &t2, &vx, &vy); n     vx -= x; n     vy -= y; n     vx /= t2 - t1; n     vy /= t2 - t1; n     x -= t1 * vx; n     y -= t1 * vy; n   } n } line[2000]; n struct point { n   double x, y; n   point() {} n   point(double x, double y) : x(x), y(y) {} n   double det(point res) { return x * res.y - y * res.x; } n   bool operator<(const point& rhs) const { n     if (abs(x * rhs.y - y * rhs.x) < eps) { n       if (abs(x - rhs.x) < eps) return y < rhs.y; n       return x < rhs.x; n     } else n       return x * rhs.y - y * rhs.x < 0; n   } n } b[2000]; n int main() { n   scanf( %d , &n); n   if (n) ans = 1; n   for (int i = 1; i <= n; i++) line[i].read(); n   for (int id = 1; id <= n; id++) { n     int tot = 0; n     for (int j = 1; j <= n; j++) n       if (id != j) { n         double vx = line[j].vx - line[id].vx, vy = line[j].vy - line[id].vy; n         double t = fabs(vx) > eps   ? (line[j].x - line[id].x) / vx n                    : fabs(vy) > eps ? (line[j].y - line[id].y) / vy n                                     : 0; n         if (fabs(line[j].x - line[id].x - t * vx) <= eps && n             fabs(line[j].y - line[id].y - t * vy) <= eps) n           a[++tot] = t, b[tot] = point(vx, vy); n       } n     sort(a + 1, a + 1 + tot); n     int cnt = 0; n     for (int i = 1; i <= tot; i++) { n       if (i == 1 || a[i] - a[i - 1] >= eps) n         cnt = 1; n       else n         cnt++; n       ans = max(ans, cnt + 1); n     } n     sort(b + 1, b + tot + 1); n     cnt = 0; n     for (int i = 1; i <= tot; i++) { n       if (i == 1 || fabs(b[i].det(b[i - 1])) > eps) n         cnt = 1; n       else if (fabs(b[i].x - b[i - 1].x) > eps || n                fabs(b[i].y - b[i - 1].y) > eps) n         cnt++; n       ans = max(ans, cnt + 1); n     } n   } n   cout << ans << endl; n } n


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


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


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse2 ) n #pragma GCC target( avx2 ) n using namespace std; n inline void opting() { n   ios_base::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n } n int inp() { n   int x; n   cin >> x; n   return x; n } n void make_unique(vector<int> &vec, bool sorted = false) { n   if (!sorted) sort((vec).begin(), (vec).end()); n   vec.resize(unique((vec).begin(), (vec).end()) - vec.begin()); n } n const int SQRT = 450, lg = 18 + 2, inlim = 2147483647; n const int maxn = 2e6 + 69, CL = 40, delta = 1e9 + 9, inf = 1e9 + 420; n int last[4 * maxn]; n int n; n struct seg_node { n   int max_ones = 0; n   int pref = 0; n   int suff = 0; n   int sz = 0; n   int l_kid, r_kid; n } emp; n inline seg_node merge_nodes(const seg_node &A, const seg_node &B) { n   seg_node X; n   X.max_ones = max({A.max_ones, B.max_ones, A.suff + B.pref}); n   X.sz = A.sz + B.sz; n   X.suff = B.suff; n   X.pref = A.pref; n   if (A.pref == A.sz) X.pref += B.pref; n   if (B.suff == B.sz) X.suff += A.suff; n   return X; n } n seg_node seg[4 * maxn]; n int cur_node = 0; n pair<int, int> kid[maxn]; n void show(seg_node A) { n   cout << A.max_ones <<     << A.pref <<     << A.suff <<     << A.sz <<   <>   n        << endl; n } n void add_(int id, int idx, const int cheat, int L = 0, int R = n) { n   if (L <= idx and idx < R) { n     if (R - L == 1) n       seg[id].sz = seg[id].pref = seg[id].suff = seg[id].max_ones = 1; n     else { n       int mid = (L + R) >> 1; n       int lt = seg[cheat].l_kid; n       int rt = seg[cheat].r_kid; n       if (idx < mid) { n         lt = cur_node++; n         add_(lt, idx, seg[cheat].l_kid, L, mid); n       } else { n         rt = cur_node++; n         add_(rt, idx, seg[cheat].r_kid, mid, R); n       } n       seg[id] = merge_nodes(seg[lt], seg[rt]); n       seg[id].l_kid = lt; n       seg[id].r_kid = rt; n     } n   } n } n seg_node get_(int id, int l, int r, int L = 0, int R = n) { n   if (R <= l or r <= L) return emp; n   if (l <= L and R <= r) return seg[id]; n   int mid = (L + R) >> 1; n   seg_node A = get_(seg[id].l_kid, l, r, L, mid); n   seg_node B = get_(seg[id].r_kid, l, r, mid, R); n   return merge_nodes(A, B); n } n int prime_set(int L = 0, int R = n) { n   int id = cur_node++; n   seg[id].sz = R - L; n   if (R == L + 1) return id; n   int mid = (L + R) >> 1; n   seg[id].l_kid = prime_set(L, mid); n   seg[id].r_kid = prime_set(mid, R); n   return id; n } n int starter[maxn]; n inline bool check(int l, int r, int w, int H_key) { n   return get_(starter[H_key], l, r).max_ones >= w; n } n int bns(int l, int r, int w) { n   int st = 0; n   int en = n; n   while (en - st > 1) { n     int mid = (st + en) >> 1; n     if (check(l, r, w, mid)) n       st = mid; n     else n       en = mid; n   } n   return st; n } n vector<pair<int, int> > v; n void input() { n   cin >> n; n   for (int i = 0; i < n; i++) v.push_back(make_pair(inp(), i)); n } n void predo() { n   prime_set(); n   sort((v).begin(), (v).end()); n   int prev = 0; n   for (int i = n - 1; i > -1; i--) { n     starter[i] = cur_node++; n     add_(cur_node - 1, v[i].second, prev); n     prev = starter[i]; n   } n } n void solve() { n   int m = inp(); n   while (m--) { n     int l, r, w; n     cin >> l >> r >> w; n     l--; n     cout << v[bns(l, r, w)].first <<    ; n   } n } n int main() { n   opting(); n   input(); n   predo(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n namespace red { n inline long long read() { n   long long x = 0; n   char f = 0, ch; n   for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar()) n     ; n   if (ch ==  - ) f = 1, ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = (x << 1) + (x << 3) + ch -  0 ; n     ch = getchar(); n   } n   return f ? -x : x; n } n const long long N = 1e5 + 10; n long long T, n; n long long a[N], c[N], pos[N], num; n struct node { n   long long l, r, d; n } e[N]; n long long tot; n inline void main() { n   T = read(); n   while (T--) { n     n = read(); n     num = tot = 0; n     for (long long i = 1; i <= n; ++i) a[i] = read(), c[++num] = a[i]; n     sort(c + 1, c + num + 1); n     for (long long i = 1; i <= n; ++i) { n       for (long long j = 1; j <= n; ++j) { n         if (a[i] == c[j]) { n           a[i] = j; n           c[j] = 1e9 + 10; n           break; n         } n       } n     } n     for (long long pos, i = 1; i <= n; ++i) { n       pos = i; n       for (long long j = i; j <= n; ++j) { n         if (a[j] == i) { n           pos = j; n           break; n         } n       } n       if (pos == i) continue; n       e[++tot].l = i, e[tot].r = pos, e[tot].d = pos - i; n       for (long long j = pos; j > i; --j) a[j] = a[j - 1]; n       a[i] = i; n     } n     printf( %lld n , tot); n     for (long long i = 1; i <= tot; ++i) { n       printf( %lld %lld %lld n , e[i].l, e[i].r, e[i].d); n     } n   } n } n }  // namespace red n signed main() { n   red::main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[10][10]; n int ans; n int main() { n   cin >> c[1] >> c[2] >> c[3] >> c[4] >> c[5] >> c[6] >> c[7] >> c[8]; n   for (int i = 1; i <= 8; i++) { n     int p = 0; n     for (int j = 0; j < 8; j++) n       if (c[i][j] ==  B ) p++; n     if (p == 8) ans++; n     p = 0; n     for (int j = 1; j <= 8; j++) n       if (c[j][i - 1] ==  B ) p++; n     if (p == 8) ans++; n   } n   if (ans != 16) n     cout << ans; n   else n     cout << 8; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2147483647; n const double PI = 3.141592653589793; n int n, k, l, a[105], used[105], suma, i, j, q, b; n double maxx, minn; n vector<int> wek; n int main() { n   scanf( %d %d , &n, &k); n   l = n / k; n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     used[i] = 0; n   } n   maxx = -INF; n   minn = INF; n   scanf( %d , &q); n   for (j = 0; j < q; j++) { n     suma = 0; n     for (i = 0; i < l; i++) { n       scanf( %d , &b); n       b--; n       suma += a[b]; n       used[b] = 1; n     } n     maxx = max(maxx, suma * 1.0 / l); n     minn = min(minn, suma * 1.0 / l); n   } n   wek.resize(0); n   for (i = 0; i < n; i++) n     if (!used[i]) wek.push_back(a[i]); n   sort(wek.begin(), wek.end()); n   if (wek.size() == n - k * l) { n     printf( %.8lf %.8lf n , minn, maxx); n     return 0; n   } n   suma = 0; n   for (i = 0; i < l; i++) suma += wek[i]; n   maxx = max(maxx, suma * 1.0 / l); n   minn = min(minn, suma * 1.0 / l); n   suma = 0; n   for (i = wek.size() - 1; i >= (int)wek.size() - l; i--) suma += wek[i]; n   maxx = max(maxx, suma * 1.0 / l); n   minn = min(minn, suma * 1.0 / l); n   printf( %.8lf %.8lf n , minn, maxx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long hash1 = 201326611; n const double eps = 1e-8; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int inf = 0x3f3f3f3f; n const long long mod = 1e9 + 7; n const int N = 1e5 + 10; n const int M = 12; n const int dif = 26; n const double PI = acos(-1.0); n inline void Mod(long long& x) { n   if (x >= mod) x -= mod; n } n void BinaryBitset(int n) { cout << bitset<sizeof(int) * 4>(n) << endl; } n struct node { n   long long l, r, len; n } p[22]; n void init() { n   p[1].l = 1; n   p[1].r = 9; n   p[1].len = 9; n   for (int i = 2; i <= 18; i++) { n     p[i].l = p[i - 1].l * 10; n     p[i].r = p[i - 1].r * 10 + 9; n     p[i].len = p[i - 1].len * 10; n   } n } n int q; n long long k; n bool isOK(long long x, long long k) { n   long long ans = 0; n   for (int i = 1; i <= 20; i++) { n     if (x > p[i].r) { n       long long left = x - p[i].r + 1, right = x - p[i].l + 1; n       ans += p[i].len * i * (right + left) / 2; n     } else { n       long long left = 1, right = x - p[i].l + 1; n       ans += (right - left + 1) * i * (left + right) / 2; n       break; n     } n     if (ans >= k) return 1; n   } n   return ans >= k; n } n long long getsum(long long x) { n   long long ans = 0; n   for (int i = 1; i <= 20; i++) { n     if (x > p[i].r) { n       long long left = x - p[i].r + 1, right = x - p[i].l + 1; n       ans += p[i].len * i * (right + left) / 2; n     } else { n       long long left = 1, right = x - p[i].l + 1; n       ans += (right - left + 1) * i * (left + right) / 2; n       return ans; n     } n   } n   return ans; n } n bool isOK2(long long x, long long k) { n   long long ans = 0; n   for (int i = 1; i <= 20; i++) { n     if (x > p[i].r) { n       ans += p[i].len * i; n     } else { n       long long left = 1, right = x - p[i].l + 1; n       ans += (right - left + 1) * i; n       break; n     } n     if (ans >= k) return 1; n   } n   return ans >= k; n } n long long getsum2(long long x) { n   long long ans = 0; n   for (int i = 1; i <= 20; i++) { n     if (x > p[i].r) { n       ans += p[i].len * i; n     } else { n       long long left = 1, right = x - p[i].l + 1; n       ans += (right - left + 1) * i; n       return ans; n     } n   } n } n int main() { n   init(); n   scanf( %d , &q); n   while (q--) { n     scanf( %lld , &k); n     long long left = 1, right = 482720320; n     while (left <= right) { n       long long mid = (left + right) >> 1; n       if (isOK(mid, k)) n         right = mid - 1; n       else n         left = mid + 1; n     } n     k -= getsum(left - 1); n     left = 1; n     right = 1e10; n     while (left <= right) { n       long long mid = (left + right) >> 1; n       if (isOK2(mid, k)) n         right = mid - 1; n       else n         left = mid + 1; n     } n     k -= getsum2(left - 1); n     vector<int> ans; n     long long x = left; n     while (x) { n       ans.push_back(x % 10); n       x /= 10; n     } n     int j = 0, h = ans.size() - 1; n     while (j <= h) { n       swap(ans[j], ans[h]); n       j++; n       h--; n     } n     printf( %d n , ans[k - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> card; n void init() { n   for (int i = 6, j = 1; i < 15; i++, j++) card.insert(make_pair(i, j)); n } n int isCard(char num) { n   int res = 0; n   if (num >=  0  && num <=  9 ) n     res = num -  0 ; n   else { n     if (num ==  T ) n       res = 10; n     else if (num ==  J ) n       res = 11; n     else if (num ==  Q ) n       res = 12; n     else if (num ==  K ) n       res = 13; n     else n       res = 14; n   } n   return res; n } n int main() { n   char mn; n   string s; n   cin >> s; n   mn = s[0]; n   cin >> s; n   int id[2]; n   char ch[2]; n   id[0] = isCard(s[0]); n   ch[0] = s[1]; n   cin >> s; n   id[1] = isCard(s[0]); n   ch[1] = s[1]; n   map<int, bool> mp; n   mp.insert(make_pair(mn, true)); n   if (mp.find(ch[0]) != mp.end() && mp.find(ch[1]) == mp.end()) n     cout <<  YES ; n   else if (mp.find(ch[0]) == mp.end() && mp.find(ch[1]) != mp.end()) n     cout <<  NO ; n   else if (ch[0] != ch[1]) n     cout <<  NO ; n   else if (id[0] > id[1]) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> table(n), d = {119, 18, 93, 91, 58, 107, 111, 82, 127, 123}; n   for (int i = 0; i < n; ++i) { n     string tmp; n     cin >> tmp; n     reverse(tmp.begin(), tmp.end()); n     for (int j = 0; j < 7; ++j) { n       if (tmp[j] ==  1 ) { n         table[i] += (1 << j); n       } n     } n   } n   vector<vector<int>> dp(n + 1, vector<int>(k + 1, -1)); n   vector<vector<int>> par(n + 1, vector<int>(k + 1, -1)); n   dp[n][0] = 0; n   for (int i = n - 1; i >= 0; --i) { n     for (int j = 0; j <= k; ++j) { n       for (int k = 9; k >= 0; --k) { n         int cnt = __builtin_popcount(d[k] ^ table[i]); n         if (j >= cnt && (d[k] | table[i]) == d[k] && dp[i + 1][j - cnt] != -1) { n           dp[i][j] = k; n           par[i][j] = j - cnt; n           break; n         } n       } n     } n   } n   if (dp[0][k] == -1) { n     cout << -1 <<   n ; n   } else { n     int i = 0, j = k; n     while (i < n && j >= 0) { n       cout << dp[i][j]; n       j = par[i][j]; n       ++i; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int N = 1000001; n   vector<int> count(N); n   long long n; n   cin >> n; n   vector<long long> a(n), ans; n   long long sum = 0, i, j, k; n   for (i = 0; i < n; i++) cin >> a[i], sum += a[i], count[a[i]]++; n   for (i = 0; i < n; i++) n     if ((sum - a[i]) % 2 == 0 && (sum - a[i]) / 2 < N && n         (count[(sum - a[i]) / 2] > 1 || n          (count[(sum - a[i]) / 2] == 1 && a[i] != (sum - a[i]) / 2))) n       ans.push_back(i + 1); n   cout << ans.size() << endl; n   for (auto x : ans) cout << x <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const ll M = 1000000007; n const ll M1 = 998244353; n using vl = vector<ll>; n using pll = pair<ll, ll>; n ll power(ll x, ll y) { n   if (y == 0) return 1; n   ll res = power(x, y / 2); n   res = (res * res); n   if (y & 1) res = (res * x); n   return res; n } n ll powermod(ll x, ll y, ll mod) { n   if (y == 0) return 1; n   ll res = powermod(x, y / 2, mod); n   res = (res * res) % mod; n   if (y & 1) res = (res * x) % mod; n   return res; n } n ll findxor(ll a) { n   switch (a & 3) { n     case 0: n       return a; n     case 1: n       return 1; n     case 2: n       return a + 1; n     case 3: n       return 0; n   } n   return -1; n } n int n; n vector<int> visi; n vector<string> gr; n void dfs(int node, vector<int> &rec_visit) { n   visi[node] = 1; n   rec_visit.push_back(node); n   for (int con_node = 0; con_node < n; con_node++) { n     if (visi[con_node] || gr[node][con_node] ==  0 ) continue; n     dfs(con_node, rec_visit); n   } n } n void solve() { n   cin >> n; n   int ans[n]; n   for (int i = 0; i < n; i++) cin >> ans[i]; n   gr.resize(n); n   visi.resize(n, 0); n   for (int i = 0; i < n; i++) cin >> gr[i]; n   for (int i = 0; i < n; i++) { n     if (visi[i]) continue; n     vector<int> rec_visit; n     dfs(i, rec_visit); n     vector<int> val; n     for (int j = 0; j < rec_visit.size(); j++) val.push_back(ans[rec_visit[j]]); n     sort(val.begin(), val.end()); n     sort(rec_visit.begin(), rec_visit.end()); n     for (int j = 0; j < rec_visit.size(); j++) ans[rec_visit[j]] = val[j]; n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[50], c[50]; n int t1 = 0, t2 = 0; n int main() { n   cin >> s >> c; n   for (int i = 0; i < strlen(s); i += 2) { n     if ((s[i] ==  8  && c[i] ==  [ ) || (s[i] ==  [  && c[i] ==  ( ) || n         (s[i] ==  (  && c[i] ==  8 )) n       t1++; n     else if (s[i] != c[i]) n       t2++; n   } n   if (t1 > t2) n     cout <<  TEAM 1 WINS ; n   else if (t2 > t1) n     cout <<  TEAM 2 WINS ; n   else n     cout <<  TIE ; n } n


#include <bits/stdc++.h> n using namespace std; n long long c[110][110]; n long long a[110]; n long long tmp[110]; n long long dp[10][110]; n long long gao(long long n) { n   memset(dp, 0, sizeof(dp)); n   long long i, j, k; n   long long m = 0; n   for (i = 0; i <= 9; i++) m += a[i]; n   if (m > n) return 0; n   for (i = a[0]; i <= n; i++) { n     dp[0][i] = c[n][i]; n   } n   for (i = 1; i <= 9; i++) n     for (j = 0; j <= n; j++) { n       for (k = a[i]; k <= j; k++) { n         dp[i][j] = n             (dp[i][j] + dp[i - 1][j - k] * c[n - (j - k)][k] % 1000000007) % n             1000000007; n       } n     } n   return dp[9][n] % 1000000007; n } n int main() { n   long long i, j, m, n; n   for (i = 0; i < 110; i++) n     for (j = 0; j < 110; j++) { n       if (j > i) { n         c[i][j] = 0; n         continue; n       } n       if (j == 0) n         c[i][j] = 1; n       else n         c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007; n     } n   while (cin >> n) { n     m = 0; n     for (i = 0; i <= 9; i++) { n       cin >> a[i]; n       tmp[i] = a[i]; n       m += a[i]; n     } n     if (m > n) { n       cout << 0 << endl; n       continue; n     } n     long long res = 0; n     for (long long l = max(1LL, m); l <= n; l++) { n       for (i = 0; i <= n; i++) a[i] = tmp[i]; n       long long ans = 0; n       for (i = 1; i <= 9; i++) { n         long long tt = a[i]; n         a[i] = max(a[i] - 1, 0LL); n         ans = (ans + gao(l - 1)) % 1000000007; n         a[i] = tt; n       } n       res = (res + ans) % 1000000007; n     } n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f[16][16][1 << 17]; n int b[16]; n long long dp(int x, int Mx, int sum, bool flag) { n   if (x == 0) { n     return (sum >> Mx) & 1; n   } n   if (!flag && f[x][Mx][sum] != -1) return f[x][Mx][sum]; n   int lm = flag ? b[x] : 15; n   long long ans = 0; n   for (int i = 0; i <= lm; i++) { n     int tmp = sum; n     if (x <= 4) tmp |= i << ((x - 1) * 4); n     ans += dp(x - 1, max(Mx, i), tmp, flag && i == lm); n   } n   return flag ? ans : f[x][Mx][sum] = ans; n } n long long solve(long long x) { n   int p = 0; n   memset(b, 0, sizeof(b)); n   while (x) { n     b[++p] = x % 16; n     x /= 16; n   } n   return dp(p, 0, 0, 1); n } n int main() { n   int _; n   scanf( %d , &_); n   memset(f, -1, sizeof(f)); n   while (_--) { n     long long l, r; n     scanf( %I64x%I64x , &l, &r); n     printf( %I64d n , solve(r) - solve(l - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   long double f; n   int i; n   cin >> n; n   long long int m = n; n   for (i = 1; n / pow(10, i) >= 1; ++i) n     ; n   i--; n   f = n / pow(10, i); n   if (ceil(f) == f) f++; n   f = ceil(f); n   n = f * pow(10, i); n   cout << n - m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long A[100001], B[100001]; n bool valid[100001]; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) cin >> A[i]; n   for (int i = 0; i < n; ++i) cin >> B[i]; n   long long ac = 0, bc = 0; n   long long mini = (1LL << 62); n   for (int i = 0; i < n; ++i) { n     ac += A[i]; n     bc += B[i]; n     mini = min(mini, ac - bc); n   } n   for (int i = 0; i < n; ++i) { n     valid[i] = mini >= 0; n     mini -= A[i] - B[i]; n   } n   mini = (1LL << 62); n   ac = bc = 0; n   for (int i = 0; i < n; ++i) { n     ac += A[n - i - 1]; n     bc += B[(n - i - 2 + n) % n]; n     mini = min(mini, ac - bc); n   } n   for (int i = 0; i < n; ++i) { n     assert(mini <= 0); n     valid[n - i - 1] |= mini >= 0; n     mini -= A[n - i - 1] - B[(n - i - 2 + n) % n]; n   } n   bool first = true; n   int ans = 0; n   for (int i = 0; i < n; ++i) ans += valid[i]; n   cout << ans << endl; n   for (int i = 0; i < n; ++i) n     if (valid[i]) { n       if (not first) cout <<    ; n       cout << i + 1; n       first = false; n     } n   cout << endl; n } n


#include <bits/stdc++.h> n const long long mod = 998244353; n const int kN = 5e3 + 10; n int n, a[kN], lim[kN]; n long long f[kN], fac[kN], invfac[kN]; n inline int read() { n   int f = 1, w = 0; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = getchar()) { n     w = (w << 3) + (w << 1) + (ch ^  0 ); n   } n   return f * w; n } n void Chkmax(int &fir_, int sec_) { n   if (sec_ > fir_) fir_ = sec_; n } n void Chkmin(int &fir_, int sec_) { n   if (sec_ < fir_) fir_ = sec_; n } n long long QPow(long long x_, long long y_) { n   x_ %= mod; n   long long ret = 1; n   for (; y_; y_ >>= 1ll) { n     if (y_ & 1) ret = ret * x_ % mod; n     x_ = x_ * x_ % mod; n   } n   return ret; n } n long long A(long long n_, long long m_) { n   if (n_ < 0 || m_ < 0 || m_ > n_) return 0; n   return 1ll * fac[n_] * invfac[n_ - m_] % mod; n } n void Prepare() { n   n = read(); n   invfac[0] = fac[0] = 1; n   for (int i = 1; i <= n; ++i) { n     a[i] = read(); n     fac[i] = 1ll * fac[i - 1] * i % mod; n     invfac[i] = QPow(fac[i], mod - 2); n   } n   std::sort(a + 1, a + n + 1); n   for (int i = 1, j = 0; i <= n; ++i) { n     while (j <= n && 2ll * a[j] <= 1ll * a[i]) ++j; n     --j; n     lim[i] = j; n   } n } n int main() { n   Prepare(); n   if (lim[n] != n - 1) { n     printf( 0 n ); n     return 0; n   } n   f[0] = 1, lim[0] = -1; n   for (int i = 1; i <= n; ++i) { n     for (int j = 0; j <= lim[i]; ++j) { n       f[i] += 1ll * f[j] * n               A(1ll * n - 2ll - lim[j], 1ll * lim[i] - lim[j] - 1ll) % mod; n       f[i] %= mod; n     } n   } n   printf( %lld n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 109; n int n, suma, K, sumb, f[10086][N], ans = 0; n struct node { n   int a, b; n } c[N]; n bool cmp(const node& a, const node& b) { return a.b > b.b; } n int main() { n   scanf( %d , &n); n   for (register int i = 1; i <= n; i++) scanf( %d , &c[i].a), suma += c[i].a; n   for (register int i = 1; i <= n; i++) scanf( %d , &c[i].b); n   sort(c + 1, c + n + 1, cmp); n   while (sumb < suma) sumb += c[++K].b; n   printf( %d  , K); n   memset(f, 128, sizeof(f)); n   f[0][0] = 0; n   for (register int i = 1; i <= n; i++) n     for (register int j = sumb; j >= c[i].b; j--) n       for (register int k = 1; k <= K; k++) n         f[j][k] = max(f[j][k], f[j - c[i].b][k - 1] + c[i].a); n   for (register int j = suma; j <= sumb; j++) ans = max(ans, f[j][K]); n   printf( %d , suma - ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n pair<long long, long long> a[100005]; n long long pymax[100005], pymin[100005]; n long long symax[100005], symin[100005]; n bool trial(long long x) { n   for (int i = 0; i < n; i++) { n     symax[i] = pymax[i] = a[i].second - x; n     symin[i] = pymin[i] = a[i].second + x; n   } n   for (int i = 1; i < n; i++) { n     pymax[i] = max(pymax[i], pymax[i - 1]); n     pymin[i] = min(pymin[i], pymin[i - 1]); n   } n   for (int i = n - 2; i >= 0; i--) { n     symax[i] = max(symax[i], symax[i + 1]); n     symin[i] = min(symin[i], symin[i + 1]); n   } n   int e = 0; n   for (int i = 0; i < n; i++) { n     while (e < n && a[e].first <= a[i].first + x * 2) { n       e++; n     } n     long long maxv = -1e18, minv = 1e18; n     if (i) maxv = max(maxv, pymax[i - 1]), minv = min(minv, pymin[i - 1]); n     if (e < n) maxv = max(maxv, symax[e]), minv = min(minv, symin[e]); n     if (maxv <= minv) { n       return 1; n     } n   } n   return 0; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     a[i] = pair<long long, long long>(x + y, x - y); n     a[i].first *= 2ll; n     a[i].second *= 2ll; n   } n   sort(a, a + n); n   long long s = 0, e = 1e10; n   while (s != e) { n     long long m = (s + e) / 2; n     if (trial(m)) n       e = m; n     else n       s = m + 1; n   } n   printf( %.10f , s * 0.5); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[1007]; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int ans, min = 10000007, sum = 0; n   for (int i = 1; i <= 100; i++) { n     sum = 0; n     for (int j = 0; j < n; j++) { n       if (a[j] > i + 1) n         sum += a[j] - i - 1; n       else if (a[j] < i - 1) n         sum += i - 1 - a[j]; n     } n     if (min > sum) min = sum, ans = i; n   } n   cout << ans <<     << min << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n const int maxN = 1000010; n int len; n int ra[maxN], tra[maxN], sa[maxN], tmpsa[maxN], cnt[maxN]; n void countSort(int k) { n   int maxr = max(300, len); n   memset(cnt, 0, sizeof(cnt[0]) * (maxr + 5)); n   for (int i = 0; i < len; i++) cnt[sa[i] + k < len ? ra[sa[i] + k] : 0]++; n   for (int i = 0, t, sum = 0; i < maxr; i++) t = cnt[i], cnt[i] = sum, sum += t; n   for (int i = 0; i < len; i++) n     tmpsa[cnt[sa[i] + k < len ? ra[sa[i] + k] : 0]++] = sa[i]; n   for (int i = 0; i < len; i++) sa[i] = tmpsa[i]; n } n void buildsa() { n   for (int i = 0; i < len; i++) ra[i] = s[i], sa[i] = i; n   for (int k = 1; k < len; k <<= 1) { n     countSort(k); n     countSort(0); n     int r = 0; n     tra[sa[0]] = 0; n     for (int i = 1; i < len; i++) { n       int t1 = (sa[i] + k < len ? ra[sa[i] + k] : 0); n       int t2 = (sa[i - 1] + k < len ? ra[sa[i - 1] + k] : 0); n       tra[sa[i]] = (ra[sa[i]] == ra[sa[i - 1]] && t1 == t2) ? r : ++r; n     } n     for (int i = 0; i < len; i++) ra[i] = tra[i]; n     if (ra[sa[len - 1]] == len - 1) break; n   } n   string os = s; n } n int phi[maxN], LCP[maxN]; n void computeLCP() { n   phi[sa[0]] = -1; n   for (int i = 1; i < len; i++) phi[sa[i]] = sa[i - 1]; n   int L = 0; n   for (int i = 0; i < len; i++) { n     if (phi[i] == -1) { n       LCP[ra[i]] = 0; n       continue; n     } n     while (L < len && s[i + L] == s[phi[i] + L]) L++; n     int TL = L; n     LCP[ra[i]] = TL; n     L = max(L - 1, 0); n   } n } n int tlft[maxN], trgt[maxN]; n void hgram(int data[], int n) { n   data[0] = -1; n   data[n + 1] = -1; n   stack<int> bosta; n   bosta.push(0); n   for (int i = 1; i <= n + 1; i++) { n     while (data[i] < data[bosta.top()]) { n       trgt[bosta.top()] = i; n       bosta.pop(); n     } n     bosta.push(i); n   } n   bosta.push(n + 1); n   for (int i = n + 1; i >= 0; i--) { n     while (data[i] < data[bosta.top()]) { n       tlft[bosta.top()] = i; n       bosta.pop(); n     } n     bosta.push(i); n   } n } n int cross[100100]; n long long sum[100010]; n vector<pair<long long, pair<long long, long long> > > vv[100010]; n void qry(int k) { n   for (int i = 1; i < len; i++) { n     if (i >= cross[LCP[i]]) { n       cross[LCP[i]] = max(cross[LCP[i]], trgt[i]); n       long long range = trgt[i] - tlft[i]; n       long long occ = n           min(LCP[i], min(LCP[i] - LCP[tlft[i]], LCP[i] - LCP[trgt[i]])); n       long long gain = occ * range; n       if (gain) { n         vv[tlft[i]].push_back(make_pair(LCP[i] - occ, make_pair(occ, gain))); n         sum[tlft[i]] += gain; n       } n     } n   } n   long long tot = 0; n   for (int i = 1; i < len; i++) { n     if (tot + sum[i] >= k) { n       sort(vv[i].begin(), vv[i].end()); n       for (int j = 0; j < vv[i].size(); j++) { n         long long cur = vv[i][j].second.second; n         if (tot + cur >= k) { n           long long st = vv[i][j].first; n           long long oc = vv[i][j].second.first; n           long long cnt = cur / oc; n           long long need = k - tot; n           long long pos = ceil(need / (1.00 * cnt)); n           cout << s.substr(sa[i], st + pos); n           return; n         } n       } n       return; n     } n     tot += sum[i]; n     long long exgain = len - 1 - sa[i]; n     long long repitition = LCP[i]; n     if (i < len - 1) repitition = max(repitition, (long long)LCP[i + 1]); n     exgain -= repitition; n     if (tot + exgain >= k) { n       long long need = k - tot; n       cout << s.substr(sa[i], repitition + need) << endl; n       return; n     } n     tot += exgain; n   } n   cout <<  No such line.  << endl; n } n int main() { n   cin >> s; n   s +=  & ; n   len = s.size(); n   buildsa(); n   computeLCP(); n   hgram(LCP, len - 1); n   int k; n   cin >> k; n   qry(k); n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 20; n int a[105]; n int u[105], res[105]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d , &a[i]); n   } n   int pos = a[0], ans = 1; n   while (ans < m) { n     if (a[ans] > pos) { n       if (res[pos] == 0) { n         if (u[a[ans] - pos]) { n           puts( -1 ); n           return 0; n         } n         res[pos] = a[ans] - pos; n       } else { n         if (a[ans] % n != (res[pos] + pos) % n) { n           puts( -1 ); n           return 0; n         } n       } n       u[a[ans] - pos] = 1; n     } else { n       if (res[pos] == 0) { n         if (u[a[ans] + n - pos]) { n           puts( -1 ); n           return 0; n         } n         res[pos] = a[ans] + n - pos; n       } else { n         if (a[ans] % n != (res[pos] + pos) % n) { n           puts( -1 ); n           return 0; n         } n       } n       u[a[ans] + n - pos] = 1; n     } n     pos = a[ans++]; n   } n   for (int i = 1; i <= n; i++) { n     if (res[i] == 0) { n       for (int j = 1; j <= n; j++) { n         if (u[j] == 0) { n           res[i] = j; n           u[j] = 1; n           break; n         } n       } n     } n     printf( %d  , res[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n long long a[10], n, rem[10], par[10], res = N, rem_factors[10], factors[10]; n inline bool is_prime(long long u) { n   if (u == 1) return false; n   if (u == 2) return true; n   if (u % 2 == 0) return false; n   for (long long i = 3; i * i <= u; i += 2) n     if (u % i == 0) return false; n   return true; n } n int get(long long u) { n   if (u == 1) return 0; n   if (is_prime(u)) return 1; n   int res = 0; n   while (u % 2 == 0) { n     u /= 2; n     res++; n   } n   if (u == 1) return res; n   if (is_prime(u)) { n     return res + 1; n   } n   for (long long i = 3; i * i <= u; i += 2) { n     while (u % i == 0) { n       res++; n       u /= i; n     } n   } n   if (u > 2) res++; n   return res; n } n int PRIME[10]; n void backtrack(int idx) { n   if (idx == n) { n     int val = 0, cnt_par = 0; n     for (int i = 0; i < n; i++) { n       if (!PRIME[i]) val += rem_factors[i]; n       cnt_par += (par[i] != -1); n     } n     if (n - cnt_par > 1) n       res = min(res, val + n + 1); n     else n       res = min(res, val + n); n     return; n   } n   for (int i = idx + 1; i < n; i++) { n     if (rem[i] >= a[idx] && a[i] > a[idx] && rem[i] % a[idx] == 0) { n       rem[i] /= a[idx]; n       rem_factors[i] -= factors[idx]; n       par[idx] = i; n       backtrack(idx + 1); n       rem_factors[i] += factors[idx]; n       par[idx] = -1; n       rem[i] *= a[idx]; n     } n   } n   backtrack(idx + 1); n } n int main() { n   ios_base::sync_with_stdio(false); n   scanf( %d , &n); n   memset(par, -1, sizeof(par)); n   for (int i = 0; i < n; i++) scanf( %lld , &a[i]); n   sort(a, a + n); n   for (int i = 0; i < n; i++) rem[i] = a[i]; n   for (int i = 0; i < n; i++) PRIME[i] = is_prime(a[i]); n   for (int i = 0; i < n; i++) { n     rem_factors[i] = get(a[i]); n     factors[i] = rem_factors[i]; n   } n   backtrack(0); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const long long inf = 1e12; n int n, h[N], w[N], u, v; n long long ans, f[N][2]; n vector<int> g[N]; n void dfs(int u, int fa) { n   vector<long long> vec; n   long long sum = 0; n   for (auto v : g[u]) { n     if (v ^ fa) { n       dfs(v, u); n       sum += f[v][0]; n       vec.push_back(f[v][1] - f[v][0]); n     } n   } n   sort(vec.begin(), vec.end()); n   for (int t = 0; t < 2; ++t) { n     f[u][t] = inf; n     if (u > 1 && ((!t && h[fa] > h[u]) || (t && h[fa] < h[u]))) { n       continue; n     } n     int out = vec.size() + t; n     long long cur = sum; n     for (int i = 0; ~out; ++i, --out) { n       if (i && i <= vec.size()) { n         cur += vec[i - 1]; n       } n       f[u][t] = n           min(f[u][t], cur + 1ll * w[u] * max(out, (int)g[u].size() - out)); n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &w[i]); n   } n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &h[i]); n   } n   for (int i = 1, u, v; i < n; ++i) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1, 0); n   printf( %lld n , f[1][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e5 + 5; n int head[maxn], e[maxn << 1], nxt[maxn << 1], cnt = 1; n void addedge(int u, int v) { n   e[++cnt] = v, nxt[cnt] = head[u], head[u] = cnt; n   e[++cnt] = u, nxt[cnt] = head[v], head[v] = cnt; n } n int s[maxn], t[maxn]; n int f[maxn], num; n int d[maxn]; n int n, C = 2e5; n void dfs(int u) { n   while (head[u] && f[head[u] >> 1]) head[u] = nxt[head[u]]; n   if (head[u]) { n     f[head[u] >> 1] = ++num; n     dfs(e[head[u]]); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1, x, y; i <= n; i++) { n     scanf( %d%d , &x, &y); n     d[x]++, d[y + C]++; n     s[i] = x, t[i] = y + C; n     addedge(x, y + C); n   } n   int last, tot = 0; n   for (int i = 1; i <= 2 * C; i++) n     if (d[i] % 2) addedge(i, 2 * C + 1); n   dfs(2 * C + 1); n   for (int i = 1; i <= 2 * C; i++) dfs(i); n   memset(d, 0, sizeof(d)); n   for (int i = 1; i <= n; i++) { n     if (f[i] % 2) n       d[s[i]]++, d[t[i]]++; n     else n       d[s[i]]--, d[t[i]]--; n   } n   for (int i = 1; i <= 2 * C; i++) n     if (d[i] > 1 || d[i] < -1) { n       printf( shaleba n ); n       return 0; n     } n   for (int i = 1; i <= n; i++) { n     if (f[i] % 2) n       printf( r ); n     else n       printf( b ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long T[1001][1001]; n int main() { n   long long n; n   cin >> n; n   long long a[n]; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < 1001; i++) { n     for (int j = 0; j <= i; j++) { n       if (j == 0 || i == j) n         T[i][j] = 1; n       else n         T[i][j] = (T[i - 1][j] + T[i - 1][j - 1]) % 998244353; n     } n   } n   long long L[n + 1]; n   L[n] = 1; n   for (long long i = n - 1; i >= 0; i--) { n     if (a[i] <= 0 || (i + a[i]) >= n) { n       L[i] = 0; n     } else { n       long long s = 0; n       for (long long k = i + a[i]; k < n; k++) { n         s = (s + (T[k - i][a[i]] * (L[k + 1])) % 998244353) % 998244353; n       } n       L[i] = s; n     } n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) ans = (ans + L[i]) % 998244353; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 1e6 + 5; n const double delta = 1e-6; n const long long mod = 1e9 + 7; n struct ev { n   double coord; n   int type; n   int mincost; n }; n const bool operator<(const ev &f, const ev &s) { return f.coord < s.coord; } n int n, m; n const int magic_const = 2e6; n class segment_tree { n  private: n   vector<int> a; n   vector<int> b; n   vector<int> a_left; n   vector<int> b_right; n   int deltaa, deltab, x, n, now_right; n   int answer = 0; n   void update_vertex(int v, bool is_leaf) { n     if (is_leaf) { n       int min_t = min(a[v], b[v]); n       a_left[v] = a[v] - min_t; n       b_right[v] = b[v] - min_t; n     } else { n       int l = a_left[v * 2]; n       int r = b_right[v * 2 + 1]; n       int min_t = min(l, r); n       a_left[v] = l - min_t + a_left[v * 2 + 1]; n       b_right[v] = r - min_t + b_right[v * 2]; n     } n   } n   void build(int v, int l, int r, vector<int> &a1, vector<int> &b1) { n     bool leaf = is_leaf(l, r); n     if (leaf) { n       a[v] = a1[l]; n       b[v] = b1[l]; n     } else { n       int mid = (l + r) / 2; n       build(v * 2, l, mid, a1, b1); n       build(v * 2 + 1, mid + 1, r, a1, b1); n     } n     update_vertex(v, leaf); n   } n   void update(int v, int l, int r) { n     bool leaf = is_leaf(l, r); n     if (leaf) { n       a[v] += deltaa; n       b[v] += deltab; n     } else { n       int mid = (l + r) / 2; n       if (contains_x(l, mid)) update(v * 2, l, mid); n       if (contains_x(mid + 1, r)) update(v * 2 + 1, mid + 1, r); n     } n     update_vertex(v, leaf); n   } n   void get_answer(int v, int l, int r) { n     if (is_leaf(l, r)) n       answer = l; n     else { n       int mid = (l + r) / 2; n       int now_delta = now_right - a_left[v * 2 + 1]; n       if (now_delta < 0) { n         get_answer(v * 2 + 1, mid + 1, r); n       } else { n         now_right = now_delta + b_right[v * 2 + 1]; n         get_answer(v * 2, l, mid); n       } n     } n   } n   bool is_leaf(int l, int r) { return l == r; } n   bool contains_x(int l, int r) { return x >= l && x <= r; } n  n  public: n   segment_tree(vector<int> &a1, vector<int> &b1) { n     n = a1.size() - 1; n     a.resize(a1.size() * 4); n     a_left.resize(a1.size() * 4); n     b.resize(b1.size() * 4); n     b_right.resize(b1.size() * 4); n     build(1, 0, n, a1, b1); n   } n   void update_ab(int x1, int da, int db) { n     x = x1; n     deltaa = da; n     deltab = db; n     update(1, 0, n); n   } n   int get_answer() { n     answer = 0; n     now_right = 0; n     get_answer(1, 0, n); n     if (answer == 0) return -1; n     return answer; n   } n }; n void solve() { n   cin >> n >> m; n   vector<int> a(MAX_N); n   vector<int> b(MAX_N); n   a[0] = magic_const; n   vector<int> an(n); n   vector<int> bm(m); n   for (auto &i : an) { n     cin >> i; n     a[i]++; n   } n   for (auto &i : bm) { n     cin >> i; n     b[i]++; n   } n   segment_tree str(a, b); n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     int type, num, x; n     cin >> type >> num >> x; n     num--; n     if (type == 1) { n       str.update_ab(an[num], -1, 0); n       str.update_ab(x, 1, 0); n       an[num] = x; n     } else { n       str.update_ab(bm[num], 0, -1); n       str.update_ab(x, 0, 1); n       bm[num] = x; n     } n     cout << str.get_answer() <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   srand(58164); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 10; n long long n; n long long pre[N]; n long long cal(long long x) { n   if (x == n * (n - 1) + 1) return 1; n   long long p = lower_bound(pre + 1, pre + n + 1, x) - pre; n   long long b = x - pre[p - 1]; n   if (b & 1) n     return p; n   else n     return p + b / 2; n } n signed main() { n   long long t; n   cin >> t; n   while (t--) { n     long long l, r; n     cin >> n >> l >> r; n     for (long long i = 1; i <= n; i++) pre[i] = pre[i - 1] + 2 * (n - i); n     for (long long i = l; i <= r; i++) cout << cal(i) <<    ; n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int siz = 1e5 + 7; n const int siz2 = 2e5 + 7; n int t, n; n int a[222]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n A: n   while (t--) { n     cin >> n; n     map<int, int> mp; n     vector<int> Ans; n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n       mp[a[i]]++; n     } n     if (n > 1) { n       for (int i = 0; i < n; ++i) { n         for (int j = a[i]; j <= 2 * n; ++j) { n           if (!mp[j]) { n             mp[j]++; n             Ans.push_back(a[i]); n             Ans.push_back(j); n             break; n           } n         } n       } n       if (Ans.size() != 2 * n) { n         cout << -1 << endl; n         goto A; n       } n     } else { n       if (a[0] == 1) { n         cout << 1 <<     << 2 << endl; n         goto A; n       } else { n         cout << -1 << endl; n         goto A; n       } n     } n     for (auto it : Ans) cout << it <<    ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20 * 1000 + 200; n const int INF = 1000 * 1000 * 1000; n int d[N]; n int n, m; n inline void read() { scanf( %d %d , &n, &m); } n inline void solve() { n   for (int i = 0; i < N; i++) d[i] = INF; n   queue<int> q; n   q.push(n); n   d[n] = 0; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     if (v * 2 <= 20 * 1000 && d[v * 2] == INF) { n       q.push(v * 2); n       d[v * 2] = d[v] + 1; n     } n     if (v - 1 > 0 && d[v - 1] == INF) { n       q.push(v - 1); n       d[v - 1] = d[v] + 1; n     } n   } n   cout << d[m]; n } n int main() { n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n int N, M; n int dist[200000]; n int interval[200000]; n int cnt[200000]; n int main(void) { n   cin >> N; n   for (int i = 0; i < (int)(N); ++i) scanf( %d , dist + i); n   for (int i = 0; i < (int)(N - 1); ++i) interval[i] = dist[i + 1] - dist[i]; n   cin >> M; n   map<int, int> _ma; n   for (int i = 0; i < (int)(M); ++i) { n     int b; n     scanf( %d , &b); n     cnt[b - 1]++; n     _ma[b - 1]++; n   } n   vector<int> candid; n   for (int i = 1; i < (int)(N - 1); ++i) n     if (cnt[i - 1] != cnt[i] or cnt[i] != cnt[i + 1]) n       if (cnt[i]) candid.push_back(i); n   candid.push_back(0); n   candid.push_back(N - 1); n   long long res = -1; n   for (int s : candid) { n     for (int sd = -1; sd <= 1; sd += 2) { n       map<int, int> ma = _ma; n       int now = s, d = sd; n       long long sum = 0; n       ma[now]--; n       if (ma[now] == 0) ma.erase(now); n       while (true) { n         if (ma.find(now) == ma.end() and ma.size() == 0) { n           if (res == -1 or res == sum) { n             res = sum; n             break; n           } else { n             cout << -1 << endl; n             return 0; n           } n         } n         now = now + d; n         if (!(0 <= (now) && (now) < (N))) { n           d *= -1; n           now += 2 * d; n         } n         sum += interval[min(now, now - d)]; n         if (ma[now] == 0) break; n         ma[now]--; n         if (ma[now] == 0) ma.erase(now); n       } n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int G[100010]; n int A[1000]; n int g(int q) { n   int n = 2, m, i, g, t, nn; n   memset(A, 0, sizeof(A)); n   n = 2; n   nn = -1; n   while (q >= n * (n + 1) / 2) { n     m = q - n * (n + 1) / 2; n     if (m % n != 0) { n       n++; n       continue; n     } n     m /= n; n     t = 0; n     for (i = m + 1; i < m + n + 1; i++) { n       t ^= G[i]; n     } n     A[t] = 1; n     if ((t == 0) && (nn == -1)) nn = n; n     n++; n   } n   for (i = 0; i < 1000; i++) n     if (A[i] == 0) break; n   G[q] = i; n   return nn; n } n int main() { n   int i, n, k, j, d; n   memset(G, 0xFF, sizeof(G)); n   scanf( %d , &n); n   for (i = 0; i < n; i++) g(i); n   printf( %d n , g(n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 15; n int cc[N]; n long long sum[N]; n long long getSeg(int pos, int p, int x, int y) { n   int last = pos + p - 1; n   int t = x / y; n   int ed = max(pos, last - t); n   long long ret = (long long)(cc[ed] - cc[pos]) * x; n   long long tot = (long long)(cc[last] - cc[ed]); n   long long u = pos + p; n   tot *= u; n   long long totSum = sum[last] - sum[ed]; n   ret += (tot - totSum) * y; n   return ret; n } n bool isPrime[N]; n void solve() { n   int n, x, y; n   scanf( %d%d%d , &n, &x, &y); n   for (int i = 0; i < n; ++i) { n     int a; n     scanf( %d , &a); n     ++cc[a]; n     sum[a] += a; n   } n   for (int i = 1; i < N; ++i) { n     cc[i] += cc[i - 1]; n     sum[i] += sum[i - 1]; n   } n   for (int i = 2; i < N; ++i) { n     if (!isPrime[i]) { n       for (int j = i + i; j < N; j += i) isPrime[j] = true; n     } n   } n   long long ret = 1e18; n   for (int i = 2; i <= 1e6; ++i) { n     if (isPrime[i]) continue; n     long long tot = 0; n     for (int pos = 0; pos <= 1e6; pos += i) { n       tot += getSeg(pos, i, x, y); n     } n     ret = min(ret, tot); n   } n   cout << ret << endl; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void Max(T &a, T b) { n   if (b > a) a = b; n } n template <class T> n void Min(T &a, T b) { n   if (b < a) a = b; n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = (3), _t = (n + 1); i < _t; ++i) { n     ans += (i - 1) * i; n   } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n #define __fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) n #define MOD 1000000007 n using namespace std; n   n typedef long long int ll; n   n   n int tc; n   n void solve() n { n     int n,w,x; n     multiset<int>st; n     vector<int>r; n     cin>>n>>w; n     for(int i=0; i<n; i++){ n         cin>>x; n         r.push_back(x); n     } n     sort(r.rbegin(),r.rend()); n   n     int h=0; n     for(int i=0; i<n; i++){ n         if(!st.empty() && r[i]<= *(st.rbegin()) ){ n             x=*(st.rbegin()); n             st.erase( st.lower_bound(x) ); n             x-=r[i]; n             if(x>0)st.insert(x); n         } n         else{ n             h++; n             if(w-r[i]>0)st.insert(w-r[i]); n         } n     } n     cout<<h<<endl; n } n   n int main() n { n   n     __fastIO; n   n     cin>>tc; while(tc--)solve(); n   n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int x[10], p[50], dp[200][200]; n int pp[50], q[50]; n int n, k; n int maxi; n double suma; n int nm = 0; n void check(int a, int b, int c, int d) { n   nm++; n   for (int i = 1; i <= n; i++) p[i] = x[i]; n   int br = q[a]; n   for (int j = pp[a]; j <= ((q[a] + pp[a]) >> 1); j++) { n     int pom = p[j]; n     p[j] = p[br]; n     p[br] = pom; n     br--; n   } n   if (b > 0) { n     int br = q[b]; n     for (int j = pp[b]; j <= ((q[b] + pp[b]) >> 1); j++) { n       int pom = p[j]; n       p[j] = p[br]; n       p[br] = pom; n       br--; n     } n   } n   if (c > 0) { n     int br = q[c]; n     for (int j = pp[c]; j <= ((q[c] + pp[c]) >> 1); j++) { n       int pom = p[j]; n       p[j] = p[br]; n       p[br] = pom; n       br--; n     } n   } n   if (d > 0) { n     int br = q[d]; n     for (int j = pp[d]; j <= ((q[d] + pp[d]) >> 1); j++) { n       int pom = p[j]; n       p[j] = p[br]; n       p[br] = pom; n       br--; n     } n   } n   int cnt = 0; n   for (int j = 1; j <= n; j++) n     for (int f = (j + 1); f <= n; f++) n       if (p[j] > p[f]) cnt++; n   suma = suma + cnt; n } n int main() { n   srand(0); n   scanf( %d%d , &n, &k); n   suma = 0.0; n   maxi = n * (n + 1) / 2; n   int pom = maxi; n   for (int i = 2; i <= 4; i++) { n     if (k < i) break; n     pom = pom * maxi; n   } n   maxi = pom; n   for (int i = 1; i <= n; i++) scanf( %d , &x[i]); n   int cnt = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) n       if (x[i] > x[j]) cnt++; n   int i, j, i1, i2, j1, j2; n   int br = 0; n   for (i = 1; i <= n; i++) n     for (j = i; j <= n; j++) { n       pp[++br] = i; n       q[br] = j; n     } n   int ppp = 0; n   for (i = 1; i <= br; i++) { n     if (k == 1) { n       check(i, 0, 0, 0); n       continue; n     } n     for (j = 1; j <= br; j++) { n       if (k == 2) { n         check(i, j, 0, 0); n         continue; n       } n       for (i1 = 1; i1 <= br; i1++) { n         if (k == 3) { n           check(i, j, i1, 0); n           continue; n         } n         for (i2 = 1; i2 <= br; i2++) { n           check(i, j, i1, i2); n           ppp++; n         } n       } n     } n   } n   suma = suma / maxi; n   printf( %.11lf n , suma); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:512000000 ) n using namespace std; n void solve(bool); n void precalc(); n clock_t start; n int main() { n   start = clock(); n   int t = 1; n   cout.sync_with_stdio(0); n   cin.tie(0); n   precalc(); n   cout.precision(10); n   cout << fixed; n   int testNum = 1; n   while (t--) { n     solve(true); n   } n   cout.flush(); n   return 0; n } n template <typename T> n T binpow(T q, T w, T mod) { n   if (!w) return 1 % mod; n   if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod; n   return binpow(q * 1LL * q % mod, w / 2, mod); n } n template <typename T> n T gcd(T q, T w) { n   while (w) { n     q %= w; n     swap(q, w); n   } n   return q; n } n template <typename T> n T lcm(T q, T w) { n   return q / gcd(q, w) * w; n } n template <typename T> n void make_unique(vector<T>& a) { n   sort(a.begin(), a.end()); n   a.erase(unique(a.begin(), a.end()), a.end()); n } n template <typename T> n void relax_min(T& cur, T val) { n   cur = min(cur, val); n } n template <typename T> n void relax_max(T& cur, T val) { n   cur = max(cur, val); n } n void precalc() {} n void solve(bool read) { n   long long n, Q; n   cin >> n >> Q; n   while (Q--) { n     long long x; n     cin >> x; n     --x; n     long long cur_n = n; n     long long pref = 0; n     long long steps = 0; n     bool printed = false; n     while (x % 2 != steps) { n       if (cur_n == 1) { n         cout << pref + 1 <<   n ; n         printed = true; n         break; n       } n       long long dec = (cur_n + 1 - steps) / 2; n       pref += dec; n       steps = steps + 2 * (dec - 1) == cur_n - 1; n       cur_n -= dec; n       x /= 2; n     } n     if (!printed) { n       cout << pref + (x - steps) / 2 + 1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[102][102] = {0}; n int main() { n   int n, m, a, b, sum = -1, minsum = -1; n   scanf( %d%d , &n, &m); n   int cost[n + 1]; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &cost[i]); n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &a, &b); n     arr[a][b] = arr[b][a] = 1; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       for (int k = 1; k <= n; k++) { n         if (sum == -1 && j != k && i != j && j != k && arr[i][j] == 1 && n             arr[j][k] == 1 && arr[k][i] == 1) n           minsum = sum = cost[i] + cost[j] + cost[k]; n         else if (j != k && i != j && j != k && arr[i][j] == 1 && n                  arr[j][k] == 1 && arr[k][i] == 1) { n           sum = cost[i] + cost[j] + cost[k]; n           if (minsum > sum) minsum = sum; n         } n       } n     } n   } n   printf( %d n , minsum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = (int)1e6; n long long n, m, a; n int main() { n   cin >> a; n   if (a == 1) { n     cout <<  1 1  n 1 ; n     return 0; n   } n   cout << (a - 1) * 2 <<     << 2 <<   n ; n   cout <<  1 2 ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   bool bracket, flag; n   vector<int> op; n }; n map<string, node> def; n map<char, int> op; n void del_space(string tmp) { n   int x = tmp.find_first_not_of(   ); n   tmp.erase(0, x); n   x = tmp.find_last_not_of(   ); n   tmp.erase(x + 1, tmp.length()); n   string s =   ; n   for (int i = 0; i < tmp.length(); i++) { n     if (tmp[i] !=    ) { n       s += tmp[i]; n     } else { n       if (tmp[i + 1] !=    ) s += tmp[i]; n     } n   } n   x = s.find( define ) + 7; n   int y = x; n   while (s[y] !=    ) y++; n   string s1, s2; n   s1.append(s.begin() + x, s.begin() + y); n   for (int i = y + 1; i < s.length(); i++) { n     if (s[i] !=    ) s2 += s[i]; n   } n   node tmp_node; n   tmp_node.flag = 0; n   int cnt = 0; n   for (int i = 0; i < s2.length(); i++) { n     if (s2[i] ==  ( ) cnt++; n     if (s2[i] ==  ) ) cnt--; n     if (op[s2[i]] && cnt == 0) { n       tmp_node.op.push_back(op[s2[i]]); n     } n   } n   for (int i = 0; i < s2.length(); i++) { n     if (s2[i] ==  *  || s2[i] ==  / ) { n       string ss1, ss2; n       bool bracket = 0; n       if (s2[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) { n         ss1 += s2[j]; n       } n       map<string, node>::iterator it = def.find(ss1); n       if (it != def.end()) { n         bracket = bracket | def[ss1].bracket; n         if (def[ss1].flag == 1) { n           tmp_node.flag = 1; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[ss1].op.size(); k++) { n             if (def[ss1].op[k] == 1 || def[ss1].op[k] == 2) { n               tmp_node.flag = 1; n             } n           } n         } n       } n       bracket = 0; n       for (int j = i - 1; s2[j] !=  (  && !op[s2[j]] && j >= 0; j--) { n         ss2 += s2[j]; n       } n       reverse(ss2.begin(), ss2.end()); n       it = def.find(ss2); n       if (it != def.end()) { n         bracket = bracket | def[ss2].bracket; n         if (def[ss2].flag == 1) { n           tmp_node.flag = 1; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[ss2].op.size(); k++) { n             if (def[ss2].op[k] == 1 || def[ss2].op[k] == 2) { n               tmp_node.flag = 1; n             } n           } n         } n       } n     } n     if (s2[i] ==  - ) { n       string ss1; n       bool bracket = 0; n       if (s2[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) { n         ss1 += s2[j]; n       } n       map<string, node>::iterator it = def.find(ss1); n       if (it != def.end()) { n         bracket = bracket | def[ss1].bracket; n         if (def[ss1].flag == 1) { n           tmp_node.flag = 1; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[ss1].op.size(); k++) { n             if (def[ss1].op[k] == 1 || def[ss1].op[k] == 2) { n               tmp_node.flag = 1; n             } n           } n         } n       } n     } n     if (s2[i] ==  / ) { n       string ss1; n       bool bracket = 0; n       if (s2[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; s2[j] !=  )  && !op[s2[j]] && j < s2.length(); j++) { n         ss1 += s2[j]; n       } n       map<string, node>::iterator it = def.find(ss1); n       if (it != def.end()) { n         bracket = bracket | def[ss1].bracket; n         if (def[ss1].flag == 1 || (bracket == 0 && !def[ss1].op.empty())) { n           tmp_node.flag = 1; n         } n       } n     } n   } n   tmp_node.bracket = 1; n   cnt = 0; n   if (s2[0] ==  ( ) cnt++; n   for (int i = 1; i < s2.length() - 1; i++) { n     if (s2[i] ==  ( ) cnt++; n     if (s2[i] ==  ) ) cnt--; n     if (cnt == 0) tmp_node.bracket = 0; n   } n   def[s1] = tmp_node; n } n int main() { n   op[ + ] = 1; n   op[ - ] = 2; n   op[ * ] = 3; n   op[ / ] = 4; n   int n, flag = 1; n   cin >> n; n   getchar(); n   while (n--) { n     string tmp; n     getline(cin, tmp); n     del_space(tmp); n   } n   string tmp, exp; n   getline(cin, tmp); n   int x = tmp.find_first_not_of(   ); n   tmp.erase(0, x); n   x = tmp.find_last_not_of(   ); n   tmp.erase(x + 1, tmp.length()); n   for (int i = 0; i < tmp.length(); i++) { n     if (tmp[i] !=    ) { n       exp += tmp[i]; n     } n   } n   for (map<string, node>::iterator it = def.begin(); it != def.end(); ++it) { n     if (exp.find(it->first) != string::npos && it->second.flag == 1) { n       cout <<  Suspicious  << endl; n       return 0; n     } n   } n   for (int i = 0; i < exp.length(); i++) { n     if (exp[i] ==  *  || exp[i] ==  / ) { n       string s1, s2; n       bool bracket = 0; n       if (exp[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length(); n            j++) { n         s1 += exp[j]; n       } n       map<string, node>::iterator it = def.find(s1); n       if (it != def.end()) { n         bracket = bracket | def[s1].bracket; n         if (def[s1].flag == 1) { n           cout <<  Suspicious  << endl; n           return 0; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[s1].op.size(); k++) { n             if (def[s1].op[k] == 1 || def[s1].op[k] == 2) { n               cout <<  Suspicious  << endl; n               return 0; n             } n           } n         } n       } n       bracket = 0; n       for (int j = i - 1; exp[j] !=  (  && !op[exp[j]] && j >= 0; j--) { n         s2 += exp[j]; n       } n       reverse(s2.begin(), s2.end()); n       it = def.find(s2); n       if (it != def.end()) { n         bracket = bracket | def[s2].bracket; n         if (def[s2].flag == 1) { n           cout <<  Suspicious  << endl; n           return 0; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[s2].op.size(); k++) { n             if (def[s2].op[k] == 1 || def[s2].op[k] == 2) { n               cout <<  Suspicious  << endl; n               return 0; n             } n           } n         } n       } n     } n     if (exp[i] ==  - ) { n       string s1; n       bool bracket = 0; n       if (exp[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length(); n            j++) { n         s1 += exp[j]; n       } n       map<string, node>::iterator it = def.find(s1); n       if (it != def.end()) { n         bracket = bracket | def[s1].bracket; n         if (def[s1].flag == 1) { n           cout <<  Suspicious  << endl; n           return 0; n         } n         if (bracket == 0) { n           for (int k = 0; k < def[s1].op.size(); k++) { n             if (def[s1].op[k] == 1 || def[s1].op[k] == 2) { n               cout <<  Suspicious  << endl; n               return 0; n             } n           } n         } n       } n     } n     if (exp[i] ==  / ) { n       string s1; n       bool bracket = 0; n       if (exp[i + 1] ==  ( ) bracket = 1; n       for (int j = i + 1; exp[j] !=  )  && !op[exp[j]] && j < exp.length(); n            j++) { n         s1 += exp[j]; n       } n       map<string, node>::iterator it = def.find(s1); n       if (it != def.end()) { n         bracket = bracket | def[s1].bracket; n         if (def[s1].flag == 1 || (bracket == 0 && !def[s1].op.empty())) { n           cout <<  Suspicious  << endl; n           return 0; n         } n       } n     } n   } n   cout <<  OK  << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int MOD = 1000000007; n int dp[1001][1001]; n int main() { n   int k; n   cin >> k; n   int balls[1000]; n   int n = 0; n   for (int i = 0; i < k; i++) { n     cin >> balls[i]; n     n += balls[i]; n   } n   long long l = 1; n   for (int i = 0; i <= n; i++) { n     dp[i][0] = 1; n     dp[i][i] = 1; n     for (int j = 1; j <= i; j++) { n       dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD; n     } n   } n   long long ans = 1; n   int cur = balls[0]; n   for (int i = 1; i < k; i++) { n     cur += balls[i]; n     ans = ((ans % MOD) * (dp[cur - 1][balls[i] - 1]) % MOD) % MOD; n   } n   cout << ans << endl; n   return 0; n } n