#include <bits/stdc++.h>   using namespace std;   const int MAX_INT = 1000 * 1000 * 1000;   int n, m;   vector<int> ver;   vector<int> hor;   int main() {     cin >> n >> m;     ver.reserve(n + 1);     ver.resize(n);     for (int i = 0; i < n; ++i) cin >> ver.at(i), ver.at(i) += 1;     ver.push_back(MAX_INT + 1);     sort(ver.begin(), ver.end());     for (int i = 0; i < m; ++i) {       int x1, x2, y;       cin >> x1 >> x2 >> y;       if (x1 == 1) hor.push_back(x2 + 1);     }     sort(hor.begin(), hor.end());     int bestAns = n + m;     for (int i = 0; i < ver.size(); ++i) {       auto it = lower_bound(hor.begin(), hor.end(), ver.at(i));       int mustBreak = distance(it, hor.end());       bestAns = min(bestAns, i + mustBreak);     }     cout << bestAns << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     string a(s);     int n;     cin >> n;     for (int i = 0; i < int(s.size()); ++i) {       if (isupper(s[i])) {         s[i] -=  A ;         s[i] +=  a ;       }       if (s[i] <  a  + n) {         a[i] = s[i] -  a  +  A ;       } else         a[i] = s[i];     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void timer() { return; }   const int mod = 1e9 + 7;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   string ds =  RLDU ;   const int mx = 5e4 + 10;   long long sum[mx];   void solve() {     int n, t;     cin >> n >> t;     for (int i = (1); i < (n + 1); ++i) {       for (int j = (0); j < (n - i); ++j) {         cout << 0 <<    ;       }       cout << t <<    ;       for (int j = (n - i + 1); j < (n); ++j) cout << 0 <<    ;       cout << endl;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     timer();     int t = 1;     for (int i = (1); i < (t + 1); ++i) {       solve();     }     timer();   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   enum dir {     DOWN = 0,     UP,     RIGHT,     LEFT,     DOWN_RIGHT,     DOWN_LEFT,     UP_RIGHT,     UP_LEFT   };   int dir_r[] = {1, -1, 0, 0, 1, 1, -1, -1};   int dir_c[] = {0, 0, 1, -1, 1, -1, 1, -1};   bool p(long long s) {     if (s == 1 || (s % 2 == 0 && s != 2)) return 0;     for (int i = 2; i <= sqrt(s); i++) {       if (s % i == 0) return 0;     }     return 1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     if (p(n)) return cout << 1, 0;     long long ans = 1e12;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (p(i)) {           ans = min(ans, i);         }         if (p(n / i)) ans = min(ans, i);       }     }     if (ans == 1e12)       cout << 0;     else {       n -= ans;       cout << n / 2 + 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[200000], b[200000];   bool ok(long long x) {     int p(1);     long long q(0);     for (int i = 1; i <= (m); ++i)       if (b[i] > q) {         while (p <= n && a[p] + x < b[i]) ++p;         if (a[p] - x > b[i] || p > n) return false;         if (a[p] <= b[i])           q = a[p] + x;         else           q = max(b[i] + x - (a[p] - b[i]), a[p] + (x - (a[p] - b[i])) / 2);         ++p;       }     return true;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= (n); ++i) scanf( %I64d , &a[i]);     for (int i = 1; i <= (m); ++i) scanf( %I64d , &b[i]);     long long L = -1, R = 1LL << 40;     while (L + 1 < R) (ok(L + R >> 1) ? R : L) = L + R >> 1;     printf( %I64d n , R);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x;     cin >> x;     vector<long long> result;     for (long long i = 1; i <= x; i++) {       long long n;       cin >> n;       vector<long long> v(n);       for (long long h = 0; h <= n - 1; h++) cin >> v[h];       sort(v.begin(), v.end());       if (v[n - 1] == 1 || v[n - 2] == 1)         result.push_back(0);       else if ((n - 2) < v[n - 2])         result.push_back(n - 2);       else if ((n - 2) >= v[n - 2])         result.push_back(v[n - 2] - 1);     }     for (long long i = 0; i <= x - 1; i++) cout << result[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int test_number);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.setf(ios::fixed);     cout.precision(9);     cerr.setf(ios::fixed);     cerr.precision(3);     int n = 1;     for (int i = 0; i < n; i++) {       solve(i);     }   }   const int MAX_N = 300005;   int n, n_edge, deg[MAX_N];   int point[MAX_N], head[MAX_N], next_edge[MAX_N];   bool line[MAX_N];   void add_edge(int u, int v) {     point[n_edge] = v, next_edge[n_edge] = head[u], head[u] = n_edge++;     point[n_edge] = u, next_edge[n_edge] = head[v], head[v] = n_edge++;   }   bool is_line(int u, int p) {     int cnt = 0;     for (int i = head[u]; i >= 0; i = next_edge[i]) {       int v = point[i];       if (v == p) {         continue;       }       if (!line[v]) {         return false;       }       cnt++;       if (cnt > 2) {         return false;       }     }     return true;   }   bool good(int u, int p, int lim) {     int cnt = 0, all = 0;     for (int i = head[u]; i >= 0; i = next_edge[i]) {       int v = point[i];       if (v == p) {         continue;       }       if (is_line(v, u)) {         cnt++;       } else if (!good(v, u, 1)) {         return false;       }       all++;     }     if (all - cnt <= lim) {       return true;     }     return false;   }   void dfs_line(int u, int p) {     int cnt = 0, lst = -1;     for (int i = head[u]; i >= 0; i = next_edge[i]) {       int v = point[i];       if (v == p) {         continue;       }       cnt++;       lst = v;       dfs_line(v, u);     }     if (cnt == 0 || (cnt == 1 && line[lst])) {       line[u] = true;     }   }   void solve(int test_number) {     cin >> n;     memset(head, -1, sizeof(head));     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       --u, --v;       add_edge(u, v);       deg[u]++;       deg[v]++;     }     for (int root = 0; root < min(n, 50); root++) {       memset(line, false, sizeof(line));       dfs_line(root, -1);       if (good(root, -1, 2) || is_line(root, -1)) {         cout <<  Yes  << endl;         return;       }     }     cout <<  No  << endl;   }


#include <bits/stdc++.h>   long long int n, m;   long long int pow(long long int k) {     long long int a = 1, t = 3;     for (; k; k /= 2) {       if (k & 1) a = (a * t) % m;       t = t * t % m;     }     return a;   }   void suru() { scanf( %I64d %I64d , &n, &m); }   void truli() {}   void sutru() { printf( %I64d n , (pow(n) - 1 + m) % m); }   int main() {     suru();     truli();     sutru();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9;   template <typename T>   inline T read() {     T sum = 0, fl = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) fl = -1;     for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch -  0 ;     return sum * fl;   }   const int maxn = 1e6 + 5;   int n, mx;   pair<int, int> id;   struct Node {     int first, second, w;   } o[maxn];   int li[maxn];   long long ans;   bool operator<(const Node& a, const Node& b) { return a.second < b.second; }   namespace SEG {   pair<long long, int> tr[maxn << 2];   long long tag[maxn << 2];   inline pair<long long, int> Merge(const pair<long long, int>& a,                                     const pair<long long, int>& b) {     return a.first > b.first ? a : b;   }   inline void pushdown(int rt) {     if (!tag[rt]) return;     tr[(rt << 1)].first += tag[rt];     tr[(rt << 1 | 1)].first += tag[rt];     tag[(rt << 1)] += tag[rt];     tag[(rt << 1 | 1)] += tag[rt];     tag[rt] = 0;   }   void build(int rt, int l, int r) {     if (l == r) return (void)(tr[rt] = make_pair(li[l], l));     build((rt << 1), l, ((l + r) >> 1));     build((rt << 1 | 1), ((l + r) >> 1) + 1, r);     tr[rt] = Merge(tr[(rt << 1)], tr[(rt << 1 | 1)]);   }   void update(int rt, int l, int r, int ql, int qr, int v) {     if (l >= ql && r <= qr) return (void)(tr[rt].first += v, tag[rt] += v);     pushdown(rt);     if (((l + r) >> 1) >= ql) update((rt << 1), l, ((l + r) >> 1), ql, qr, v);     if (((l + r) >> 1) < qr)       update((rt << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v);     tr[rt] = Merge(tr[(rt << 1)], tr[(rt << 1 | 1)]);   }   pair<long long, int> query(int rt, int l, int r, int ql, int qr) {     if (l >= ql && r <= qr) return tr[rt];     pair<long long, int> ans = make_pair(0, 0);     pushdown(rt);     if (((l + r) >> 1) >= ql)       ans = Merge(ans, query((rt << 1), l, ((l + r) >> 1), ql, qr));     if (((l + r) >> 1) < qr)       ans = Merge(ans, query((rt << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr));     return ans;   }   }  // namespace SEG   void Solve() {     n = read<int>();     ans = 0;     id = make_pair(2e9, 2e9);     for (int i = 1; i <= n; ++i)       o[i].first = read<int>(), o[i].second = read<int>(), o[i].w = read<int>();     for (int i = 1; i <= n; ++i) li[i] = o[i].first, li[i + n] = o[i].second;     sort(li + 1, li + n + n + 1);     mx = unique(li + 1, li + n + n + 1) - li - 1;     for (int i = 1; i <= n; ++i) {       int first = min(o[i].first, o[i].second),           second = max(o[i].first, o[i].second);       o[i].first = lower_bound(li + 1, li + mx + 1, first) - li;       o[i].second = lower_bound(li + 1, li + mx + 1, second) - li;     }     sort(o + 1, o + n + 1);     SEG ::build(1, 1, mx);     for (int i = 1; i <= n;) {       do {         SEG ::update(1, 1, mx, 1, o[i].first, o[i].w);         ++i;       } while (i <= n && o[i].second == o[i - 1].second);       pair<long long, int> now = SEG ::query(1, 1, mx, 1, o[i - 1].second);       int r = o[i - 1].second;       if (now.first - li[r] > ans && now.second)         ans = now.first - li[r], id = make_pair(li[now.second], li[r]);     }     printf( %lld n%d %d %d %d n , ans, id.first, id.first, id.second, id.second);   }   int main() {     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int n = s.length();     int r = 0;     vector<int> fin(3, -1);     fin[0] = 0;     vector<int> z(n + 1);     for (int i = 1; i <= n; i++) {       r = (r + s[i - 1] -  0 ) % 3;       z[i] = z[i - 1];       if (fin[r] != -1) z[i] = max(z[i], z[fin[r]] + 1);       fin[r] = i;     }     cout << z[n] << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tst = 1;     while (tst--) solve();     return 0;   }


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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