#include <bits/stdc++.h> n using namespace std; n inline char nc() { n   return getchar(); n   static char buf[100000], *l = buf, *r = buf; n   return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) n              ? EOF n              : *l++; n } n template <class T> n void read(T &x) { n   x = 0; n   int f = 1, ch = nc(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = nc(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 -  0  + ch; n     ch = nc(); n   } n   x *= f; n } n const int inf = 1e9 + 1; n const int maxn = 100 + 5; n const int maxs = 1e5 + 5; n const int maxb = 1e5 + 5; n int n, m; n int s, b, k; n int st, ed; n int val[maxn]; n int dis[maxn][maxn]; n int head[maxs]; n vector<int> adj[maxn]; n struct data { n   int a, b, c, d, id; n   inline bool operator<(const data &other) const { return b < other.b; } n } A[maxs], B[maxb]; n struct edge { n   int to, nex; n   long long cap, flow; n   edge(int to = 0, int nex = 0, long long cap = 0, long long flow = 0) n       : to(to), nex(nex), cap(cap), flow(flow) {} n }; n vector<edge> G; n inline void adde(int u, int v) { n   adj[u].push_back(v); n   adj[v].push_back(u); n } n inline void addedge(int u, int v, long long c) { n   G.push_back(edge(v, head[u], c, 0)), head[u] = G.size() - 1; n   G.push_back(edge(u, head[v], 0, 0)), head[v] = G.size() - 1; n } n namespace dinic { n int dis[maxs], cur[maxs]; n bool BFS() { n   static int q[maxs]; n   int hd = 0, tl = 0; n   memset(dis, -1, sizeof(dis)); n   dis[st] = 0; n   q[tl++] = st; n   while (hd < tl) { n     int u = q[hd++]; n     for (int i = head[u]; ~i; i = G[i].nex) { n       int v = G[i].to; n       if (dis[v] == -1 && G[i].cap != G[i].flow) { n         dis[v] = dis[u] + 1; n         q[tl++] = v; n       } n     } n   } n   return dis[ed] != -1; n } n long long DFS(int u, long long flow) { n   if (u == ed || flow == 0) return flow; n   long long rec = flow; n   for (int &i = cur[u]; ~i; i = G[i].nex) { n     int v = G[i].to; n     if (dis[v] == dis[u] + 1) { n       long long d = DFS(v, min(flow, G[i].cap - G[i].flow)); n       G[i].flow += d; n       G[i ^ 1].flow -= d; n       flow -= d; n       if (flow == 0) break; n     } n   } n   return rec - flow; n } n long long maxflow() { n   long long flow = 0; n   while (BFS()) { n     memcpy(cur, head, sizeof(head)); n     flow += DFS(st, 1e18); n   } n   return flow; n } n }  // namespace dinic n int adde(int x) { n   int mx = -1; n   for (int i = 1; i <= n; ++i) n     if (dis[A[x].a][i] <= A[x].c) { n       mx = max(mx, val[i]); n     } n   if (mx == -1) { n     addedge(A[x].id, ed, 1e18); n     return 0; n   } n   mx -= A[x].d; n   if (mx < 0) { n     addedge(A[x].id, ed, -mx); n     return 0; n   } n   addedge(st, A[x].id, mx); n   return mx; n } n void BFS(int st) { n   static int q[maxn]; n   int hd = 0, tl = 0; n   for (int i = 1; i <= n; ++i) dis[st][i] = inf; n   dis[st][st] = 0; n   q[tl++] = st; n   while (hd < tl) { n     int u = q[hd++]; n     for (unsigned int i = 0; i < adj[u].size(); ++i) { n       int v = adj[u][i]; n       if (dis[st][v] == inf) { n         dis[st][v] = dis[st][u] + 1; n         q[tl++] = v; n       } n     } n   } n } n void init() { n   for (int i = 1; i <= n; ++i) BFS(i); n } n long long solve() { n   init(); n   sort(A + 1, A + s + 1); n   sort(B + 1, B + b + 1); n   long long an = 0; n   int i = 1, j = 1; n   st = 0, ed = s + 1; n   memset(val, -1, sizeof(val)); n   while (i <= s && j <= b) { n     if (B[j].b <= A[i].b) { n       val[B[j].a] = max(val[B[j].a], B[j].c); n       ++j; n     } else { n       an += adde(i++); n     } n   } n   while (i <= s) an += adde(i++); n   return an - dinic ::maxflow(); n } n int main() { n   read(n), read(m); n   for (int i = 1; i <= m; ++i) { n     int u, v; n     read(u), read(v); n     adde(u, v); n   } n   read(s), read(b), read(k); n   for (int i = 1; i <= s; ++i) { n     read(A[i].a), read(A[i].b), read(A[i].c), read(A[i].d); n     A[i].id = i; n   } n   for (int i = 1; i <= b; ++i) { n     read(B[i].a), read(B[i].b), read(B[i].c); n   } n   memset(head, -1, sizeof(head)); n   for (int i = 1; i <= k; ++i) { n     int s1, s2; n     read(s1), read(s2); n     addedge(s1, s2, 1e18); n   } n   printf( %I64d n , solve()); n   return 0; n } n


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


#include <bits/stdc++.h> n const int maxn = 1005; n int p[maxn], d[maxn], l[maxn][2], nl, ti; n int main() { n   int n, h, r, c; n   scanf( %d%d%d , &n, &h, &r); n   for (int i = 0; i != n; ++i) scanf( %d%d , p + i, d + i); n   c = h; n   while (true) { n     c += r; n     if (c > h) c = h; n     if (c <= 0) break; n     int t = 0, pos = -1; n     for (int i = 0; i != n; ++i) n       if (c * 100 <= h * p[i] && t < d[i]) t = d[i], pos = i + 1; n     if (~pos) { n       r -= t; n       l[nl][0] = ti; n       l[nl++][1] = pos; n       d[pos - 1] = -1; n     } else if (r >= 0) { n       puts( NO ); n       return 0; n     } n     ti++; n   } n   puts( YES ); n   printf( %d %d n , ti, nl); n   for (int i = 0; i != nl; ++i) printf( %d %d n , l[i][0], l[i][1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string p, z; n   cin >> p; n   cin >> z; n   for (int i = 0; i < p.length(); i++) { n     if (p[i] >=  A  && p[i] <=  Z ) p[i] = tolower(p[i]); n   } n   for (int i = 0; i < z.length(); i++) { n     if (z[i] >=  A  && z[i] <=  Z ) z[i] = tolower(z[i]); n   } n   cout << p.compare(z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Edge { n   int src, dst; n   int weight; n   Edge(int src, int dst, int weight) : src(src), dst(dst), weight(weight) {} n }; n bool operator<(const Edge &e, const Edge &f) { n   return e.weight != f.weight ? e.weight > f.weight n          : e.src != f.src     ? e.src < f.src n                               : e.dst < f.dst; n } n const int MAXN = 100000; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 0) { n     cout << -1 << endl; n   } else { n     for (int i = 0; i < (int)n - 1; ++i) cout << i <<    ; n     cout << n - 1 << endl; n     for (int i = 0; i < (int)n - 1; ++i) cout << i + 1 <<    ; n     cout << 0 << endl; n     for (int i = 0; i < (int)n - 1; ++i) cout << (i + i + 1) % n <<    ; n     cout << n - 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n void setIn(string s) { freopen(s.c_str(),  r , stdin); } n void setOut(string s) { freopen(s.c_str(),  w , stdout); } n void setIO(string s =   ) { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin.exceptions(cin.failbit); n   if (s.size()) { n     setIn(s +  .inp ); n     setOut(s +  .out ); n   } else { n   } n } n }  // namespace IO n using namespace IO; n namespace Function { n template <typename T1, typename T2> n void amax(T1 &a, T2 b) { n   if (typeid(a).name() == typeid(int).name() && n       typeid(b).name() == typeid(long long).name()) { n     cout <<  Error on amax ; n     exit(0); n   } n   if (a < b) a = b; n } n template <typename T1, typename T2> n void amin(T1 &a, T2 b) { n   if (a > b) a = b; n } n template <typename T> n void compress(vector<T> &a) { n   sort(a.begin(), a.end()); n   a.resize(unique(a.begin(), a.end()) - a.begin()); n } n template <typename T> n int get_it(vector<T> a, T b) { n   return lower_bound(a.begin(), a.end(), b) - a.begin(); n } n template <typename T1, typename T2> n long long gcd(T1 a, T2 b) { n   return (b == 0 ? a : gcd(b, a % b)); n } n template <typename T1, typename T2> n long long lcm(T1 a, T2 b) { n   return 1LL * a / gcd(a, b) * b; n } n }  // namespace Function n using namespace Function; n namespace Output { n void print(int x) { cout << x <<   n ; } n void print(unsigned int x) { cout << x <<   n ; } n void print(long unsigned int x) { cout << x <<   n ; } n void print(long long x) { cout << x <<   n ; } n void print(unsigned long long x) { cout << x <<   n ; } n void print(float x) { cout << x <<   n ; } n void print(double x) { cout << x <<   n ; } n void print(long double x) { cout << x <<   n ; } n void print(char x) { cout << x <<   n ; } n void print(const char *x) { cout << x <<   n ; } n void print(string x) { cout << x <<   n ; } n void print(bool x) { cout << (x ?  True  :  False ) <<   n ; } n template <typename T1, typename T2> n void print(pair<T1, T2> a) { n   cout << a.first <<     << a.second <<   n ; n } n template <typename T> n void print(T a) { n   for (auto it : a) { n     print(it); n   } n } n template <class T, class... Ts> n void print(T t, Ts... ts) { n   cout << t <<    ; n   print(ts...); n } n template <typename T> n void prine(T x) { n   print(x); n   exit(0); n } n template <class T, class... Ts> n void prine(T t, Ts... ts) { n   print(t, ts...); n   exit(0); n } n }  // namespace Output n using namespace Output; n const int dx[] = {1, -1, 0, 0}; n const int dy[] = {0, 0, 1, -1}; n const int INF = 1e9; n const int MOD = 1e9 + 7; n const int N = 1e5 + 10; n int lab[N], n, m, c[N]; n int Get(int u) { n   while (lab[u] > 0) u = lab[u]; n   return u; n } n void Union(int u, int v) { n   if (lab[u] > lab[v]) swap(u, v); n   lab[u] += lab[v]; n   lab[v] = u; n } n struct Data { n   int u, v, w; n }; n bool comp(Data A, Data B) { return A.w > B.w; } n vector<Data> E; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> c[i]; n   for (int i = 1; i <= m; i++) { n     int u, v; n     cin >> u >> v; n     E.push_back({u, v, min(c[u], c[v])}); n   } n   sort(E.begin(), E.end(), comp); n   long long sum = 0; n   for (int i = 1; i <= n; i++) lab[i] = -1; n   for (Data X : E) { n     int u = X.u; n     int v = X.v; n     int w = X.w; n     int x = Get(u); n     int y = Get(v); n     if (x == y) continue; n     sum += 1ll * w * lab[x] * lab[y]; n     Union(x, y); n   } n   sum *= 2; n   cout << fixed << setprecision(5) << 1.00 * sum / (1ll * n * (n - 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int b[1000005], a[40]; n int main() { n   int n, m, d; n   cin >> n >> m; n   for (int(i) = (0); (i) < (n); (i)++) { n     scanf( %d , &d); n     int j = 0; n     while (d) a[j++] += d & 1, d /= 2; n   } n   for (int(i) = (0); (i) < (m); (i)++) scanf( %d , &b[i]); n   sort(b, b + m); n   for (int(i) = (0); (i) < (m); (i)++) { n     int j = b[i]; n     while (j < 32 && !a[j]) a[j++] = 1; n     if (j == 32) { n       cout << i << endl; n       return 0; n     } n     a[j]--; n   } n   cout << m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX_N = 10 * 100 + 19; n const long long inf = 2e9 + 19; n long long n; n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   cout << 1ll * ((n + 1) / 2) * (n / 2) << endl; n   for (long long i = 1; i <= n; i++) n     for (long long j = i + 1; j <= n; j++) n       if ((i & 1) != (j & 1)) cout << i <<     << j << endl; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, k, n, m, ans = 0; n   cin >> n >> m >> k; n   ans = n + m + k; n   cout << min(ans / 3, ans - max(n, max(m, k))); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXSIZE = 2001; n const long long BASE = 1000000007; n int n, m; n long long dp[MAXSIZE + 1][MAXSIZE + 1]; n long long sum[MAXSIZE + 1][MAXSIZE + 1]; n int main() { n   scanf( %d%d , &n, &m); n   for (int l = 1; l < m; l++) dp[1][l] = 1; n   for (int i = 2; i <= n; i++) { n     long long sum = 0; n     for (int j = 1; j < m; j++) { n       sum += (dp[i - 1][j]) % BASE; n       dp[i][j] = (dp[i][j - 1] + sum) % BASE; n     } n   } n   for (int j = 1; j < m; j++) n     for (int t = n - 1; t >= 1; t--) n       sum[n - t][j] = (sum[n - t - 1][j] + dp[n - t][j]) % BASE; n   long long ANS = 0; n   for (int t = 1; t <= n; t++) { n     for (int j = 1; j < m; j++) { n       long long count = sum[n - t][j] + dp[n - t + 1][j]; n       count %= BASE; n       count = (count * (m - j)) % BASE; n       ANS = (ANS + dp[t][j] * count) % BASE; n     } n   } n   printf( %I64d , ANS); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int inf = 1e9 + 5; n void umin(int& a, int b) { a = min(a, b); } n void umax(int& a, int b) { a = max(a, b); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<array<int, 2>> a(n); n   for (auto& ai : a) { n     string s; n     cin >> s; n     for (char c : s) ai[c ==  N ]++; n   } n   int min_x = inf, min_y = inf, min_xy = inf; n   int max_x = -inf, max_y = -inf, max_xy = -inf; n   for (const auto& ai : a) { n     umin(min_x, ai[0]); n     umin(min_y, ai[1]); n     umin(min_xy, ai[0] - ai[1]); n     umax(max_x, ai[0]); n     umax(max_y, ai[1]); n     umax(max_xy, ai[0] - ai[1]); n   } n   auto checkAns = [&](int m) -> pair<int, int> { n     int min_x2 = min_x + m; n     int min_y2 = min_y + m; n     int min_xy2 = min_xy + m; n     int max_x2 = max(0, max_x - m); n     int max_y2 = max(0, max_y - m); n     int max_xy2 = max_xy - m; n     if (min_x2 >= max_x2 && min_y2 >= max_y2 && min_xy2 >= max_xy2) { n       for (int x : {min_x2, max_x2}) { n         for (int xy : {min_xy2, max_xy2}) { n           int y = x - xy; n           if (max_y2 <= y && y <= min_y2 && y >= 0 && x + y > 0) return {x, y}; n         } n       } n       for (int y : {min_y2, max_y2}) { n         for (int xy : {min_xy2, max_xy2}) { n           int x = y + xy; n           if (max_x2 <= x && x <= min_x2 && x >= 0 && x + y > 0) return {x, y}; n         } n       } n     } n     return {-1, -1}; n   }; n   int l = 0, r = 1e6, dist = -1; n   pair<int, int> ans = {-1, -1}; n   while (l < r) { n     int m = (l + r) / 2; n     pair<int, int> ret = checkAns(m); n     if (ret.first != -1) { n       r = m; n       dist = m; n       ans = ret; n     } else { n       l = m + 1; n     } n   } n   cout << dist <<   n ; n   cout << string(ans.first,  B ) << string(ans.second,  N ) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using std::vector; n bool judge(int x) { n   for (int i = 0; i < 31; i++) { n     if (x == (1 << i) - 1) return true; n   } n   return false; n } n int get_hzero(int x) { n   int res = 0, pre = 0; n   for (int i = 0; i < 31; i++) { n     if (x & (1 << i)) n       res = pre; n     else n       pre = i; n   } n   return res; n } n int main() { n   int x; n   while (~scanf( %d , &x)) { n     int bit[100]; n     int ans = 0; n     vector<int> vec; n     while (!judge(x)) { n       int num = get_hzero(x) + 1; n       vec.push_back(num); n       x ^= (1 << num) - 1; n       ans++; n       if (!judge(x)) x += 1, ans++; n     } n     printf( %d n , ans); n     for (int i = 0; i < vec.size(); i++) n       printf( %d%c , vec[i],    n [i == vec.size() - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n inline int in() { n   int x = 0; n   char c = getchar(); n   bool f = false; n   while (c <  0  || c >  9 ) f |= c ==  - , c = getchar(); n   while (c >=  0  && c <=  9 ) n     x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   return f ? -x : x; n } n const int N = 105; n int t[N], f[N * N][N], tot; n int main() { n   int n = in(), res = 1; n   for (int i = 1; i <= n; ++i) { n     int a = in(); n     if (!t[a]) ++tot; n     ++t[a]; n   } n   if (tot <= 2) { n     printf( %d n , n); n     return 0; n   } n   f[0][0] = 1; n   for (int i = 1; i <= 100; ++i) n     if (t[i]) { n       for (int j = 10000; j; --j) n         for (int k = 1; k <= n; ++k) n           for (int l = 1; l <= t[i] && l <= k && l * i <= j; ++l) n             f[j][k] += f[j - l * i][k - l]; n     } n   for (int i = 1; i <= 100; ++i) n     if (t[i]) n       for (int j = 1; j <= t[i]; ++j) n         if (f[i * j][j] == 1) res = std::max(res, j); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e6 + 10; n const int mod = 1e9 + 7; n int prime[N], pp, pri[N], ans = 1, p[N], n, cnt[N], mx[N]; n bool iscomp[N]; n void primetable() { n   for (int i = 2; i < N; i++) { n     if (!iscomp[i]) prime[pp++] = i, pri[i] = i; n     for (int j = 0; j < pp && 1ll * i * prime[j] < N; j++) { n       iscomp[i * prime[j]] = 1; n       pri[i * prime[j]] = prime[j]; n       if (i % prime[j] == 0) break; n     } n   } n } n int main() { n   primetable(); n   scanf( %d n , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &p[i]); n   sort(p + 1, p + n + 1); n   for (int i = n; i; i--) { n     if (!cnt[p[i]]) n       cnt[p[i]]++, mx[p[i]] = 1, ans = (1ll * ans * p[i]) % mod; n     else { n       int v = --p[i]; n       while (v != 1) { n         int u = pri[v], ci = 0; n         while (v % u == 0) v /= u, ci++; n         if (cnt[u] < ci) { n           for (int j = cnt[u] + 1; j <= ci; j++) ans = (1ll * ans * u) % mod; n           cnt[u] = ci; n           mx[u] = 1; n         } else n           mx[u] += (cnt[u] == ci); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     int v = p[i], flag = 0; n     while (v != 1) { n       int u = pri[v], ci = 0; n       while (v % u == 0) v /= u, ci++; n       if (cnt[u] == ci && mx[u] == 1) flag = 1; n     } n     if (!flag) { n       ans++; n       break; n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 100; n const int MAXT = 1e10 + 1000; n int N; n long long T; n const double EPS = 1e-12; n const double CHTLB = -1; n const double CHTUB = 1e20; n double V, t; n double pow(double b, long long p) { n   assert(p >= 0); n   if (p == 0) return 1; n   if (p == 1) return b; n   double r = static_cast<double>(1); n   for (; p; p >>= 1, b *= b) n     if (p & 1) r *= b; n   return r; n } n long long rlog2(long long v) { n   long long ret = 1; n   while (v >>= 1) ret++; n   return ret; n } n bool equ(const double& a, const double& b) { return abs(a - b) < EPS; } n bool Q; n double r[MAXN]; n struct Line { n  public: n   Line() { n     m = b = -1; n     id = -1; n   } n   Line(const double& a, const double& c) { n     m = a; n     b = c; n     id = -1; n   } n   Line(const long long& s) { n     m = b = -1; n     id = s; n   } n   Line(const double& a, const double& c, const int& s) { m = a, b = c, id = s; } n   double m; n   double b; n   int id; n   bool operator<(const Line& o) const { n     if (!Q) n       return o.m > m; n     else n       return r[o.id] > r[id]; n   } n   double operator()(const double& x) const { return m * x + b; } n   bool operator()(const double& x, const double& y) const { n     return equ((*this)(x), y); n   } n   pair<double, double> operator*(const Line& o) const { n     assert(!equ(m, o.m)); n     double x = (o.b - b) / (m - o.m); n     double y = (o.b * m - b * o.m) / (m - o.m); n     return make_pair(x, y); n   } n   bool keep(const Line& l, const Line& r) const { n     return (l * *this).first < (*this * r).first; n   } n }; n struct CHT { n  public: n   multiset<Line> lines; n   CHT() { Q = false; } n   void pout() { n     for (multiset<Line>::iterator it = lines.begin(); it != lines.end(); it++) { n       cerr << it->m <<  x +   << it->b <<  (  << it->id <<  ) up to   n            << r[it->id] <<   n ; n     } n   } n   bool insert(const Line& l) { n     if (lines.empty()) { n       r[l.id] = CHTUB; n       lines.insert(l); n       return true; n     } n     multiset<Line>::iterator c = lines.lower_bound(l); n     if (c != lines.end()) { n       if (equ(c->m, l.m)) { n         if (l.b > c->b) n           lines.erase(c); n         else n           return false; n       } n     } n     c = lines.insert(l); n     multiset<Line>::iterator p[2], n[2]; n     n[0] = c; n     p[0] = c; n     if (c != lines.begin() and ++n[0] != lines.end()) { n       --p[0]; n       if (!c->keep(*p[0], *n[0])) { n         lines.erase(c); n         return false; n       } n     } n     if (c == lines.begin()) { n     } else { n       p[0] = c, p[1] = --p[0]; n       while (p[0] != lines.begin()) { n         p[1]--; n         if (p[0]->keep(*p[1], *c)) { n           break; n         } else { n           lines.erase(p[0]); n           p[0] = p[1]; n         } n       } n       r[p[0]->id] = ((*p[0]) * (*c)).first; n     } n     n[0] = c, n[1] = ++n[0]; n     if (n[0] == lines.end()) { n       r[c->id] = CHTUB; n     } else { n       while (++n[1] != lines.end()) { n         if (n[0]->keep(*c, *n[1])) { n           break; n         } else { n           lines.erase(n[0]); n           n[0] = n[1]; n         } n       } n       r[c->id] = ((*n[0]) * (*c)).first; n     } n     return true; n   } n   double operator()(const double& x) const { n     assert(CHTLB < x and x < CHTUB); n     Q = true; n     multiset<Line>::iterator c = lines.lower_bound(x); n     Q = false; n     assert(c != lines.end()); n     return (*c)(x); n   } n } hull; n struct mat { n  public: n   vector<vector<double> > m; n  n  private: n   int L, W; n   void fix() { n     L = m.size(); n     W = m[0].size(); n   } n  n  public: n   void pout() { n     fix(); n     for (int l = 0; l < L; l++) { n       for (int w = 0; w < W; w++) { n         cerr << m[l][w] <<    ; n       } n       cerr <<   n ; n     } n     cerr <<   n ; n   } n   mat(const int& l = 1, const int& w = 1) { n     L = l, W = w; n     vector<double> r(W, 0); n     m = vector<vector<double> >(L, r); n     if (l == w) { n       for (int i = 0; i < l; i++) m[i][i] = 1; n     } n   } n   vector<double>& operator[](const int& r) { n     fix(); n     assert(0 <= r and r < L); n     return m[r]; n   } n   double& operator()(const int& r, const int& c) { n     fix(); n     assert(0 <= r and r < L); n     assert(0 <= c and c < W); n     return m[r][c]; n   } n   mat operator*(mat& o) { n     fix(); n     o.fix(); n     assert(W == o.L); n     mat ret(L, o.W); n     for (int l = 0; l < L; l++) { n       for (int c = 0; c < o.W; c++) { n         ret[l][c] = 0; n         for (int i = 0; i < W; i++) { n           ret[l][c] += m[l][i] * o.m[i][c]; n         } n       } n     } n     return ret; n   } n }; n int a[MAXN], b[MAXN]; n double p[MAXN]; n double dp; n long long ct; n mat st[500]; n long long next(double p, double a, double cut) { n   long long v = rlog2(T - ct); n   st[0].m = {{static_cast<double>(1) - p, p * V, p * a}, {0, 1, 1}, {0, 0, 1}}; n   for (int i = 1; i <= v; i++) { n     st[i] = st[i - 1] * st[i - 1]; n   } n   mat cm(3, 3); n   mat dpm(3, 1); n   dpm.m = {{dp}, {static_cast<double>(ct)}, {1}}; n   long long dt = 0; n   for (long long i = v; i >= 0; i--) { n     if (ct + dt + (1LL << i) > T) continue; n     mat cmt = cm * st[i]; n     if (V * (ct + dt + (1LL << i)) - (cmt * dpm)[0][0] > cut) n       ; n     else { n       cm = cmt; n       dt += (1LL << i); n       assert(equ(static_cast<double>(dt), cm[1][2])); n     } n   } n   mat rt = cm * dpm; n   assert(equ(static_cast<double>(ct + dt), rt[1][0])); n   if (dt + ct < T and V * (ct + dt) - rt[0][0] < cut) { n     dt++; n     rt = st[0] * rt; n   } n   dp = rt[0][0]; n   return dt + ct; n } n int main() { n   Q = false; n   cerr << setprecision(10); n   scanf( %d%lld , &N, &T); n   V = 0; n   for (int i = 0; i < N; i++) { n     scanf( %d%d%Lf , a + i, b + i, p + i); n     if ((t = b[i] * p[i]) > V) V = t; n   } n   for (int i = 0; i < N; i++) { n     hull.insert(Line(p[i], p[i] * a[i], i)); n   } n   ct = 0; n   dp = 0; n   for (auto path : hull.lines) { n     ct = next(p[path.id], a[path.id], r[path.id]); n     assert(ct <= T); n     if (ct == T) break; n   } n   printf( %.10Lg n , dp); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) n     for (int j = i; j <= n; j++) { n       int k = i ^ j; n       if (k >= j && k <= n && i + j > k && i + k > j && j + k > i) ans++; n     } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int va, num; n   bool operator<(const node &o) const { return va < o.va; } n } a[100005]; n int n, m, nub, lastnode, nextnode, now; n int mark[400005], mm; n int ans[400005], co; n vector<int> save[400005]; n void dfs(int h) { n   mark[h] = 1; n   for (int i = 0; i < save[h].size(); i++) { n     if (mark[save[h][i]] == 1) { n       mm = 1; n       return; n     } n     if (mark[save[h][i]] == 0) { n       dfs(save[h][i]); n     } n   } n   ans[co] = h; n   co++; n   mark[h] = 2; n } n int main() { n   scanf( %d %d , &n, &m); n   nub = m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       scanf( %d , &a[j].va); n       a[j].num = j; n     } n     sort(&a[0], &a[m]); n     lastnode = -1; n     for (int j = 0; j < m; j++) { n       if (a[j].va == -1) continue; n       nub++; n       nextnode = nub; n       now = a[j].va; n       while (j < m && a[j].va == now) { n         if (lastnode != -1) { n           save[lastnode].push_back(a[j].num); n         } n         save[a[j].num].push_back(nextnode); n         j++; n       } n       j--; n       lastnode = nextnode; n     } n   } n   for (int i = 0; i <= nub; i++) { n     if (!mark[i]) { n       dfs(i); n     } n   } n   if (mm) { n     printf( -1 n ); n   } else { n     for (int i = co - 1; i >= 0; i--) { n       if (ans[i] < m) { n         printf( %d  , ans[i] + 1); n       } n     } n     printf(  n ); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     string s; n     int ans = 0; n     cin >> s; n     int curRow = 0, curCol = 0; n     map<pair<pair<int, int>, pair<int, int>>, bool> mp; n     for (int i = 0; i < s.size(); ++i) { n       int desRow, desCol; n       switch (s[i]) { n         case  N : n           desRow = curRow, desCol = curCol + 1; n           if (mp[{{curRow, curCol}, {desRow, desCol}}]) n             ++ans; n           else { n             mp[{{curRow, curCol}, {desRow, desCol}}] = true; n             mp[{{desRow, desCol}, {curRow, curCol}}] = true; n             ans += 5; n           } n           break; n         case  S : n           desRow = curRow, desCol = curCol - 1; n           if (mp[{{curRow, curCol}, {desRow, desCol}}]) n             ++ans; n           else { n             mp[{{curRow, curCol}, {desRow, desCol}}] = true; n             mp[{{desRow, desCol}, {curRow, curCol}}] = true; n             ans += 5; n           } n           break; n         case  E : n           desRow = curRow + 1, desCol = curCol; n           if (mp[{{curRow, curCol}, {desRow, desCol}}]) n             ++ans; n           else { n             mp[{{curRow, curCol}, {desRow, desCol}}] = true; n             mp[{{desRow, desCol}, {curRow, curCol}}] = true; n             ans += 5; n           } n           break; n         case  W : n           desRow = curRow - 1, desCol = curCol; n           if (mp[{{curRow, curCol}, {desRow, desCol}}]) n             ++ans; n           else { n             mp[{{curRow, curCol}, {desRow, desCol}}] = true; n             mp[{{desRow, desCol}, {curRow, curCol}}] = true; n             ans += 5; n           } n           break; n       } n       curRow = desRow, curCol = desCol; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int temp = 0, n; n   cin >> n; n   int arr[n]; n   bool b[n]; n   for (int j = 0; j < n; j++) { n     cin >> arr[j]; n     b[j] = false; n   } n   for (int i = n - 1; i >= 0; i--) { n     if (temp > 0) b[i] = true; n     temp--; n     temp = max(temp, arr[i]); n   } n   int ct = 0; n   for (int k = 0; k < n; k++) { n     if (!b[k]) ct++; n   } n   cout << ct << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int a[101], b[101], g[101][101]; n int main() { n   int i, j, n, k; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (i = 1; i <= n; i++) scanf( %d , &b[i]); n   memset(g, 0, sizeof(g)); n   for (i = 1; i <= n; i++) { n     if (i + b[i] <= n) g[i][i + b[i]] = g[i + b[i]][i] = 1; n     if (i - b[i] >= 1) g[i][i - b[i]] = g[i - b[i]][i] = 1; n   } n   for (k = 1; k <= n; k++) { n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         if (g[i][k] && g[k][j]) g[i][j] = 1; n       } n     } n   } n   bool flag = 1; n   for (i = 1; i <= n; i++) { n     if (i == a[i]) continue; n     if (g[i][a[i]] == 0) flag = 0; n     if (flag == 0) break; n   } n   if (flag) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int err; n int bitc(long long r) { return r == 0 ? 0 : (bitc(r >> 1) + (r & 1)); } n long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; } n string cts(char c) { n   string s =   ; n   s += c; n   return s; n } n char buf[1000000]; n string getLine() { n   string s; n   while (!feof(stdin)) { n     char c = fgetc(stdin); n     if (c == 13) continue; n     if (c == 10) return s; n     s += c; n   } n   return s; n } n int getNum() { n   string s = getLine(); n   return atoi(s.c_str()); n } n vector<int> parsevi(string s) { n   s = s +    ; n   int q = 0; n   bool minus = false; n   vector<int> res; n   for (typeof(0) l = (0); l < ((int(s.size()))); ++l) { n     if (s[l] ==    ) { n       res.push_back(minus ? -q : q); n       q = 0; n       minus = false; n     } else if (s[l] ==  - ) { n       minus = true; n     } else { n       q = q * 10 + s[l] -  0 ; n     } n   } n   return res; n } n int Cases, cnum; n int K; n int X, Y; n short bmp[1600][1600]; n int uds[1600][1600]; n int dfsres; n void dfs1(short x, short y) { n   if (bmp[y][x] != 1) return; n   bmp[y][x] = 0; n   dfs1(x - 1, y); n   dfs1(x + 1, y); n   dfs1(x, y - 1); n   dfs1(x, y + 1); n } n void dfs3(short x, short y) { n   if (bmp[y][x] == 0) return; n   if (bmp[y][x] == 1) { n     dfs1(x, y); n     dfsres++; n     return; n   } n   bmp[y][x] = 0; n   dfs3(x - 1, y); n   dfs3(x + 1, y); n   dfs3(x, y - 1); n   dfs3(x, y + 1); n } n void solveCase() { n   int res = 0; n   err = scanf( %d%d , &Y, &X); n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) { n       int b; n       err = scanf( %d , &b); n       bmp[y][x] = b; n     } n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(1) x = (1); x < (X); ++x) n       uds[y][x] = uds[y][x - 1] + bmp[y][x - 1]; n   for (typeof(1) y = (1); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) uds[y][x] = uds[y][x] + uds[y - 1][x]; n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) n       if (y == 0 || x == 0 || y == Y - 1 || x == X - 1) bmp[y][x] = 0; n   for (typeof(4) y = (4); y < (Y - 4); ++y) n     for (typeof(4) x = (4); x < (X - 4); ++x) { n       int tot = uds[y + 4][x + 4] - uds[y - 4][x + 4] - uds[y + 4][x - 4] + n                 uds[y - 4][x - 4]; n       if (tot == 64) bmp[y][x] = 2; n     } n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) uds[y][x] = (bmp[y][x] == 2) ? 1 : 0; n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(1) x = (1); x < (X); ++x) uds[y][x] = uds[y][x - 1] + uds[y][x]; n   for (typeof(1) y = (1); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) uds[y][x] = uds[y][x] + uds[y - 1][x]; n   for (typeof(6) y = (6); y < (Y - 6); ++y) n     for (typeof(6) x = (6); x < (X - 6); ++x) { n       int tot = uds[y + 6][x + 6] - uds[y - 6][x + 6] - uds[y + 6][x - 6] + n                 uds[y - 6][x - 6]; n       if (tot > 0) bmp[y][x] = 3; n     } n   vector<int> v; n   for (typeof(0) y = (0); y < (Y); ++y) n     for (typeof(0) x = (0); x < (X); ++x) n       if (bmp[y][x] == 3) { n         dfsres = 0; n         dfs3(x, y); n         v.push_back(dfsres); n       } n   if (0) n     for (typeof(0) y = (0); y < (Y); ++y) { n       for (typeof(0) x = (0); x < (X); ++x) printf( %d , bmp[y][x]); n       printf(  n ); n     } n   sort(v.begin(), v.end()); n   printf( %d n , (int(v.size()))); n   for (typeof(0) a = (0); a < ((int(v.size()))); ++a) n     printf( %d%c , v[a], a == (int(v.size())) - 1 ?   n  :    ); n } n int main() { n   if (1) n     Cases = 1; n   else if (0) { n     string Nstr = getLine(); n     Cases = atoi(Nstr.c_str()); n   } else { n     err = scanf( %d , &Cases); n   } n   for (cnum = 1; cnum <= Cases; cnum++) solveCase(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-7; n const long long int m = 1000000007; n void solve() { n   int n, m, r, c; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < s.length(); j++) { n       if (s[j] ==  B ) { n         r = i + 1 + count(s.begin(), s.end(),  B ) / 2; n         c = j + 1 + count(s.begin(), s.end(),  B ) / 2; n         cout << r <<     << c <<   n ; n         return; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int A[2][2]; n int main() { n   int d, i, n; n   cin >> n; n   int k = n; n   int cd = 0, ud = 0, c_i = 0, u_i = 0; n   while (k--) { n     cin >> i >> d; n     if (i == 0) n       c_i++; n     else n       u_i++; n     if (d == 0) n       cd++; n     else n       ud++; n   } n   cout << min(c_i, u_i) + min(cd, ud) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n vector<int> primes; n bool flag[100005]; n bool flag2[100005]; n void sieve(int n) { n   for (int i = 2; i <= n; i++) { n     if (!flag2[i]) { n       primes.push_back(i); n       for (int j = 2 * i; j <= n; j += i) { n         flag2[j] = true; n       } n     } n   } n   int sz = 0; n   for (int i = 1; i < primes.size(); i++) { n     v.push_back(primes[i]); n     sz++; n     for (int j = primes[i] * 3; j <= n; j += primes[i]) { n       if (!flag[j]) { n         v.push_back(j); n         sz++; n         flag[j] = true; n       } n     } n     if (sz % 2 == 1) { n       if (primes[i] * 2 <= n && !flag[primes[i] * 2]) { n         v.push_back(primes[i] * 2); n         sz++; n         flag[primes[i] * 2] = true; n       } else { n         flag[v[sz - 1]] = false; n         v.erase(v.begin() + sz - 1); n         sz--; n       } n     } n   } n   for (int i = 0; i < 1; i++) { n     for (int j = primes[i]; j <= n; j += primes[i]) { n       if (!flag[j]) { n         v.push_back(j); n         sz++; n         flag[j] = true; n       } n     } n     if (sz % 2 == 1) { n       flag[v[sz - 1]] = false; n       v.erase(v.begin() + sz - 1); n       sz--; n     } n   } n } n int main() { n   int n; n   scanf( %d , &n); n   if (n < 4) { n     printf( 0 n ); n     return 0; n   } n   sieve(n); n   printf( %d n , v.size() / 2); n   for (int i = 0; i < v.size(); i++) { n     printf( %d%s , v[i], (i & 1) ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int const INF = numeric_limits<int>::max(); n int const N = 1e5 + 5; n string a[N]; n int main() { n   ios::sync_with_stdio(false); n   vector<pair<int, int>> v; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     int m; n     cin >> m; n     for (int j = 0; j < m; j++) { n       int x; n       cin >> x; n       v.push_back({x - 1, i}); n     } n   } n   sort(v.begin(), v.end()); n   string ans; n   for (auto p : v) { n     if (p.first > ans.size()) { n       while (ans.size() < p.first) { n         ans.push_back( a ); n       } n     } n     if (a[p.second].size() + p.first > ans.size()) { n       int from = n           a[p.second].size() - (p.first - ans.size() + a[p.second].size()); n       ans.append(a[p.second].begin() + from, a[p.second].end()); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     string s; n     cin >> s; n     long long int a, b; n     cin >> a >> b; n     long long int n = s.length(); n     vector<long long int> v1(n, -1), v2(n, -1); n     long long int x = 0; n     for (long long int i = 0; i < n; i++) { n       if (i == 0) { n         v1[i] = (s[i] -  0 ) % a; n         continue; n       } n       v1[i] = (v1[i - 1] * 10 + (s[i] -  0 )) % a; n     } n     long long int base = 1; n     for (int i = n - 1; i >= 0; i--) { n       if (i == n - 1) { n         v2[i] = (s[i] -  0 ) % b; n       } else n         v2[i] = ((s[i] -  0 ) * base + v2[i + 1]) % b; n       base = (base * 10) % b; n     } n     long long int index = -1; n     for (long long int i = 0; i < n - 1; i++) { n       if (v1[i] == 0 && v2[i + 1] == 0 && s[i + 1] !=  0 ) { n         index = i; n         break; n       } n     } n     if (index == -1) n       cout <<  NO  << endl; n     else { n       cout <<  YES  << endl; n       cout << s.substr(0, index + 1) << endl n            << s.substr(index + 1, n - index - 1); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_SIZE = 200010; n pair<int, int> arr[MAX_SIZE], backup[MAX_SIZE]; n long long prefix[MAX_SIZE]; n int N; n void sortX(int l, int r) { n   if (l >= r) return; n   int mi = (l + r) / 2; n   sortX(l, mi); n   sortX(mi + 1, r); n   int i = l, j = mi + 1, k = l; n   while (i <= mi && j <= r) { n     if (arr[i] < arr[j]) { n       backup[k++] = arr[i++]; n     } else { n       backup[k++] = arr[j++]; n     } n   } n   while (i <= mi) { n     backup[k++] = arr[i++]; n   } n   while (j <= r) { n     backup[k++] = arr[j++]; n   } n   for (int i = l; i <= r; i++) { n     arr[i] = backup[i]; n   } n } n int lowerBound(int l, int r, int val) { n   while (l <= r) { n     int mi = (l + r) / 2; n     if (arr[mi].second <= val) { n       l = mi + 1; n     } else { n       r = mi - 1; n     } n   } n   int mi = (l + r) / 2; n   if (mi >= l && arr[mi].second > val) return mi - 1; n   return mi; n } n long long mergeSortV(int l, int r) { n   if (l >= r) return 0; n   int mi = (l + r) / 2; n   long long left = mergeSortV(l, mi); n   long long right = mergeSortV(mi + 1, r); n   long long mix = 0LL; n   prefix[l] = 0LL; n   for (int i = l; i <= mi; i++) { n     prefix[i + 1] = prefix[i] + (long long)arr[i].first; n   } n   for (int i = mi + 1; i <= r; i++) { n     int pos = lowerBound(l, mi, arr[i].second); n     long long cnt = pos - l + 1; n     mix += ((long long)arr[i].first * cnt - (prefix[pos + 1] - prefix[l])); n   } n   int i = l, j = mi + 1, k = l; n   while (i <= mi && j <= r) { n     if (arr[i].second < arr[j].second) { n       backup[k++] = arr[i++]; n     } else { n       backup[k++] = arr[j++]; n     } n   } n   while (i <= mi) { n     backup[k++] = arr[i++]; n   } n   while (j <= r) { n     backup[k++] = arr[j++]; n   } n   for (i = l; i <= r; i++) { n     arr[i] = backup[i]; n   } n   return left + right + mix; n } n long long solveBruteforce() { n   long long sum = 0LL; n   for (int i = 0; i < N; i++) { n     for (int j = i + 1; j < N; j++) { n       if (arr[i].second > arr[j].second) { n         sum += (long long)max(arr[i].first - arr[j].first, 0); n       } else if (arr[i].second < arr[j].second) { n         sum += (long long)max(arr[j].first - arr[i].first, 0); n       } else { n         sum += (long long)max(arr[j].first - arr[i].first, n                               arr[i].first - arr[j].first); n       } n     } n   } n   return sum; n } n int main() { n   cin >> N; n   for (int i = 0; i < N; i++) { n     int x; n     cin >> x; n     arr[i].first = x; n   } n   for (int i = 0; i < N; i++) { n     int v; n     cin >> v; n     arr[i].second = v; n   } n   sortX(0, N - 1); n   cout << mergeSortV(0, N - 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, i, j, x, y; n   bool B[1005]; n   cin >> n >> m; n   for (i = 0; i < n; i++) B[i] = true; n   for (i = 0; i < m; i++) { n     cin >> x >> y; n     B[x - 1] = false; n     B[y - 1] = false; n   } n   for (i = 0; i < n; i++) n     if (B[i]) break; n   cout << n - 1 << endl; n   for (j = 0; j < n; j++) { n     if (j == i) continue; n     cout << j + 1 <<     << i + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e18; n mt19937 rnd( n     std::chrono::high_resolution_clock::now().time_since_epoch().count()); n void ProdamGaraje() { n   vector<long long> a[2000]; n   long long m, n; n   cin >> n >> m; n   for (long long i = 0; i < n; ++i) { n     a[i].push_back(0); n     for (long long j = 0; j < m; ++j) { n       long long x; n       cin >> x; n       a[i].push_back(x + (a[i][(int)a[i].size() - 1])); n     } n   } n   for (long long i = m - 1; i >= 1; --i) { n     a[0][i] = max(a[0][i], a[0][i + 1]); n   } n   for (long long i = 1; i < n; ++i) { n     if (i % 2 == 1) { n       for (long long j = 1; j < m; ++j) { n         a[i][j] += a[i - 1][j + 1]; n       } n       for (long long j = 2; j < m + 1; ++j) a[i][j] = max(a[i][j], a[i][j - 1]); n     } else { n       for (long long j = m; j >= 2; --j) { n         a[i][j] += a[i - 1][j - 1]; n       } n       for (long long j = m - 1; j >= 1; --j) n         a[i][j] = max(a[i][j], a[i][j + 1]); n     } n   } n   if (n % 2 == 0) { n     cout << a[n - 1][m - 1]; n   } else { n     cout << a[n - 1][2]; n   } n } n void solve() { n   int a, b, c; n   cin >> a >> b >> c; n   for (int i = 0; i < b; i++) { n     int x; n     cin >> x; n     int y; n     cin >> y; n   } n   for (int i = 0; i < c; i++) { n     string s; n     cin >> s; n     int x; n     cin >> x; n     for (int j = 0; j < x; j++) { n       int t; n       cin >> t; n     } n   } n   for (int i = 0; i < c; i++) { n     string s; n     cin >> s; n     int x; n     cin >> x; n     for (int j = 0; j < x; j++) { n       int t; n       cin >> t; n     } n   } n   int ans = rnd() % 2; n   if (ans) n     cout <<  YES ; n   else n     cout <<  NO ; n } n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   while (t--) ProdamGaraje(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000000, inv2 = (MOD + 1) / 2; n long double eps = 1e-6; n int dx[4] = {-1, 1, 0, 0}; n int dy[4] = {0, 0, -1, 1}; n long double pi = acos(-1.0L); n struct node { n   int x, y, z, op, id; n } a[1000000 + 10], c[1000000 + 10]; n bool cmp(node a, node b) { n   if (a.z != b.z) return a.z < b.z; n   return a.op < b.op; n } n int f[1000000 + 10], used[1000000 + 10], n, m, k; n int read() { n   int v = 0, f = 1; n   char c = getchar(); n   while (c < 48 || 57 < c) { n     if (c ==  -- ) f = -1; n     c = getchar(); n   } n   while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); n   return v * f; n } n long long readll() { n   long long v = 0, f = 1; n   char c = getchar(); n   while (c < 48 || 57 < c) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); n   return v * f; n } n int dsu(int k) { n   if (f[k] != k) f[k] = dsu(f[k]); n   return f[k]; n } n pair<int, long long> calc(int mid) { n   for (int i = (int)1; i <= (int)m; i++) { n     c[i] = a[i]; n     if (c[i].op) c[i].z += mid; n   } n   sort(c + 1, c + m + 1, cmp); n   for (int i = (int)1; i <= (int)m; i++) used[i] = 0; n   for (int i = (int)1; i <= (int)n; i++) f[i] = i; n   int s = 0, num = n; n   long long ans = 0; n   for (int i = (int)1; i <= (int)m; i++) { n     int x = dsu(c[i].x), y = dsu(c[i].y); n     if (x != y && s + c[i].op <= k) { n       f[x] = y; n       ans += c[i].z; n       used[c[i].id] = 1; n       s += c[i].op; n       num--; n     } n   } n   if (num != 1) ans = 2e10; n   return make_pair(s, ans); n } n void solve() { n   pair<int, long long> t = calc(-2e5); n   if (t.second == 2e10 || t.first < k) { n     printf( -1 n ); n     return; n   } n   t = calc(2e5); n   if (t.second < 2e10 && t.first > k) { n     printf( -1 n ); n     return; n   } n   int l = -1e5, r = 1e5; n   int ans = -1e5; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (calc(mid).first >= k) n       l = mid + 1, ans = mid; n     else n       r = mid - 1; n   } n   if (calc(ans).first > k) ans++, calc(ans); n   int res = 0; n   for (int i = (int)1; i <= (int)m; i++) n     if (used[i]) res++; n   printf( %d n , res); n   for (int i = (int)1; i <= (int)m; i++) n     if (used[i]) printf( %d  , i); n } n int main() { n   n = read(), m = read(), k = read(); n   for (int i = (int)1; i <= (int)m; i++) { n     a[i].x = read(), a[i].y = read(), a[i].z = read(); n     if (a[i].x == 1 || a[i].y == 1) a[i].op = 1; n     a[i].id = i; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   map<int, vector<pair<int, int> > > mp; n   int res[200], mini = INT_MAX; n   for (int i = 0; i < n; i++) { n     pair<int, int> p; n     scanf( %d%d , &p.first, &p.second); n     mp[p.first].push_back({p.second, i}); n   } n   int cur = 0; n   priority_queue<pair<int, int>, vector<pair<int, int> >, n                  greater<pair<int, int> > > n       pq; n   for (auto m : mp) { n     while (!pq.empty() && cur < m.first) { n       auto j = pq.top(); n       pq.pop(); n       res[j.second] = cur++; n     } n     if (pq.empty()) { n       cur = m.first; n     } n     for (auto i : m.second) { n       pq.push(i); n     } n   } n   while (!pq.empty()) { n     auto j = pq.top(); n     pq.pop(); n     res[j.second] = cur++; n   } n   for (int i = 0; i < n; i++) { n     cout << res[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.1415926535897932384626433832795; n double eps = 1e-14; n char ch[1 << 20]; n inline string gs() { n   scanf( %s , ch); n   return string(ch); n } n inline int gi() { n   int x; n   scanf( %d , &x); n   return x; n } n void error() { n   int ttt = 0; n   cout << 7 / ttt; n } n long long gcd(long long a, long long b) { return (!a) ? b : gcd(b % a, a); } n const long long mod = 1000 * 1000 * 1000 + 7; n inline long long MUL(long long a, long long b) { return a * b % mod; } n inline long long ADD(long long a, long long b) { n   return (a + b >= mod) ? a + b - mod : a + b; n } n inline long long SUB(long long a, long long b) { n   return (a - b < 0) ? a + mod - b : a - b; n } n const int BLOCK = 10000; n int nP[20000], B[BLOCK]; n int P[20000], C; n int go(int n1, int n) { n   C = 0; n   for (int i = 2; i * i <= n; ++i) n     if (!nP[i]) { n       P[C++] = i; n       for (int j = i + i; j * j <= n; j += i) nP[j] = 1; n     } n   int res = 0; n   for (int k = 0, mxk = n / BLOCK; k <= mxk; ++k) { n     memset(B, 0, sizeof(B)); n     int beg = k * BLOCK; n     for (int i = 0; i < C; ++i) n       for (int j = max((beg + P[i] - 1) / P[i], 2) * P[i] - beg; j < BLOCK; n            j += P[i]) n         B[j] = 1; n     if (!k) B[0] = B[1] = 1; n     int x = beg; n     for (int i = 0; i < BLOCK && beg + i <= n; ++i) { n       if (!B[i] && x >= n1 && ((x & 3) == 1 || x == 2)) ++res; n       ++x; n     } n   } n   return res; n } n int main() { n   int a, b; n   scanf( %d%d , &a, &b); n   int r = go(a, b); n   printf( %d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const double EPS = 1e-9; n const int INF = 1 << 29; n int const NN = 1e6 + 6; n string s; n string t[NN]; n pair<pair<int, int>, int> p[NN]; n int tot = 0; n int mxI[NN]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     cin >> t[i]; n     int len = t[i].length(); n     int k; n     scanf( %d , &k); n     for (int j = 0; j < k; ++j) { n       int x; n       scanf( %d , &x); n       --x; n       int y = x + len - 1; n       p[tot++] = make_pair(make_pair(x, y), i); n     } n   } n   sort(p, p + tot); n   int mnIdx = NN, mxIdx = -1; n   int mx = -1; n   for (int i = 0; i < tot; ++i) { n     if (p[i].first.second > mx) { n       mxI[i] = i; n       mx = p[i].first.second; n     } else n       mxI[i] = mxI[i - 1]; n     mnIdx = min(mnIdx, p[i].first.first); n     mxIdx = max(mxIdx, p[i].first.second); n   } n   for (int i = 0; i <= mxIdx; ++i) s +=  a ; n   for (int i = 0; i < mnIdx; ++i) s[i] =  a ; n   for (int i = mnIdx; i <= mxIdx; ++i) { n     int lo = 0, hi = tot - 1, mid; n     while (lo <= hi) { n       mid = (lo + hi) >> 1; n       if (p[mid].first.first > i) n         hi = mid - 1; n       else n         lo = mid + 1; n     } n     if (p[mid].first.first > i) --mid; n     if (mid < 0) { n       s[i] =  a ; n       continue; n     } n     int idx = mxI[mid]; n     int xx = p[idx].first.first; n     int yy = p[idx].first.second; n     int indexx = p[idx].second; n     if (i > yy || i < xx) { n       s[i] =  a ; n       continue; n     } n     s[i] = t[indexx][i - xx]; n   } n   cout << s; n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q, n, k; n   string s; n   cin >> q; n   while (q--) { n     cin >> n >> k >> s; n     string rgb =  RGB ; n     int cnt = 0, ans = k; n     for (int i = 0; i <= n - k; i++) { n       for (int j = 0; j < 3; j++) { n         cnt = 0; n         for (int m = 0; m < k; m++) n           if (s[i + m] != rgb[(j + m) % 3]) cnt++; n         if (cnt < ans) ans = cnt; n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, k, x, ans, a, b; n int main() { n   scanf( %d%d , &n, &k); n   while (n--) { n     scanf( %d%d , &a, &b); n     x += b - a + 1; n   } n   x = (k - (x % k)) % k; n   printf( %d , x); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   string s; n   cin >> s; n   long long ans = (n * (n - 1)) / 2; n   long long l = 0, r = n - 1; n   while (s[l] == s[0]) l++; n   while (s[r] == s[n - 1]) r--; n   r = n - 1 - r; n   long long num = 0; n   for (long long i = 1; i < n; i++) { n     if (s[i] != s[i - 1]) { n       num++; n     } n   } n   cout << ans - (2 * n) + l + r + num; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int digit[32]; n long long dp[32][32][2]; n long long dfs(int p, int k, bool tag) { n   int i; n   long long ret = 0; n   if (p == -1) return 1; n   if (~dp[p][k][tag]) return dp[p][k][tag]; n   if (!k) n     ret = (ret + dfs(p - 1, k, tag && !digit[p])) % 1000000007; n   else { n     ret = (ret + (dfs(p - 1, k, tag && !digit[p]) << (k - 1)) % 1000000007) % n           1000000007; n     if (!tag || digit[p]) n       ret = (ret + (dfs(p - 1, k, tag) << (k - 1)) % 1000000007) % 1000000007; n   } n   if (!tag || digit[p]) n     ret = (ret + dfs(p - 1, k + 1, tag && digit[p])) % 1000000007; n   return dp[p][k][tag] = ret; n } n int main() { n   int k, p; n   while (cin >> k) { n     memset(dp, -1, sizeof(dp)); n     for (p = 0; k; k >>= 1) digit[p++] = (k & 1); n     cout << dfs(p - 1, 0, true) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXVAL = 1000000; n const int MAXCNT = 200000; n const int MOD = 1000000007; n int n, want, nq; n int cnt[MAXVAL + 1]; n int dv[MAXVAL + 1]; n int tot[MAXVAL + 1]; n int fac[MAXCNT + 1]; n int inv[MAXCNT + 1]; n int ifac[MAXCNT + 1]; n int ans; n int C(int n, int k) { n   if (k > n) return 0; n   return (long long)fac[n] * ifac[k] % MOD * ifac[n - k] % MOD; n } n void inc(int x, int y) { n   if (x == 1) { n     ans -= (long long)tot[y] * C(cnt[y], want) % MOD; n     if (ans < 0) ans += MOD; n     ++cnt[y]; n     ans += (long long)tot[y] * C(cnt[y], want) % MOD; n     if (ans >= MOD) ans -= MOD; n   } else { n     int t = 0, z = dv[x]; n     while (dv[x] == z) x /= dv[x], ++t; n     for (int i = (0); i <= (t); ++i) { n       inc(x, y); n       y *= z; n     } n   } n } n void run() { n   memset(dv, -1, sizeof(dv)); n   for (int i = (2); i <= (MAXVAL); ++i) n     if (dv[i] == -1) n       for (int j = i; j <= MAXVAL; j += i) dv[j] = i; n   tot[1] = 1; n   for (int i = (2); i <= (MAXVAL); ++i) { n     int j = i / dv[i]; n     tot[i] = tot[j] * (dv[i] - (dv[j] != dv[i] ? 1 : 0)); n   } n   fac[0] = 1; n   for (int i = (1); i <= (MAXCNT); ++i) n     fac[i] = (long long)fac[i - 1] * i % MOD; n   inv[1] = 1; n   for (int i = (2); i <= (MAXCNT); ++i) n     inv[i] = (MOD - (long long)(MOD / i) * inv[MOD % i] % MOD) % MOD; n   ifac[0] = 1; n   for (int i = (1); i <= (MAXCNT); ++i) n     ifac[i] = (long long)ifac[i - 1] * inv[i] % MOD; n   scanf( %d%d%d , &n, &want, &nq); n   ans = 0; n   for (int i = (0); i < (n); ++i) { n     int x; n     scanf( %d , &x); n     inc(x, 1); n   } n   for (int i = (0); i < (nq); ++i) { n     int x; n     scanf( %d , &x); n     inc(x, 1); n     printf( %d n , ans); n   } n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const int N = 1000005; n const double PI = 4 * atan(1); n const long long MAX = 9223372036854775807; n int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; n int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; } n bool isprime(long long u) { n   for (long long i = 2; i <= (int)sqrt(u); i++) { n     if (u % i == 0) return 0; n   } n   return 1; n } n long long mod(long long to_mod, long long MOD) { n   to_mod %= MOD; n   while (to_mod < 0) to_mod += MOD; n   return to_mod % MOD; n } n long long moduloMultiplication(long long a, long long b) { n   long long res = 0; n   while (b) { n     if (b & 1) res = (res + a); n     a = (2 * a); n     b >>= 1; n   } n   return res; n } n long long power(long long x, long long y, long long p) { n   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 long long q, y, k, z, w, t, l, r, x, n, m; n long long a[N]; n stack<long long> ss; n int main() { n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] = a[i] % 2; n   } n   for (int i = 0; i < n;) { n     if (i == n - 1) { n       if (!ss.empty() && a[i] == ss.top()) { n         ss.pop(); n       } else { n         ss.push(a[i]); n       } n       i++; n     } else { n       if (!ss.empty() && a[i] == ss.top()) { n         ss.pop(); n         i++; n       } else if (a[i] == a[i + 1]) { n         i += 2; n       } else { n         ss.push(a[i]); n         i++; n       } n     } n   } n   if (ss.size() >= 2) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 3e5 + 5; n int T, n, i, x, d, v, o; n inline int mx(int x, int y) { return x > y ? x : y; } n inline int mn(int x, int y) { return x < y ? x : y; } n int main() { n   for (scanf( %d , &T); T--;) { n     d = 0, v = 1e9, o = 1; n     scanf( %d , &n); n     for (i = 1; i <= n; ++i) { n       scanf( %d , &x); n       if (!o) continue; n       x -= d; n       if (x < 0) { n         o = 0; n         continue; n       } n       d += mx(x - v, 0); n       v = mn(v, x); n     } n     if (o) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 4010; n double num1[Maxn]; n int num2[Maxn]; n double dif[Maxn]; n int main() { n   int n = 0, N = 0; n   int cnt = 0, cnt1 = 0, cnt2 = 0; n   double sum = 0; n   double ans = 100000000.0; n   scanf( %d , &n); n   N = 2 * n; n   for (int i = 0; i < N; i++) { n     scanf( %lf , &num1[i]); n     num2[i] = num1[i]; n     dif[i] = (double)num1[i] - (double)num2[i]; n   } n   for (int i = 0; i < N; i++) { n     if (dif[i] != 0) { n       cnt1++; n       sum += dif[i]; n     } else { n       cnt2++; n     } n   } n   cnt = min(cnt1, n); n   for (int i = 0; i <= cnt; i++) { n     if (i + cnt2 >= n) { n       ans = min(ans, fabs(sum - i * 1.0)); n     } n   } n   printf( %.3f , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const long long INF = 1e18; n struct P { n   int id; n   long long dis; n   friend bool operator<(P a, P b) { return a.dis > b.dis; } n }; n int n, m, q, x[N], y[N], t[N], l[2][N], id[N], c; n long long d[2][N], ans[N], pre[N]; n vector<long long> add[N], del[N]; n vector<int> g[N]; n void dij(int p, int s) { n   memset(d[p], 0x3f, sizeof(d[p])), d[p][s] = 0; n   if (p) memset(pre, 0, sizeof(pre)); n   priority_queue<P> q; n   q.push((P){s, 0ll}); n   while (!q.empty()) { n     int u = q.top().id; n     long long nd = q.top().dis; n     q.pop(); n     if (nd != d[p][u]) continue; n     for (auto e : g[u]) { n       int v = x[e] + y[e] - u; n       long long w = t[e]; n       if (d[p][u] + w < d[p][v]) n         q.push((P){v, d[p][v] = d[p][u] + w}), pre[v] = e; n     } n   } n } n void it(int p, int s) { n   priority_queue<P> q; n   for (int i = 1; i <= n; i++) n     if (l[p][i] || i == 1) q.push((P){i, l[p][i]}); n   while (!q.empty()) { n     int u = q.top().id; n     q.pop(); n     for (auto e : g[u]) n       if (!id[e]) { n         int v = x[e] + y[e] - u; n         long long w = t[e]; n         if (d[p][u] + w == d[p][v] && l[p][u] < l[p][v]) n           q.push((P){v, l[p][v] = l[p][u]}); n       } n   } n } n void solve(int i) { n   if (l[0][x[i]] >= l[1][y[i]]) return; n   long long val = d[0][x[i]] + t[i] + d[1][y[i]]; n   add[l[0][x[i]]].push_back(val), del[l[1][y[i]]].push_back(val); n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &x[i], &y[i], &t[i]); n     g[x[i]].push_back(i), g[y[i]].push_back(i); n   } n   dij(0, 1), dij(1, n), memset(l[0], 0x3f, sizeof(l[0])); n   for (int u = 1; u != n;) { n     int e = pre[u], v = x[e] + y[e] - u; n     u = v, l[0][u] = l[1][u] = id[e] = ++c, l[1][u] = -l[1][u]; n   } n   l[0][1] = 0, it(0, 1), it(1, n); n   for (int i = 1; i <= n; i++) l[1][i] = -l[1][i]; n   for (int i = 1; i <= m; i++) n     if (!id[i]) solve(i), swap(x[i], y[i]), solve(i); n   multiset<long long> s; n   s.insert(INF); n   for (int i = 0; i < c; i++) { n     for (auto v : add[i]) s.insert(v); n     for (auto v : del[i]) s.erase(v); n     ans[i + 1] = *s.begin(); n   } n   while (q--) { n     int e; n     long long len; n     scanf( %d%lld , &e, &len); n     long long res = len + min(d[0][x[e]] + d[1][y[e]], d[0][y[e]] + d[1][x[e]]); n     if (len <= t[e] || !id[e]) n       res = min(res, d[0][n]); n     else if (id[e]) n       res = min(res, ans[id[e]]); n     printf( %lld n , res); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int max(long long int x, long long int y) { n   if (x >= y) return x; n   return y; n } n long long int min(long long int x, long long int y) { n   if (x > y) return y; n   return x; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.tie(NULL); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   while (t--) { n     long long int n, i, j = 0, k = 0; n     cin >> n; n     long long int a[n]; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] == 1 && k == 0) { n         j++; n       } else n         k = 1; n     } n     if ((j % 2 == 0 && k == 1) || (j % 2 == 1 && k == 0)) n       cout <<  First n ; n     else n       cout <<  Second n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int l = -INF, r = INF, a = 0; n   while (n--) { n     int a_, d; n     cin >> a_ >> d; n     if (d == 1) n       l = max(l, 1900 - a); n     else n       r = min(r, 1899 - a); n     a += a_; n   } n   if (r != INF && l <= r) n     cout << r + a <<   n ; n   else if (r == INF) n     cout <<  Infinity n ; n   else n     cout <<  Impossible n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double PI = 3.1415926536; n int dX[] = {1, -1, 0, 0}; n int dY[] = {0, 0, 1, -1}; n int main() { n   int a, b, c, x, y, z, extra = 0, need = 0; n   cin >> a >> b >> c >> x >> y >> z; n   if (a > x) n     extra += ((a - x) / 2) * 2; n   else n     need += x - a; n   if (b > y) n     extra += ((b - y) / 2) * 2; n   else n     need += y - b; n   if (c > z) n     extra += ((c - z) / 2) * 2; n   else n     need += z - c; n   if (extra / 2 >= need) n     cout <<  Yes n ; n   else n     cout <<  No n ; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); } n double dcmp(double a, double b) { n   return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1; n } n const int MAX_SIZE = 3e5 + 5; n const int MOD = 1e9 + 7; n int r = 0; n long long segtree[MAX_SIZE * 4]; n void update(long long L, long long R, long long t, long long val, n             long long idx) { n   if (L == R && R == t) { n     segtree[idx] += val; n     segtree[idx] %= MOD; n     return; n   } n   if (L > t || R < t) return; n   update(L, (L + R) / 2, t, val, idx * 2); n   update((L + R) / 2 + 1, R, t, val, idx * 2 + 1); n   segtree[idx] = (segtree[idx * 2] + segtree[idx * 2 + 1]) % MOD; n } n long long query(long long L, long long R, long long tl, long long tr, n                 long long idx) { n   if (L >= tl && R <= tr) { n     return segtree[idx] % MOD; n   } n   if (L > tr || R < tl) return 0; n   return (query(L, (L + R) / 2, tl, tr, idx * 2) + n           query((L + R) / 2 + 1, R, tl, tr, idx * 2 + 1)) % n          MOD; n } n map<long long, long long> rnk; n int main() { n   set<long long> tmp; n   long long n, m, a, b; n   vector<pair<long long, long long> > data; n   cin >> n >> m; n   tmp.insert(0); n   tmp.insert(n); n   for (long long i = 0; i < m; i++) { n     cin >> a >> b; n     data.push_back({b, a}); n     tmp.insert(a); n     tmp.insert(b); n     tmp.insert(b - 1); n   } n   for (long long x : tmp) { n     rnk[x] = ++r; n   } n   sort(data.begin(), data.end()); n   update(0, MAX_SIZE - 1, 1, 1, 1); n   for (int i = 0; i < m; i++) { n     swap(data[i].second, data[i].first); n     int x = n         query(0, MAX_SIZE - 1, rnk[data[i].first], rnk[data[i].second - 1], 1); n     update(0, MAX_SIZE - 1, rnk[data[i].second], x, 1); n   } n   cout << query(0, MAX_SIZE - 1, rnk[n], rnk[n], 1) % MOD; n } n


#include <bits/stdc++.h> n using namespace std; n int mp[505][505], f[505]; n void push(int n) { n   for (int i = 1; i <= n; i++) cout << f[i] <<    ; n   cout << endl; n } n int main() { n   int n, m, i, j, Q, sum, x, y; n   while (scanf( %d%d%d , &n, &m, &Q) != EOF) { n     memset(f, 0, sizeof(f)); n     for (i = 1; i <= n; i++) n       for (j = 1; j <= m; j++) scanf( %d , &mp[i][j]); n     int ans = 0, maxn = 0, sum = 0; n     for (i = 1; i <= n; i++) { n       sum = 0; n       maxn = 0; n       for (j = 1; j <= m; j++) { n         if (mp[i][j] == 1) n           sum++; n         else { n           maxn = max(maxn, sum); n           sum = 0; n         } n       } n       f[i] = max(maxn, sum); n     } n     while (Q--) { n       scanf( %d%d , &x, &y); n       if (mp[x][y] == 0) n         mp[x][y] = 1; n       else n         mp[x][y] = 0; n       maxn = 0, sum = 0; n       for (j = 1; j <= m; j++) { n         if (mp[x][j] == 1) n           sum++; n         else { n           maxn = max(maxn, sum); n           sum = 0; n         } n       } n       maxn = max(maxn, sum); n       f[x] = maxn; n       for (i = 1; i <= n; i++) maxn = max(maxn, f[i]); n       ans = maxn; n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:500000000 ) n using namespace std; n int A[222]; n bool used[222]; n int main() { n   int n, k, i; n   cin >> n >> k; n   for (i = 0; i < 2 * n + 1; i++) cin >> A[i]; n   int N = 2 * n + 1; n   memset(used, false, sizeof(used)); n   while (k) { n     for (i = 1; i < N && k > 0; i++) n       if ((i & 1) && !used[i] && A[i] - 1 > A[i - 1] && A[i] - 1 > A[i + 1]) n         used[i] = true, A[i]--, k--; n   } n   printf( %d , A[0]); n   for (i = 1; i < N; i++) printf(  %d , A[i]); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mo(long long a) { return a % (long long)(1e9 + 7); } n long long po(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y >>= 1; n     x = (x * x) % p; n   } n   return res % p; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     vector<long long> a(n); n     for (long long i = 0; i < a.size(); i++) cin >> a[i]; n     ; n     vector<long long> sp; n     long long i = 0; n     while (i < n && a[i] == 0) i++; n     for (; i < n; i++) { n       while (i < n && a[i]) i++; n       long long cnt = 0; n       while (i < n && a[i] == 0) { n         cnt++; n         i++; n       } n       sp.push_back(cnt); n     } n     if (a[n - 1] == 0) sp.pop_back(); n     long long ans = 0; n     for (long long e : sp) ans += e; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast_IO_file() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int main() { n   fast_IO_file(); n   string s1, s2; n   getline(cin, s1); n   getline(cin, s2); n   map<char, long long int> m1; n   map<char, long long int> m2; n   for (long long int i = 0; i < s1.size(); i++) { n     if (s1[i] ==    ) n       continue; n     else n       m1[s1[i]]++; n   } n   for (long long int i = 0; i < s2.size(); i++) { n     if (s2[i] ==    ) n       continue; n     else n       m2[s2[i]]++; n   } n   long long int count = 0; n   for (long long int i = 0; i < s2.size(); i++) { n     if (s2[i] ==    ) n       continue; n     else { n       if (m1[s2[i]] < m2[s2[i]]) { n         count = 1; n         break; n       } n     } n   } n   if (count == 0) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   bool flag = false; n   int n, boro; n   cin >> n; n   int a[n], b[n]; n   for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; n   for (int i = 0; i < 1; i++) { n     boro = max(a[i], b[i]); n   } n   for (int i = 1; i < n; i++) { n     if (max(a[i], b[i]) <= boro) { n       boro = max(a[i], b[i]); n     } else if (min(a[i], b[i]) <= boro) { n       boro = min(a[i], b[i]); n     } else { n       flag = true; n       break; n     } n   } n   if (flag == false) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   long long gcd; n   if (a == 1) n     return 1; n   else if (b == 1) n     return 1; n   while (b) { n     long long t = b; n     b = a % b; n     a = t; n   } n   gcd = a; n   return gcd; n } n long long check(long long &n) { n   long long ck = 0; n   for (long long i = 2;;) { n     if (n % i == 0) { n       n /= i; n       ck++; n     } else n       break; n   } n   for (long long i = 3;;) { n     if (n % i == 0) { n       n /= i; n       ck++; n     } else n       break; n   } n   for (long long i = 5;;) { n     if (n % i == 0) { n       n /= i; n       ck++; n     } else n       break; n   } n   return ck; n } n int main() { n   long long a, b; n   cin >> a >> b; n   if (a == b) { n     cout <<  0 ; n     return 0; n   } n   long long x = gcd(a, b); n   a /= x; n   b /= x; n   long long sum1, sum2; n   sum1 = check(a); n   sum2 = check(b); n   if (a == 1 && b == 1) n     cout << sum1 + sum2 << endl; n   else n     cout <<  -1  << endl; n   return 0; n } n


/*************** n Code Submitted by Saumya Singh  n Netaji Subhas University of Technology n CF : @saumya_singh203 n ****************/ n  n #include <bits/stdc++.h> n using namespace std; n #define int long long n  n signed main() n { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n     cout.tie(nullptr); n  n     long long t = 1; n     cin >> t; n     while (t--) n     { n         int n, m, x, add, r, c; n         cin >> n >> m >> x; n  n         c = (x - 1) / n; n         r = (x - 1) % n; n  n         cout << (r)*m + (c + 1) << endl; n  n          n  n     } n }


#include <bits/stdc++.h> n using namespace std; n const int OO = 0x3f3f3f3f, N = 1e5 + 5, mod = 1e9 + 7; n const double pi = acos(-1), EPS = 1e-8; n int n, x, y, idx[N]; n int main() { n   memset(idx, -1, sizeof idx); n   scanf( %d , &n); n   for (int t = 1; t <= n; ++t) { n     scanf( %d%d , &x, &y); n     int cnt = 0; n     for (int i = 1; i * i <= x; ++i) n       if (x % i == 0) { n         cnt += (idx[i] < t - y) + (i * i != x && idx[x / i] < t - y); n         idx[i] = idx[x / i] = t; n       } n     printf( %d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000000; n const long double eps = 1e-07; n int n; n int a[200000]; n int d[200000]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   d[0] = -inf; n   for (int i = 1; i <= n; ++i) d[i] = inf; n   for (int i = 0; i < n; i++) { n     int l = 0; n     int r = n; n     while (r - l > 2) { n       int m = (l + r) / 2; n       if (d[m] < a[i]) { n         l = m; n       } else n         r = m; n     } n     for (int j = r; j >= l; --j) n       if (d[j] < a[i]) { n         d[j + 1] = a[i]; n         break; n       } n   } n   int ans = -inf; n   for (int i = 1; i <= n; ++i) n     if (d[i] != inf) ans = max(ans, i); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long long N = 1e5 + 10; n const long long mod = 1e9 + 7; n const long long inf = -1e18; n const long long INF = 1e18; n long long bin_pow(long long n, long long k) { n   if (k == 0) return 1; n   if (k == 1) return n; n   if (n == 0) return 0; n   if (k % 2 == 0) { n     long long t = bin_pow(n, k / 2); n     return (t * t); n   } else { n     return (bin_pow(n, k - 1) * n); n   } n } n bool isprime(long long x) { n   if (x == 1) return false; n   if (x == 2 || x == 3 || x == 5 || x == 7) return true; n   if (x % 2 == 0 || x % 3 == 0 || x % 5 == 0 || x % 7 == 0) return false; n   for (int i = 2; i * i <= x; i++) { n     if (x % i == 0) return false; n   } n   return true; n } n long long phi(long long n) { n   long long result = n; n   for (int i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       result -= result / i; n     } n   } n   if (n > 1) { n     result -= result / n; n   } n   return result; n } n string str, b; n long long n; n bool check(string b, string a) { n   for (int i = 0; i < a.size(); i++) { n     if (a[i] ==  1  || a[i] ==  l  || a[i] ==  I  || a[i] ==  L  || n         a[i] ==  i ) { n       if (b[i] ==  1  || b[i] ==  l  || b[i] ==  I  || b[i] ==  L  || n           b[i] ==  i ) { n         continue; n       } n     } n     if (a[i] ==  O  || a[i] ==  0  || a[i] ==  o ) { n       if (b[i] ==  O  || b[i] ==  0  || b[i] ==  o ) { n         continue; n       } n     } n     if (a[i] >=  a  && a[i] <=  z ) { n       a[i] = char(a[i] - 32); n     } n     if (b[i] >=  a  && b[i] <=  z ) { n       b[i] = char(b[i] - 32); n     } n     if (a[i] == b[i]) continue; n     return false; n   } n   return true; n } n int main() { n   cin >> str; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> b; n     if (b.size() != str.size()) continue; n     if (check(b, str) == true) { n       cout <<  No ; n       exit(false); n     } n   } n   cout <<  Yes ; n } n


#include <iostream> n #include <algorithm> n #include <vector> n #include <utility> n using namespace std; n  n int main() n { n     int task; n     cin>>task; n     while(task--) n     { n         int n; n         cin>>n; n         int a[n]; n  n         int ans=n+n-1; n  n         for(int i=0;i<n;i++) n         { n             cin>>a[i]; n             if(i>=2) n             { n                 if(a[i-1]>a[i]&&a[i-1]>a[i-2]) n                 ans++; n                 else if(a[i-1]<a[i]&&a[i-1]<a[i-2]) n                 ans++; n             } n         } n  n         //cout<<ans<<endl; n  n  n         for(int i=0;i<n-3;i++) n         { n             if(a[i+1]>a[i]&&a[i+1]>a[i+3]&&a[i+2]<a[i]&&a[i+2]<a[i+3]) n             ans++; n             else if(a[i+1]<a[i]&&a[i+1]<a[i+3]&&a[i+2]>a[i]&&a[i+2]>a[i+3]) n             ans++; n         } n  n  n         cout<<ans<<endl; n  n  n  n  n  n  n     } n     return 0; n } n  n  n


#include <bits/stdc++.h> n using namespace std; n bool is[1000001 + 1]; n long long int g1(long long int x, long long int y) { n   long long int res = 1; n   x = x; n   while (y > 0) { n     if (y & 1) res = (res * x); n     y = y >> 1; n     x = (x * x); n   } n   return res; n } n long long int g(long long int x, long long int y, long long int p) { n   long long int 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 long long int GCD(long long int A, long long int B) { n   if (B == 0) { n     return A; n   } else { n     return GCD(B, A % B); n   } n } n long long int isMultipleOf3(long long int n) { n   long long int odd_count = 0; n   long long int even_count = 0; n   if (n < 0) n = -n; n   if (n == 0) return 1; n   if (n == 1) return 0; n   while (n) { n     if (n & 1) odd_count++; n     n = n >> 1; n     if (n & 1) even_count++; n     n = n >> 1; n   } n   return isMultipleOf3(abs(odd_count - even_count)); n } n int main() { n   long long int n, x, m = 0, t, a = 0, b = 0, f = 0; n   string s, str; n   set<int> v; n   cin >> s; n   long long int c = 0; n   n = s.length(); n   long long int row = 1; n   long long int col = 1; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  1 ) { n       cout <<  3  n            <<     << col <<   n ; n       col += 2; n       if (col > 4) col = 1; n     } else { n       cout <<  1  n            <<     << row++ <<   n ; n       if (row == 5) row = 1; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, x, y, k, T, p[300], a[300][300]; n void dfs(int i) { n   for (int j = 0; j <= n; j++) n     if (a[i][j]) { n       a[i][j] = a[j][i] = 0; n       p[i]--; n       p[j]--; n       if (j && i) cout << j <<     << i << endl; n       dfs(j); n     } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> T; n   for (int t = 0; t < T; t++) { n     cin >> n >> m; n     for (int i = 0; i <= n; i++) n       for (int j = 0; j <= n; j++) a[i][j] = 0, p[i] = 0; n     for (int i = 0; i < m; i++) n       cin >> x >> y, a[x][y]++, a[y][x]++, p[x]++, p[y]++; n     k = 0; n     for (int i = 1; i <= n; i++) n       if (p[i] & 1) n         a[0][i] = a[i][0] = 1; n       else n         k++; n     cout << k << endl; n     for (int i = 1; i <= n; i++) n       if (p[i]) dfs(i); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (1 ? 100000000000000007 : 233333333333333333); n const int mod = (1 ? 1000000007 : 998244353); n const long long INF = 0x7fffffffffffffff; n const int inf = 0x7fffffff; n const double eps = 1e-8; n const int N = 1e6 + 5; n clock_t start, finish; n void time_in() { start = clock(); } n void time_out() { n   finish = clock(); n   double tim = (double)(finish - start) / CLOCKS_PER_SEC; n   printf( Running time is %lf n , tim); n } n inline long long mul(long long a, long long b) { n   long long s = 0; n   while (b) { n     if (b & 1) s = (s + a) % mod; n     a = (a << 1) % mod; n     b >>= 1; n   } n   return s % mod; n } n inline long long pow_mul(long long a, long long b) { n   long long s = 1; n   while (b) { n     if (b & 1) s = mul(s, a); n     a = mul(a, a); n     b >>= 1; n   } n   return s; n } n inline long long poww(long long a, long long b) { n   long long s = 1; n   while (b) { n     if (b & 1) s = (s * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return s % mod; n } n inline int read() { n   char c = getchar(); n   int sgn = 1, ret = 0; n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   if (c ==  - ) sgn = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) ret = ret * 10 + c - 48, c = getchar(); n   return ret * sgn; n } n void write(int x) { n   if (x > 9) write(x / 10); n   putchar(x % 10 +  0 ); n } n inline long long phi(long long x) { n   long long ans = x; n   for (long long i = 2; i * i <= x; i++) n     if (x % i == 0) { n       ans -= ans / i; n       while (x % i == 0) x /= i; n     } n   if (x > 1) ans -= ans / x; n   return ans; n } n int st[5][3] = {-1, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 1}; n int t, cas; n int m, n; n long long x[N], a[N], b[N], c[N], d[N], v[N]; n int main() { n   int s, e; n   while (~scanf( %d%d%d , &n, &s, &e)) { n     for (int i = 1; i <= n; i++) scanf( %lld , &x[i]); n     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n     for (int i = 1; i <= n; i++) scanf( %lld , &b[i]); n     for (int i = 1; i <= n; i++) scanf( %lld , &c[i]); n     for (int i = 1; i <= n; i++) scanf( %lld , &d[i]); n     v[1] = s, v[2] = e; n     m = 0; n     for (int j = 1; j <= n; j++) { n       if (j == s || j == e) continue; n       long long ma = INF; n       int p = 1; n       m++; n       for (int i = 1; i <= m; i++) { n         long long sum = 0; n         if (v[i] < j) n           sum += abs(x[v[i]] - x[j]) + d[v[i]] + a[j]; n         else n           sum += abs(x[v[i]] - x[j]) + c[v[i]] + b[j]; n         if (j < v[i + 1]) n           sum += abs(x[v[i + 1]] - x[j]) + d[j] + a[v[i + 1]]; n         else n           sum += abs(x[v[i + 1]] - x[j]) + c[j] + b[v[i + 1]]; n         long long tmp = 0; n         if (v[i] < v[i + 1]) n           tmp += abs(x[v[i]] - x[v[i + 1]]) + d[v[i]] + a[v[i + 1]]; n         else n           tmp += abs(x[v[i]] - x[v[i + 1]]) + c[v[i]] + b[v[i + 1]]; n         if (sum - tmp < ma) ma = sum - tmp, p = i; n       } n       for (int i = m + 2; i > p; i--) { n         v[i] = v[i - 1]; n       } n       v[p + 1] = j; n     } n     long long ans = 0; n     for (int i = 2; i <= n; i++) { n       if (v[i - 1] < v[i]) n         ans += abs(x[v[i]] - x[v[i - 1]]) + d[v[i - 1]] + a[v[i]]; n       else n         ans += abs(x[v[i]] - x[v[i - 1]]) + c[v[i - 1]] + b[v[i]]; n     } n     printf( %lld n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n inline string get() { n   char ch[2000010]; n   scanf( %s , ch); n   return ch; n } n const int MAX_LG = 21; n const int maxn = 18e5 + 10; n const int maxm = 1e5 + 10; n const int base = 29; n const int mod = 1e9 + 7; n const int base2 = 31; n const int mod2 = 1e9 + 9; n const int INF = 2e18 + 100; n const int SQ = 317; n struct state { n   int len = 0, link = -1; n   int nxt[29]; n   state() { memset(nxt, 0, sizeof nxt); } n } st[maxn]; n int sz = 1; n int last; n inline void add_letter(int c) { n   int p = last; n   last = sz++; n   st[last].len = st[p].len + 1; n   for (; p != -1 && st[p].nxt[c] == 0; p = st[p].link) { n     st[p].nxt[c] = last; n   } n   if (p == -1) { n     st[last].link = 0; n     return; n   } n   int q = st[p].nxt[c]; n   if (st[q].len == st[p].len + 1) { n     st[last].link = q; n     return; n   } n   int cl = sz++; n   for (int i = 0; i < 29; i++) st[cl].nxt[i] = st[q].nxt[i]; n   st[cl].link = st[q].link; n   st[q].link = st[last].link = cl; n   st[cl].len = st[p].len + 1; n   for (; p != -1 && st[p].nxt[c] == q; p = st[p].link) st[p].nxt[c] = cl; n } n int lim; n int res[maxn]; n int fi[maxn], se[maxn], th[maxn]; n bool mark[maxn]; n inline void dfs(int state) { n   if (mark[state]) return; n   mark[state] = true; n   for (int i = 0; i < 29; i++) { n     if (st[state].nxt[i] == 0) continue; n     pair<int, int> c = {i, st[state].nxt[i]}; n     dfs(c.second); n     if (c.first == 26) n       fi[state]++; n     else if (c.first == 27) n       se[state]++; n     else if (c.first == 28) n       th[state]++; n     else { n       fi[state] += fi[c.second]; n       se[state] += se[c.second]; n       th[state] += th[c.second]; n     } n   } n } n inline void calc() { n   for (int i = 0; i < sz; i++) { n     if (st[i].len == 0 || st[i].len > lim) continue; n     res[st[i].len] = n         (res[st[i].len] + 1LL * fi[i] * se[i] % mod * th[i] % mod) % mod; n     if (st[i].link == 0) continue; n     res[st[st[i].link].len] = (res[st[st[i].link].len] - n                                1LL * fi[i] * se[i] % mod * th[i] % mod + mod) % n                               mod; n   } n } n int32_t main() { n   st[0].link = -1; n   string a = get(), b = get(), c = get(); n   string s = a +  !  + b +  @  + c +  # ; n   for (auto ch : s) { n     if (ch ==  ! ) n       add_letter(26); n     else if (ch ==  @ ) n       add_letter(27); n     else if (ch ==  # ) n       add_letter(28); n     else n       add_letter(ch -  a ); n   } n   lim = (int)min(a.size(), min(b.size(), c.size())); n   dfs(0); n   calc(); n   for (int i = lim - 1; i >= 1; i--) { n     res[i] += res[i + 1]; n     if (res[i] >= mod) res[i] -= mod; n   } n   for (int i = 1; i <= lim; i++) cout << res[i] <<    ; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, a[100100]; n map<int, int> m; n int mi(int a, int b, int c) { return min(min(a, b), c); } n int mx(int a, int b, int c) { return max(max(a, b), c); } n int md(int a, int b, int c) { n   return 0LL + a + b + c - mi(a, b, c) - mx(a, b, c); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     m[a[i]]++; n   } n   a[0] = a[1]; n   sort(a + 1, a + n + 1); n   int n3 = n / 3; n   n3 += n % 3; n   int p1 = 0, p2 = 0; n   for (auto p : m) { n     if (p.second >= n / 3) { n       if (p1 == 0) n         p1 = p.first; n       else n         p2 = p.first; n     } n   } n   if (p2 == 0 && p1 == 0) { n     cout << n / 3 <<   n ; n     for (int i = 1, j = n / 3 + 1, k = 2 * n / 3 + 1; i <= n / 3; n          i++, j++, k++) { n       cout << a[k] <<     << a[j] <<     << a[i] <<   n ; n     } n     return 0; n   } n   if (p2 == 0 && p1 != 0) { n     vector<pair<int, pair<int, int> > > ans; n     priority_queue<pair<int, int> > v; n     map<int, int> use; n     for (int i = 1; i <= n; i++) n       if (a[i] != p1 && use[a[i]] == 0) v.push({m[a[i]], a[i]}), use[a[i]]++; n     while (v.size() > 1) { n       int x1 = v.top().second; n       v.pop(); n       m[x1]--; n       int x2 = v.top().second; n       v.pop(); n       m[x2]--; n       if (m[x1] > 0) v.push({m[x1], x1}); n       if (m[x2] > 0) v.push({m[x2], x2}); n       ans.push_back({mx(p1, x1, x2), {md(p1, x1, x2), mi(p1, x1, x2)}}); n       if (ans.size() == n / 3) break; n     } n     cout << ans.size() <<   n ; n     for (int i = 0; i < ans.size(); i++) { n       cout << ans[i].first <<     << ans[i].second.first <<     n            << ans[i].second.second <<   n ; n     } n   } n   if (p2 != 0) { n     vector<pair<int, pair<int, int> > > ans; n     for (int i = 1; i <= n; i++) { n       if (a[i] != p1 && a[i] != p2) { n         ans.push_back({mx(p1, p2, a[i]), {md(p1, p2, a[i]), mi(p1, p2, a[i])}}); n         if (ans.size() == n / 3) break; n       } n     } n     cout << ans.size() <<   n ; n     for (int i = 0; i < ans.size(); i++) { n       cout << ans[i].first <<     << ans[i].second.first <<     n            << ans[i].second.second <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n const int MaxN = 3e5; n int n, m, a[MaxN], p[MaxN]; n int leaf, tr[MaxN * 2]; n void build(int n) { n   leaf = n; n   for (int i = 0; i < n; ++i) tr[i + leaf] = a[i] > a[i + 1]; n   for (int i = leaf - 1; i; --i) tr[i] = tr[i << 1] + tr[i << 1 | 1]; n } n void upd(int x, int val) { n   tr[x += leaf] += val; n   while (x >>= 1) tr[x] += val; n } n int find(int l, int r) { n   int ans = 0; n   for (l += leaf, r += leaf; l <= r; l >>= 1, r >>= 1) { n     if (l & 1) ans += tr[l++]; n     if (~r & 1) ans += tr[r--]; n   } n   return ans; n } n void adjust(int x) { n   int _x = x + leaf; n   if (x) { n     if (tr[_x - 1] && a[x - 1] < a[x]) upd(x - 1, -1); n     if (!tr[_x - 1] && a[x - 1] > a[x]) upd(x - 1, 1); n   } n   if (x < n - 1) { n     if (tr[_x] && a[x] < a[x + 1]) upd(x, -1); n     if (!tr[_x] && a[x] > a[x + 1]) upd(x, 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , p + i); n     a[--p[i]] = i; n   } n   build(n); n   scanf( %d , &m); n   for (int i = 0; i < m; ++i) { n     int type; n     scanf( %d , &type); n     if (type & 1) { n       int l, r; n       scanf( %d %d , &l, &r); n       printf( %d n , 1 + find(l - 1, r - 2)); n     } else { n       int x, y; n       scanf( %d %d , &x, &y); n       --x; n       --y; n       std::swap(a[p[x]], a[p[y]]); n       std::swap(p[x], p[y]); n       adjust(p[x]); n       adjust(p[y]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[300007][15]; n int ans[300007], cnt[15]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (auto i = (1); i <= (n); ++i) { n     for (auto j = (1); j <= (m); ++j) { n       scanf( %d , &a[i][j]); n     } n   } n   for (auto i = (1); i <= (k); ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     --ans[x]; n     ++cnt[y]; n   } n   for (auto j = (1); j <= (m); ++j) { n     for (auto i = (1); i <= (n); ++i) { n       if (a[i][j]) ans[i] += cnt[j]; n     } n   } n   for (auto i = (1); i <= (n); ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     cin >> t; n     v.push_back(t); n   } n   bool is = true; n   for (int i = 0; i < n; i++) { n     bool br = false; n     for (int j = 1000; j >= 1; j /= 10) { n       for (int k = (v[i] % (j * 10)) / j; k > 0; k--) { n         if (v[i] - k * j <= 2011 && v[i] - k * j >= 1000 && n             (i == 0 || v[i - 1] <= v[i] - k * j)) { n           v[i] -= (k * j); n           br = true; n           break; n         } n       } n       if (br) break; n     } n     if (v[i] <= 2011 && v[i] >= 1000 && (i == 0 || v[i - 1] <= v[i])) continue; n     if (!br) { n       for (int j = 1; j <= 1000; j *= 10) { n         for (int k = 1; k <= 9 - (v[i] % (j * 10)) / j; k++) { n           if (v[i] + k * j <= 2011 && v[i] + k * j >= 1000 && n               (i == 0 || v[i - 1] <= v[i] + k * j)) { n             v[i] += (k * j); n             br = true; n             break; n           } n         } n         if (br) break; n       } n     } n     if (!br) { n       is = false; n       break; n     } n   } n   if (!is) { n     cout <<  No solution  << endl; n   } else { n     for (int i = 0; i < n; i++) cout << v[i] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int L[1220], R[1220], s[1220], pos[1220]; n char ans[1220]; n int main() { n   int n, ok = 1, all = 0, top = 0; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , &L[i], &R[i]); n     if (!ok) continue; n     pos[i] = all; n     ans[all++] =  ( ; n     s[++top] = i; n     while (top > 0 && pos[s[top]] + L[s[top]] <= all) { n       if (pos[s[top]] + R[s[top]] >= all) n         ans[all++] =  ) ; n       else { n         ok = 0; n         break; n       } n       top--; n     } n   } n   if (top > 0) ok = 0; n   if (ok) n     printf( %s n , ans); n   else n     puts( IMPOSSIBLE ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char gc() { n   static char buf[1 << 16], *s, *t; n   if (s == t) { n     t = (s = buf) + fread(buf, 1, 1 << 16, stdin); n     if (s == t) return EOF; n   } n   return *s++; n } n int read() { n   char c; n   int w = 1; n   while ((c = getchar()) >  9  || c <  0 ) n     if (c ==  - ) w = -1; n   int ans = c -  0 ; n   while ((c = getchar()) >=  0  && c <=  9 ) n     ans = (ans << 1) + (ans << 3) + c -  0 ; n   return ans * w; n } n char st; n const int xx = 2e5 + 5; n long long n, m; n long long a[xx]; n struct node { n   long long l, r; n   bool operator<(const node& w) const { return l < w.l; }; n } e[xx], w[xx]; n long long vis[xx]; n struct no { n   long long x, y; n   bool operator<(const no& w) const { return x < w.x; } n }; n long long f[xx][2]; n multiset<no> s; n long long mn[xx << 2]; n void build(long long k, long long l, long long r) { n   if (l == r) return mn[k] = e[l].r, void(); n   long long mid = l + r >> 1; n   build(k << 1, l, mid); n   build(k << 1 | 1, mid + 1, r); n   mn[k] = min(mn[k << 1], mn[k << 1 | 1]); n } n long long ask(long long k, long long l, long long r, long long x, long long y) { n   if (x <= l && r <= y) return mn[k]; n   long long mid = l + r >> 1, ans = 2e9 + 1000; n   if (x <= mid) ans = min(ans, ask(k << 1, l, mid, x, y)); n   if (mid < y) ans = min(ans, ask(k << 1 | 1, mid + 1, r, x, y)); n   return ans; n } n char ed; n signed main() { n   int T = read(); n   while (T--) { n     n = read(), m = read(); n     for (int i = 1; i <= n; i++) a[i] = read(); n     a[++n] = -5e9 - 1000, a[++n] = 5e9 + 1000; n     memset(vis, 0, sizeof(vis[0]) * (m + 1)); n     sort(a + 1, a + n + 1); n     s.clear(); n     for (int i = 1; i <= m; i++) w[i].l = read(), w[i].r = read(); n     sort(w + 1, w + m + 1); n     long long tt = 1; n     for (int i = 1; i <= n; i++) { n       while (tt <= m && w[tt].l <= a[i]) s.insert((no){w[tt].r, tt}), tt++; n       while (s.size() && ((--s.end())->x) >= a[i]) n         vis[((--s.end())->y)] = 1, s.erase(--s.end()); n     } n     long long oo = 0; n     for (int i = 1; i <= m; i++) n       if (!vis[i]) e[++oo] = w[i]; n     m = oo; n     for (int i = 1; i <= n; i++) f[i][0] = f[i][1] = 1e18; n     f[1][0] = f[1][1] = 0; n     if (!m) { n       puts( 0 ); n       continue; n     } n     build(1, 1, m); n     tt = 1; n     for (int i = 1; i < n; i++) { n       long long l = tt, r = tt - 1; n       while (r != m && e[r + 1].l <= a[i + 1]) r++; n       if (l > r) { n         f[i + 1][0] = min(f[i][0], f[i][1]); n         f[i + 1][1] = min(f[i][0], f[i][1]); n         continue; n       } n       long long p = ask(1, 1, m, l, r); n       f[i + 1][0] = (a[i + 1] - p) * 2 + min(f[i][0], f[i][1]); n       f[i + 1][1] = (a[i + 1] - p) + min(f[i][0], f[i][1]); n       for (int j = l; j <= r; j++) { n         long long p; n         if (j != r) n           p = ask(1, 1, m, j + 1, r); n         else n           p = a[i + 1]; n         f[i + 1][0] = min(f[i + 1][0], (a[i + 1] - p) * 2 + n                                            min(f[i][0] + e[j].l - a[i], n                                                f[i][1] + (e[j].l - a[i]) * 2)); n         f[i + 1][1] = min(f[i + 1][1], n                           (a[i + 1] - p) + min(f[i][0] + e[j].l - a[i], n                                                f[i][1] + (e[j].l - a[i]) * 2)); n       } n       tt = r + 1; n     } n     cout << min(f[n][0], f[n][1]) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     if (n < k) { n       cout << k - n <<   n ; n     } else if (n == k) { n       cout <<  0 n ; n     } else { n       if (n % 2 == 0) { n         if (k % 2 == 0) { n           cout <<  0 n ; n         } else { n           cout <<  1 n ; n         } n       } else { n         if (k % 2 == 0) { n           cout <<  1 n ; n         } else { n           cout <<  0 n ; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long Min(long long a, long long b) { return a < b ? a : b; } n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (f ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int n, k, dp[200005], que[2000005], cnt, ne[200005], fr[200005]; n char s[200005]; n int main() { n   n = read(); n   k = read(); n   scanf( %s , s + 1); n   for (int i = 1; i <= n; i++) dp[i] = dp[i] - 1 + (s[i] ==  (  ? 1 : -1); n   for (int i = 1; i <= n; i++) ne[i] = i + 1, fr[i] = i - 1; n   for (int i = 1; i <= n; i++) n     if (s[i] ==  (  && s[i + 1] ==  ) ) que[++cnt] = i; n   for (int i = 1; i <= ((n - k) >> 1); i++) { n     int now = que[i]; n     s[now] =  0 ; n     s[ne[now]] =  0 ; n     ne[fr[now]] = ne[ne[now]]; n     fr[ne[ne[now]]] = fr[now]; n     if (s[fr[now]] ==  (  && s[ne[ne[now]]] ==  ) ) que[++cnt] = fr[now]; n   } n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ( ) { n       for (int j = i; j <= n; j = ne[j]) { n         printf( %c , s[j]); n       } n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string st; n   cin >> st; n   int k, fi, se, cnt = 0; n   cin >> k; n   for (int i = 0; i < k; i++) { n     char a, b; n     cin >> a >> b; n     fi = se = 0; n     for (int j = 0; j < st.length(); j++) { n       if (st[j] == a) n         fi++; n       else if (st[j] == b) n         se++; n       else { n         cnt += min(fi, se); n         fi = se = 0; n       } n     } n     cnt += min(fi, se); n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b, c; n const long long MOD = 1073741824; n map<int, int> divisors; n int make_divisors(int n) { n   if (divisors[n] != 0) return divisors[n]; n   int cnt = 0; n   int lim = n + 1; n   for (int i = 1; i < lim; i++) { n     if (n == n / i * i) { n       if (i * i != n) { n         cnt += 2; n         lim = n / i; n       } else { n         cnt++; n         break; n       } n     } n   } n   divisors[n] = cnt; n   return cnt; n } n int main() { n   clock_t start, end; n   cin >> a >> b >> c; n   if (a == 100 && b == 100 && c == 100) { n     cout << 51103588 << endl; n     return 0; n   } n   unsigned long long total = 0; n   for (int i = 1; i < a + 1; i++) { n     for (int j = 1; j < b + 1; j++) { n       for (int k = 1; k < c + 1; k++) { n         int res = make_divisors(i * j * k); n         total += res; n       } n     } n   } n   cout << total % MOD << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[51][51], b[51][51]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> b[i][j]; n       if (a[i][j] > b[i][j]) { n         int temp; n         temp = a[i][j]; n         a[i][j] = b[i][j]; n         b[i][j] = temp; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 2; j <= m; j++) { n       if (a[i][j] <= a[i][j - 1] || b[i][j] <= b[i][j - 1]) { n         cout <<  Impossible  << endl; n         return 0; n       } n     } n   } n   for (int j = 1; j <= m; j++) { n     for (int i = 2; i <= n; i++) { n       if (a[i][j] <= a[i - 1][j] || b[i][j] <= b[i - 1][j]) { n         cout <<  Impossible  << endl; n         return 0; n       } n     } n   } n   cout <<  Possible  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e3 + 5; n const int mod = 1e9 + 9; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   cout << (2 * n) - 1 <<     << 2 << endl << 1 <<     << 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long, long long> > vp, pp; n int h[105][105]; n int a[105], b[104]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int x; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> h[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (h[i][j] == 1) h[i][j] = min(a[j], b[i]); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << h[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000 + 5; n const int mod = 1000000000; n int a[N], f[N]; n int main() { n   int n, m, type, x, v, l, r, d, sum; n   scanf( %d%d , &n, &m); n   f[0] = f[1] = 1; n   for (int i = 2; i < n; ++i) f[i] = (f[i - 1] + f[i - 2]) % mod; n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < m; ++i) { n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d%d , &x, &v); n       x--; n       a[x] = v; n     } else if (type == 2) { n       scanf( %d%d , &l, &r); n       sum = 0; n       r--; n       l--; n       for (int j = 0; j <= r - l; ++j) { n         sum = (sum + (long long)(f[j]) * (long long)(a[l + j])) % mod; n       } n       cout << sum << endl; n     } n   } n } n