#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rread(T& num) {     num = 0;     T f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) num = num * 10 + ch -  0 , ch = getchar();     num *= f;   }   const int maxn = 1e5 + 5, maxpow = 9;   const long long inf = 1e18;   int n, m;   long long a[maxn];   vector<long long> bin;   inline void Prework() {     long long now = 1;     for (int(i) = (0); (i) < (maxpow); (i)++) bin.push_back(now), now *= 42;   }   inline long long GetToNxt(long long x) {     int tmp = lower_bound(bin.begin(), bin.end(), x) - bin.begin();     if (tmp == maxpow) return inf;     return bin[tmp] - x;   }   int root;   namespace Treap {   int ndtot;   struct TreapNode {     int l, r, len, sz;     long long val, tonxt, mini, tag;   } T[maxn];   vector<int> pool;   inline int NewNode(long long val, int len) {     int x;     if (((pool).size()))       x = pool.back(), pool.pop_back();     else       x = ++ndtot;     (T[(x)].l) = (T[(x)].r) = (T[(x)].tag) = 0;     (T[(x)].val) = val;     (T[(x)].sz) = (T[(x)].len) = len;     (T[(x)].tonxt) = (T[(x)].mini) = GetToNxt(val);     return x;   }   inline void Update(int x) {     (T[(x)].sz) = (T[(x)].len) + (T[((T[(x)].l))].sz) + (T[((T[(x)].r))].sz);     (T[(x)].mini) =         min((T[(x)].tonxt), min((T[((T[(x)].l))].mini), (T[((T[(x)].r))].mini)));   }   inline int Build(int l, int r) {     if (l > r) return 0;     int x = NewNode(a[((l + r) >> 1)], 1);     (T[(x)].l) = Build(l, ((l + r) >> 1) - 1);     (T[(x)].r) = Build(((l + r) >> 1) + 1, r);     Update(x);     return x;   }   inline void AddVal(int x, long long num) {     if (!x) return;     (T[(x)].tag) += num;     (T[(x)].val) += num;     (T[(x)].tonxt) -= num;     (T[(x)].mini) -= num;   }   inline void PushDown(int x) {     if (!x || !(T[(x)].tag)) return;     AddVal((T[(x)].l), (T[(x)].tag));     AddVal((T[(x)].r), (T[(x)].tag));     (T[(x)].tag) = 0;   }   inline int Rnd(int x, int y) {     return rand() % ((T[(x)].sz) + (T[(y)].sz)) < (T[(x)].sz);   }   inline int Merge(int x, int y) {     if (!x || !y) return x + y;     PushDown(x);     PushDown(y);     if (Rnd(x, y)) {       (T[(x)].r) = Merge((T[(x)].r), y);       Update(x);       return x;     } else {       (T[(y)].l) = Merge(x, (T[(y)].l));       Update(y);       return y;     }   }   inline pair<int, int> Split(int x, int len) {     if (!x) return make_pair(0, 0);     PushDown(x);     if ((T[((T[(x)].l))].sz) >= len) {       pair<int, int> y = Split((T[(x)].l), len);       (T[(x)].l) = y.second;       Update(x);       return make_pair(y.first, x);     }     len -= (T[((T[(x)].l))].sz);     if (len < (T[(x)].len)) {       int x1 = NewNode((T[(x)].val), len),           x2 = NewNode((T[(x)].val), (T[(x)].len) - len);       (T[(x1)].l) = (T[(x)].l);       (T[(x2)].r) = (T[(x)].r);       Update(x1);       Update(x2);       pool.push_back(x);       return make_pair(x1, x2);     }     len -= (T[(x)].len);     pair<int, int> z = Split((T[(x)].r), len);     (T[(x)].r) = z.first;     Update(x);     return make_pair(x, z.second);   }   inline long long QueryVal(int x) {     long long res;     pair<int, int> b = Split(root, x), a = Split(b.first, x - 1);     res = (T[(a.second)].val);     b.first = Merge(a.first, a.second);     root = Merge(b.first, b.second);     return res;   }   inline void Recycle(int x) {     if (!x) return;     Recycle((T[(x)].l));     pool.push_back(x);     Recycle((T[(x)].r));   }   inline void SetVal(int l, int r, long long val) {     pair<int, int> b = Split(root, r), a = Split(b.first, l - 1);     Recycle(a.second);     int x = NewNode(val, r - l + 1);     b.first = Merge(a.first, x);     root = Merge(b.first, b.second);   }   inline void FixMini(int x) {     if (!x) return;     PushDown(x);     if ((T[(x)].tonxt) == (T[(x)].mini)) {       (T[(x)].tonxt) = GetToNxt((T[(x)].val));       Update(x);       return;     }     if ((T[((T[(x)].l))].mini) < (T[((T[(x)].r))].mini))       FixMini((T[(x)].l));     else       FixMini((T[(x)].r));     Update(x);   }   inline void Print(int x) {     if (!x) return;     Print((T[(x)].l));     cerr << (T[(x)].val) <<  (  << (T[(x)].tonxt) <<  )  ;     Print((T[(x)].r));   }   inline void AddVal(int l, int r, long long x) {     pair<int, int> b = Split(root, r), a = Split(b.first, l - 1);     AddVal(a.second, x);     while (1) {       while ((T[(a.second)].mini) < 0) FixMini(a.second);       if ((T[(a.second)].mini) > 0) break;       AddVal(a.second, x);     }     b.first = Merge(a.first, a.second);     root = Merge(b.first, b.second);   }   inline void Init() { (T[(0)].mini) = inf; }   }  // namespace Treap   inline void judge() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   int main() {     Prework();     Treap::Init();     rread(n);     rread(m);     for (int(i) = (1); (i) <= (n); (i)++) rread(a[i]);     root = Treap::Build(1, n);     while (m--) {       int opt;       rread(opt);       if (opt == 1) {         int x;         rread(x);         printf( %lld n , Treap::QueryVal(x));       } else if (opt == 2) {         int l, r;         long long x;         rread(l);         rread(r);         rread(x);         Treap::SetVal(l, r, x);       } else if (opt == 3) {         int l, r;         long long x;         rread(l);         rread(r);         rread(x);         Treap::AddVal(l, r, x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   map<int, int> mx, my;   vector<int> v;   long long cal() {     long long ans = 0;     int sz = v.size();     sort(v.begin(), v.end());     int l = 0, r;     while (l < sz) {       r = l;       while (r < sz - 1 && v[r + 1] == v[l]) r++;       ans += 1ll * (r - l + 1) * (r - l) / 2;       l = r + 1;     }     return ans;   }   struct point {     int x;     int y;   } px[N], py[N];   bool cmpx(point &u, point &v) { return u.x < v.x; }   bool cmpy(point &u, point &v) { return u.y < v.y; }   int read() {     char c = getchar();     int ans = 0;     while (c ==     || c ==   n ) c = getchar();     while (c >=  0  && c <=  9 ) ans = ans * 10 + c -  0 , c = getchar();     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       int cx = 0, cy = 0;       long long ans = 0;       mx.clear();       my.clear();       int n, m, k;       cin >> n >> m >> k;       for (int i = 1, x; i <= n; i++) {         x = read();         mx[x] = 1;       }       for (int i = 1, y; i <= m; i++) {         y = read();         my[y] = 1;       }       for (int i = 1, x, y; i <= k; i++) {         x = read();         y = read();         if (mx.count(x) && my.count(y)) continue;         if (mx.count(x))           py[++cy].x = x, py[cy].y = y;         else           px[++cx].x = x, px[cx].y = y;       }       sort(px + 1, px + cx + 1, cmpx);       sort(py + 1, py + cy + 1, cmpy);       map<int, int>::iterator P = mx.begin();       int L = 1, R;       while (P != mx.end()) {         v.clear();         v.push_back(px[L].y);         int l = P->first;         P++;         int r = P->first;         if (P == mx.end()) break;         if (r < px[L].x) continue;         R = L;         while (R < cx && px[R + 1].x < r) R++, v.push_back(px[R].y);         ans += 1LL * (R - L + 1) * (R - L) / 2 - cal();         L = R + 1;       }       L = 1;       P = my.begin();       while (P != my.end()) {         v.clear();         v.push_back(py[L].x);         int l = P->first;         P++;         int r = P->first;         if (P == my.end()) break;         if (r < py[L].y) continue;         R = L;         while (R < cy && py[R + 1].y < r) R++, v.push_back(py[R].x);         ans += 1LL * (R - L + 1) * (R - L) / 2 - cal();         L = R + 1;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, excluidos = 0;   vector<priority_queue<int, vector<int>, greater<int>>> Vpq;   bool umVazio() {     for (auto u : Vpq) {       if (u.size() == 0) return true;     }     return false;   }   int procura(int indAnterior, int i) {     int num = -1;     while (Vpq[i].size() != 0) {       if (Vpq[i].top() > indAnterior) {         num = Vpq[i].top();         Vpq[i].pop();         return num;       } else {         excluidos++;         Vpq[i].pop();       }     }     return num;   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(0);     cin >> n;     int a;     Vpq.resize(6);     for (int i = 0; i < n; i++) {       cin >> a;       if (a == 4) {         Vpq[0].push(i);       } else if (a == 8) {         Vpq[1].push(i);       } else if (a == 15) {         Vpq[2].push(i);       } else if (a == 16) {         Vpq[3].push(i);       } else if (a == 23) {         Vpq[4].push(i);       } else if (a == 42) {         Vpq[5].push(i);       }     }     bool flag = 1;     while (flag) {       int indAnterior = -2;       for (int i = 0; i < 6; i++) {         indAnterior = procura(indAnterior, i);         if (indAnterior == -1) {           excluidos += i;           flag = 0;           break;         }       }     }     for (int i = 0; i < 6; i++) {       excluidos += Vpq[i].size();     }     cout << excluidos << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   const double eps = 1e-10;   int n;   int m;   double ax, ay, az, vx, vy, vz, R, r, ox, oy, oz, px, py, pz;   double scal(double x1, double y8687969, double z1, double x2, double y2,               double z2) {     return x1 * x2 + y8687969 * y2 + z1 * z2;   }   double vect(double x1, double y8687969, double z1, double x2, double y2,               double z2) {     double x3 = y8687969 * z2 - y2 * z1;     double y3 = z1 * x2 - z2 * x1;     double z3 = x1 * y2 - x2 * y8687969;     return sqrt(abs(((x3) * (x3)) + ((y3) * (y3)) + ((z3) * (z3))));   }   double dist1(double x1, double y8687969, double z1, double x2, double y2,                double z2) {     return sqrt(abs(((x2 - x1) * (x2 - x1)) +                     ((y2 - y8687969) * (y2 - y8687969)) +                     ((z2 - z1) * (z2 - z1))));   }   double dist2(double x1, double y8687969, double z1, double x2, double y2,                double z2, double x3, double y3, double z3) {     double tmp = min(dist1(x1, y8687969, z1, x2, y2, z2),                      dist1(x1, y8687969, z1, x3, y3, z3));     double s1 = scal(x1 - x2, y8687969 - y2, z1 - z2, x3 - x2, y3 - y2, z3 - z2);     double s2 = scal(x1 - x3, y8687969 - y3, z1 - z3, x2 - x3, y2 - y3, z2 - z3);     if (s1 > 0 && s2 > 0) {       double d = dist1(x2, y2, z2, x3, y3, z3);       double s =           vect(x2 - x1, y2 - y8687969, z2 - z1, x3 - x1, y3 - y8687969, z3 - z1);       tmp = s / d;     }     return tmp;   }   double get1(double x, double y, double z, double r) {     double p = 0, q = 1e13;     for (int it = 0; it < 300; it++) {       double s1 = (2 * p + q) / 3;       double s2 = (p + 2 * q) / 3;       double d1 = dist1(ax + vx * s1, ay + vy * s1, az + vz * s1, x, y, z);       double d2 = dist1(ax + vx * s2, ay + vy * s2, az + vz * s2, x, y, z);       if (d1 < d2)         q = s2;       else         p = s1;     }     double s = (p + q) / 2;     double d = dist1(ax + vx * s, ay + vy * s, az + vz * s, x, y, z);     if (d > r + R + eps) return 1e15;     p = 0;     q = s;     for (int it = 0; it < 300; it++) {       s = (p + q) / 2;       d = dist1(ax + vx * s, ay + vy * s, az + vz * s, x, y, z);       if (d > r + R)         p = s;       else         q = s;     }     return q;   }   double get2(double x1, double y8687969, double z1, double x2, double y2,               double z2) {     double p = 0, q = 1e13;     for (int it = 0; it < 300; it++) {       double s1 = (2 * p + q) / 3;       double s2 = (p + 2 * q) / 3;       double d1 = dist2(ax + vx * s1, ay + vy * s1, az + vz * s1, x1, y8687969,                         z1, x2, y2, z2);       double d2 = dist2(ax + vx * s2, ay + vy * s2, az + vz * s2, x1, y8687969,                         z1, x2, y2, z2);       if (d1 < d2)         q = s2;       else         p = s1;     }     double s = (p + q) / 2;     double d = dist2(ax + vx * s, ay + vy * s, az + vz * s, x1, y8687969, z1, x2,                      y2, z2);     if (d > R + eps) return 1e15;     p = 0;     q = s;     for (int it = 0; it < 300; it++) {       s = (p + q) / 2;       d = dist2(ax + vx * s, ay + vy * s, az + vz * s, x1, y8687969, z1, x2, y2,                 z2);       if (d > R)         p = s;       else         q = s;     }     return q;   }   int main() {     cin >> ax >> ay >> az >> vx >> vy >> vz >> R >> n;     double ans = 1e15;     for (int i = 0; i < n; i++) {       cin >> ox >> oy >> oz >> r >> m;       ans = min(ans, get1(ox, oy, oz, r));       for (int j = 0; j < m; j++) {         cin >> px >> py >> pz;         ans = min(ans, get2(ox, oy, oz, ox + px, oy + py, oz + pz));       }     }     if (ans > 5e14)       printf( -1 n );     else       printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class trio {    public:     long long first, second, third;   };   class quad {    public:     long long first, second, third, fourth;   };   class DSU {    public:     long long *par, *size;     DSU(long long n) {       par = new long long[n + 1];       size = new long long[n + 1];       for (long long i = 0; i < n + 1; ++i) {         par[i] = i;         size[i] = 0;       }     }     long long find(long long a) {       long long p = a, third;       while (par[p] != p) p = par[p];       while (p != a) {         third = par[a];         par[a] = p;         a = third;       }       return a;     }     void union_(long long a, long long b) {       long long u1 = find(a);       long long u2 = find(b);       if (size[u1] < size[u2]) {         par[u1] = u2;       } else {         if (size[u2] < size[u1]) {           par[u2] = u1;         } else {           par[u1] = u2;           size[u1]++;         }       }     }   };   bool mycom(quad a, quad b) { return a.first < b.first; }   long long *intime, *outime, timt = 1;   bool inacestor(long long a, long long b) {     return (intime[a] <= intime[b] && outime[a] >= outime[b]);   }   long long tree[100010][20];   long long dp[100010][20];   void dfs(long long i, list<pair<long long, long long> > *adj) {     intime[i] = timt;     timt++;     for (auto it : adj[i]) {       if (it.first != tree[i][0]) {         tree[it.first][0] = i;         dp[it.first][0] = it.second;         dfs(it.first, adj);       }     }     outime[i] = timt;     timt++;   }   long long func(long long a, long long b) {     long long ans = 0;     for (long long j = 19; j >= 0; --j) {       if (inacestor(tree[a][j], b)) continue;       ans = max(ans, dp[a][j]);       a = tree[a][j];     }     for (long long j = 19; j >= 0; --j) {       if (inacestor(tree[b][j], a)) continue;       ans = max(ans, dp[b][j]);       b = tree[b][j];     }     if (!inacestor(a, b) && !inacestor(b, a)) {       ans = max(ans, dp[b][0]);       ans = max(ans, dp[a][0]);     } else {       if (inacestor(a, b)) {         ans = max(ans, dp[b][0]);       } else         ans = max(ans, dp[a][0]);     }     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, m;     cin >> n >> m;     quad edges[m + 1];     bool select[m + 1];     memset(select, 0, sizeof(select));     for (long long i = 0; i < m; ++i) {       cin >> edges[i].second >> edges[i].third >> edges[i].first;       edges[i].fourth = i;     }     sort(edges, edges + m, mycom);     DSU dsu1(n);     long long ans[m + 1];     for (long long i = 0; i < m; ++i) {       ans[i] = -1;     }     list<pair<long long, long long> > adj[n + 1];     for (long long i = 0; i < m; ++i) {       if (dsu1.find(edges[i].second) != dsu1.find(edges[i].third)) {         dsu1.union_(edges[i].second, edges[i].third);         select[i] = 1;         adj[edges[i].second].push_back({edges[i].third, edges[i].first});         adj[edges[i].third].push_back({edges[i].second, edges[i].first});       }     }     intime = new long long[n + 1];     outime = new long long[n + 1];     tree[1][0] = -1;     dfs(1, adj);     tree[1][0] = 1;     dp[1][0] = 0;     for (long long j = 1; j < 20; ++j) {       for (long long i = 1; i < n + 1; ++i) {         tree[i][j] = tree[tree[i][j - 1]][j - 1];         dp[i][j] = max(dp[tree[i][j - 1]][j - 1], dp[i][j - 1]);       }     }     for (long long j = 0; j < m; ++j) {       if (select[j] == 0) {         ans[edges[j].fourth] = func(edges[j].second, edges[j].third);       }     }     for (long long i = 0; i < m; ++i) {       if (ans[i] != -1) {         cout << ans[i] << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T& x) {     x = 0;     char c;     int sign = 1;     do {       c = getchar();       if (c ==  - ) sign = -1;     } while (c <  0  || c >  9 );     do {       x = x * 10 + c -  0 ;       c = getchar();     } while (c <=  9  && c >=  0 );     x *= sign;   }   const int N = 101, inf = 1e6;   int t, n, cnt, a[N], k[N];   bool vis[inf << 1];   bool check(int x) {     for (register int i = 1; i <= n; ++i)       if (vis[a[i] + x]) return 0;     for (register int i = 1; i <= n; ++i) vis[a[i] + x] = 1;     return 1;   }   inline int solve() {     cnt = 0;     memset(vis, 0, sizeof vis);     read(n);     for (register int i = 1; i <= n; ++i) read(a[i]);     sort(a + 1, a + n + 1);     for (register int i = 2; i <= n; ++i)       if (a[i] == a[i - 1]) return puts( NO ), 0;     for (register int i = 1; i <= inf; ++i)       if (cnt == n)         break;       else if (check(i))         k[++cnt] = i;     if (cnt == n) {       puts( YES );       for (register int i = 1; i <= n; ++i) printf( %d  , k[i]);       printf(  n );     } else       puts( NO );     return 0;   }   int main() {     read(t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long binPow(long long a, long long b) {     a = a % 1000000007;     if (a == 0) return 0;     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     string p;     cin >> p;     int size = p.size();     int PI[size];     PI[0] = 0;     for (int i = 1; i < size; i++) {       int j = PI[i - 1];       while (j > 0 && p[i] != p[j]) j = PI[j - 1];       if (p[i] == p[j]) j++;       PI[i] = j;     }     unordered_map<int, int> make_pair;     int j = PI[size - 1];     while (j > 0) {       make_pair[j]++;       j = PI[j - 1];     }     int y;     int last = 1;     long long count = 0;     for (int i = 0; i < m; i++) {       cin >> y;       if (y < last) {         if (make_pair[last - y] == 0) {           cout << 0 <<   n ;           return 0;         }       } else {         count += y - last;       }       last = min(n + 1, y + size);     }     count += max(0, n + 1 - last);     cout << binPow(26, count) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n], brr[n];     for (int i = 0; i < n; ++i) {       cin >> arr[i] >> brr[i];     }     for (int i = 0; i < n; ++i) {       if (arr[i] != brr[i]) {         cout <<  rated ;         return 0;       }     }     for (int i = 0; i < n - 1; ++i) {       if (arr[i] < arr[i + 1] && brr[i] < brr[i + 1]) {         cout <<  unrated ;         return 0;       }     }     cout <<  maybe ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int t, n, i, x, mx, mn, f, j, s, r, y, c, m, k, c1;     cin >> t;     while (t--) {       cin >> n;       vector<long long int> v;       f = 0;       for (i = 0; i < n; i++) {         cin >> x;         v.push_back(x);         if (x == 0) f = 1;       }       s = 2;       r = pow(3, n);       while (s < r) {         x = s;         s++;         c = c1 = 0;         set<long long int> S;         for (i = 0; i < n; i++) {           if (x % 3 == 1)             c += v[i];           else if (x % 3 == 2)             c -= v[i];           else             S.insert(v[i]);           x /= 3;         }         if (S.count(c)) f = 1;       }       if (f)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     cin >> x;   }   template <typename T, typename T0>   void read(T &x, T0 &y) {     cin >> x >> y;   }   template <typename T, typename T0, typename T1>   void read(T &x, T0 &y, T1 &z) {     cin >> x >> y >> z;   }   bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }   int digits(int n) {     int x = floor(log10(n)) + 1;     return x;   }   long long int fact(long long int n) {     if (n == 0) return 1;     return n * fact(n - 1);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   vector<bool> sieve(1000000, true);   void sieve_er() {     sieve[0] = false;     sieve[1] = false;     for (long long int i = 2; i * i <= 1000000; i++) {       if (sieve[i] == true) {         for (long long int j = i * i; j < 1000000; j += i) sieve[j] = false;       }     }   }   vector<long long int> vec;   void divisors(long long int n) {     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           vec.push_back(i);         else {           vec.push_back(i);           vec.push_back(n / i);         }       }     }   }   long long int total_divisors(long long int n) {     long long int c = 0;     for (long long int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           c = c + 1;         else           c = c + 2;       }     }     return c;   }   long long int nCr(long long int n, long long int r) {     long long int ans = 1;     for (int i = 0; i < r; i++) {       ans *= n - i;       ans /= i + 1;     }     return ans;   }   long long int power_m(long long int a, long long int b,                         long long int m = 1000000007) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long int strTo(string s) {     stringstream tmp(s);     long long int x = 0;     tmp >> x;     return x;   }   string NoTo(long long int n) {     ostringstream str1;     str1 << n;     string ans = str1.str();     return ans;   }   void start() {}   long long int tree[4000001];   long long int a[10000001];   void build(int i, int s, int e) {     if (s > e) return;     if (s == e) {       tree[i] = a[s];       return;     }     int mid = (s + e) / 2;     build(2 * i, s, mid);     build(2 * i + 1, mid + 1, e);     tree[i] = (tree[2 * i] + tree[2 * i + 1]);     return;   }   void un(int in, int s, int e, int i, int val) {     if (i < s || i > e) return;     if (s == e) {       tree[in] += val;       return;     }     int mid = (s + e) / 2;     un(2 * in, s, mid, i, val);     un(2 * in + 1, mid + 1, e, i, val);     tree[in] = (tree[2 * in] + tree[2 * in + 1]);     return;   }   long long int query(int in, int s, int e, int qs, int qe) {     if (qs > e || qe < s) return 0;     if (s >= qs && e <= qe) return tree[in];     int mid = (s + e) / 2;     long long int left = query(2 * in, s, mid, qs, qe);     long long int right = query(2 * in + 1, mid + 1, e, qs, qe);     return left + right;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int a, b, c;     read(a, b, c);     int ans = 0;     int z = min(a / 3, min(b / 2, c / 2));     ans += (7 * z);     a -= (z * 3);     b -= (z * 2);     c -= (z * 2);     char ar[7] = { a ,  a ,  b ,  c ,  a ,  c ,  b };     int ma = -1;     for (int i = 0; i < 7; i++) {       int j = i;       int a1 = a, b1 = b, c1 = c;       int x = 0;       while (true) {         if (ar[j] ==  a ) {           if (a1 > 0) {             a1--;             x++;           } else             break;         }         if (ar[j] ==  b ) {           if (b1 > 0) {             b1--;             x++;           } else             break;         }         if (ar[j] ==  c ) {           if (c1 > 0) {             c1--;             x++;           } else             break;         }         if (j == 6)           j = 0;         else           j++;       }       ma = max(ma, x);     }     ans += ma;     cout << ans <<   n ;     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios::sync_with_stdio(false);     int n;     std::cin >> n;     std::vector<int> data(n);     for (int i = 0; i < n; i++) {       std::cin >> data[i];     }     int s;     int t;     std::cin >> s;     std::cin >> t;     --s;     --t;     if (s > t) {       std::swap(s, t);     }     int sum1 = 0;     for (int i = s; i < t; i++) {       sum1 += data[i];     }     int sum2 = std::accumulate(data.begin(), data.end(), 0) - sum1;     int solution = std::min(sum1, sum2);     std::cout << solution << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int f[N], ff[N];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       f[x]++;     }     multiset<int> ms;     for (int i = 1; i < N; i++) {       ms.insert(f[i]);       ff[f[i]]++;     }     int q;     cin >> q;     while (q--) {       char c;       int x;       cin >> c >> x;       ff[f[x]]--;       ms.erase(ms.find(f[x]));       if (c ==  + ) {         f[x]++;       } else {         f[x]--;       }       ff[f[x]]++;       ms.insert(f[x]);       if (ms.empty()) {         cout <<  NO n ;         continue;       }       if (*ms.rbegin() >= 8) {         cout <<  YES n ;         continue;       }       vector<int> t(8);       for (int i = 1; i < 8; i++) t[i] = ff[i];       bool f = 0;       int twos = 0;       for (int i = 7; i >= 4; i--) {         if (t[i]) {           f = 1;           t[i]--;           t[i - 4]++;           break;         }       }       for (int i = 7; i >= 2; i--) {         twos += (i / 2) * t[i];       }       if (f && twos >= 2) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   const int inf = 1e7 + 7;   long long mod = 1e9 + 7;   const double eps = 1e-9;   using namespace std;   int num[1000005];   char s[1000005];   int main() {     cin >> s;     int len = strlen(s);     num[len] = 0;     for (int i = len - 1; i >= 0; i--) {       if (s[i] ==  0 )         num[i] = num[i + 1] - 1;       else {         num[i] = num[i + 1] + 1;         if (num[i] > 0) {           num[i] = 0;           s[i] =  0 ;         }       }     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, x, r;   int main() {     for (cin >> n >> a >> b, r = n; x * a <= n; x++)       r = min(r, (n - x * a) % (5 * b));     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   typedef long double ld;   const long double PI =       3.141592653589793238462643383279502884197169399375105820974944;   long long mod = 1e9 + 7;   const long long inf = 1e18;   const long long maxn = 3e5 + 5;   void solve() {     long long n, k;     cin >> n >> k;     vector<pair<long long, pair<long long, long long>>> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second.first;       v[i].second.second = i + 1;     }     sort((v).begin(), (v).end());     multiset<pair<long long, long long>> s;     vector<long long> ans;     for (auto i : v) {       while (!s.empty() && (*s.begin()).first < i.first) s.erase(s.begin());       while ((long long)((s).size()) > k) {         auto it = --s.end();         ans.push_back((*it).second);         s.erase(it);       }       if ((long long)((s).size()) == k) {         auto it = --s.end();         if ((*it).first >= i.second.first) {           ans.push_back((*it).second);           s.erase(it);           s.insert({i.second.first, i.second.second});         } else           ans.push_back(i.second.second);       } else         s.insert({i.second.first, i.second.second});     }     cout << (long long)((ans).size()) <<   n ;     for (auto i : ans) cout << i <<    ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc = 1;     while (tc--) {       solve();       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (i == a[a[a[i]]]) {         return cout <<  YES , 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int T, N, P, ap[109][109];   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d %d , &N, &P), P += 2 * N;       for (int df = 1; df < N && P; df++)         for (int i = 0; i < N && P; i++) ap[i][(i + df) % N] = 1, P--;       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++)           if (ap[i][j]) printf( %d %d n , i + 1, j + 1);       for (int i = 0; i < N; i++)         for (int j = 0; j < N; j++) ap[i][j] = 0;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int a1, a2;     cin >> a1 >> a2;     int res = 0;     while (a1 && a2 && (a1 > 1 || a2 > 1)) {       if (a1 > a2) swap(a1, a2);       ++a1;       a2 -= 2;       ++res;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long fact[1100000];   void find_fact() {     fact[0] = fact[1] = 1;     for (int i = 2; i <= 1e6; i++) fact[i] = (i * fact[i - 1]) % mod;   }   bool isvalid(long long num, int num1, int num2) {     while (num > 0) {       int cval = (num % 10);       if ((cval != num1) && (cval != num2)) return 0;       num = (num / 10);     }     return 1;   }   long long my_exp(int base, int exp) {     if (exp == 0) return 1;     if (exp == 1) return base;     long long ans = my_exp(base, exp / 2);     ans = (ans * ans) % mod;     if (exp % 2) ans = (ans * base) % mod;     return ans;   }   long long my_comb(int n, int i) {     return (fact[n] * my_exp((fact[i] * fact[n - i]) % mod, mod - 2)) % mod;   }   int main() {     find_fact();     int num1, num2, n;     cin >> num1 >> num2 >> n;     long long csm, ans = 0;     for (int i = 0; i <= n; i++) {       csm = (i * num1 + (n - i) * num2);       if (isvalid(csm, num1, num2)) ans = (ans + my_comb(n, i)) % mod;     }     cout << ans;     return 0;   }


#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 = 2e5 + 5;   int N, K, A, B, Q;   int total[MAXN];   class SegmentTree {    public:     typedef struct segment_st {       int numa, numb;       int l, r;     } TreeNode;     vector<TreeNode> tree;     int N;     int tree_size;     vector<int> leaves;     SegmentTree(int n) { build_tree(n); }     int query(int ll, int rr, int limit) { return query(1, ll, rr, limit); }     void update(int at, int val) { internal_update(at, val); }       private:     void initialize_node(int at) {       tree[at].numa = 0;       tree[at].numb = 0;     }     void update_up(int at) {       int left = at + at;       int right = at + at + 1;       tree[at].numa = tree[left].numa + tree[right].numa;       tree[at].numb = tree[left].numb + tree[right].numb;     }     void update_result(int &res, int val) { res += val; }     void update_leaf_value(int at, int &val, int d) {       tree[at].numa = min(A, total[d]);       tree[at].numb = min(B, total[d]);     }     int query(int at, int ll, int rr, int limit) {       if (ll > tree[at].r || rr < tree[at].l) return 0;       if (ll <= tree[at].l && tree[at].r <= rr) {         if (limit == 0) {           return tree[at].numb;         } else {           return tree[at].numa;         }       } else {         int res = 0;         update_result(res, query(at + at, ll, rr, limit));         update_result(res, query(at + at + 1, ll, rr, limit));         return res;       }     }     void internal_update(int at, int &val) {       int tmp = at;       at = leaves[at];       update_leaf_value(at, val, tmp);       at >>= 1;       while (at) {         update_up(at);         at >>= 1;       }     }     void build_tree(int n) {       N = n;       int base = 1;       while (base < N) base <<= 1;       tree_size = base << 1;       leaves.resize(N + 1);       tree = vector<TreeNode>(tree_size);       init(1, 1, n);     }     void init(int at, int ll, int rr) {       tree[at].l = ll;       tree[at].r = rr;       initialize_node(at);       if (ll == rr) {         leaves[ll] = at;       } else {         int mid = (tree[at].l + tree[at].r) >> 1;         init(at + at, tree[at].l, mid);         init(at + at + 1, mid + 1, tree[at].r);         update_up(at);       }     }   };   int main() {     scanf( %d %d %d %d %d , &N, &K, &A, &B, &Q);     SegmentTree tree(N);     int c;     for (int(i) = 0; (i) < (Q); ++(i)) {       scanf( %d , &c);       if (c == 1) {         int d, a;         scanf( %d %d , &d, &a);         total[d] += a;         tree.update(d, a);       } else {         int p;         scanf( %d , &p);         int res = 0;         if (p - 1 >= 1) res += tree.query(1, p - 1, 0);         p += K;         if (p <= N) res += tree.query(p, N, 1);         printf( %d n , res);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     int ans = 0;     cin >> a >> b;     ans += a;     while (a >= b) {       ans += (a / b);       a = (a / b) + (a % b);     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long mx, my, w;   map<double, int> a, b;   int rev(long long x) {     long long ret = 0;     while (x) {       ret *= 10;       ret += x % 10;       x /= 10;     }     return ret;   }   long long get(long long x, long long y) {     a.clear();     for (long long i = 1; i <= y; ++i) {       double tmp = 1.0 * rev(i) / i;       a[tmp]++;     }     long long ret = 0;     for (long long i = 1; i <= x; ++i) {       double tmp = 1.0 * i / rev(i);       ret += a[tmp];     }     return ret;   }   int main() {     cin >> mx >> my >> w;     if (get(mx, my) < w) {       puts( -1 );       return 0;     }     int nx = mx, ny = 1, ax = mx, ay = my;     long long now = get(nx, ny);     a.clear();     for (long long i = 1; i <= nx; ++i) {       a[1.0 * i / rev(i)]++;     }     b.clear();     for (long long i = 1; i <= ny; ++i) {       b[1.0 * rev(i) / i]++;     }     while (nx >= 1 && ny <= my) {       if (now < w) {         ny++;         double tmp = 1.0 * rev(ny) / ny;         now += a[tmp];         b[tmp]++;       } else {         if (1ll * nx * ny < 1ll * ax * ay) {           ax = nx;           ay = ny;         }         double tmp = 1.0 * nx / rev(nx);         nx--;         now -= b[tmp];         a[tmp]--;       }     }     cout << ax <<     << ay << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int a, b, c;     cin >> a >> b >> c;     string s;     cin >> s;     vector<int> brr[26];     int p1 =  R  -  A ;     int p2 =  P  -  A ;     int p3 =  S  -  A ;     for (int i = 0; i < s.size(); ++i) {       brr[s[i] -  A ].emplace_back(i);     }     string ans;     for (int i = 0; i < n; ++i) {       ans +=  * ;     }     int cnt = 0;     while (brr[p1].size()) {       if (b == 0) break;       ans[brr[p1].back()] =  P ;       brr[p1].pop_back();       --b;       ++cnt;     }     while (brr[p2].size()) {       if (c == 0) break;       ans[brr[p2].back()] =  S ;       brr[p2].pop_back();       --c;       ++cnt;     }     while (brr[p3].size()) {       if (a == 0) break;       ans[brr[p3].back()] =  R ;       brr[p3].pop_back();       --a;       ++cnt;     }     int half = ceil(n / 2.0);     if (cnt >= half) {       for (int i = 0; i < ans.size(); ++i) {         if (ans[i] ==  * ) {           if (a > 0)             ans[i] =  R , --a;           else if (b > 0)             ans[i] =  P , --b;           else if (c > 0)             ans[i] =  S , --c;         }       }       assert(a == 0 && b == 0 && c == 0);       cout <<  YES n  << ans <<   n ;     } else {       cout <<  NO n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     while (T--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int a[30];   bool mark[N];   bool dp[30][1000];   int n;   void update() {     dp[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j < 1000; j++) {         dp[i][j] = dp[i - 1][j];         if (j >= a[i] && !mark[i]) dp[i][j] |= dp[i - 1][j - a[i]];       }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     update();     int k = n;     for (int i = 1; i <= n; i++) {       int t = a[i] - 1;       for (int j = i - 1; j >= 1; j--) {         if (a[j] != a[i] - 1 && a[j] <= t && !mark[j] && dp[j - 1][t - a[j]]) {           update();           mark[j] = 1;           t -= a[j];           k--;         }       }       if (t) k = 200;     }     if (k == 1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 100 * 1000;   int a[MAXN + 10];   int dp[MAXN + 10];   int mx = 0;   using namespace std;   int main() {     long long n, m, k, s = 0;     cin >> k >> n >> m;     long long shif = (k - (n % k)) % k;     n = n + shif;     if (m < n)       cout << 0 << endl;     else       cout << (m - n) / k + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int a[(1 << 17) + 1];   int tree[4 * (1 << 17)];   void build(int nd, int s, int e, bool ex) {     if (s == e) {       tree[nd] = a[s];       return;     }     int mid = (s + e) / 2;     int left = 2 * nd;     int right = 2 * nd + 1;     build(left, s, mid, !ex);     build(right, mid + 1, e, !ex);     if (ex) {       tree[nd] = tree[left] ^ tree[right];     } else {       tree[nd] = tree[left] | tree[right];     }   }   void update(int nd, int s, int e, int p, int v, bool ex) {     if (s == e && s == p) {       tree[nd] = v;       return;     }     if (e < p || s > p) return;     int mid = (s + e) / 2;     int left = 2 * nd;     int right = 2 * nd + 1;     update(left, s, mid, p, v, !ex);     update(right, mid + 1, e, p, v, !ex);     if (ex) {       tree[nd] = tree[left] ^ tree[right];     } else {       tree[nd] = tree[left] | tree[right];     }   }   int main() {     int n, m, total;     cin >> n >> m;     total = (1 << n);     for (int i = 1; i <= total; i++) {       scanf( %d , a + i);     }     build(1, 1, total, !(n & 1));     int p, v;     while (m--) {       scanf( %d %d , &p, &v);       update(1, 1, total, p, v, !(n & 1));       cout << tree[1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   queue<int> q[2];   int main() {     ios_base::sync_with_stdio();     cin.tie();     cin >> n >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  D ) {         q[0].push(i);       }       if (s[i] ==  R ) {         q[1].push(i);       }     }     while (q[1].size() > 0 && q[0].size() > 0) {       int x = q[0].front();       int y = q[1].front();       if (x < y) {         q[1].pop();         q[0].pop();         q[0].push(x + n);       } else {         q[0].pop();         q[1].pop();         q[1].push(y + n);       }     }     if (q[0].size()) {       cout <<  D n ;     } else {       cout <<  R n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   pair<int, int> t[300100];   pair<int, int> up[300100];   pair<int, int> down[300100];   pair<int, int> inter(pair<int, int> a, pair<int, int> b) {     int f = max(a.first, b.first);     int s = min(a.second, b.second);     pair<int, int> res = {f, s};     return res;   }   long long int len(pair<int, int> a) {     int res = a.second - a.first;     if (res < 0) res = 0;     return res;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> t[i].first >> t[i].second;     down[0] = t[0];     up[n - 1] = t[n - 1];     for (int i = 0; i < n - 1; i++) down[i + 1] = inter(down[i], t[i + 1]);     for (int i = n - 1; i > 0; i--) up[i - 1] = inter(up[i], t[i - 1]);     long long int ma = -1;     ma = max(ma, len(up[1]));     ma = max(ma, len(down[n - 2]));     for (int i = 1; i < n - 1; i++) {       long long int a = len(inter(down[i - 1], up[i + 1]));       ma = max(ma, a);     }     cout << ma;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int x, int y) { return x < y ? x : y; }   int max(int x, int y) { return x > y ? x : y; }   void swap(int &x, int &y) {     int t;     t = x, x = y, y = t;   }   char s[200000];   int main() {     int x, y, i, j, n, k, t;     while (~scanf( %d%d , &n, &k)) {       if ((k + n - 1) / n == 2) {         printf( %d n , n);         continue;       }       for (i = 0;; i++) {         t = k - i * 2;         if (t == 0) break;         if (n - i <= 0) {           i--;           break;         }         if ((t) / (n - i) > 2) {           break;         }       }       printf( %d n , i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = INT_MAX - 1;   bool check(ll r, ll g, ll b, ll w, ll total) {     if (r < 0 || g < 0 || b < 0 || w < 0) {       return false;     }     ll numberIsOne = 0;     if (r & 1) {       numberIsOne++;     }     if (g & 1) {       numberIsOne++;     }     if (b & 1) {       numberIsOne++;     }     if (w & 1) {       numberIsOne++;     }     if (numberIsOne == 0 && total % 2 == 0) {       return true;     }     if (total % 2 == 1 && numberIsOne == 1) {       return true;     }   }   void solve() {     ll r, g, b, w;     cin >> r >> g >> b >> w;     ll total = r + g + b + w;     ll minNum = min(r, min(g, b));     if (check(r, g, b, w, total)) {       cout <<  Yes n ;       return;     }     if (check(r - 1, g - 1, b - 1, w + 3, total)) {       cout <<  Yes n ;       return;     }     if (check(r - 2, g - 2, b - 2, w + 6, total)) {       cout <<  Yes n ;       return;     }     if (check(r - minNum, g - minNum, b - minNum, w + minNum * 3, total)) {       cout <<  Yes n ;       return;     }     cout <<  No n ;   }   int main() {     ios_base::sync_with_stdio(false);     ll t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const long long INFF = 1e18;   const int INF = 1e9;   const int mod = 1e9 + 7;   const int MAX = 2e7 + 7;   vector<long long> st1, st2;   int main(void) {     long long a, b;     scanf( %lld %lld , &a, &b);     ;     long long c = a + b;     for (long long i = 1; i <= MAX; ++i) {       if (i * i > a) break;       if (a % i == 0) st1.push_back(i);     }     int tp = ((int)st1.size()) - 1;     for (int i = tp; i >= 0; --i) st1.push_back(a / st1[i]);     for (long long i = 1; i <= MAX; ++i) {       if (i * i > b) break;       if (b % i == 0) st2.push_back(i);     }     tp = ((int)st2.size()) - 1;     for (int i = tp; i >= 0; --i) st2.push_back(b / st2[i]);     long long ans = INFF;     for (long long i = 1; i <= MAX; ++i) {       if (i * i > c) break;       if (c % i == 0) {         bool ok = 0;         long long n = i, m = c / i;         long long n1 = *(--upper_bound((st1).begin(), (st1).end(), n));         if (m >= a / n1) ok = 1;         n1 = *(--upper_bound((st1).begin(), (st1).end(), m));         if (n >= a / n1) ok = 1;         n1 = *(--upper_bound((st2).begin(), (st2).end(), n));         if (m >= b / n1) ok = 1;         n1 = *(--upper_bound((st2).begin(), (st2).end(), m));         if (n >= b / n1) ok = 1;         if (ok) ans = min(ans, 2 * (n + m));       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string second;       cin >> second;       int mi = 0, gr = 0, le = 0, ans = 0;       for (int i = 0; i < second.length(); i++) {         if (second[i] ==  - )           mi++;         else if (second[i] ==  > )           gr++;         else           le++;       }       if (mi == n || gr == n || le == n) {         cout << n << endl;         continue;       }       if (mi == 0 && gr && le) {         cout << 0 << endl;         continue;       }       if ((mi && gr && !le) || (mi && le && !gr)) {         cout << n << endl;         continue;       }       for (int i = 0; i < second.length(); i++) {         if (second[i] ==  -  || second[(i - 1 + n) % n] ==  - ) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 7;   const int MOD = 1e9 + 7;   int a[MAX], h[MAX], c[MAX] = {0};   int main() {     int n, m, i, j, k, q;     scanf( %d %d %d , &n, &k, &m);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) {       h[i] = a[i] % m;       c[h[i]]++;     }     for (i = 0; i < m; i++)       if (c[i] >= k) break;     if (i == m) {       printf( No n );       return 0;     }     printf( Yes n );     j = i, q = 0;     for (i = 0; i < n && q < k; i++) {       if (h[i] == j) printf( %d  , a[i]), q++;     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long logN = 20;   const long long M = 1000000007;   const long long INF = 1e12;   const long long N = 100005;   const long int maxi = 1000000;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, m, h1, i, j;     cin >> n >> m >> h1;     long long a[m];     for (i = 0; i < m; i++) {       cin >> a[i];     }     long long b[n];     for (i = 0; i < n; i++) {       cin >> b[i];     }     long long h[n][m], ans[n][m];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> h[i][j];         ans[i][j] = 0;       }     }     for (i = 0; i < m; i++) {       if (a[i] > 0) {         for (j = 0; j < n; j++) {           if (h[j][i] == 1 && a[i] <= b[j]) {             ans[j][i] = a[i];             break;           }         }       }     }     for (i = 0; i < n; i++) {       if (b[i] > 0) {         for (j = 0; j < m; j++) {           if (h[i][j] == 1 && ans[i][j] == 0 && b[i] <= a[j]) {             ans[i][j] = b[i];             break;           }         }       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cout << max(ans[i][j], h[i][j]) <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int solve(int w, int h, int S) {     if (S == (2 * w + 1) * (2 * h + 1)) return 2 * (w + 1) * (h + 1) - 1;     if (S > (2 * w + 1) * (2 * h + 1)) return 0;     S = (2 * w + 1) * (2 * h + 1) - S;     if (S & 3) return 0;     S /= 4;     int res = 0;     for (int w2 = 0; w2 < w; w2++) {       if (S % (w - w2)) continue;       int h2 = h - S / (w - w2);       if (h2 < 0 || h2 >= h) continue;       res++;     }     return 2 * res;   }   int main() {     int W, H, s;     while (scanf( %d%d%d , &W, &H, &s) >= 1) {       long long ans = 0;       for (int w = 0; 2 * w + 1 <= W; w++) {         for (int h = 0; 2 * h + 1 <= H; h++) {           ans += solve(w, h, s) * (long long)(W - (2 * w + 1) + 1) *                  (H - (2 * h + 1) + 1);         }       }       printf(            %lld              n ,           ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int max1 = 0, max2 = 0, min1 = (1000000000 + 9),                   min2 = (1000000000 + 9);     for (int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       if (y < min1) {         min1 = y;       }       if (x > max1) {         max1 = x;       }     }     long long int m;     cin >> m;     for (int i = 0; i < m; i++) {       long long int x, y;       cin >> x >> y;       if (y < min2) {         min2 = y;       }       if (x > max2) {         max2 = x;       }     }     long long int x1 = (max1 - min2);     long long int x2 = (max2 - min1);     long long int x3 = max(x1, x2);     if (x3 < 0) {       cout << 0 << endl;     } else {       cout << x3 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool debug = true;   const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};   const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1, 0};   template <typename X>   inline X square(const X& a) {     return a * a;   }   int scan_d() {     bool minus = false;     int result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = (result << 3) + (result << 1) + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   long scan_ld() {     bool minus = false;     long result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = (result << 3) + (result << 1) + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   long long scan_lld() {     bool minus = false;     long long result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     if (ch ==  - )       minus = true;     else       result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = (result << 3) + (result << 1) + (ch -  0 );     }     if (minus)       return -result;     else       return result;   }   long long unsigned scan_llu() {     long long unsigned result = 0;     char ch;     ch = getchar();     while (true) {       if (ch ==  - ) break;       if (ch >=  0  && ch <=  9 ) break;       ch = getchar();     }     result = ch -  0 ;     while (true) {       ch = getchar();       if (ch <  0  || ch >  9 ) break;       result = (result << 3) + (result << 1) + (ch -  0 );     }     return result;   }   void print_d(int n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 10;     char output_buffer[10];     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 10);   }   void print_ld(long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 11;     char output_buffer[11];     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 11);   }   void print_lld(long long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 21;     char output_buffer[21];     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 21);   }   void print_llu(long long unsigned n) {     int i = 21;     char output_buffer[21];     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 21);   }   void println_d(int n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 10;     char output_buffer[11];     output_buffer[10] =   n ;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 11);   }   void println_ld(long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 11;     char output_buffer[12];     output_buffer[11] =   n ;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 12);   }   void println_lld(long long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 21;     char output_buffer[22];     output_buffer[21] =   n ;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 22);   }   void println_llu(long long unsigned n) {     int i = 21;     char output_buffer[22];     output_buffer[21] =   n ;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 22);   }   char sp;   void printsp_d(int n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 10;     char output_buffer[11];     output_buffer[10] = sp;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 11);   }   void printsp_ld(long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 11;     char output_buffer[12];     output_buffer[11] = sp;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 12);   }   void printsp_lld(long long n) {     if (n < 0) {       n = -n;       putchar( - );     }     int i = 21;     char output_buffer[22];     output_buffer[21] = sp;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 22);   }   void printsp_llu(long long unsigned n) {     int i = 21;     char output_buffer[22];     output_buffer[21] = sp;     do {       output_buffer[--i] = (n % 10) +  0 ;       n /= 10;     } while (n);     do {       putchar(output_buffer[i]);     } while (++i < 22);   }   long long cal[100005][15], dp[105][105][15];   vector<pair<int, int> > ind;   int main() {     int n, q, c, j, i, x, y, x1, x2, y1, y2, t;     long long ans = 0;     n = scan_d();     q = scan_d();     c = scan_d();     for (i = 0; i < n; i++) {       x = scan_d();       y = scan_d();       t = scan_d();       cal[i][0] = t;       dp[x][y][0] += t;       ind.push_back(make_pair(x, y));     }     for (i = 1; i <= c + 3; i++) {       for (j = 0; j < n; j++) {         cal[j][i] = (cal[j][i - 1] + 1) % (c + 1);         dp[ind[j].first][ind[j].second][i] += (cal[j][i]);       }     }     for (t = 0; t <= c + 3; t++) {       for (i = 1; i <= 100; i++) {         for (j = 1; j <= 100; j++) {           dp[i][j][t] += dp[i][j - 1][t];         }       }     }     while (q--) {       ans = 0;       t = scan_d();       x1 = scan_d();       y1 = scan_d();       x2 = scan_d();       y2 = scan_d();       if (y1 > y2) swap(y1, y2);       if (x1 > x2) swap(x1, x2);       t %= (c + 1);       for (i = x1; i <= x2; i++) {         ans += (dp[i][y2][t] - dp[i][y1 - 1][t]);       }       println_lld(ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:20000007 )   #pragma GCC optimize( unroll-loops )   const int N = (int)1e6 + 100;   const int maxn = (int)1e3 + 100;   const int base = (int)1e9;   const int mod = (int)1e9 + 7;   const int inf = INT_MAX;   const long long ll_inf = LLONG_MAX;   const long double PI = acos((long double)-1.0);   const long double eps = 1e-8;   void solve() {     int n, s;     scanf( %d%d , &n, &s);     vector<int> P(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &P[i]);     }     multiset<int> S;     for (int i = 0; i < n; ++i) {       S.insert(P[i]);     }     map<int, int> C;     for (int i = 0; i < n; ++i) {       C[P[i]]++;     }     int ans = 0;     --s;     if (P[s]) {       C[P[s]]--;       S.erase(S.find(P[s]));       C[0]++;       ++ans;       P[s] = 0;     }     ans += C[0] - 1;     int have = C[0] - 1;     S.erase(0);     int now = 1;     while (!S.empty() && now <= *(--S.end())) {       if (S.find(now) != S.end())         ;       else if (have)         --have;       else {         ++ans;         S.erase(--S.end());       }       ++now;     }     printf( %d n , ans);   }   int main() {     int T = 1;     for (; T; --T) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int det(long long int a, long long int b, int bit) {     if (!bit) {       if (a & 1) return a;       if (b & 1) return b;       return a;     }     if (a & (1ll << bit)) return det(a, b, bit - 1);     if (!(b & (1ll << bit))) return det(a, b, bit - 1);     if ((b & ((1ll << (bit + 1)) - 1)) == ((1ll << (bit + 1)) - 1)) return b;     return ((a & (~((1ll << bit) - 1))) | ((1ll << bit) - 1));   }   int main() {     int n = 0;     cin >> n;     long long int a = 0, b = 0;     while (n--) {       cin >> a >> b;       cout << det(a, b, 60) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int n, m, b[N][N], a[N][N];   void solve() {     if (n % 2) {       printf( %d n , n);       return;     }     bool ok = 1;     while (n > 1 && ok && n % 2 == 0) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (b[i][j] != b[n - i - 1][j]) {             ok = 0;             break;           }         }       }       if (ok) n /= 2;     }     printf( %d n , n);   }   int main() {     ios::sync_with_stdio(false);     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &b[i][j]);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   int n, t;   int a[100100], cur = 0, all;   int binpow(int a, int k) {     if (k == 0) return 1;     int ans = binpow(a, k / 2);     ans = 1ll * ans * ans % mod;     if (k % 2) ans = 1ll * ans * a % mod;     return ans;   }   int main() {     cin >> n;     int bad = 0;     for (int i = 1; i < 4; i++) {       for (int j = 1; j < 4; j++) {         for (int k = 1; k < 4; k++) {           if (i + j + k == 6) bad++;         }       }     }     bad = binpow(bad, n);     all = binpow(3, 3 * n);     all -= bad;     all %= mod;     all += mod;     all %= mod;     cout << all << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ceilVal(long long a, long long b) {     long long sum = a / b;     if (a % b) return ++sum;     return sum;   }   int main() {     long long a, n, m;     scanf( %lld%lld%lld , &n, &m, &a);     long long sum = 0;     sum = ceilVal(n, a) * ceilVal(m, a);     printf( %lld , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void p(vector<int> a) {     int x = 0;     for (int y : a) {       if (x) printf(   );       printf( %d , y);       x = 1;     }     puts(  );   }   int main() {     int n;     cin >> n;     if (n % 2 == 0) return !printf( -1 n );     vector<int> a, b, c;     for (int i = 0; i < n; ++i) a.emplace_back(i), b.emplace_back(i);     for (int i = 0; i < n; ++i) c.emplace_back((a[i] + b[i]) % n);     p(a);     p(b);     p(c);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y, sum = 0;     cin >> n >> x >> y;     sum = (n * y) / 100;     if ((n * y) % 100 != 0) {       sum += 1;     }     if (sum <= x)       cout << 0;     else       cout << abs(sum - x);     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;     cin >> n;     if (n & 1)       cout << n / 2 <<   n ;     else {       long long int p = 1;       for (long long int i = 1; 2 * p <= n; i++) p = 1 << i;       cout << (n - p) / 2 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     while (b > 0) {       a %= b;       swap(a, b);     }     return a;   }   template <class _T>   inline _T sqr(const _T& first) {     return first * first;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const double EPS = 1e-9;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void input(int& a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = 10 * a + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(long long a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[20];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   const int MAXN = 300000;   long long powers[MAXN + 1];   struct data {     int len;     long long data1;     long long data2;   };   data merge(const data& l, const data& r) {     data res;     res.len = l.len + r.len;     res.data1 = r.data1 + l.data1 * powers[r.len];     res.data2 = l.data2 + r.data2 * powers[l.len];     return res;   }   int main() {     int(n);     input((n));     ;     int first[n];     powers[0] = 1;     for (int i = 1; i <= n; ++i) {       powers[i] = powers[i - 1] * 3;     }     for (int i = 0; i < n; ++i) {       first[i] = nxt() - 1;     }     data t[n + n];     for (int i = 0; i < n; ++i) {       t[i + n].len = 1;       t[i + n].data1 = t[i + n].data2 = 0;     }     for (int i = n - 1; i > 0; --i) {       t[i] = merge(t[i + i], t[i + i + 1]);     }     for (int i = 0; i < n; ++i) {       t[first[i] + n].data1 = t[first[i] + n].data2 = 1;       int pos = first[i] + n;       for (pos >>= 1; pos; pos >>= 1) {         t[pos] = merge(t[pos + pos], t[pos + pos + 1]);       }       int r = min(first[i], n - first[i] - 1);       data L{0, 0, 0};       data R{0, 0, 0};       int a = first[i] - r, b = first[i] + r;       for (a += n, b += n; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {         if (a & 1) {           L = merge(L, t[a]);         }         if (!(b & 1)) {           R = merge(t[b], R);         }       }       data res = merge(L, R);       if (res.data1 != res.data2) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   template <class T1, class T2, class T3, class T4>   inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {     printsp(x1), printsp(x2), printsp(x3), println(x4);   }   int son[400400][2], pa[400400], sz[400400];   long long sum[400400];   long long ans;   struct SplayTree {     int root;     void init(int first) {       root = first;       sz[first] = 1;       sum[first] = first;     }     void push_up(int first) {       sum[first] = first + sum[son[first][0]] + sum[son[first][1]];       sz[first] = 1 + sz[son[first][0]] + sz[son[first][1]];     }     void rot(int first, int d) {       int second = pa[first], z = pa[second];       son[second][!d] = son[first][d];       pa[son[first][d]] = second;       pa[first] = pa[second];       if (son[z][0] == second)         son[z][0] = first;       else if (son[z][1] == second)         son[z][1] = first;       pa[second] = first;       son[first][d] = second;       push_up(second);     }     void splay(int first, int g) {       while (pa[first] != g) {         if (pa[pa[first]] == g)           rot(first, son[pa[first]][0] == first);         else {           int second = pa[first], z = pa[second];           int d = (son[z][0] == second);           son[second][d] == first ? rot(first, !d) : rot(second, d);           rot(first, d);         }       }       push_up(first);       if (g == 0) root = first, pa[first] = 0;     }     void insert(int first, int second) {       if (second < first) {         if (son[first][0])           insert(son[first][0], second);         else           son[first][0] = second, pa[second] = first;       } else {         if (son[first][1])           insert(son[first][1], second);         else           son[first][1] = second, pa[second] = first;       }       push_up(first);     }     long long insert1(int first, int f) {       son[first][0] = son[first][1] = 0;       sz[first] = 1;       insert(root, first);       splay(first, 0);       if (!f) return -(long long)first * sz[son[first][0]] + sum[son[first][0]];       return -sum[son[first][1]] + (long long)first * sz[son[first][1]];     }     void get(int first, vector<int> &vec) {       if (son[first][0]) get(son[first][0], vec);       vec.push_back(first);       if (son[first][1]) get(son[first][1], vec);     }   } tree[400400];   int id[400400], pos[400400];   int nxt[400400];   int find_nxt(int u) { return u == nxt[u] ? u : nxt[u] = find_nxt(nxt[u]); }   void merge(int u, int v, int f = 0) {     if (sz[tree[u].root] < sz[tree[v].root]) swap(u, v), f = 1;     vector<int> vec;     tree[v].get(tree[v].root, vec);     if (!f) reverse(vec.begin(), vec.end());     for (int i = 0; i < vec.size(); i++) {       ans += tree[u].insert1(vec[i], f);       id[pos[vec[i]]] = u;     }   }   int main() {     int n;     gn(n);     for (int i = 1; i < 400400; i++) nxt[i] = i;     for (int i = 1; i <= n; i++) tree[i].init(i);     for (int i = 0, a, b; i < n; i++) {       gn(a, b);       int aa = a;       a = find_nxt(a);       ans += (long long)(a - aa) * b;       pos[b] = a;       id[a] = b;       nxt[a] = a + 1;       if (nxt[a - 1] > a - 1) merge(id[a - 1], id[a]);       if (nxt[a + 1] > a + 1) merge(id[a], id[a + 1]);       println(ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2007;   const int mod = 998244353;   template <class I>   inline void read(I &x) {     int f = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (x = 0; c >=  0  && c <=  9 ;          x = (x << 3) + (x << 1) + (c & 15), c = getchar())       ;     x *= f;   }   long long ksm(int x, int y) {     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       y >>= 1;       x = 1ll * x * x % mod;     }     return res;   }   long long f[2 * N][2 * N][2], jc[N * 2];   int main() {     int n, l, k;     read(n), read(k), read(l);     f[0][0][0] = 1;     for (int i = 0; i <= 2 * n; i++)       for (int j = 0; j <= i; j++)         for (int o = 0; o <= 1; o++) {           f[i + 1][j + 1][o] = (f[i + 1][j + 1][o] + f[i][j][o]) % mod;           if (o == 0 && j >= k)             f[i + 1][j][1] = (f[i + 1][j][1] + f[i][j][o]) % mod;           if (j) f[i + 1][j - 1][o] = (f[i + 1][j - 1][o] + f[i][j][o] * j) % mod;         }     jc[0] = 1;     for (int i = 1; i <= 2 * n + 1; i++) jc[i] = jc[i - 1] * i % mod;     long long ans = f[2 * n + 1][0][1] * ksm(2, n) % mod * jc[n] % mod *                     ksm(jc[2 * n + 1], mod - 2) % mod * l % mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   long long expow(long long a, long long b, long long p) {     long long v = 1;     for (; b; b >>= 1, a = a * a % p)       if (b & 1) v = v * a % p;     return v;   }   long long inv(long long a, long long p) { return expow(a, p - 2, p); }   using namespace std;   const int N = 1000 + 11;   const int M = 1000000007;   struct node {     int a, b, c, d, e;   } p[N];   node sub(node a, node b) {     return (node){a.a - b.a, a.b - b.b, a.c - b.c, a.d - b.d, a.e - b.e};   }   double mix(node a, node b) {     return 1.0 * a.a * b.a + a.b * b.b + a.c * b.c + a.d * b.d + a.e * b.e;   }   vector<int> ans;   int main() {     int k;     scanf( %d , &k);     for (int i = 0; i < k; i++) {       scanf( %d%d%d%d%d , &p[i].a, &p[i].b, &p[i].c, &p[i].d, &p[i].e);     }     for (int j = 0; j < k; j++) {       bool f = false;       for (int i = 0; i < k; i++)         if (i != j) {           for (int l = 0; l < k; l++)             if (l != i && l != j) {               node cha = sub(p[j], p[i]), cha2 = sub(p[j], p[l]);               double ding = mix(cha, cha2),                      di = sqrt(mix(cha, cha)) * sqrt(mix(cha2, cha2));               double xx = ding / di;               if (xx > 0 && xx <= 1) {                 f = true;                 break;               }             }           if (f) break;         }       if (!f) ans.push_back(j + 1);     }     int sz = ans.size();     printf( %d n , sz);     for (int j = 0; j < sz; j++) printf( %d n , ans[j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int Inf = 0x3f3f3f3f;   struct Edge {     int id;     int u, v, w;     Edge(int x = 0, int y = 0, int z = 0) : v(x), w(y), id(z) {}   } e[N];   vector<Edge> edges;   vector<int> G[N];   int ans[N], fa[N][20], dep[N], st[N][20], used[N], f[N], to[N];   int n, m;   void addeage(int u, int v, int w, int id) {     edges.push_back(Edge(v, w, id));     int tot = edges.size();     G[u].push_back(tot - 1);   }   void dfs(int u, int fat) {     fa[u][0] = fat;     for (int i = 1; i <= 18; ++i)       fa[u][i] = fa[fa[u][i - 1]][i - 1],       st[u][i] = max(st[u][i - 1], st[fa[u][i - 1]][i - 1]);     for (int i = 0; i < G[u].size(); ++i) {       Edge e = edges[G[u][i]];       if (e.v == fat) continue;       to[e.v] = e.id;       st[e.v][0] = e.w;       dep[e.v] = dep[u] + 1;       dfs(e.v, u);     }   }   int LCA(int u, int v, int& d) {     d = 0;     if (dep[u] < dep[v]) swap(u, v);     int t = dep[u] - dep[v];     for (int i = 0; i <= 18; ++i)       if ((1 << i) & t) {         d = max(d, st[u][i]);         u = fa[u][i];       }     if (u == v) return u;     for (int i = 18; i >= 0; --i) {       if (fa[u][i] != fa[v][i]) {         d = max(d, max(st[u][i], st[v][i]));         u = fa[u][i];         v = fa[v][i];       }     }     d = max(d, max(st[u][0], st[v][0]));     return fa[u][0];   }   int getfa(int u) { return (u == f[u]) ? u : f[u] = getfa(f[u]); }   bool cmp(Edge x, Edge y) { return x.w < y.w; }   void KrusKal() {     int tot = 0;     sort(e + 1, e + 1 + m, cmp);     for (int i = 1; i <= m; ++i) {       int u = e[i].u, v = e[i].v;       int u1 = getfa(u), v1 = getfa(v);       if (u1 != v1) {         f[u1] = v1;         used[i] = 1;         addeage(u, v, e[i].w, e[i].id);         addeage(v, u, e[i].w, e[i].id);         tot++;       }       if (tot == n - 1) break;     }   }   void modify(int u, int v, int d) {     u = getfa(u);     while (dep[u] > dep[v]) {       ans[to[u]] = min(ans[to[u]], d);       int y = getfa(fa[u][0]);       f[u] = y;       u = getfa(u);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       e[i].u = u, e[i].v = v, e[i].w = w, e[i].id = i;     }     for (int i = 1; i <= n; ++i) f[i] = i;     KrusKal();     dfs(1, 1);     memset(ans, Inf, sizeof ans);     for (int i = 1; i <= n; ++i) f[i] = i;     for (int i = 1; i <= m; ++i) {       if (used[i]) continue;       int u = e[i].u, v = e[i].v;       int ffa = LCA(u, v, ans[e[i].id]);       ans[e[i].id]--;       modify(u, ffa, e[i].w - 1);       modify(v, ffa, e[i].w - 1);     }     for (int i = 1; i <= m; ++i)       if (ans[i] == Inf)         printf( -1  );       else         printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 10, M = 26;   template <typename T = int>   inline T read() {     T x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   char s[N];   int a[N], pre[N][26], suf[N][26], f[N][26], g[N], dp[27];   inline int mex(int a) {     int res = 0;     while (a >> res & 1) ++res;     return res;   }   inline int solve(int l, int r, int c) {     if (l > r) return 0;     if (dp[c] != -1) return dp[c];     int sta = 0;     for (int i = 0; i < 26; ++i) {       int L = suf[l][i], R = pre[r][i];       if (R < L) continue;       sta |= 1 << (f[L - 1][c] ^ g[R] ^ g[L] ^ solve(R + 1, r, i));     }     return dp[c] = mex(sta);   }   inline int Solve(int l, int r, int c) {     if (l > r) return 0;     if (dp[c] != -1) return dp[c];     int sta = 0;     for (int i = 0; i < 26; ++i) {       int L = suf[l][i], R = pre[r][i];       if (R < L) continue;       sta |= 1 << (Solve(l, L - 1, i) ^ g[R] ^ g[L] ^ f[r][i]);     }     return dp[c] = mex(sta);   }   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     for (int i = 1; i <= n; ++i) a[i] = s[i] -  a ;     for (int i = 0; i < 26; ++i) suf[n + 1][i] = n + 1;     for (int i = 1; i <= n; ++i)       memcpy(pre[i], pre[i - 1], sizeof(pre[i])), pre[i][a[i]] = i;     for (int i = n; i >= 1; --i)       memcpy(suf[i], suf[i + 1], sizeof(suf[i])), suf[i][a[i]] = i;     for (int i = 1; i <= n; ++i) {       memset(dp, -1, sizeof(dp)), g[i] = g[pre[i - 1][a[i]]] ^ f[i - 1][a[i]];       for (int c = 0; c < 26; ++c) f[i][c] = solve(pre[i][c] + 1, i, c);     }     for (int q = read(); q; --q) {       int l = read(), r = read();       memset(dp, -1, sizeof(dp));       puts(Solve(l, r, 26) ?  Alice  :  Bob );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long n) {     long long ans = 1;     for (int i = 1; i <= n; i++) ans *= x;     return ans;   }   long long gcd(long long x, long long y) {     return (x % y == 0) ? y : gcd(y, x % y);   }   long long n, l, r;   int main() {     cin >> n >> l >> r;     if (n == 1)       cout << r - l + 1;     else if (n == 2) {       cout << (r - l + 1) * (r - l);     } else if (n > 30) {       cout << 0;     } else {       long long ans = 0;       for (int i = 2; i < r; i++) {         int p = i, R = r / power(p, n - 1);         if (R == 0) break;         for (int j = 1; j < p; j++) {           int q = j;           int L = (l - 1) / power(q, n - 1) + 1;           if (L > R) continue;           if (gcd(p, q) == 1) {             ans += (R - L + 1);           }         }       }       cout << ans * 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int M = 200000 + 10;   int a[M];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     double R_L = 0;     double R_R = 0.5 * a[n - 1] - 0.5 * a[0];     int num = 0;     double C1, C2, C3;     C2 = a[0];     while (num < 200) {       double R_M = (R_L + R_R) / 2;       double D1 = a[0] + R_M * 2;       int ind1 = -1;       for (int i = 0; i < n; i++) {         if (a[i] > D1) {           ind1 = i;           break;         }       }       double D2 = R_M * 2;       int ind2 = -1;       for (int i = n - 1; i >= 0; i--) {         if (a[i] + D2 < a[n - 1]) {           ind2 = i;           break;         }       }       if (ind1 == -1 || ind2 == -1) {         R_R = R_M;       } else {         if (ind1 > ind2) {           R_R = R_M;         } else {           int Dis = a[ind2] - a[ind1];           C2 = 0.5 * (a[ind2] + a[ind1]);           if (Dis <= R_M * 2) {             R_R = R_M;           } else {             R_L = R_M;           }         }       }       num++;     }     C1 = a[0] + R_R;     C3 = a[n - 1] - R_R;     C2 = a[0];     for (int i = 0; i < n; i++) {       if (a[i] > a[0] + 2 * R_R) {         C2 = a[i] + R_R;         break;       }     }     printf( %.10f n , R_R);     printf( %.10f %.10f %.10f n , C1, C2, C3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 10;   using ll = long long;   using pii = pair<int, int>;   int pa[maxn];   int sz[maxn];   int d[maxn];   int f[maxn];   vector<ll> pre[maxn];   vector<int> g[maxn], dis[maxn];   map<pii, ll> ans;   int find(int p) { return p == pa[p] ? pa[p] : pa[p] = find(pa[p]); }   void unionPQ(int p, int q) {     int pp = find(p);     int pq = find(q);     if (pp != pq) {       pa[pp] = pq;       sz[pq] += sz[pp];     }   }   int depth, id, root, flag;   void dfs(int node, int fa = -1, int h = 0) {     if (h > depth) {       depth = h;       id = node;     }     if (f[node] < h) f[node] = h;     if (flag) dis[root].push_back(f[node]);     for (auto v : g[node])       if (v != fa) dfs(v, node, h + 1);   }   int main() {     int n, m, q;     scanf( %d%d%d , &n, &m, &q);     for (int i = 0; i < n; ++i) {       pa[i] = i;       sz[i] = 1;     }     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       a--, b--;       g[a].push_back(b);       g[b].push_back(a);       unionPQ(a, b);     }     for (int i = 0; i < n; ++i)       if (i == pa[i]) {         flag = false;         root = i;         depth = 0;         id = i;         dfs(i);         depth = 0;         dfs(id);         d[i] = depth;         flag = true;         dfs(id);         sort(dis[i].begin(), dis[i].end());         pre[i].resize(1 + sz[i]);         pre[i][0] = 0;         for (int j = 0; j < sz[i]; ++j) pre[i][j + 1] = pre[i][j] + dis[i][j];       }     for (int i = 0; i < q; ++i) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       u = find(u);       v = find(v);       if (u == v) {         printf( -1 n );         continue;       }       if (sz[u] > sz[v] || (sz[u] == sz[v] && u > v)) swap(u, v);       if (ans.count({u, v})) {         printf( %.10f n , (double)ans[{u, v}] / sz[u] / sz[v]);         continue;       }       int maxd = max(d[u], d[v]);       ll t = 0;       int p = sz[v] - 1;       for (int x : dis[u]) {         while (p >= 0 && x + 1 + dis[v][p] > maxd) p--;         t += (ll)maxd * (p + 1) + (ll)(x + 1) * (sz[v] - p - 1) + pre[v].back() -              pre[v][p + 1];       }       ans[{u, v}] = t;       printf( %.10f n , (double)ans[{u, v}] / sz[u] / sz[v]);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   long long ans;   int d[100005];   int main(){    int t; cin>>t; while(t--){     int n; scanf( %d ,&n);     for(int i=1;i<=n;++i)scanf( %d ,&d[i]);     sort(d+1,d+1+n); ans=d[n];     for(int i=1;i<=n;++i)ans+=d[i]*(n+1ll-i-i);     printf( %lld n ,ans);    }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void solve() {     int a, b, n;     cin >> a >> b >> n;     bool aturn = true;     while (n > 0) {       int x;       if (aturn) {         x = gcd(a, n);         aturn = false;       } else {         x = gcd(b, n);         aturn = true;       }       n -= x;     }     if (aturn == false)       cout <<  0             <<   n ;     else       cout <<  1             <<   n ;   }   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int res = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar();     return res * f;   }   const int maxn = 2e5 + 10;   int n, k, val[26];   char s[maxn];   int main() {     int T = read();     while (T--) {       n = read();       k = read();       int ans = 0;       scanf( %s , s + 1);       for (int i = 1; i <= k / 2; i++) {         memset(val, 0, sizeof(val));         for (int j = 0; j < n / k; j++) {           val[s[i + j * k] -  a ]++;           val[s[k - i + 1 + j * k] -  a ]++;         }         int tmp = 0;         for (int j = 0; j < 26; j++) tmp = max(tmp, val[j]);         ans += n / k * 2 - tmp;       }       if (k & 1) {         memset(val, 0, sizeof(val));         for (int j = 0; j < n / k; j++) {           val[s[k / 2 + 1 + j * k] -  a ]++;         }         int tmp = 0;         for (int j = 0; j < 26; j++) tmp = max(tmp, val[j]);         ans += n / k - tmp;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     while (cin >> a >> b) {       long long divi = a - b, cnt = 0;       if (a == b)         cout <<  infinity  << endl;       else {         for (long long i = 1; i * i <= divi; i++) {           if (divi % i == 0) {             long long other = divi / i;             if (i > b) cnt++;             if (other > b && other != i) cnt++;           }         }         cout << cnt << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   const long long MAX = 300000;   const double PI = 3.14159265358979323846;   long long T[MAX * 2];   long long ceil_log2(long long n) {     long long v = 1;     long long log = 0;     while (v < n) {       v <<= 1;       log++;     }     return log;   }   std::bitset<64> reverse(std::bitset<64> set, long long bit_count) {     for (long long i = 0; i < bit_count / 2; i++) {       bool tmp = set[i];       set[i] = set[bit_count - 1 - i];       set[bit_count - 1 - i] = tmp;     }     return set;   }   void fft(std::complex<double> *A, long long bit_count, bool inverse = false) {     static std::complex<double> W[MAX];     long long N = 1 << bit_count;     for (long long i = 0; i < N; i++) {       long long j = T[i];       if (i < j) std::swap(A[i], A[j]);     }     for (long long step = 1; step < N; step <<= 1) {       double angle = -PI / step;       if (inverse) angle = -angle;       std::complex<double> w(1, 0), wn(std::cos(angle), std::sin(angle));       for (long long i = 0; i < step; i++) {         W[i] = w;         w *= wn;       }       for (long long start_even = 0; start_even < N; start_even += step * 2) {         auto start_odd = start_even + step;         for (long long i = 0; i < step; i++) {           std::complex<double> U = A[start_even + i];           std::complex<double> V = W[i] * A[start_odd + i];           A[start_even + i] = U + V;           A[start_odd + i] = U - V;         }       }     }     if (inverse) {       for (long long i = 0; i < N; i++) A[i] /= N;     }   }   long long C[MAX];   long long zero_count = 0;   long long n, x;   long long C_len, bit_count, N;   void init() {     std::fill(C, C + n + 1, 0);     C[0] = 1;     C_len = n + 1;     bit_count = ceil_log2(C_len * 2);     N = 1 << bit_count;     for (long long i = 0; i < N; i++) {       T[i] = reverse(i, bit_count).to_ullong();     }   }   void input() {     std::cin >> n >> x;     init();     long long sum = 0;     for (long long i = 0; i < n; i++) {       long long v;       std::cin >> v;       sum += v < x;       C[sum]++;     }     for (long long i = 0; i <= sum; i++)       if (C[i] > 1) zero_count += C[i] * (C[i] - 1) / 2;   }   int main() {     input();     std::cout << zero_count <<    ;     static std::complex<double> A[MAX * 2], B[MAX * 2];     std::copy(C, C + C_len, A);     std::fill(A + C_len, A + N, 0);     std::fill(B, B + 2 * n - C_len, 0);     std::reverse_copy(C, C + C_len, B + 2 * n - C_len);     std::fill(B + 2 * n, B + N, 0);     fft(A, bit_count);     fft(B, bit_count);     for (long long i = 0; i < N; i++) A[i] *= B[i];     fft(A, bit_count, true);     for (long long k = 1; k <= n; k++)       std::cout << (long long)std::round(A[2 * n - k - 1].real()) <<    ;     std::cout << std::endl;     return 0;     for (long long i = 0; i < N; i++) std::cout << A[i] <<    ;     std::cout << std::endl;     for (long long i = 0; i < N; i++) std::cout << B[i] <<    ;     std::cout << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   int add_MOD(int a, int b) {     a += b;     if (a >= MOD) {       return a - MOD;     }     if (a < 0) {       return a + MOD;     }     return a;   }   int mul_MOD(int a, int b) { return a * (long long)b % MOD; }   const int N = (int)2e5 + 7;   int n;   int q;   int brute[N];   vector<vector<int>> queries;   vector<pair<int, int>> segments[N];   vector<bool> is[N];   vector<int> urm[N];   map<int, int> who_l[N];   map<int, int> who_r[N];   map<int, int> id[N];   set<int> changes[N];   struct T {     int a;     int b;     int val;   };   T segt[4 * N];   void push(int v, int tl, int tr) {     segt[v].val =         add_MOD(mul_MOD(tr - tl + 1, segt[v].b), mul_MOD(segt[v].val, segt[v].a));     if (tl < tr) {       segt[2 * v].a = mul_MOD(segt[2 * v].a, segt[v].a);       segt[2 * v + 1].a = mul_MOD(segt[2 * v + 1].a, segt[v].a);       segt[2 * v].b = add_MOD(segt[v].b, mul_MOD(segt[2 * v].b, segt[v].a));       segt[2 * v + 1].b =           add_MOD(segt[v].b, mul_MOD(segt[2 * v + 1].b, segt[v].a));     }     segt[v].a = 1;     segt[v].b = 0;   }   void add(int v, int tl, int tr, int l, int r) {     push(v, tl, tr);     if (tr < l || r < tl) {       return;     }     if (l <= tl && tr <= r) {       segt[v].b = 1;       push(v, tl, tr);       return;     }     int tm = (tl + tr) / 2;     add(2 * v, tl, tm, l, r);     add(2 * v + 1, tm + 1, tr, l, r);     segt[v].val = add_MOD(segt[2 * v].val, segt[2 * v + 1].val);   }   void mult(int v, int tl, int tr, int l, int r) {     push(v, tl, tr);     if (tr < l || r < tl) {       return;     }     if (l <= tl && tr <= r) {       segt[v].a = 2;       push(v, tl, tr);       return;     }     int tm = (tl + tr) / 2;     mult(2 * v, tl, tm, l, r);     mult(2 * v + 1, tm + 1, tr, l, r);     segt[v].val = add_MOD(segt[2 * v].val, segt[2 * v + 1].val);   }   int get(int v, int tl, int tr, int l, int r) {     push(v, tl, tr);     if (tr < l || r < tl) {       return 0;     }     if (l <= tl && tr <= r) {       return segt[v].val;     } else {       int tm = (tl + tr) / 2;       return add_MOD(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));     }   }   void add_brute(int l, int r) {     add(1, 1, n, l, r);     return;     for (int i = l; i <= r; i++) {       brute[i] = add_MOD(brute[i], 1);     }   }   void mult_brute(int l, int r) {     mult(1, 1, n, l, r);     return;     for (int i = l; i <= r; i++) {       brute[i] = mul_MOD(brute[i], 2);     }   }   int get_brute(int l, int r) {     return get(1, 1, n, l, r);     int sol = 0;     for (int i = l; i <= r; i++) {       sol = add_MOD(sol, brute[i]);     }     return sol;   }   void add(int l, int r, int x) {     int p = who_l[x][l];     int p2 = who_r[x][r];     while (p <= p2) {       if (is[x][p]) {         int until = urm[x][p];         if (until > p2) {           until = p2;         }         mult_brute(segments[x][p].first, segments[x][until].second);         int ant_p = p;         p = urm[x][p] + 1;         urm[x][ant_p] = max(urm[x][ant_p], p2);       } else {         is[x][p] = 1;         add_brute(segments[x][p].first, segments[x][p].second);         urm[x][p] = p2;         p++;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int i = 0; i < 4 * N; i++) {       segt[i].a = 1;     }     cin >> n >> q;     for (int i = 1; i <= q; i++) {       int t, l, r;       cin >> t >> l >> r;       if (t == 1) {         int x;         cin >> x;         queries.push_back({l, r, x});         changes[x].insert(l);         changes[x].insert(r + 1);       } else {         queries.push_back({l, r});       }     }     for (int x = 1; x <= n; x++) {       changes[x].insert(1);       changes[x].insert(n + 1);       int j = -1;       for (auto &i : changes[x]) {         if (j != -1) {           segments[x].push_back({j, i - 1});         }         j = i;       }       is[x].resize((int)segments[x].size(), 0);       urm[x].resize((int)segments[x].size());       for (int j = 0; j < (int)segments[x].size(); j++) {         who_l[x][segments[x][j].first] = j;         who_r[x][segments[x][j].second] = j;       }     }     for (auto &vec : queries) {       if ((int)vec.size() == 3) {         add(vec[0], vec[1], vec[2]);       } else {         cout << get_brute(vec[0], vec[1]) <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx )   #pragma GCC target( avx,tune=native )   using namespace std;   const long long mod = 1e9 + 7;   long long w[11];   vector<vector<long long> > mul(vector<vector<long long> >& a,                                  vector<vector<long long> >& b) {     vector<vector<long long> > ret(a.size(), vector<long long>(a.size(), 0));     for (long long i = 0; i < a.size(); i++)       for (long long j = 0; j < a.size(); j++) ret[i][j] = 0;     for (long long i = 0; i < a.size(); i++) {       for (long long j = 0; j < a.size(); j++) {         for (long long k = 0; k < a.size(); k++) {           ret[i][j] += a[i][k] * b[k][j];           ret[i][j] %= mod;         }       }     }     return ret;   }   vector<vector<long long> > Pow(vector<vector<long long> > a, long long k) {     vector<vector<long long> > ret = a, m = a;     k--;     do {       if (k & 1) ret = mul(ret, m);       m = mul(m, m);     } while (k >>= 1);     return ret;   }   long long dp[1 << 7], tdp[1 << 7], pre;   void solve(long long x, long long times) {     vector<vector<long long> > mat((1 << x), vector<long long>((1 << x), 0));     for (long long st = 0; st < (1 << x); st++) {       for (long long ed = 0; ed < (1 << x); ed++) {         for (long long bt = 0; bt < (1 << (x - 1)); bt++) {           long long add = 1;           for (long long j = 0; j < x; j++) {             long long cnt = 0;             if (bt & (1 << j) || j == x - 1) cnt++;             if (j == 0 || (bt & (1 << (j - 1)))) cnt++;             if (st & (1 << j)) cnt++;             if (ed & (1 << j)) cnt++;             if (cnt == 4) add = 0;           }           if (add) mat[st][ed]++;           if (mat[st][ed] >= mod) mat[st][ed] -= mod;         }       }     }     mat = Pow(mat, times);     memset(tdp, 0, sizeof tdp);     long long or_mask = 0;     for (long long i = pre; i < x; i++) or_mask |= (1 << i);     for (long long i = 0; i < (1 << x); i++) {       for (long long j = 0; j < (1 << x); j++) {         tdp[j] += dp[i] * mat[i | or_mask][j];         tdp[j] %= mod;       }     }     memcpy(dp, tdp, sizeof tdp);     pre = x;   }   signed main() {     for (long long i = 1; i <= 7; i++) cin >> w[i];     for (long long i = 1; i <= 7; i++) {       if (w[i]) {         dp[(1 << i) - 1] = 1;         break;       }     }     for (long long i = 1; i <= 7; i++) {       if (w[i]) {         solve(i, w[i]);       }     }     for (long long i = 7; i >= 1; i--) {       if (w[i]) {         cout << dp[(1 << i) - 1] << endl;         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   long long int dx[] = {0, 0, 1, -1};   long long int dy[] = {1, -1, 0, 0};   long long int m = 0, n, res = 0, k;   string s2, ch =   , s, t, s1 =   ;   vector<pair<string, long long int> > vm;   vector<pair<pair<long long int, long long int>, long long int> > vvv;   vector<pair<long long int, long long int> > vv, vv2;   vector<long long int> v[200005], v2, v1;   long long int a[500005], vis[500005], dp[500005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int i = 0, x = 0, z = 0, y = 0, j = 0, q, mx = 0, idx = 0, ok = 0,                   l = 0, r = 0, negatif = 0, positif = 0, l1, r1, p, t, d;     set<pair<long long int, long long int> >::iterator itp;     cin >> n >> k >> d;     for (i = 1; i <= n; i++) {       cin >> a[i];       dp[i] = 0;     }     sort(a + 1, a + 1 + n);     dp[0] = 1;     dp[1] = -1;     for (i = 1; i <= n; i++) {       if (!dp[i - 1]) continue;       dp[i] += dp[i - 1];       x = a[i] + d;       l = i + k - 1;       r = upper_bound(a + i, a + 1 + n, x) - a - 1;       if (r >= l) {         dp[l]++;         dp[r + 1]--;       }     }     if (dp[n])       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (1 << 20);   class Disjoint_Set {    public:     int sz[MX], P[MX];     int find_(int x) {       if (x != P[x]) P[x] = find_(P[x]);       return P[x];     }     int comp;     void init(int N) {       for (int j = 1; j <= N; j++) sz[j] = 1, P[j] = j;       comp = N;     }     bool same(int x, int y) { return find_(x) == find_(y); }     int compsize(int node) { return sz[find_(node)]; }     bool merge_(int x, int y) {       int px = find_(x), py = find_(y);       if (px == py) return false;       if (sz[px] < sz[py]) swap(px, py);       P[py] = px;       comp--;       sz[px] += sz[py];       return true;     }   } G;   int n, m;   int main() {     scanf( %d %d , &n, &m);     if (n != m) {       puts( NO );       return 0;     }     G.init(n);     int tt = 0;     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       if (!G.merge_(a, b)) tt++;     }     if (tt == 1)       puts( FHTAGN! );     else       puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200007;   int n, m, q, p[N], a[N], apre[N], lst[N], ppre[N], fa[N], dep[N], w[N], b[N];   vector<int> G[N];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a < b ? a : b; }   int read() {     int x;     scanf( %d , &x);     return x;   }   void dfs(int u) {     int i, v;     b[dep[u]] = u, w[u] = dep[u] >= n ? b[dep[u] - (n - 1)] : m + 1;     for (i = G[u].size() - 1; ~i; --i) v = G[u][i], dep[v] = dep[u] + 1, dfs(v);   }   int main() {     n = read(), m = read(), q = read();     int i, j;     for (i = 1; i <= n; ++i) p[i] = read();     p[0] = p[n];     for (i = 1; i <= n; ++i) ppre[p[i]] = p[i - 1];     for (i = 1; i <= m; ++i) {       a[i] = read(), apre[i] = lst[a[i]], lst[a[i]] = i;       for (j = lst[ppre[a[i]]]; j && !fa[j]; j = apre[j]) fa[j] = i;     }     for (i = 1; i <= m; ++i) fa[i] ? G[fa[i]].push_back(i) : G[0].push_back(i);     dfs(0);     for (i = m - 1; i; --i) w[i] = min(w[i + 1], w[i]);     while (q--) i = read(), j = read(), putchar(48 + (w[i] <= j));   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e6;   long long a[MAXN], mod = 1e9 + 7, ans;   long long power(long long x, long long y) {     if (y == 0) return 1;     long long mid = power(x, y / 2);     if (y % 2 == 1)       return mid * mid % mod * x % mod;     else       return mid * mid % mod;   }   int main() {     int n;     cin >> n;     bool is = false, is2 = false;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0) is = true;       if (a[i] != 1) is2 = true;     }     for (int i = 0; i < n; i++) {       if (i == 0)         ans = power(2, a[i]);       else         ans = power(ans, a[i]);     }     ans = ans * power(2, mod - 2) % mod;     long long ans2 = ans;     long long k = -1;     if (is) k = 1;     ans = (ans + k) * power(3, mod - 2) % mod;     cout << ans <<  /  << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, j = 0, c1 = 0, c0 = 0;     string a, b;     vector<long long int> v0, v1;     cin >> n;     cin >> a;     cin >> b;     for (i = 0; i < n; i++) {       if (b[i] ==  0 ) {         if (a[i] ==  1 )           v1.push_back(i);         else           v0.push_back(i);       }       if (a[i] ==  0 )         c0++;       else         c1++;     }     j = v0.size() * c1;     j += (v1.size() * c0);     j -= (v1.size() * v0.size());     cout << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check(long long n, long long s) {     long long sum = 0;     while (n) {       sum += n % 10;       n /= 10;     }     return sum == s;   }   int main() {     long long n, s, rt, ans = -1;     cin >> n;     for (s = 1; s < 100; s++) {       rt = sqrt(s * s + 4 * n);       if (rt * rt == s * s + 4 * n) {         if ((rt - s) % 2 == 0) {           if (check((rt - s) / 2, s)) {             if (ans == -1)               ans = (rt - s) / 2;             else               ans = min(ans, (rt - s) / 2);           }         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e;   double best = -1;   int main() {     int n, u;     cin >> n >> u;     for (int i = 0; i < n; i++) {       int k = 0;       cin >> k;       e.push_back(k);     }     int k = 2;     for (int j = 1; j < n; j++) {       int ej = e[j];       int ei = e[j - 1];       while (k < n && e[k] - ei <= u) {         k++;       }       k--;       if (k <= j) {         continue;       }       double value = ((double)(e[k] - ej)) / (e[k] - ei);       if (value > best) {         best = value;       }     }     cout << setprecision(12) << best;     return 0;   }