#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T a, const T b) {     return a < b ? a : b;   }   template <typename T>   inline T qmax(const T a, const T b) {     return a > b ? a : b;   }   template <typename T>   inline void getmin(T &a, const T b) {     if (a > b) a = b;   }   template <typename T>   inline void getmax(T &a, const T b) {     if (a < b) a = b;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = 1e9;   const long long linf = 1e17 + 7;   const int N = 2e5 + 7;   struct seg {     int h, l, r;     seg() {}     seg(int _h, int _l, int _r) : h(_h), l(_l), r(_r) {}     bool operator<(const seg &b) const { return h < b.h; }   } a[N];   struct node {     int l, r, v;     seg s;     node() {}     node(int _l, int _r, int _v, seg _s) : l(_l), r(_r), v(_v), s(_s) {}     bool operator<(const node &b) const { return l < b.l; }   };   inline int overlap(int l1, int r1, int l2, int r2) {     return qmax(0, qmin(r1, r2) - qmax(l1, l2));   }   inline bool canget(const seg &a, set<node>::iterator it) {     set<node>::iterator ul = it, ur = it;     --ul;     ++ur;     seg pre = ul->s, nxt = ur->s, cur = it->s;     if (pre.h < a.h && pre.h > cur.h && overlap(a.l, a.r, pre.l, pre.r) &&         overlap(pre.l, pre.r, cur.l, cur.r))       return false;     if (nxt.h < a.h && nxt.h > cur.h && overlap(a.l, a.r, nxt.l, nxt.r) &&         overlap(nxt.l, nxt.r, cur.l, cur.r))       return false;     return true;   }   set<node> s;   int n, t;   int main() {     scanf( %d%d , &n, &t);     for (int i = 1; i <= n; ++i) scanf( %d%d%d , &a[i].h, &a[i].l, &a[i].r);     a[++n] = seg(t, -inf, inf);     sort(a + 1, a + n + 1);     node bot(-inf, inf, inf << 1, seg(0, -inf, inf));     node left(-inf - 1, -inf, 0, seg());     node right(inf, inf + 1, 0, seg());     s.insert(bot);     s.insert(left);     s.insert(right);     for (int i = 1; i <= n; ++i) {       set<node>::iterator ul = s.upper_bound(node(a[i].l, a[i].r, 0, seg())), ur;       int ans = 0;       for (--ul; ul->r <= a[i].l; ++ul)         ;       for (ur = ul; ur->l < a[i].r; ++ur) {         if (!canget(a[i], ur)) continue;         getmax(ans, qmin(overlap(a[i].l, a[i].r, ur->l, ur->r), ur->v));       }       --ur;       int l = ul->l, r = ur->r, v1 = ul->v, v2 = ur->v;       seg s1 = ul->s, s2 = ur->s;       ++ur;       s.erase(ul, ur);       s.insert(node(a[i].l, a[i].r, ans, a[i]));       if (l < a[i].l) s.insert(node(l, a[i].l, v1, s1));       if (r > a[i].r) s.insert(node(a[i].r, r, v2, s2));     }     set<node>::iterator ite = s.begin();     ++ite;     printf( %d n , ite->v);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   const long long int INF = 2e9;   void init(vector<int> &dsu) {     for (int i = 0; i < ((int)(dsu).size()); i++) {       dsu[i] = i;     }   }   int find_p(vector<int> &dsu, int id) {     if (dsu[id] == id) return id;     return dsu[id] = find_p(dsu, dsu[id]);   }   bool unite(vector<int> &dsu, int f, int s) {     f = find_p(dsu, f);     s = find_p(dsu, s);     if (f == s) return true;     dsu[f] = s;     return false;   }   inline bool in(long double f, long double s, long double d) {     return s >= f && s <= d;   }   bool intr(pair<long double, long double> f, pair<long double, long double> s,             long double time) {     if (time == INF) return true;     long double a1 = -1, b1 = -1, c1 = -(a1 * f.first + b1 * f.second);     long double a2 = 1, b2 = -1, c2 = -(a2 * s.first + b2 * s.second);     long double x = (b1 * c2 - b2 * c1) / (a1 * b2 - b1 * a2),                 y = (c1 * a2 - a1 * c2) / (a1 * b2 - b1 * a2);     return in(f.first - time, x, f.first + time) &&            in(f.second - time, y, f.second + time) &&            in(s.first - time, x, s.first + time) &&            in(s.second - time, y, s.second + time);   }   bool ini(long double f, long double s, long double time) {     return (f - s) <= time * 2;   }   bool intr2(pair<long double, long double> f, pair<long double, long double> s,              int q, long double time) {     if (!q && !(f.first + f.second == s.first + s.second)) return false;     if (q && !(f.first - f.second == s.first - s.second)) return false;     if (time == INF) return true;     long double x = min(f.first, s.first), x2 = max(f.first, s.first);     long double y = min(f.second, s.second), y2 = max(f.second, s.second);     return ini(x, x2, time) && ini(y, y2, time);   }   bool can(vector<pair<long double, long double> > p1,            vector<pair<long double, long double> > p2, long long int time) {     int n = (int)(p1).size(), m = (int)(p2).size();     for (int q = 0; q < (2); q++) {       vector<int> with(n, -1);       vector<int> dsu(m);       init(dsu);       for (int i = 0; i < (n); i++) {         for (int j = 0; j < (m); j++) {           if (intr(!q ? p1[i] : p2[j], !q ? p2[j] : p1[i], time)) {             if (with[i] == -1)               with[i] = j;             else {               if (unite(dsu, j, with[i])) {                 return true;               }             }           }         }         for (int j = 0; j < (i); j++) {           if (i == j) continue;           if (with[j] == -1 || with[i] == -1) continue;           if (intr2(p1[i], p1[j], q, time)) {             if (unite(dsu, with[i], with[j])) {               return true;             }           }         }       }       swap(n, m);       swap(p1, p2);     }     return false;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<long double, long double> > p1(n), p2(m);     bool yes = false;     for (int i = 0; i < (n); i++) {       int a, b;       scanf( %d%d , &a, &b);       p1[i] = make_pair(a, b);       if (i && a + b != p1[i - 1].first + p1[i - 1].second) yes = true;     }     bool yes2 = false;     for (int i = 0; i < (m); i++) {       int a, b;       scanf( %d%d , &a, &b);       p2[i] = make_pair(a, b);       if (i && a - b != p2[i - 1].first - p2[i - 1].second) yes2 = true;     }     if ((!yes || !yes2) || !can(p1, p2, INF)) {       cout <<  Poor Sereja! ;       return 0;     }     long long int l = 0, r = INF;     while (l != r) {       long long int m = (l + r) / 2;       if (can(p1, p2, m)) {         r = m;       } else         l = m + 1;     }     cout << l;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   const int MAXN = 150005;   int N;   int in[MAXN];   bool good(int a, int b) {     swap(in[a], in[b]);     bool bad = false;     for (int(i) = 0; (i) < (N - 1); ++(i)) {       if (i % 2 == 0) {         if (in[i] >= in[i + 1]) {           bad = true;           break;         }       } else {         if (in[i] <= in[i + 1]) {           bad = true;           break;         }       }     }     swap(in[a], in[b]);     return !bad;   }   bool check2(int p) {     if (p < 0 || p >= N) return true;     if (p % 2 == 0) {       if (p + 1 < N && in[p] >= in[p + 1]) return false;       if (p - 1 >= 0 && in[p] >= in[p - 1]) return false;     } else {       if (p + 1 < N && in[p] <= in[p + 1]) return false;       if (p - 1 >= 0 && in[p] <= in[p - 1]) return false;     }     return true;   }   bool check_local(int a, int b) {     swap(in[a], in[b]);     bool g1 = true;     for (int i = -1; i <= 1; i++) {       g1 &= check2(a + i);       g1 &= check2(b + i);     }     swap(in[a], in[b]);     return g1;   }   int main() {     scanf( %d , &N);     for (int(i) = 0; (i) < (N); ++(i)) {       scanf( %d , &in[i]);     }     set<int> bad;     int num_bad_local = 0;     int xx = -1;     for (int(i) = 0; (i) < (N - 1); ++(i)) {       if (i % 2 == 0) {         if (in[i] >= in[i + 1]) {           bad.insert(i);           bad.insert(i + 1);           num_bad_local++;           xx = i;           i++;         }       } else {         if (in[i] <= in[i + 1]) {           bad.insert(i);           bad.insert(i + 1);           num_bad_local++;           xx = i;           i++;         }       }     }     if (((int)(bad).size()) > 10) {       printf( 0 n );       return 0;     }     set<pair<int, int> > ans;     for (int first : bad) {       for (int second : bad) {         if (first < second) {           if (good(first, second)) {             ans.insert(pair<int, int>(first, second));           }         }       }     }     if (num_bad_local == 1) {       for (int(g) = 0; (g) < (N); ++(g)) {         if (g != xx && g != xx + 1) {           if (check_local(g, xx)) {             int a = g;             int b = xx;             if (a > b) swap(a, b);             ans.insert(pair<int, int>(a, b));           }           if (check_local(g, xx + 1)) {             int a = g;             int b = xx + 1;             if (a > b) swap(a, b);             ans.insert(pair<int, int>(a, b));           }         }       }     }     cout << ((int)(ans).size()) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9 + 7;   const double pi = 3.14159265358979323846;   template <class T>   T sqr(T x) {     return x * x;   }   double len(const pair<int, int> &p1, const pair<int, int> &p2) {     return sqrt(sqr((long long)p1.first - p2.first) +                 sqr((long long)p1.second - p2.second));   }   double foo(const vector<pair<int, int>> &pol, int l, int r, bool side) {     static vector<vector<vector<double>>> dp(         2, vector<vector<double>>(2500, vector<double>(2501, -1)));     if (r <= l + 1) return 0;     if (l > (int)pol.size() / 2)       return foo(pol, l - (pol.size() + 1) / 2, r - (pol.size() + 1) / 2, side);     if (dp[side][l][r - l] == -1)       if (side)         dp[side][l][r - l] =             max(len(pol[r - 1], pol[l]) + foo(pol, l, r - 1, 0),                 len(pol[r - 1], pol[r - 2]) + foo(pol, l, r - 1, 1));       else         dp[side][l][r - l] = max(len(pol[l], pol[l + 1]) + foo(pol, l + 1, r, 0),                                  len(pol[l], pol[r - 1]) + foo(pol, l + 1, r, 1));     return dp[side][l][r - l];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<int, int>> pol(n);     for (auto &it : pol) cin >> it.first >> it.second;     for (int i = 0; i < n - 1; i++) pol.push_back(pol[i]);     double best = numeric_limits<double>::lowest();     for (int i = 0; i < n - 1; i++)       best = max(best, max(foo(pol, i, i + n, 0), foo(pol, i, i + n, 1)));     cout.precision(20);     cout << fixed << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 4;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     cin >> s;     long long n = s.size();     long long sub = 0;     for (int k = 1; k <= 8; k++) {       for (int i = 0; i + k <= n; i++) {         bool flag = false;         for (int j = 1; 2 * j < k; j++) {           for (int st = i; st + 2 * j < i + k; st++) {             if (s[st] == s[st + j] && s[st] == s[st + 2 * j]) {               flag = true;             }           }         }         if (!flag) sub++;       }     }     cout << n * (n + 1) / 2 - sub <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3E4 + 7;   int x[N], y[N];   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     x[0] = a[0], y[0] = 0;     for (int i = 1; i < n; i++) {       x[i] = min(x[i - 1], a[i]), y[i] = a[i] - x[i];       if (y[i] >= y[i - 1]) continue;       y[i] = y[i - 1], x[i] = a[i] - y[i];       if (x[i] < 0) {         cout <<  NO n ;         return;       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   struct Tree {     int tl, tr;     int mx;   } tree[maxn << 2];   set<int> st[maxn];   int ve[maxn], n, m;   void build(int id, int l, int r) {     tree[id].tl = l;     tree[id].tr = r;     tree[id].mx = -1;     if (l == r) return;     int mid = (l + r) >> 1;     build(id << 1, l, mid);     build(id << 1 | 1, mid + 1, r);   }   void update(int id, int pos, int val, int y) {     int l = tree[id].tl, r = tree[id].tr;     if (l == r) {       if (st[pos].size())         tree[id].mx = *(--st[pos].end());       else         tree[id].mx = -1;       return;     }     int mid = (l + r) >> 1;     if (pos <= mid)       update(id << 1, pos, val, y);     else       update(id << 1 | 1, pos, val, y);     tree[id].mx = max(tree[id << 1].mx, tree[id << 1 | 1].mx);   }   int query(int id, int ql, int qr, int y) {     int l = tree[id].tl, r = tree[id].tr;     if (tree[id].mx <= y || ql > qr) {       return -1;     }     int mid = (l + r) >> 1;     if (l == r) return l;     if (qr <= mid)       return query(id << 1, ql, qr, y);     else if (ql > mid)       return query(id << 1 | 1, ql, qr, y);     else {       int tmp = query(id << 1, ql, mid, y);       if (tmp != -1) return tmp;       return query(id << 1 | 1, mid + 1, qr, y);     }   }   struct Point {     int x, y;     char op[5];     void init() { scanf( %s%d%d , op, &x, &y); }   } q[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       q[i].init();       ve[i] = q[i].x;     }     sort(ve + 1, ve + 1 + n);     int m = unique(ve + 1, ve + 1 + n) - (ve + 1);     build(1, 1, m);     for (int i = 1; i <= n; i++) {       int pos = lower_bound(ve + 1, ve + 1 + m, q[i].x) - ve;       if (q[i].op[0] ==  a ) {         st[pos].insert(q[i].y);         update(1, pos, 1, q[i].y);       } else if (q[i].op[0] ==  r ) {         st[pos].erase(q[i].y);         update(1, pos, 1, q[i].y);       } else {         int ans = query(1, pos + 1, m, q[i].y);         if (ans == -1)           printf( -1 n );         else           printf( %d %d n , ve[ans], *st[ans].upper_bound(q[i].y));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, k;     cin >> n >> k;     string s[n + 1];     set<string> ar;     for (int x = 0; x < n; x++) {       cin >> s[x];       ar.insert(s[x]);     }     char a[3] = { S ,  E ,  T };     long long int ans = 0;     for (int x = 0; x < n; x++) {       for (int y = x + 1; y < n; y++) {         string d;         for (int z = 0; z < k; z++) {           if (s[x][z] == s[y][z]) {             d += s[x][z];           } else {             for (int i = 0; i < 3; i++) {               if (a[i] != s[x][z] && a[i] != s[y][z]) {                 d += a[i];                 break;               }             }           }         }         if (d.length() != 0)           if (ar.count(d)) ++ans;       }     }     cout << ans / 3 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n & 1) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n & 1) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   const int N = 300005;   long long x[N];   long long d[N], a[N];   long long find(int i, int j) {     if (i == 0) return x[j];     return (x[j] - x[i - 1] + 1000000007) % 1000000007;   }   int main() {     int i, j;     int n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %lld , &a[i]);     sort(a, a + n);     x[0] = 1;     for (i = 1; i < n; i++) {       d[i] = a[i] - a[i - 1];       x[i] = (power(2ll, i, 1000000007) + x[i - 1]) % 1000000007;     }     long long ans = 0;     for (i = 1; i < n; i++) {       ans += (d[i] * find(i - 1, n - 2)) % 1000000007;     }     long long z = ans;     for (i = 2; i < n; i++) {       z = (z - (d[i - 1] * x[n - i]) % 1000000007 + 1000000007) % 1000000007;       z = (z * power(2, 1000000007 - 2, 1000000007)) % 1000000007;       ans = (ans + z) % 1000000007;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y;   int n, m, k;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> x >> y;       if (x <= 5 || y <= 5 || n - x <= 4 || m - y <= 4) {         cout <<  YES  << endl;         return 0;       }     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:100000000 )   using namespace std;   const int N = 155;   const int INF = 1000000000;   struct Edge {     int to, flow, cap, cost;     Edge() {}     Edge(int to, int flow, int cap, int cost)         : to(to), flow(flow), cap(cap), cost(cost) {}   };   vector<Edge> g[N];   void add_edge(int from, int to, int cap, int cost) {     g[from].push_back(Edge(to, 0, cap, cost));     g[to].push_back(Edge(from, cap, cap, -cost));   }   int* count_letters(string s) {     int* a = new int[26];     memset(a, 0, 26 * sizeof(int));     for (int(i) = 0; (i) < ((int)(s).size()); (i)++) a[s[i] -  a ]++;     return a;   }   int d[N], p[N], id[N];   void find_flow(int src, int goal, int need) {     int flow = 0, n = goal + 1, cost = 0;     while (flow < need) {       for (int(i) = 0; (i) < (n); (i)++) d[i] = INF, p[i] = id[i] = -1;       d[src] = 0;       for (int(i) = 0; (i) < (n - 1); (i)++) {         for (int(a) = 0; (a) < (n); (a)++) {           for (int(j) = 0; (j) < ((int)(g[a]).size()); (j)++) {             int b = g[a][j].to;             if (g[a][j].flow < g[a][j].cap && d[b] > d[a] + g[a][j].cost) {               d[b] = d[a] + g[a][j].cost;               p[b] = a;               id[b] = j;             }           }         }       }       if (d[goal] == INF) {         puts( -1 );         return;       }       int push = INF, cur = goal;       while (cur != src) {         push = min(push, g[p[cur]][id[cur]].cap - g[p[cur]][id[cur]].flow);         cur = p[cur];       }       cur = goal;       flow += push;       while (cur != src) {         g[p[cur]][id[cur]].flow += push;         cost += push * g[p[cur]][id[cur]].cost;         for (int(i) = 0; (i) < ((int)(g[cur]).size()); (i)++) {           if (g[cur][i].to == p[cur]) {             g[cur][i].flow -= push;             break;           }         }         cur = p[cur];       }     }     printf( %d n , cost);   }   int main() {     string t;     cin >> t;     int* a = count_letters(t);     int n;     cin >> n;     for (int(i) = 0; (i) < (26); (i)++) add_edge(n + 1 + i, n + 27, a[i], 0);     for (int(i) = 0; (i) < (n); (i)++) {       string s;       int cap;       cin >> s >> cap;       int* b = count_letters(s);       add_edge(0, i + 1, cap, i + 1);       for (int(j) = 0; (j) < (26); (j)++) add_edge(i + 1, n + 1 + j, b[j], 0);     }     find_flow(0, n + 27, (int)(t).size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int i, t, c, sum = 0;     cin >> t;     long long int a[t];     for (i = 0; i < t; i++) {       cin >> a[i];     }     for (i = 0; i < t; i++) {       sum += a[i];     }     if (sum % 2 == 0) {       cout << sum << endl;     } else {       long long int min = 1000000001;       for (i = 0; i < t; i++) {         if (a[i] <= min && a[i] % 2 != 0) {           min = a[i];         }       }       sum = sum - min;       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, s[10001], ss[10001];     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     for (int i = 1; i < n; i++) {       ss[i] = abs(s[i] - s[i + 1]);     }     ss[n] = abs(s[n] - s[1]);     int t, min = 999999;     for (int i = 1; i <= n; i++) {       if (min > ss[i]) {         min = ss[i];         t = i;       }     }     if (t != n)       printf( %d %d n , t, t + 1);     else       printf( %d %d n , t, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 132700;   int n;   tuple<int, int, int, int> esq[N], dir[N];   vector<tuple<int, int, int, int>> v;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       v.emplace_back(a, b, c, d);     }     esq[0] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f);     for (int i = 1; i <= n; i++) {       int xb, yb, xu, yu;       tie(xb, yb, xu, yu) = v[i - 1];       get<0>(esq[i]) = max(get<0>(esq[i - 1]), xb);       get<1>(esq[i]) = max(get<1>(esq[i - 1]), yb);       get<2>(esq[i]) = min(get<2>(esq[i - 1]), xu);       get<3>(esq[i]) = min(get<3>(esq[i - 1]), yu);     }     dir[n + 1] = make_tuple(-0x3f3f3f3f, -0x3f3f3f3f, +0x3f3f3f3f, +0x3f3f3f3f);     for (int i = n; i >= 1; i--) {       int xb, yb, xu, yu;       tie(xb, yb, xu, yu) = v[i - 1];       get<0>(dir[i]) = max(get<0>(dir[i + 1]), xb);       get<1>(dir[i]) = max(get<1>(dir[i + 1]), yb);       get<2>(dir[i]) = min(get<2>(dir[i + 1]), xu);       get<3>(dir[i]) = min(get<3>(dir[i + 1]), yu);     }     for (int i = 1; i <= n; i++) {       int xb, yb, xu, yu;       xb = max(get<0>(esq[i - 1]), get<0>(dir[i + 1]));       yb = max(get<1>(esq[i - 1]), get<1>(dir[i + 1]));       xu = min(get<2>(esq[i - 1]), get<2>(dir[i + 1]));       yu = min(get<3>(esq[i - 1]), get<3>(dir[i + 1]));       if (xb <= xu and yb <= yu) {         cout << xb <<     << yb << endl;         return 0;       }     }     assert(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b;   int main() {     cin >> a >> b;     if (abs(a - b) <= 1 && (a || b)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Q_Q() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   map<int, bool> mp;   int main() {     Q_Q();     int n, k;     double t;     cin >> n >> k >> t;     int arr[n];     long long int sum = 0;     for (int i = 0; i < n; i++) {       arr[i] = k;       sum += k;     }     int j = n - 1;     while ((sum * 1.0 / ((n * k) * 1.0)) > t / 100) {       arr[j]--;       if (arr[j] == 0) j--;       sum--;     }     for (int i = 0; i < n; i++) cout << arr[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned int n, m, l;     cin >> n >> m >> l;     int s = 0;     while (l--) {       s += 2 * (n + m - 2);       n -= 4;       m -= 4;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 2;   long long d, k, a, b, t;   int main() {     cin >> d >> k >> a >> b >> t;     if (d <= k) {       cout << d * a;     } else if (t + k * a > k * b) {       cout << k * a + (d - k) * b;     } else {       long long cnt = d / k;       long long ans =           k * a * cnt + (cnt - 1) * t + min(t + (d % k) * a, (d % k) * b);       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i;     scanf( %I64d , &n);     if (n <= 3) {       printf( 1 );       return 0;     }     if (n == 4) {       printf( 2 );       return 0;     }     if (n % 2 == 0)       printf( 2 );     else {       bool u = 1;       for (i = 2; i * i <= n; i++)         if (n % i == 0) {           u = 0;           break;         }       if (u)         printf( 1 );       else {         n = n - 2;         bool v = 1;         for (i = 2; i * i <= n; i++)           if (n % i == 0) {             v = 0;             break;           }         if (v)           printf( 2 );         else           printf( 3 );       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long inf = 4e18;   const long long N = 2e5 + 5;   long long ans[N];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tt = 1;     while (tt--) {       long long n;       cin >> n;       long long l, r;       map<long long, long long> mp;       for (long long i = 0; i < n; ++i) {         cin >> l >> r;         ++mp[l];         --mp[r + 1];       }       long long cnt = 0;       l = -1;       for (auto it : mp) {         if (l == -1) {           l = it.first;           cnt += it.second;         } else {           ans[cnt] += (it.first - l);           l = it.first;           cnt += it.second;         }       }       for (long long i = 1; i <= n; ++i) cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int a[6] = {3, 3, 3, 2, 2, 1};   const int b[6] = {2, 1, 0, 1, 0, 0};   const int inf = 1000000000;   const double eps = 1e-6;   int Dist[6];   double X[7];   int Round(double X) {     int T = (int)X;     if (T + 1 - X < eps) T++;     return T;   }   bool Check(int Len) {     static double G[7][7], A[7];     memset(G, 0, sizeof(G));     for (int i = 0; i < 6; i++)       for (int j = 0; j < 7; j++) {         bool F0 = (j + 1) & (1 << a[i]);         bool F1 = (j + 1) & (1 << b[i]);         G[i][j] = F0 ^ F1;       }     for (int i = 0; i < 7; i++) G[6][i] = 1;     for (int i = 0; i < 6; i++) A[i] = Dist[i];     A[6] = Len;     for (int i = 0; i < 7; i++) {       if (!G[i][i]) {         int P = i + 1;         while (!G[P][i]) P++;         for (int j = i; j < 7; j++) swap(G[i][j], G[P][j]);         swap(A[i], A[P]);       }       for (int j = i + 1; j < 7; j++)         if (G[j][i]) {           double T = G[j][i] / G[i][i];           for (int k = i; k < 7; k++) G[j][k] -= G[i][k] * T;           A[j] -= A[i] * T;         }     }     for (int i = 6; i >= 0; i--) {       X[i] = A[i] / G[i][i];       for (int j = 0; j < i; j++) A[j] -= X[i] * G[j][i];     }     for (int i = 0; i < 7; i++)       if (fabs(X[i] - Round(X[i])) > eps || X[i] < -eps) return false;     return true;   }   int main() {     for (int i = 0; i < 6; i++) scanf( %d , &Dist[i]);     int Ans = -1, Sum = 0;     for (int i = 0; i < 6; i++) Sum += Dist[i];     for (int i = Sum / 4; Ans == -1 && i <= Sum / 3; i++)       if (Check(i)) Ans = i;     printf( %d n , Ans);     if (Ans == -1) return 0;     string S[4];     for (int i = 0; i < 7; i++) {       int M = Round(X[i]);       for (int j = 0; j < M; j++) {         S[0] +=  a ;         for (int k = 1; k < 4; k++)           S[k] += ((i + 1) & (1 << (3 - k))) ?  b  :  a ;       }     }     for (int i = 0; i < 4; i++) cout << S[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MO = 1e9 + 7;   int n, K;   long long dp[105][44], tt[44];   vector<int> e[105];   void add(long long &x, long long y) { x = (x + y) % MO; }   void mul(long long &x, long long y) { x = x * y % MO; }   void dfs(int u, int f) {     dp[u][K + 1] = 1;     dp[u][0] = 1;     for (auto v : e[u])       if (v != f) {         dfs(v, u);         for (int i = 0; i <= 2 * K; ++i)           for (int j = 0; j <= 2 * K; ++j)             add(tt[i + j <= 2 * K ? min(i, j + 1) : max(i, j + 1)],                 dp[u][i] * dp[v][j]);         memcpy(dp[u], tt, sizeof tt);         memset(tt, 0, sizeof tt);       }   }   int main() {     cin >> n >> K;     for (int i = 1, x, y; i < n; ++i) {       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1, 0);     long long ans = 0;     for (int i = 0; i <= K; ++i) add(ans, dp[1][i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, val[105], c[105][105], pref[105][105], calc[105][105],       dp[105][10005];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       cin >> val[i];       for (long long j = 1; j <= val[i]; ++j)         cin >> c[i][j], pref[i][j] = pref[i][j - 1] + c[i][j];     }     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= min(m, val[i]); ++j)         for (long long k = 0; k <= j; ++k)           calc[i][j] = max(calc[i][j], pref[i][k] + pref[i][val[i]] -                                            pref[i][val[i] - (j - k)]);     long long tot = 0;     for (long long i = 1; i <= n; ++i) {       tot += val[i];       for (long long j = 1; j <= min(tot, m); ++j) {         for (long long k = 0; k <= min(j, val[i]); ++k) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + calc[i][k]);         }       }     }     cout << dp[n][m] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t[90];     bool ans = false;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> t[i];     }     if (t[0] > 15) {       cout << 15;       ans = true;     }     for (int i = 0; i < n - 1 && ans == false; i++) {       t[i] += 15;       if (t[i] < t[i + 1]) {         cout << t[i];         ans = true;       }     }     t[n - 1] += 15;     if (t[n - 1] >= 90 && ans == false) {       cout << 90;     }     if (t[n - 1] < 90 && ans == false) {       cout << t[n - 1];     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Abel>   struct BIT2D {     vector<vector<Abel>> dat[4];     BIT2D(int h, int w) {       for (int which = 0; which < 4; which++)         dat[which].assign(h + 1, vector<Abel>(w + 1));     }     inline void sub_add(int which, int a, int b, Abel x) {       int h = dat[which].size(), w = dat[which][0].size();       for (int i = a; i < h; i += i & -i)         for (int j = b; j < w; j += j & -j) dat[which][i][j] += x;     }     inline void add(int si, int sj, Abel x) {       sub_add(0b00, si, sj, x * (si - 1) * (sj - 1));       sub_add(0b10, si, sj, -x * (si - 1));       sub_add(0b01, si, sj, -x * (sj - 1));       sub_add(0b11, si, sj, x);     }     inline void add(int si, int ti, int sj, int tj, Abel x) {       add(si, sj, x), add(si, tj, -x), add(ti, sj, -x), add(ti, tj, x);     }     inline Abel sub_sum(int which, int a, int b) {       Abel res = Abel(0);       for (int i = a; i > 0; i -= i & -i)         for (int j = b; j > 0; j -= j & -j) res += dat[which][i][j];       return res;     }     inline Abel sum(int si, int sj) {       Abel res = Abel(0);       res += sub_sum(0b00, si - 1, sj - 1);       res += sub_sum(0b10, si - 1, sj - 1) * (sj - 1);       res += sub_sum(0b01, si - 1, sj - 1) * (si - 1);       res += sub_sum(0b11, si - 1, sj - 1) * (si - 1) * (sj - 1);       return res;     }     inline Abel sum(int si, int ti, int sj, int tj) {       return sum(ti, tj) - sum(si, tj) - sum(ti, sj) + sum(si, sj);     }   };   struct Xor {     long long val;     Xor(long long val_ = 0) : val(val_) {}     Xor operator=(long long val_) {       this->val = val_;       return *this;     }     Xor operator-() { return val; }     const Xor &operator+=(const Xor &x);     const Xor &operator-=(const Xor &x);     friend ostream &operator<<(ostream &os, const Xor &a) { return os << a.val; }   };   Xor operator+(Xor x, Xor y) { return x.val ^ y.val; }   Xor operator-(Xor x, Xor y) { return x.val ^ y.val; }   Xor operator*(Xor x, int p) { return p & 1 ? x : 0; }   const Xor &Xor::operator+=(const Xor &x) { return *this = *this + x; }   const Xor &Xor::operator-=(const Xor &x) { return *this = *this - x; }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     BIT2D<Xor> bit(n, n);     while (m--) {       int op;       cin >> op;       int si, sj, ti, tj;       cin >> si >> sj >> ti >> tj;       if (op == 1) {         cout << bit.sum(si, ti + 1, sj, tj + 1) << endl;       }       if (op == 2) {         long long v;         cin >> v;         bit.add(si, ti + 1, sj, tj + 1, v);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     long long x = n * (n * n + 1) / 2;     vector<long long> a[101];     for (long long j = 0; j < n / 2; j++)       for (long long i = 1; i < n + 1; i++) {         long long x = n * j + i;         a[i].push_back(x);         a[i].push_back(n * n - x + 1);       }     for (long long i = 1; i < n + 1; i++) {       for (auto x : a[i]) cout << x <<    ;       cout <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long TESTS = 1;     while (TESTS--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T power(T a, T b) {     T x;     if (b == 0)       x = 1;     else       x = a;     for (size_t i = 1; i < b; i++) x *= a;     return x;   }   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int n, m, a, b, c, ab, ba, x, y, z, avg, total, ans, sum;   long long int arr2[300001], arr3[100001], arr4[100001], arr5[100001];   char c1, c2;   vector<pair<string, long long int> > vec;   vector<long long int> v;   bool f, f1, f2, found;   string str, s1, s2, s3, s4;   map<long long int, long long int> mp, mp1;   set<int> seto;   double d, d1;   long long int x1, x2, y11, y2;   long long int mini = 10000000000, maxi = 0;   set<string> sets;   void rec(int n, string s) {     if (n == 11) return;     sets.insert(s);     rec(n + 1, s +  4 );     rec(n + 1, s +  7 );   }   int main() {     rec(0,   );     for (set<string>::iterator i = sets.begin(); i != sets.end(); i++) {       string s = *i;       if (!s.empty()) arr2[x++] = stoll(s);     }     sort(arr2, arr2 + x);     cin >> n >> m;     y = n;     for (long long int i = 0; i < x; i++) {       if (y <= arr2[i]) {         sum += (min(arr2[i] - y, m - y) + 1) * arr2[i];         y = arr2[i] + 1;       }       if (y > m) break;     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %i%i , &n, &k);     if (k * 2 >= n)       printf( -1 n );     else {       printf( %i n , n * k);       for (int i = 0; i < n; i++)         for (int j = 0; j < k; j++) printf( %i %i n , i + 1, (i + j + 1) % n + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> lucky;   void backtrack(long long num) {     if (num > 10000000000) return;     lucky.push_back(num);     backtrack(num * 10 + 4);     backtrack(num * 10 + 7);   }   int main() {     backtrack(0);     sort(lucky.begin(), lucky.end());     pair<long long, long long> P, V;     int k;     cin >> P.first >> P.second;     cin >> V.first >> V.second;     cin >> k;     long long denominator =         1LL * (P.second - P.first + 1) * (V.second - V.first + 1);     long long numerator = 0;     for (int i = k; i + 1 < (int)lucky.size(); i++) {       long long pLo = max(lucky[i - k] + 1, P.first);       long long pHi = min(lucky[i - k + 1], P.second);       long long vLo = max(lucky[i], V.first);       long long vHi = min(lucky[i + 1] - 1, V.second);       vLo = max(vLo, max(pLo, pHi));       long long yo = 1LL * max(0LL, pHi - pLo + 1) * max(0LL, vHi - vLo + 1);       numerator += yo;       pLo = max(lucky[i], P.first);       pHi = min(lucky[i + 1] - 1, P.second);       vLo = max(lucky[i - k] + 1, V.first);       vHi = min(lucky[i - k + 1], V.second);       pLo = max(pLo, max(vLo, vHi));       yo = 1LL * max(0LL, pHi - pLo + 1) * max(0LL, vHi - vLo + 1);       numerator += yo;     }     if (k == 1)       for (int i = 0; i < (int)lucky.size(); i++)         if (lucky[i] >= max(P.first, V.first) &&             lucky[i] <= min(P.second, V.second))           numerator -= 1;     printf( %.9lf n , (1.0 * numerator) / denominator);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> Neighbors[2000000];   bool Visited[2000000];   bool Leaf[2000000];   char Color[500001];   queue<int> Queue;   void bfs(int i) {     Visited[i] = true;     Queue.push(i);     while (Queue.empty() == false) {       int u = Queue.front();       Queue.pop();       Leaf[u] = true;       for (int v = 0; v < Neighbors[u].size(); v++)         if (Visited[Neighbors[u][v]] == false) {           Visited[Neighbors[u][v]] = true;           Queue.push(Neighbors[u][v]);           Leaf[u] = false;         }     }   }   int main() {     int T;     scanf( %d , &T);     for (int t = 1; t <= T; t++) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) Neighbors[i].clear();       int u, v;       for (int i = 0; i + 1 < n; i++) {         scanf( %d %d , &u, &v);         Neighbors[u].push_back(v);         Neighbors[v].push_back(u);       }       scanf( %s , Color);       if (n < 3) {         printf( Draw n );         continue;       }       int n_ = n;       for (int i = 1; i <= n; i++)         if (Color[i - 1] ==  W ) {           Neighbors[n_ + 1].clear();           Neighbors[n_ + 2].clear();           Neighbors[n_ + 3].clear();           Neighbors[i].push_back(n_ + 1);           Neighbors[n_ + 1].push_back(i);           Neighbors[n_ + 1].push_back(n_ + 2);           Neighbors[n_ + 1].push_back(n_ + 3);           Neighbors[n_ + 2].push_back(n_ + 1);           Neighbors[n_ + 3].push_back(n_ + 1);           n_ += 3;         }       n = n_;       int won = 0;       for (int i = 1; i <= n; i++)         if (Neighbors[i].size() >= 4) {           printf( White n );           won = 1;           break;         }       if (won) continue;       for (int i = 1; i <= n; i++) Visited[i] = 0;       bfs(1);       if (Neighbors[1].size() == 1) Leaf[1] = true;       for (int i = 1; i <= n; i++)         if (Neighbors[i].size() >= 3) {           int leaves = 0;           for (int j = 0; j < Neighbors[i].size(); j++)             if (Leaf[Neighbors[i][j]]) leaves++;           if (Neighbors[i].size() - leaves >= 2) {             printf( White n );             won = 1;             break;           }         }       if (won) continue;       int left = 1;       while (left <= n && Neighbors[left].size() < 3) left++;       int right = n;       while (right > 0 && Neighbors[right].size() < 3) right--;       if (left <= n && right > 0 && left < right) {         int curr, prev = left;         int len = 2;         for (int i = 0; i < Neighbors[prev].size(); i++)           if (Leaf[Neighbors[prev][i]] == 0) curr = Neighbors[prev][i];         while (curr != right) {           if (Neighbors[curr][0] != prev) {             prev = curr;             curr = Neighbors[curr][0];           } else {             prev = curr;             curr = Neighbors[curr][1];           }           len++;         }         if (len % 2 == 1) {           printf( White n );           continue;         }       }       printf( Draw n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i < 100000; i++) {       n *= 3;       m *= 2;       if (n > m) {         cout << i << endl;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 500;   int R, n, m, d[M][M];   pair<int, int> hd[M], tl[M], par[M][M];   bool wins = 0, draw = 0;   int mark[M][M];   void dfs(int x, int y) {     if (x < 0 || y < 0) return;     if (x + y > R) {       mark[x][y] = 2;       return;     }     mark[x][y] = 1;     if (x + y == 0) {       wins = 1;       return;     }     for (int i = 1; i <= min(n, x); i++) {       int nx = x - i + hd[i].first, ny = y + hd[i].second;       if (mark[nx][ny] == 1)         draw = 1;       else if (mark[nx][ny] == 0)         dfs(nx, ny);     }     for (int i = 1; i <= min(m, y); i++) {       int nx = x + tl[i].first, ny = y - i + tl[i].second;       if (mark[nx][ny] == 1)         draw = 1;       else if (mark[nx][ny] == 0)         dfs(nx, ny);     }     mark[x][y] = 2;   }   int dp[M][M], dis;   void dfs2(int x, int y) {     if (x + y > R) {       dis = max(dis, dp[x][y]);       return;     }     for (int i = 1; i <= min(n, x); i++) {       int nx = x - i + hd[i].first, ny = y + hd[i].second;       if (nx >= 0 && ny >= 0 && (dp[nx][ny] == 0 || (dp[nx][ny] < dp[x][y] + 1)))         dp[nx][ny] = dp[x][y] + 1, dfs2(nx, ny);     }     for (int i = 1; i <= min(m, y); i++) {       int nx = x + tl[i].first, ny = y - i + tl[i].second;       if (nx >= 0 && ny >= 0 && (dp[nx][ny] == 0 || (dp[nx][ny] < dp[x][y] + 1)))         dp[nx][ny] = dp[x][y] + 1, dfs2(nx, ny);     }   }   int main() {     int h, t;     scanf( %d %d %d , &h, &t, &R);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &hd[i].first, &hd[i].second);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d %d , &tl[i].first, &tl[i].second);     dfs(h, t);     if (!wins && draw) return printf( Draw n ), 0;     memset(mark, 0, sizeof mark);     if (wins) {       printf( Ivan n );       queue<pair<int, int> > q;       d[h][t] = 0;       mark[h][t] = 1;       q.push({h, t});       while (q.size()) {         int x = q.front().first, y = q.front().second;         q.pop();         for (int i = 1; i <= min(x, n); i++) {           int nx = x - i + hd[i].first, ny = y + hd[i].second;           if (nx >= 0 && ny >= 0 && nx + ny <= R) {             if (!mark[nx][ny] or (mark[nx][ny] && d[nx][ny] > d[x][y] + 1))               mark[nx][ny] = 1, d[nx][ny] = d[x][y] + 1, q.push({nx, ny});           }         }         for (int i = 1; i <= min(m, y); i++) {           int nx = x + tl[i].first, ny = y - i + tl[i].second;           if (nx >= 0 && ny >= 0 && nx + ny <= R) {             if (!mark[nx][ny] or (mark[nx][ny] && d[nx][ny] > d[x][y] + 1))               mark[nx][ny] = 1, d[nx][ny] = d[x][y] + 1, q.push({nx, ny});           }         }       }       printf( %d , d[0][0]);     } else {       printf( Zmey n );       dfs2(h, t);       printf( %d , dis);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     bool sorted = 0;     int a, b, c;     c = count(s.begin(), s.end(),  c );     a = count(s.begin(), s.end(),  a );     b = count(s.begin(), s.end(),  b );     string ss = s;     sort(ss.begin(), ss.end());     for (int i = 0; i < s.size(); i++) {       if (ss[i] == s[i]) {         sorted = 1;       } else {         cout <<  NO ;         return 0;       }     }     s.erase(unique(s.begin(), s.end()), s.end());     if (s[0] ==  a  && s[1] ==  b  && s[2] ==  c ) sorted = 1;     if (a >= 1 && b >= 1 && (c == a || c == b) && sorted) {       cout <<  YES ;       return 0;     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const long long mod = 1e9 + 7;   int mp[510][510];   struct mon {     int x, y, t;   } t[510 * 510];   int n, m, k, q;   int cmp(mon a, mon b) { return a.t < b.t; }   int sum[510][510];   int check(int tim) {     int i, j;     memset(mp, 0, sizeof(mp));     for (i = 1; i <= tim; i++) mp[t[i].x][t[i].y] = 1;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mp[i][j];       }     for (i = 1; i <= n - k + 1; i++) {       for (j = 1; j <= m - k + 1; j++) {         int temp = sum[i + k - 1][j + k - 1] - sum[i + k - 1][j - 1] -                    sum[i - 1][j + k - 1] + sum[i - 1][j - 1];         if (temp == k * k) return 1;       }     }     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k >> q;     int i;     for (i = 1; i <= q; i++) {       cin >> t[i].x >> t[i].y >> t[i].t;     }     sort(t + 1, t + q + 1, cmp);     int l = 1;     int r = q + 1;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     if (l == q + 1)       cout << -1;     else       cout << t[l].t;   }


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


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const int SIZE = 2e5 + 5;   const long long INF = 1LL << 60;   const double eps = 1e-4;   const double PI = 3.1415926535897932;   int last[26];   int main() {     string s;     cin >> s;     int n = ((int)(s).size());     for (int i = 0; i < (26); ++i) last[i] = -1;     for (int i = 0; i < (n); ++i) last[s[i] -  a ] = i;     int cl = 0;     stack<int> st;     string ans =   ;     for (int i = 0; i < (n); ++i) {       while (cl < 26 && last[cl] < i) {         while (((int)(st).size()) && (st.top() <= cl)) {           ans +=  a  + st.top();           st.pop();         }         cl++;       }       if (cl >= 26) break;       while (((int)(st).size()) && (st.top() <= cl)) {         ans +=  a  + st.top();         st.pop();       }       if (last[cl] > i) {         if (s[i] ==  a  + cl) {           ans += s[i];         } else {           st.push(s[i] -  a );         }       } else if (last[cl] == i) {         ans += s[i];         cl++;       }     }     while (((int)(st).size())) {       int i = st.top();       st.pop();       ans +=  a  + i;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l1, r1, l2, r2, k;     scanf( %I64d %I64d %I64d %I64d %I64d , &l1, &r1, &l2, &r2, &k);     long long l, r;     l = max(l1, l2);     r = min(r1, r2);     long long ans = (r - l) + 1;     if (k <= r && k >= l) ans--;     ans = max(0LL, ans);     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int x, int y) { return x > y; }   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     int n;     cin >> n;     vector<pair<int, int> > a(n);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a[i] = make_pair(x, y);     }     int res = 0;     for (int i = 0; i < n; i++) {       int x1 = a[i].first;       int y1 = a[i].second;       int upper = 0, lower = 0, right = 0, left = 0;       for (int j = 0; j < n; j++) {         if (i != j) {           int x2 = a[j].first;           int y2 = a[j].second;           if (x2 > x1 && y1 == y2) right++;           if (x2 < x1 && y1 == y2) left++;           if (x1 == x2 && y2 > y1) upper++;           if (x1 == x2 && y2 < y1) lower++;         }       }       if (upper >= 1 && lower >= 1 && right >= 1 && left >= 1) res++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char kata[1005];   int panjang, total[30], batas;   int main() {     scanf( %s , kata);     panjang = strlen(kata);     for (int i = 0; i < panjang; ++i) ++total[kata[i] -  a ];     scanf( %d , &batas);     int cek = 0;     for (int i = 0; i < 26; ++i)       if (total[i]) ++cek;     if (cek > batas) {       printf( -1 n );       return 0;     }     int kiri = 0;     int kanan = panjang;     while (kanan - kiri > 1) {       int tengah = (kanan + kiri) / 2;       int pakai = 0;       for (int i = 0; i < 26; ++i) {         pakai += (total[i] + tengah - 1) / tengah;       }       if (pakai > batas)         kiri = tengah;       else         kanan = tengah;     }     printf( %d n , kanan);     for (int i = 0; i < 26; ++i) {       int temp = (total[i] + kanan - 1) / kanan;       for (int j = 0; j < temp; ++j) printf( %c , i +  a );       batas -= temp;     }     for (int i = 0; i < batas; ++i) printf( a );     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, dem = 0;     cin >> n;     dem = n / 2520;     cout << dem;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[1000000 + 10];   int a[1000000 + 10];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] <= m) {         cnt[a[i]]++;       }     }     for (int i = m; i >= 1; i--) {       for (int j = i; (j += i) <= m;) {         cnt[j] += cnt[i];       }     }     int i, j;     for (i = j = 1; i <= m; i++) {       if (cnt[i] > cnt[j]) {         j = i;       }     }     cout << j <<     << cnt[j] << endl;     for (i = 0; i < n; i++) {       if (j % a[i] == 0) {         cout << i + 1 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 160;   const int maxM = (int)1e6 + 100;   const int mod = (int)1e9 + 7;   const int maxlog = (int)20;   const int P = mod;   int n, q, l[maxn], r[maxn], mx[maxn], mn[maxn], t[maxn], v[maxn], b[maxn],       cnt[maxn], ans = INT_MAX, tot = 5000000, was[maxn], a[maxn];   int get() {     for (int i = 1; i <= n; i++) cnt[a[i]]++;     int res = 0;     for (int i = 1; i <= n; i++) {       res += cnt[i] * cnt[i];     }     return res;   }   int randint(int l, int r) {     int v = (rand() << 15) ^ rand();     v %= r - l + 1;     return v + l;   }   int main() {     srand(time(0));     cin >> n >> q;     if (q == 0) {       cout << n;       return 0;     }     for (int i = 1; i <= n; i++) {       mn[i] = 1;       mx[i] = n;     }     for (int i = 1; i <= q; i++) {       cin >> t[i] >> l[i] >> r[i] >> v[i];       for (int j = l[i]; j <= r[i]; j++) {         if (t[i] == 2)           mx[j] = min(mx[j], v[i]);         else           mn[j] = max(mn[j], v[i]);       }     }     for (int i = 1; i <= n; i++) {       if (mx[i] < mn[i]) {         cout << -1;         return 0;       }       a[i] = mn[i];     }     ans = get();     int timer = 0;     while (clock() / (double)CLOCKS_PER_SEC < 2.95) {       memset(cnt, 0, sizeof(cnt));       timer++;       for (int i = 1; i <= n; i++) b[i] = a[i];       int x = min(n, randint(1, max(1, n / 3)) + 1);       for (int i = 1; i <= x; i++) {         int pos = randint(1, n);         while (was[pos] == timer) pos = randint(1, n);         was[pos] = timer;         a[pos] = randint(mn[pos], mx[pos]);       }       for (int i = 1; i <= n; i++) cnt[a[i]]++;       int cur = 0;       for (int i = 1; i <= n; i++) cur += cnt[i] * cnt[i];       if (ans >= cur)         ans = cur;       else {         for (int i = 1; i <= n; i++) a[i] = b[i];       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(T t) {     return t * t;   }   inline void files() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int n1, m1, n2, m2;   int a[150][150], b[150][150];   int mx, ansx, ansy;   int main() {     files();     cin >> n1 >> m1;     for (int i = 1; i <= n1; i++)       for (int j = 1; j <= m1; j++) {         char c;         cin >> c;         a[i][j] = c -  0 ;       }     cin >> n2 >> m2;     for (int i = 1; i <= n2; i++)       for (int j = 1; j <= m2; j++) {         char c;         cin >> c;         b[i][j] = c -  0 ;       }     for (int x = -50; x <= 50; x++) {       for (int y = -50; y <= 50; y++) {         int cur = 0;         for (int i = 1; i <= n1; i++)           for (int j = 1; j <= m1; j++)             if (i + x <= n2 && j + y <= m2 && i + x >= 1 && j + y >= 1)               cur += (a[i][j] * b[i + x][j + y]);         if (mx < cur) {           mx = cur;           ansx = x;           ansy = y;         }       }     }     cout << ansx <<     << ansy;   }


#include <bits/stdc++.h>   int main() {     char a[10], e[10];     int b[10], d[10], i, j, c = 0, t;     scanf( %s , a);     scanf( %s , e);     for (i = 0; i < strlen(a); i++) {       b[i] = a[i] -   0 ;       b[i] = b[i] - 48;       d[i] = e[i] -   0 ;       d[i] = d[i] - 48;     }     for (i = 0; i < strlen(a); i++) {       for (j = i + 1; j < strlen(a); j++) {         if (b[i] > b[j]) {           t = b[i];           b[i] = b[j];           b[j] = t;         }       }     }     for (i = 0; i < strlen(a); i++) {       if (b[i] == 0)         c++;       else         break;     }     if (c != strlen(a)) {       t = b[c];       b[c] = b[0];       b[0] = t;     }     c = 0;     for (i = 0; i < strlen(a); i++) {       if (b[i] == d[i]) c++;     }     if (c == strlen(a) && c == strlen(e))       printf( OK );     else       printf( WRONG_ANSWER );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename C, typename T = decay<decltype(*begin(declval<C>()))>,             typename enable_if<!is_same<C, string>::value>::type * = nullptr>   ostream &operator<<(ostream &os, const C &c) {     bool f = true;     os <<  [ ;     for (const auto &x : c) {       if (!f) os <<  ,  ;       f = false;       os << x;     }     return os <<  ] ;   }   template <typename T>   void debug(string s, T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename T, typename... Args>   void debug(string s, T x, Args... args) {     cerr << s.substr(0, s.find( , )) <<   =   << x <<   |  ;     debug(s.substr(s.find( , ) + 2), args...);   }   int a[200000];   bool isMountain[200000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       for (int i = 0; i < n; i++) cin >> a[i];       int ret = 0, cnt = 0;       for (int i = 0; i < n; i++)         isMountain[i] =             (i > 0 && i < n - 1 && a[i] > a[i - 1] && a[i] > a[i + 1]);       for (int i = 1; i < k - 1; i++) cnt += isMountain[i];       ret = cnt;       int l = 0;       for (int i = k; i < n; i++) {         cnt -= isMountain[i - (k - 1)];         cnt += isMountain[i - 1];         if (cnt > ret) {           ret = cnt;           l = i - k + 1;         }       }       cout << ret + 1 <<     << l + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f(string s) {     int answer = 0;     answer += 600 * (int(s[0]) - 48);     answer += 60 * (int(s[1]) - 48);     answer += 10 * (int(s[3]) - 48);     answer += (int(s[4]) - 48);     return answer;   }   string s(int a) {     string answer;     answer.clear();     answer += char(a / 600 + 48);     a = a % 600;     answer += char(a / 60 + 48);     a = a % 60;     answer +=  : ;     answer += char(a / 10 + 48);     a = a % 10;     answer += char(a + 48);     return answer;   }   int timer[2880] = {0};   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       timer[f(s) % 1440] = 1;       timer[(f(s) % 1440) + 1440] = 1;     }     int best = 0;     int temp = 0;     for (int i = 0; i < 2880; i++) {       if (timer[i] == 0)         temp++;       else {         best = max(best, temp);         temp = 0;       }     }     cout << s(best);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     pair<int, char> p[200005];     for (int i = 0; i < n; i++) {       scanf( %d %c , &p[i].first, &p[i].second);     }     sort(p, p + n);     int minred = 1e9 + 1, maxred = 1e9 + 1;     int mingreen = 1e9 + 1, maxgreen = 1e9 + 1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  R ) {         maxred = p[i].first;         minred = min(minred, p[i].first);       } else if (p[i].second ==  B ) {         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       } else {         maxred = p[i].first;         minred = min(minred, p[i].first);         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       }     }     long long ans = (long long)maxred - minred + maxgreen - mingreen;     int lastp = -1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  P ) {         if (lastp != -1) {           int lastr = p[lastp].first;           int lastg = p[lastp].first;           int maxr = 0, maxg = 0;           for (int j = lastp + 1; j < i; j++) {             if (p[j].second ==  R ) {               maxr = max(p[j].first - lastr, maxr);               lastr = p[j].first;             } else {               maxg = max(p[j].first - lastg, maxg);               lastg = p[j].first;             }           }           maxr = max(p[i].first - lastr, maxr);           maxg = max(p[i].first - lastg, maxg);           ans -= max(0, maxr + maxg - (p[i].first - p[lastp].first));         }         lastp = i;       }     }     printf( %lld n , ans);   }


#include  bits/stdc++.h    using namespace std;      #define ffor(n) for(int i = 0; i < n; i++)   #define fffor(n) for(int j = 0; j < n; j++)   #define uwu ios_base::sync_with_stdio(false);cin.tie(NULL);   #pragma GCC optimize( Ofast )      const int INF = 1e9 + 7;   const long long INF2 = 1e15;      void solve(void) {       }      bool valid = true;      void verify(int current, vector <vector <int>>& asd, vector <int>& state, vector <int>& res) {    if (valid == false) return;    if (state[current] == 1) {     valid = false;     return;    }    if (state[current] == 2) return;    if (state[current] == 0) {     state[current] = 1;     for (int nextnode: asd[current]) {      verify(nextnode, asd, state, res);     }     state[current] = 2;     res.push_back(current);    }   }         int main(void) {    uwu       int n, k;    cin >> n >> k;    vector <int> v(n);    ffor(n) cin >> v[i];    vector <pair <int, int>> v2(k);    ffor(k) cin >> v2[i].first >> v2[i].second;       set <pair <int, int>> edges;    ffor(n) {     if (v[i] != 0) edges.insert({v[i] - 1, i});    }    ffor(k) {     edges.insert({v2[i].first - 1, v2[i].second - 1});    }        // next in chain    vector <int> next(n, -1), prev(n, -1);    for(int i = 0; i < k; i++) {     next[v2[i].first - 1] = v2[i].second - 1;     prev[v2[i].second - 1] = v2[i].first - 1;    }    vector <int> chained(n, -1);     for(int i = 0; i < n; i++) {     if (chained[i] != -1) continue;     auto head = i, tail = i;     chained[i] = i;     while(prev[head] != -1) {      if (chained[prev[head]] != -1) {       valid = false;       break;      }      head = prev[head];      chained[head] = i;     }     while(next[tail] != -1) {      if (chained[next[tail]] != -1) {       valid = false;       break;      }      tail = next[tail];      chained[tail] = i;     }     while(tail != head) {      if (v[tail] != 0 && chained[v[tail] - 1] != i) {       edges.insert({v[tail] - 1, head});      }      tail = prev[tail];     }    }        // adjacency list    vector <vector <int>> asd(n);    for(auto e: edges) {     asd[e.first].push_back(e.second);    }        // topological sort    vector <int> state(n), res;    for(int i = 0; i < n; i++) {     if (v[i] == 0) {      verify(i, asd, state, res);     }    }        vector <bool> visited(n);    reverse(res.begin(), res.end()); // reverse reversed topological sort    vector <int> ans, order_of(n);            for(int e: res) {     auto current = e;     if (visited[current]) continue;     // follow chain     while(next[current] != -1 && visited[next[current]] != true) {      ans.push_back(current);      visited[current] = true;      current = next[current];     }     ans.push_back(current);     visited[current] = true;     current = next[current];    }         if (valid) {     // find position in answer     for(int i = 0; i < ans.size(); i++) {      order_of[ans[i]] = i;     }     // verify ordering     for(int i = 0; i < v.size(); i++) {      if (v[i] == 0) continue;      if (order_of[v[i] - 1] > order_of[i]) valid = false;     }     for(int i = 0; i < k; i++) {      if (order_of[v2[i].first - 1] + 1 != order_of[v2[i].second - 1]) valid = false;     }     if (valid) {      for (auto e: ans) cout << e + 1 <<    ;      cout <<   n ;     }     else cout << 0 <<   n ;    }    else cout << 0 <<   n ;   }                         /*   C: Users User Desktop comp_programming final_straw_after_this_im_switching_to_vs_code finally_switched_to_geany.cpp   */


#include <bits/stdc++.h>   using namespace std;   int a[1005], dp[1005][1005], dp_sum[1005][1005];   int main() {     ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int limit = a[n] / (k - 1);     int ans = 0;     for (int diff = 1; diff <= limit; diff++) {       for (int j = 1; j <= n; j++) dp_sum[j][1] = j, dp[j][1] = 1;       for (int ct = 2; ct <= k; ct++) {         for (int j = 1, l = 1; j <= n; j++) {           while (l < j && a[j] - a[l] >= diff) l++;           dp[j][ct] = dp_sum[l - 1][ct - 1];           dp_sum[j][ct] = dp[j][ct] + dp_sum[j - 1][ct];           if (dp_sum[j][ct] >= 998244353) dp_sum[j][ct] -= 998244353;         }       }       ans += dp_sum[n][k];       if (ans >= 998244353) ans -= 998244353;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long t, n, a[205], b, c[205];   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> t;     while (t--) {       cin >> n >> b;       for (int i = 0; i < n; i++) {         cin >> a[i];         c[a[i]] = 1;       }       for (int i = 1;; i++) {         if (c[i] == 0) {           b--;         }         if (b == 0) {           for (int j = i + 1;; j++) {             if (c[j] == 0) {               cout << j - 1 <<   n ;               break;             }           }           break;         }       }       for (int i = 0; i < 105; i++) {         a[i] = 0;         c[i] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100005];   vector<pair<int, int>> t;   bool pairsort(pair<int, int> e1, pair<int, int> e2) {     return e1.first <= e2.first;   }   int main() {     int n;     cin >> n;     int pos, pow;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &pos, &pow);       t.push_back(make_pair(pos, pow));     }     sort(t.begin(), t.end(), pairsort);     memset(a, 0, sizeof(a));     a[0] = 0;     a[1] = 1;     for (int i = 1; i < t.size(); i++) {       if (t[i].first - t[i].second > t[i - 1].first) {         a[i + 1] = a[i] + 1;       } else {         int l = 0;         int r = i - 1;         int k = t[i].first - t[i].second;         while (r > l) {           int mid = (r + l) / 2;           if (t[mid].first >= k)             r = mid;           else             l = mid + 1;         }         a[i + 1] = a[l] + 1;       }     }     int max = 0;     for (int i = 0; i <= n; i++) {       max = max > a[i] ? max : a[i];     }     int ans = n - max;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct fenwickTree {     long long n;     vector<long long> bit;     fenwickTree() {}     fenwickTree(long long siz) : n(siz + 5), bit(siz + 5, 0) {}     void add(long long pos, long long upd) {       for (; pos < n; pos += pos & (-pos)) bit[pos] += upd;     }     long long sum(long long pos) {       long long ret = 0;       for (; pos; pos -= pos & (-pos)) ret += bit[pos];       return ret;     }     long long query(long long pos) {       return sum(n - 1) - sum(min(n - 1, pos - 1));     }   };   const long long nax = 100005;   long long c[nax], ss[nax] = {0}, dsu[nax], siz[nax] = {0}, ans[nax];   vector<long long> g[nax];   vector<pair<long long, long long>> q[nax];   vector<map<long long, long long>> mp(nax);   vector<fenwickTree> bitarr(nax);   void dfs(long long u, long long p) {     ss[u] = siz[u] = 1;     long long mx = -1, mxc = -1;     for (auto &k : g[u])       if (k != p) {         dfs(k, u);         ss[u] += ss[k];         if (ss[k] > mx) mx = ss[k], mxc = k;       }     if (mxc != -1) {       dsu[u] = dsu[mxc];       siz[dsu[mxc]] = ss[u];     }   }   void add(long long u, long long col, long long cnt) {     if (!cnt) return;     if (mp[u].count(col)) bitarr[u].add(mp[u][col], -1);     mp[u][col] += cnt;     bitarr[u].add(mp[u][col], 1);   }   void dfs2(long long u, long long p) {     for (auto &k : g[u])       if (k != p) dfs2(k, u);     add(dsu[u], c[u], 1);     for (auto &k : g[u])       if (k != p && dsu[k] != dsu[u])         for (auto &col : mp[dsu[k]]) add(dsu[u], col.first, col.second);     for (auto &qry : q[u]) ans[qry.first] = bitarr[dsu[u]].query(qry.second);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) dsu[i] = i;     for (long long i = 1; i <= n; i++) cin >> c[i];     for (long long i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 1);     for (long long i = 1; i <= n; i++) bitarr[i] = fenwickTree(siz[i]);     for (long long i = 0; i < m; i++) {       long long a, b;       cin >> a >> b;       q[a].push_back({i + 1, b});     }     dfs2(1, 1);     for (long long i = 1; i <= m; i++) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, inf = 0x3f3f3f3f;   int main() {     int a, b, h1, h2;     while (cin >> h1 >> h2) {       cin >> a >> b;       int add = a * 12, de = b * 12, first = 8 * a;       if (a <= b) {         if (h1 + first >= h2)           puts( 0 );         else           puts( -1 );         continue;       }       int ans = 0;       h1 += first;       if (h1 >= h2)         puts( 0 );       else {         add -= de;         ans += (h2 - h1) / add;         if ((h2 - h1) % add) ans++;         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 159, INF = 2e9 + 9;   struct mat {     bitset<MAX> a[MAX];     mat(int v = 0) {       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++)           if (i == j)             a[i][j] = v;           else             a[i][j] = 0;     }   } adj(0);   mat operator*(mat a, mat b) {     mat tmp(0), ret(0);     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++) tmp.a[i][j] = b.a[j][i];     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++)         ret.a[i][j] = ((a.a[i] & tmp.a[j]).count() > 0);     return ret;   }   mat operator^(mat a, int n) {     mat ret(1);     if (!n) return ret;     ret = a ^ (n >> 1);     if (n & 1) return ret * ret * a;     return ret * ret;   }   map<int, vector<pair<int, int> > > m;   bitset<MAX> can, t;   bool mark[MAX];   vector<int> g[MAX];   long long n, e, a, b, d, dis[MAX][MAX], h[MAX];   queue<int> q;   long long bfs() {     while (q.size()) {       int v = q.front();       q.pop();       if (v == n - 1) return h[v];       for (auto u : g[v])         if (!mark[u]) q.push(u), h[u] = h[v] + 1, mark[u] = true;     }     return INF;   }   int main() {     cin >> n >> e;     for (int i = 0; i < MAX; i++)       for (int j = 0; j < MAX; j++) dis[i][j] = (i == j ? 0 : INF);     for (int i = 0; i < e; i++)       cin >> a >> b >> d, a--, b--, m[d].push_back({a, b}), dis[a][b] = 1;     can[0] = 1, m[0].push_back({0, 0}), m[0].pop_back();     long long last, ans = INF;     for (map<int, vector<pair<int, int> > >::iterator it = m.begin();          it != m.end(); it++) {       long long d1 = it->first;       it++;       if (it == m.end()) {         it--;         last = it->first;         break;       }       long long d2 = it->first;       it--;       for (auto i : it->second)         adj.a[i.first][i.second] = 1, g[i.first].push_back(i.second);       memset(h, 0, sizeof h), memset(mark, 0, sizeof mark);       while (q.size()) q.pop();       for (int i = 0; i < MAX; i++)         if (can[i]) mark[i] = true, q.push(i);       ans = min(ans, bfs() + d1);       mat tmp = adj, tmp2;       tmp = tmp ^ (d2 - d1);       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++) tmp2.a[i][j] = tmp.a[j][i];       t = can;       for (int i = 0; i < MAX; i++) can[i] = (t & tmp2.a[i]).count() > 0;     }     for (int k = 0; k < MAX; k++)       for (int i = 0; i < MAX; i++)         for (int j = 0; j < MAX; j++)           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);     for (int i = 0; i < MAX; i++)       if (can[i]) ans = min(ans, dis[i][n - 1] + last);     if (ans < INF)       cout << ans;     else       cout <<  Impossible ;   }


#include <bits/stdc++.h>   using namespace std;   int getint() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x *= 10, x += (c -  0 ), c = getchar();     return x;   }   vector<pair<int, int> > v[2];   int n, a[2][10010];   void XOR(int i, int j, int idx) {     v[idx].push_back(make_pair(i, j));     a[idx][i] ^= a[idx][j];   }   void init() {     n = getint();     for (int j = 0; j < 2; j++)       for (int i = 0; i < n; i++) a[j][i] = getint();   }   void Gauss(int idx) {     int pre = 0;     for (int i = 30; i >= 0; i--)       for (int j = pre; j < n; j++)         if (a[idx][j] & (1 << i)) {           if (j != pre) {             XOR(j, pre, idx);             XOR(pre, j, idx);             XOR(j, pre, idx);           }           for (int k = 0; k < n; k++)             if (k != pre && (a[idx][k] & (1 << i))) XOR(k, pre, idx);           pre++;           break;         }   }   void solve() {     for (int i = 0; i < 2; i++) Gauss(i);     for (int i = 0; i < n; i++)       if (a[0][i]) {         int bs = (1 << 30);         while ((a[0][i] & bs) == 0) bs >>= 1;         for (int j = 0; j <= 30 && j < n; j++)           if ((a[0][j] ^ a[1][j]) & bs) XOR(j, i, 0);       } else         break;     for (int i = 0; i < n; i++)       if (a[0][i] != a[1][i]) {         puts( -1 );         return;       }     printf( %d n , (int)v[0].size() + (int)v[1].size());     for (int i = 0; i < (int)v[0].size(); i++)       printf( %d %d n , v[0][i].first + 1, v[0][i].second + 1);     for (int i = (int)v[1].size() - 1; i >= 0; i--)       printf( %d %d n , v[1][i].first + 1, v[1][i].second + 1);   }   int main() {     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, zheng = 0, mmax = 0, strc, stra, cuowu;     char a[1000], b[26], c[1000];     double bb[26], sheng[26], bisheng[26], cc[26];     cin >> a;     cin >> n;     sort(a, a + strlen(a));     memset(c, 0, sizeof(c));     b[0] =  a ;     for (int i = 1; i < 26; i++) {       b[i] = b[i - 1] + 1;     }     for (int i = 0; i < 26; i++) {       bb[i] = 0, cc[i] = 0, sheng[i] = 0, bisheng[i] = 0;     }     for (int i = 0; i < strlen(a); i++) {       for (int j = 0; j < 26; j++) {         if (a[i] == b[j]) bb[j]++;       }     }     for (int i = 0; i < 26; i++) {       if (bb[i] != 0) zheng++;       if (bb[i] > mmax) mmax = bb[i];     }     stra = strlen(a);     if (n > strlen(a)) {       cout << 1 << endl;       int cuowu = 0;       for (int k = 0; k < 26; k++) {         if (sheng[k] > sheng[cuowu]) cuowu = k;       }       for (int i = 0; i < n - stra; i++) {         a[i + stra] = a[cuowu];       }       for (int i = 0; i < n; i++) {         cout << a[i];       }       cout << endl;     } else if (n < zheng) {       cout << -1 << endl;     } else {       int j = 0, yu;       for (int i = 0; i < 26; i++) {         sheng[i] = bb[i];         bisheng[i] = bb[i];         if (bb[i] != 0) {           c[j] = b[i];           cc[i] = 1;           j++;         }       }       yu = n - strlen(c);       if (yu == 0) {         cout << mmax << endl;         cout << c << endl;       } else {         strc = strlen(c);         mmax = 0;         for (int i = 0; i < yu; i++) {           for (int k = 0; k < 26; k++) {             if (sheng[k] > sheng[mmax]) mmax = k;           }           cc[mmax] += 1;           sheng[mmax] = bisheng[mmax] / cc[mmax];           c[i + strc] = b[mmax];         }         for (int k = 0; k < 26; k++) {           if (sheng[k] > sheng[mmax]) mmax = k;         }         cout << ceil(sheng[mmax]) << endl;         cout << c << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vector<pair<int, int>> vec;     int n, a, b;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       if (a != b) {         cout <<  rated ;         return 0;       }       vec.push_back({a, b});     }     for (int i = 0; i < vec.size() - 1; i++) {       if (vec[i].first < vec[i + 1].first) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;   }


#include <bits/stdc++.h>   #define int long long   #define F0R(i, n) for(int i = 0; i < (n); i++)   using namespace std;      signed main()   {       ios::sync_with_stdio(0);       cin.tie(0), cout.tie(0);       int T; cin >> T;       F0R(cas,T) {           int N; cin >> N;           vector<int> a(N);           for(int &x : a)               cin >> x;           sort(a.begin(),a.end(),greater<int>());           int evsum = 0, odsum = 0;           F0R(i,N) {               if(i%2 && a[i]%2)                   odsum += a[i];               if((i%2 == 0) && (a[i]%2 == 0))                   evsum += a[i];           }           if(evsum >  odsum) cout <<  Alice n ;           if(evsum == odsum) cout <<  Tie n ;           if(evsum <  odsum) cout <<  Bob n ;       }       return 0;   }


#include <bits/stdc++.h>   #pragma optimize( TKACHENKO-GORYACHENKO )   using namespace std;   const int maxn = 11e5;   const int inf = 1e18;   int n, m, k;   int A[maxn];   int B[maxn];   int C[maxn];   int V[4 * maxn];   int T[4 * maxn];   inline void push(int v, int tl, int tr) {     if (T[v] == 0) {       return;     }     V[v] += T[v];     if (tl != tr) {       T[2 * v] += T[v];       T[2 * v + 1] += T[v];     }     T[v] = 0;   }   inline void build(int v, int tl, int tr) {     if (tl == tr) {       V[v] = C[tl];       return;     }     int tm = (tl + tr) / 2;     build(2 * v, tl, tm);     build(2 * v + 1, tm + 1, tr);     V[v] = min(V[2 * v], V[2 * v + 1]);   }   inline void update(int v, int tl, int tr, int l, int r, int color) {     push(v, tl, tr);     if (l > r || tl > r || l > tr) {       return;     }     if (tl == l && tr == r) {       T[v] += color;       push(v, tl, tr);       return;     }     int tm = (tl + tr) / 2;     update(2 * v, tl, tm, l, min(r, tm), color);     update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, color);     V[v] = min(V[2 * v], V[2 * v + 1]);   }   inline void changea(int i, int j) {     if (j >= i) {       update(1, 0, maxn - 1, i + 1, j, -1);     } else {       update(1, 0, maxn - 1, j + 1, i, 1);     }   }   inline void changeb(int i, int j) {     if (j >= i) {       update(1, 0, maxn - 1, i + 1, j, 1);     } else {       update(1, 0, maxn - 1, j + 1, i, -1);     }   }   inline int getans(int v, int tl, int tr) {     push(v, tl, tr);     int tm = (tl + tr) / 2;     if (tl != tr) {       push(2 * v, tl, tm);       push(2 * v + 1, tm + 1, tr);     }     if (V[v] >= 0) {       return -1;     }     if (tl == tr) {       return tl;     }     if (V[2 * v + 1] < 0) {       return getans(2 * v + 1, tm + 1, tr);     }     if (V[2 * v] < 0) {       return getans(2 * v, tl, tm);     }   }   int main() {     int q, w, e, a, b, f;     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (q = 0; q < n; q++) {       cin >> A[q];       C[A[q]]--;     }     for (q = 0; q < m; q++) {       cin >> B[q];       C[B[q]]++;     }     cin >> k;     for (q = maxn - 2; q >= 0; q--) {       C[q] += C[q + 1];     }     build(1, 0, maxn - 1);     for (e = 0; e < k; e++) {       int i, x, comm;       cin >> comm >> i >> x;       i--;       if (comm == 1) {         changea(A[i], x);         A[i] = x;       } else {         changeb(B[i], x);         B[i] = x;       }       cout << getans(1, 0, maxn - 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool tr = false;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       if (x != y) tr = true;     }     if (tr)       cout <<  Happy Alex n ;     else       cout <<  Poor Alex n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool ACS(string s) {     int n1 = s.length();     for (int i = 1; i < n1; i++)       if (s[i] != s[0]) return false;     return true;   }   int main() {     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.length() == 1)         cout << 0 << endl;       else if (s[0] == s[1] && ACS(s))         cout << 1 << endl;       else {         int ss1 = 0;         map<char, int> m1;         for (int i = 0; i < s.length(); i++) m1[s[i]]++;         for (int i = 0; i < m1.size(); i++) {           if (m1[i] > 2)             ss1 = ss1 + 2;           else             ss1 = ss1 + m1[i];         }         if (ss1 % 2)           cout << (ss1 - 1) / 2 << endl;         else           cout << ss1 / 2 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   void fn(long long int a[], long long int a1, long long int b, long long int n) {     for (long long int i = 0; i < n; i++) {       a[i] = a1;       a1 += b;     }   }   void solve() {     long long int n, x, y;     cin >> n >> x >> y;     long long int bst = INT_MAX;     long long int a[n];     for (long long int i = 1; i < 51; i++) {       for (long long int j = 1; j < 51; j++) {         long long int x1 = 0, y1 = 0;         long long int a1[n];         fn(a1, i, j, n);         for (long long int i = 0; i < n; i++) {           if (a1[i] == x) {             x1 = 1;           }           if (a1[i] == y) {             y1 = 1;           }         }         if (x1 and y1 and a1[n - 1] < bst) {           for (long long int i = 0; i < n; i++) {             a[i] = a1[i];           }           bst = a[n - 1];         }       }     }     for (long long int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[3];   int main() {     int n;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     int ans1 = 0, ans2 = 0;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] ==  a ) {         ans1++;       }       if (s2[i] ==  a ) {         ans1++;       }       if (s1[i] ==  b ) {         ans2++;       }       if (s2[i] ==  b ) {         ans2++;       }     }     if (s1 == s2) {       cout << 0 << endl;       return 0;     }     if (ans1 % 2 || ans2 % 2) {       cout << -1 << endl;       return 0;     } else {       s1 =     + s1;       s2 =     + s2;       for (int i = 1; i <= s1.size(); i++) {         if (s1[i] == s2[i]) {           continue;         }         if (s1[i] ==  a ) {           v[1].push_back(i);           continue;         } else {           v[2].push_back(i);         }       }       int ans = 0;       int flag = 0;       if (v[1].size() % 2) {         flag = v[1].back();         v[2].push_back(v[1].back());         v[1].pop_back();         ans++;       }       ans = ans + v[1].size() / 2 + v[2].size() / 2;       cout << ans << endl;       if (flag) cout << flag <<     << flag << endl;       if (v[1].size() > 0)         for (int i = 0; i < v[1].size() - 1; i += 2) {           cout << v[1][i] <<     << v[1][i + 1] << endl;         }       if (v[2].size() > 0)         for (int i = 0; i < v[2].size() - 1; i += 2) {           cout << v[2][i] <<     << v[2][i + 1] << endl;         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace sat {   const int MAX = 200010;   bool vis[MAX];   vector<int> ed[MAX], rev[MAX];   int n, m;   vector<int> order;   int comp[MAX];   inline int inv(int x) { return ((x) <= n ? (x + n) : (x - n)); }   void init(int vars) {     n = vars, m = vars << 1;     for (int i = 1; i <= m; i++) {       ed[i].clear();       rev[i].clear();     }   }   inline void add(int a, int b) {     ed[a].push_back(b);     rev[b].push_back(a);   }   inline void OR(int a, int b) {     add(inv(a), b);     add(inv(b), a);   }   inline void AND(int a, int b) {     add(a, b);     add(b, a);   }   void XOR(int a, int b) {     add(inv(b), a);     add(a, inv(b));     add(inv(a), b);     add(b, inv(a));   }   inline void XNOR(int a, int b) {     add(a, b);     add(b, a);     add(inv(a), inv(b));     add(inv(b), inv(a));   }   inline void force_true(int x) { add(inv(x), x); }   void dfs(int s) {     vis[s] = true;     for (int x : ed[s]) {       if (vis[x]) continue;       dfs(x);     }     order.push_back(s);   }   void mark(int s, int c) {     comp[s] = c;     vis[s] = true;     for (int x : rev[s]) {       if (vis[x]) continue;       mark(x, c);     }   }   bool satisfy(vector<int> &res) {     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= m; i++) {       if (vis[i]) continue;       dfs(i);     }     memset(vis, 0, sizeof(vis));     reverse(order.begin(), order.end());     int it = 0;     for (int s : order) {       if (vis[s]) continue;       mark(s, ++it);     }     res.clear();     for (int i = 1; i <= n; i++) {       if (comp[i] == comp[inv(i)]) return false;       if (comp[i] > comp[inv(i)]) res.push_back(i);     }     return true;   }   }  // namespace sat   int main() {     int n, m, a, b, c;     scanf( %d %d , &n, &m);     sat::init(n);     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &a, &b, &c);       if (c == 0)         sat::XOR(a, b);       else         sat::XNOR(a, b);     }     vector<int> V;     if (sat::satisfy(V)) {       cout << V.size() << endl;       for (int i = 0; i < V.size(); i++) cout << V[i] <<    ;       puts(  );     } else       puts( Impossible );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(int a, int b, int m) {     long long res = 1;     long long base = a;     base %= m;     while (b > 0) {       if (b % 2 == 1) {         res = (res * base) % m;       }       b >>= 1;       base = (base * base) % m;     }     return res;   }   long long modInverse(int a, int m) { return modpow(a, m - 2, m); }   long long modify(long long num) { return (num + 1000000007) % 1000000007; }   long long mypow(int base, int exp) {     long long ret = 1;     for (int i = 0; i < (exp); ++i) {       ret *= base;     }     return ret;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> a;     vector<int> b;     for (int i = 0; i < (n / k); ++i) {       int nxt;       cin >> nxt;       a.push_back(nxt);     }     for (int i = 0; i < (n / k); ++i) {       int nxt;       cin >> nxt;       b.push_back(nxt);     }     long long ans = 1;     for (int i = 0; i < (n / k); ++i) {       long long minians = 0;       for (int dig = 0; dig <= 9; dig++) {         if (dig == b[i]) continue;         long long top = (long long)(dig + 1) * mypow(10, k - 1) - 1l;         long long bot = (long long)(dig)*mypow(10, k - 1) - 1l;         long long topcnt = (long long)(top / a[i]);         topcnt++;         if (dig == 0) {           minians += topcnt;           continue;         }         long long botcnt = (long long)(bot / a[i]);         botcnt++;         minians += topcnt - botcnt;         minians = (minians + 1000000007) % 1000000007;       }       ans = (ans * minians) % 1000000007;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int sum, limit, start = 0, end = 0;     cin >> sum >> limit;     vector<pair<long long int, long long int>> v;     vector<long long int> ans;     for (long long int i = 1; i <= limit; i++) {       long long int t = i, cn = 0;       while (t > 0) {         if (t % 2 == 0)           t /= 2, cn++;         else           break;       }       long long int val = pow(2, cn);       v.push_back(make_pair(val, i));     }     sort(v.begin(), v.end());     for (long long int i = v.size() - 1; i >= 0; i--) {       if (sum < v[i].first)         continue;       else         sum -= v[i].first, ans.push_back(v[i].second);       if (sum == 0) break;     }     if (sum) {       cout <<  -1 ;       return 0;     }     cout << ans.size() << endl;     for (long long int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long ret = 0, f = 1;     char x = getchar();     while (!(x >=  0  && x <=  9 )) {       if (x ==  - ) f = -1;       x = getchar();     }     while (x >=  0  && x <=  9 ) ret = ret * 10 + x -  0 , x = getchar();     return ret * f;   }   char get_char() {     char x = getchar();     while (!((x >=  a  && x <=  z ) || (x >=  A  && x <=  Z ))) x = getchar();     return x;   }   const double eps = 1e-10;   int dcmp(double n) {     if (fabs(n) < eps)       return 0;     else if (n < 0)       return -1;     else       return 1;   }   struct point {     double x, y;     point() {}     point(double x, double y) : x(x), y(y) {}     bool operator<(const point& p) const {       if (dcmp(x - p.x) != 0) return x < p.x;       if (dcmp(y - p.y) != 0) return y < p.y;       return false;     }     bool operator==(const point& p) const {       return dcmp(x - p.x) == 0 && dcmp(y - p.y) == 0;     }     void read() { scanf( %lf %lf , &x, &y); }     void print() const { printf( x:%.3lf y:%.3lf n , x, y); }     double len() const { return sqrt(x * x + y * y); }   };   point operator-(const point& a, const point& b) {     return point(a.x - b.x, a.y - b.y);   }   point operator+(const point& a, const point& b) {     return point(a.x + b.x, a.y + b.y);   }   point operator*(double num, const point& a) {     return point(a.x * num, a.y * num);   }   double det(point a, point b) { return a.x * b.y - b.x * a.y; }   double det(point a, point b, point o) { return det(a - o, b - o); }   double dot(point a, point b) { return a.x * b.x + a.y * b.y; }   double ang(point a, point b) {     double cosx = dot(a, b) / (a.len() * b.len());     return acos(cosx);   }   point rotate(point p, double d) {     double tx = cos(d) * p.x - sin(d) * p.y;     double ty = sin(d) * p.x + cos(d) * p.y;     return point(tx, ty);   }   bool on_line(point p, point a, point b) {     if (b < a) swap(a, b);     if (dcmp(p.x - a.x) < 0 || dcmp(b.x - p.x) > 0) return false;     int m = dcmp(det(b - a, p - a));     return m == 0;   }   bool is_inter(point a1, point a2, point b1, point b2) {     int m1 = dcmp(det(a2, b1, a1));     int m2 = dcmp(det(a2, b2, a1));     int m3 = dcmp(det(b2, a1, b1));     int m4 = dcmp(det(b2, a2, b1));     return m1 != m2 && m3 != m4;   }   point inter_point(point a1, point a2, point b1, point b2) {     double t = det(a1, b2, b1) / det(b2 - b1, a2 - a1);     return (a1 + t * (a2 - a1));   }   const int L_N = 30 + 10;   const double INF = 1e9;   point S, E;   vector<point> PS;   set<point> INT_SET;   int N;   double dis[L_N][L_N];   bool get_inter() {     for (int i = 0; i < PS.size(); i++) {       int nxt = (i + 1) % PS.size();       if (is_inter(S, E, PS[i], PS[nxt])) {         point t = inter_point(S, E, PS[i], PS[nxt]);         if (INT_SET.count(t)) continue;         INT_SET.insert(t);         PS.insert(PS.begin() + i + 1, t);         return true;       }     }     return false;   }   double get_ans_int() {     point p1, p2;     int sid = 0, eid = 0;     set<point>::iterator it = INT_SET.begin();     p1 = *it;     it++;     p2 = *it;     for (int i = (0); i <= ((int)PS.size() - 1); i++) {       if (PS[i] == p1)         sid = i;       else if (PS[i] == p2)         eid = i;     }     double ans = 2 * (p1 - p2).len();     ans = min(ans, dis[sid][eid]);     ans += min((S - p1).len(), (S - p2).len());     ans += min((E - p1).len(), (E - p2).len());     return ans;   }   int main() {     for (int i = (0); i <= (L_N - 1); i++)       for (int j = (0); j <= (L_N - 1); j++)         if (i != j) dis[i][j] = INF;     S.read(), E.read();     N = read();     PS.resize(N);     for (int i = (0); i <= (N - 1); i++) PS[i].read();     while (get_inter())       ;     for (int i = (0); i <= ((int)PS.size() - 1); i++) {       int nxt = (i + 1) % PS.size();       dis[i][nxt] = dis[nxt][i] = (PS[i] - PS[nxt]).len();     }     for (int k = (0); k <= (N + 2); k++)       for (int i = (0); i <= (N + 2); i++)         for (int j = (0); j <= (N + 2); j++) {           if (dcmp(dis[i][k] + dis[k][j] - dis[i][j]) < 0)             dis[i][j] = dis[i][k] + dis[k][j];         }     double ans = 0;     if (INT_SET.size() < 2)       ans = (S - E).len();     else       ans = get_ans_int();     printf( %.10lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   long long x[200001], y[200001];   set<long long> sx, sy;   long long indx[200001], indy[200001];   long long find_indx(long long a) {     long long l = 0, r = n - 1;     long long ind = -1;     while (l <= r) {       long long mid = (l + r) / 2;       if (x[mid] >= a) {         ind = mid;         r = mid - 1;       } else         l = mid + 1;     }     assert(ind != -1);     return ind;   }   long long find_indy(long long b) {     long long l = 0, r = m - 1;     long long ind = -1;     while (l <= r) {       long long mid = (l + r) / 2;       if (y[mid] >= b) {         ind = mid;         r = mid - 1;       } else         l = mid + 1;     }     assert(ind != -1);     return ind;   }   void solv() {     long long res = 0;     cin >> n >> m >> k;     sx.clear();     sy.clear();     for (long long i = 0; i < n; i++) {       indx[i] = 0;       cin >> x[i];       sx.insert(x[i]);     }     for (long long i = 0; i < m; i++) {       indy[i] = 0;       cin >> y[i];       sy.insert(y[i]);     }     vector<pair<long long, long long>> onx, ony;     for (long long i = 0; i < k; i++) {       long long a, b;       cin >> a >> b;       if (sx.count(a) && sy.count(b)) continue;       if (sx.count(a))         onx.push_back({a, b});       else         ony.push_back({b, a});     }     pair<long long, long long> las = {-1, -1};     long long cnt = 0;     sort(onx.begin(), onx.end());     sort(ony.begin(), ony.end());     for (long long i = 0; i < onx.size(); i++) {       long long xx = find_indx(onx[i].first), yy = find_indy(onx[i].second);       if (make_pair(xx, yy) != las)         cnt = 0, las = {xx, yy};       else         cnt++;       res += indy[yy] - cnt;       indy[yy]++;     }     las = {-1, -1}, cnt = 0;     for (long long i = 0; i < ony.size(); i++) {       long long xx = find_indx(ony[i].second), yy = find_indy(ony[i].first);       if (make_pair(xx, yy) != las)         cnt = 0, las = {xx, yy};       else         cnt++;       res += indx[xx] - cnt;       indx[xx]++;     }     cout << res <<   n ;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long t;     cin >> t;     while (t--) solv();   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MAX_N = 1e6 + 5;   using pii = pair<long long, long long>;   struct edge {     long long to, flow, cap, cost, rev;   };   struct MinCostMaxFlow {     long long nodes;     vector<long long> prio, curflow, prevedge, prevnode, q, pot;     vector<bool> inqueue;     vector<vector<edge>> graph;     MinCostMaxFlow() {}     MinCostMaxFlow(long long n)         : nodes(n),           prio(n, 0),           curflow(n, 0),           prevedge(n, 0),           prevnode(n, 0),           q(n, 0),           pot(n, 0),           inqueue(n, 0),           graph(n) {}     void addEdge(long long source, long long to, long long capacity,                  long long cost) {       edge a = {to, 0, capacity, cost, (long long)graph[to].size()};       edge b = {source, 0, 0, -cost, (long long)graph[source].size()};       graph[source].push_back(a);       graph[to].push_back(b);     }     void bellman_ford(long long source, vector<long long> &dist) {       fill(dist.begin(), dist.end(), INT_MAX);       dist[source] = 0;       long long qt = 0;       q[qt++] = source;       for (long long qh = 0; (qh - qt) % nodes != 0; qh++) {         long long u = q[qh % nodes];         inqueue[u] = false;         for (auto &e : graph[u]) {           if (e.flow >= e.cap) continue;           long long v = e.to;           long long newDist = dist[u] + e.cost;           if (dist[v] > newDist) {             dist[v] = newDist;             if (!inqueue[v]) {               inqueue[v] = true;               q[qt++ % nodes] = v;             }           }         }       }     }     pair<long long, long long> minCostFlow(long long source, long long dest,                                            long long maxflow) {       bellman_ford(source, pot);       long long flow = 0;       long long flow_cost = 0;       while (flow < maxflow) {         priority_queue<pair<long long, long long>,                        vector<pair<long long, long long>>,                        greater<pair<long long, long long>>>             q;         q.push({0, source});         fill(prio.begin(), prio.end(), INT_MAX);         prio[source] = 0;         curflow[source] = INT_MAX;         while (!q.empty()) {           long long d = q.top().first;           long long u = q.top().second;           q.pop();           if (d != prio[u]) continue;           for (long long i = 0; i < graph[u].size(); i++) {             edge &e = graph[u][i];             long long v = e.to;             if (e.flow >= e.cap) continue;             long long newPrio = prio[u] + e.cost + pot[u] - pot[v];             if (prio[v] > newPrio) {               prio[v] = newPrio;               q.push({newPrio, v});               prevnode[v] = u;               prevedge[v] = i;               curflow[v] = min(curflow[u], e.cap - e.flow);             }           }         }         if (prio[dest] == INT_MAX) break;         for (long long i = 0; i < nodes; i++) pot[i] += prio[i];         long long df = min(curflow[dest], maxflow - flow);         flow += df;         for (long long v = dest; v != source; v = prevnode[v]) {           edge &e = graph[prevnode[v]][prevedge[v]];           e.flow += df;           graph[v][e.rev].flow -= df;           flow_cost += df * e.cost;         }       }       return {flow, flow_cost};     }   };   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     MinCostMaxFlow network = MinCostMaxFlow(2 * n + 3);     long long s = 0;     long long t = 2 * n + 2;     for (long long i = 0; i < n; i++) {       network.addEdge(s, i + 1, 1, 0);       network.addEdge(i + 1 + n, t, 1, 0);       long long a, b, k;       cin >> a >> b >> k;       for (long long j = 0; j <= n; j++) {         long long cc = max(0LL, a - min(k, j) * b);         network.addEdge(i + 1, j + 1 + n, 1, -cc);       }     }     network.addEdge(t - 1, t, 1, 0);     cout << -network.minCostFlow(s, t, n + 1).second;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int L = 2e5 + 7;   long long out[L], a[L], counter[1000001], szs = 900;   struct node {     long long l, r, q;   };   bool comp(node x, node y) {     long long xx = x.l / szs, yy = y.l / szs;     if (xx == yy) return x.r < y.r;     return x.l < y.l;   }   long long ans = 0;   void add(int idx) {     counter[a[idx]]++;     ans += ((counter[a[idx]]) * (counter[a[idx]]) * a[idx] -             (counter[a[idx]] - 1) * (counter[a[idx]] - 1) * a[idx]);   }   void remove(int idx) {     counter[a[idx]]--;     ans += ((counter[a[idx]]) * (counter[a[idx]]) * a[idx] -             (counter[a[idx]] + 1) * (counter[a[idx]] + 1) * a[idx]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int curl, curr, n, m, cur = 0, l, r, b, k;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i];     std::vector<node> v(m);     node temp;     for (int i = 0; i < m; ++i) {       cin >> l >> r;       l--, r--;       v[i].l = l, v[i].r = r, v[i].q = i;     }     sort(v.begin(), v.end(), comp);     l = 0, r = -1;     for (int i = 0; i < m; ++i) {       curl = v[i].l, curr = v[i].r;       while (r < curr) {         ++r;         add(r);       }       while (r > curr) {         remove(r);         --r;       }       while (l < curl) {         remove(l);         l++;       }       while (l > curl) {         --l;         add(l);       }       out[v[i].q] = ans;     }     for (int i = 0; i < m; ++i) cout << out[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b, c, d, k;       cin >> a >> b >> c >> d >> k;       int x = (a + c - 1) / c;       int y = (b + d - 1) / d;       if (x + y <= k)         cout << x <<     << y << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const double pi = acos(-1);   long long dp[1000006];   int main() {     long long n;     cin >> n;     long long a[n + 1];     memset(dp, 0, sizeof(dp));     dp[0] = 1;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       vector<long long> v;       for (long long j = 1; j * j <= a[i]; j++) {         if (a[i] % j == 0) {           if (a[i] / j == j) {             v.push_back(j);           } else {             v.push_back(j);             v.push_back(a[i] / j);           }         }       }       sort(v.begin(), v.end(), greater<long long>());       for (long long j = 0; j < v.size(); j++) {         dp[v[j]] += dp[v[j] - 1];         dp[v[j]] %= M;       }     }     long long ans = 0;     for (long long i = 1; i <= n; i++) {       ans += dp[i];       ans %= M;     }     cout << ans << endl;     return 0;   }