#include <bits/stdc++.h>   using namespace std;   int dis[75][1 << 18];   bool mark[75][1 << 18];   int n, m, A, B;   vector<pair<int, int> > ve[75];   struct zzt {     pair<int, int> to;     int di;   };   bool operator<(zzt aa, zzt bb) { return aa.di > bb.di; }   priority_queue<zzt> q;   int fa[75];   int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }   int sz[75];   void merge(int x, int y) {     x = gf(x);     y = gf(y);     if (x != y) fa[x] = y, sz[y] += sz[x];   }   int mk[75], mkid;   int ozt(int x) { return mk[x] ? (1 << (mk[x] - 1)) : 0; }   int main() {     scanf( %d%d%d%d , &n, &m, &A, &B);     for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;     for (int i = 1; i <= m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       ve[x].push_back(pair<int, int>(y, z));       ve[y].push_back(pair<int, int>(x, z));       if (z == A) merge(x, y);     }     mkid = 0;     for (int i = 1; i <= n; i++) {       if ((!mk[i]) && sz[gf(i)] > 3) {         ++mkid;         for (int j = i; j <= n; j++) {           if (gf(j) == gf(i)) mk[j] = mkid;         }       }     }     q.push((zzt){pair<int, int>(1, ozt(1)), 0});     memset(dis, 0x3f, sizeof dis);     dis[1][ozt(1)] = 0;     while (q.size()) {       int x = q.top().to.first;       int zt = q.top().to.second;       q.pop();       if (mark[x][zt]) continue;       mark[x][zt] = 1;       for (auto p : ve[x]) {         int y = p.first;         int le = p.second;         if (le == A) {           if (dis[y][zt] > dis[x][zt] + le) {             dis[y][zt] = dis[x][zt] + le;             q.push((zzt){pair<int, int>(y, zt), dis[y][zt]});           }         } else if (gf(y) != gf(x) && (ozt(y) & zt) == 0) {           if (dis[y][zt | ozt(y)] > dis[x][zt] + le) {             dis[y][zt | ozt(y)] = dis[x][zt] + le;             q.push((zzt){pair<int, int>(y, zt | ozt(y)), dis[y][zt | ozt(y)]});           }         }       }     }     for (int i = 1; i <= n; i++) {       int ans = 0x3f3f3f3f;       for (int j = 0; j <= (1 << mkid) - 1; j++) {         ans = min(ans, dis[i][j]);       }       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, k, l, m, n, t, x, y;     cin >> n;     if (n % 2 == 0)       cout << n + 4 <<     << 4 << endl;     else       cout << n + 9 <<     << 9 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool is_prime(int n) {     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return 0;     return 1;   }   inline int Exp(int a, int p, int mod) {     int res = 1;     while (p) {       if (p & 1) res = (long long)res * a % mod;       p >>= 1;       a = (long long)a * a % mod;     }     return res;   }   inline int get_root(int n) {     for (int i = 2; i < n; ++i) {       if (Exp(i, n - 1, n) != 1) continue;       bool ok = 1;       for (int j = 1; j < n - 1; ++j)         if (Exp(i, j, n) == 1) {           ok = 0;           break;         }       if (ok) return i;     }     return -1;   }   int main() {     int n;     scanf( %d , &n);     if (n == 1) {       puts( YES );       puts( 1 );       return 0;     }     if (n == 4) {       puts( YES );       puts( 1 );       puts( 3 );       puts( 2 );       puts( 4 );       return 0;     }     if (n == 2) {       puts( YES );       puts( 1 2 );       return 0;     }     if (is_prime(n)) {       puts( YES );       int g = get_root(n);       printf( %d n , Exp(g, n - 1, n));       for (int i = 1; i <= n - 2; ++i) {         if (i & 1)           printf( %d n , Exp(g, i, n));         else           printf( %d n , Exp(g, n - 1 - i, n));       }       printf( %d n , n);     } else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[105];   int main() {     int n;     scanf( %d , &n);     scanf( %s , str);     vector<int> g;     int sum = 0;     for (int i = 0; i < n; i++) {       if (str[i] ==  B ) {         sum++;       } else {         if (sum) g.push_back(sum);         sum = 0;       }     }     if (sum) g.push_back(sum);     printf( %d n , g.size());     for (int i = 0; i < g.size(); i++) {       printf( %d  , g[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     scanf( %d , &T);     while (T--) {       long long s, n, k;       scanf( %lld%lld%lld , &s, &n, &k);       if (s < k)         printf( NO n );       else if (s == k)         printf( YES n );       else {         long long left_sum = s - n;         long long extra_sum = (n / k) * k;         if (left_sum < extra_sum)           printf( YES n );         else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   long long gcd(long long a, long long b) {     if (a == 0 || b == 0) return (a + b);     if (a > b) return (gcd(a % b, b));     return (gcd(a, b % a));   }   long long lcm(long long a, long long b) { return ((a * b / gcd(a, b))); }   int sqr(int x) { return (x * x); }   void out() {     puts( NO );     exit(0);   }   using namespace std;   int n;   int p[100008];   int main() {     cin >> n;     for (int i = (int)(1); i < (int)(n + 1); ++i) p[i] = i;     if (n % 2 == 1) {       cout <<  -1 n ;       return 0;     }     for (int i = (int)(1); i < (int)(n + 1); ++i) {       swap(p[i], p[i + 1]);       i++;     }     for (int i = (int)(n); i >= (int)(1); --i) cout << i <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   const int K = 655;   const int mod = 998244353;   int T;   int n, a[N];   int q[K], v[K], w[K], top = 0;   int q2[K], v2[K], w2[K], top2 = 0;   int MOD(int x) { return x >= mod ? x - mod : x; }   int u(int x, int y) { return (x + y - 1) / y; }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);       q[top = 1] = a[n], v[1] = 0, w[1] = 1;       int ans = 0;       for (int i = n - 1; i >= 1; --i) {         top2 = 0;         for (int l = 1, r, j = 0; l <= a[i]; l = r + 1) {           r = a[i] / (a[i] / l);           q2[++top2] = a[i] / l;           v2[top2] = 0;           w2[top2] = (l == 1);           if (i == 1) {             int tmp = 1;           }           while (j < top && u(a[i], q[j + 1]) >= l && u(a[i], q[j + 1]) <= r) {             ++j;             v2[top2] = MOD(v2[top2] + MOD(v[j] + (long long)(u(a[i], q[j]) - 1) *                                                      w[j] % mod));             w2[top2] = w2[top2] + w[j];           }         }         for (int j = 1; j <= top2; ++j) {           q[j] = q2[j];           v[j] = v2[j];           w[j] = w2[j];         }         top = top2;         for (int j = 1; j <= top; ++j) ans = MOD(ans + v[j]);       }       printf( %d n , ans);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     char c = getchar();     bool f = false;     for (x = 0; !isdigit(c); c = getchar()) {       if (c ==  - ) {         f = true;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (f) {       x = -x;     }   }   template <typename T, typename... U>   inline void read(T& x, U&... y) {     read(x), read(y...);   }   const int N = 5e1 + 10;   const double eps = 1e-6;   int n;   int ID[N];   double K;   double A[N], B[N], F[N][N];   double V(int a) { return A[a] - K * B[a]; }   bool cmp(int a, int b) { return A[a] == A[b] ? V(a) > V(b) : A[a] > A[b]; }   int main() {     read(n);     for (int i = 1; i <= n; ++i) scanf( %lf , &A[i]);     for (int i = 1; i <= n; ++i) scanf( %lf , &B[i]), ID[i] = i;     double L = 0.01, R = 5e9, res = 233;     while (R - L >= eps) {       double mid = (L + R) / 2.0;       K = mid;       sort(ID + 1, ID + n + 1, cmp);       for (int i = 0; i <= n; ++i)         for (int j = 0; j <= n; ++j) F[i][j] = 1e18;       F[0][0] = 0;       int cnt = 0;       for (int i = 1; i <= n; ++i) {         ++cnt;         double sum = V(ID[i]);         int p = i;         while (p != n && A[ID[p + 1]] == A[ID[i]]) sum += V(ID[++p]);         double g = 0;         int s = p - i + 1;         for (int j = 0; j <= s; ++j) {           if (j) g += V(ID[i + j - 1]);           for (int k = 0; k <= i - 1; ++k)             if (j <= k) {               F[cnt][k - j + s - j] =                   min(F[cnt][k - j + s - j], F[cnt - 1][k] + sum - g);             }         }         i = p;       }       double ANS = 1e18;       for (int i = 0; i <= n; ++i) ANS = min(ANS, F[cnt][i]);       if (ANS <= eps)         res = mid, R = mid - eps;       else         L = mid + eps;     }     printf( %lld n , (long long)(res * 100000 + 99) / 100);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 200005;   struct M {     int val, pos;   };   M a[Maxn], b[Maxn];   int idx[Maxn], idy[Maxn], Nx[Maxn], Ny[Maxn];   int read() {     int sum = 0, t = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) t = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum * t;   }   bool cmp(M x, M y) {     return (x.val < y.val || (x.val == y.val && b[x.pos].val < b[y.pos].val));   }   long long C2(long long x) { return 1ll * x * (x - 1) / 2; }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       a[i].val = read(), b[i].val = read();       a[i].pos = b[i].pos = i;     }     sort(a + 1, a + n + 1, cmp);     int cnt = 0, same = 1;     long long res = 0;     a[0].val = b[0].val = -0x3f3f3f3f;     cnt = 0;     for (int i = 1; i <= n; ++i) {       if (a[i].val != a[i - 1].val)         cnt++, res += C2(same), same = 1;       else {         if (b[a[i].pos].val == b[a[i - 1].pos].val)           same++;         else           res += C2(same), same = 1;       }       idx[a[i].pos] = cnt;     }     res += C2(same);     sort(b + 1, b + n + 1, cmp);     cnt = 0;     for (int i = 1; i <= n; ++i) {       if (b[i].val != b[i - 1].val) cnt++;       idy[b[i].pos] = cnt;     }     for (int i = 1; i <= n; ++i) {       Nx[idx[i]]++;       Ny[idy[i]]++;     }     long long ans = 0;     for (int i = 1; i <= n; ++i) {       ans += C2(Nx[i]) + C2(Ny[i]);     }     ans -= res;     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, i, dis = 10000000, temp, a[1000];   int main() {     cin >> n >> m >> k;     for (i = 0; i < n; ++i) cin >> a[i];     for (i = 0; i < n; ++i) {       if (a[i] != 0 && a[i] <= k) {         if (m <= i)           temp = (i - m + 1) * 10;         else           temp = (m - i - 1) * 10;         if (dis > temp) dis = temp;       }     }     cout << dis;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long k, m = 9, x;     long long r = 1, n, j, d = 0;     cin >> k;     while (k - m * r > 0) {       k -= m * r;       ++r;       m = m * 10;     }     n = (k - 1) / r;     j = (k - 1) % r;     x = pow(10, r - 1) + n;     for (long i = 0; i < r - j - 1; ++i) x /= 10;     d = x % 10;     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count1 = 0, count2 = 0, sum = 0;     scanf( %d , &n);     vector<pair<int, int> > v1;     vector<pair<int, int> > v2;     for (int i = 0; i < n; i++) {       int x, a;       scanf( %d %d , &x, &a);       if (x < 0) {         v1.push_back(make_pair(x, a));         count1++;       } else {         v2.push_back(make_pair(x, a));         count2++;       }     }     sort(v1.begin(), v1.end());     reverse(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     vector<pair<int, int> >::iterator it1 = v1.begin();     vector<pair<int, int> >::iterator it2 = v2.begin();     vector<pair<int, int> >::iterator it3 = v1.end();     vector<pair<int, int> >::iterator it4 = v2.end();     if (count1 > count2) {       while (it1 != v1.end()) {         sum += it1->second;         it1++;         if (it2 != v2.end()) {           sum += it2->second;           it2++;         } else           break;       }     } else if (count1 < count2) {       while (it2 != v2.end()) {         sum += it2->second;         it2++;         if (it1 != v1.end()) {           sum += it1->second;           it1++;         } else           break;       }     } else if (count1 == count2) {       if ((it3->second) > (it4->second)) {         while (it1 != v1.end()) {           sum += it1->second;           it1++;           sum += it2->second;           it2++;         }       } else {         while (it2 != v2.end()) {           sum += it2->second;           it2++;           sum += it1->second;           it1++;         }       }     }     printf( %d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * f;   }   const int MAX_N = 1e3 + 10;   int H[MAX_N][MAX_N], CM[MAX_N][MAX_N], TM[MAX_N][MAX_N], N, M, A, B, SUM = 0;   long long S[MAX_N][MAX_N];   bool vis[MAX_N][MAX_N];   vector<pair<long long, pair<int, int> > > V, Ans;   struct MY_QUEUE {     deque<pair<int, int> > Q;     inline void reset() { Q.clear(); }     inline void push(int val, int mark) {       pair<int, int> now = make_pair(val, mark);       while (Q.size() && Q.back().first > val) Q.pop_back();       Q.push_back(make_pair(val, mark));     }     inline void pop(int mark) {       if (Q.front().second == mark) Q.pop_front();     }     inline int get() { return Q.front().first; }   };   inline bool check_X(int x) { return x >= 0 && x < N; }   inline bool check_Y(int y) { return y >= 0 && y < M; }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     N = read();     M = read();     A = read();     B = read();     for (int i = 0; i < N; i++)       for (int j = 0; j < M; j++) H[i][j] = read();     for (int i = 0; i < M; i++) {       MY_QUEUE QUEUE;       for (int j = 0; j < N; j++) {         QUEUE.push(H[j][i], j);         if (j >= A) QUEUE.pop(j - A);         if (j >= A - 1) CM[j - A + 1][i] = QUEUE.get();       }     }     for (int i = 0; i < N; i++) {       MY_QUEUE QUEUE;       for (int j = 0; j < M; j++) {         QUEUE.push(CM[i][j], j);         if (j >= B) QUEUE.pop(j - B);         if (j >= B - 1) TM[i][j - B + 1] = QUEUE.get();       }     }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++)         S[i][j] = (long long)S[i][j] + S[i][j - 1] + H[i - 1][j - 1];     for (int i = 1; i <= M; i++)       for (int j = 1; j <= N; j++) S[j][i] = (long long)S[j][i] + S[j - 1][i];     for (int i = 0; i <= N - A; i++)       for (int j = 0; j <= M - B; j++) {         long long sum = (long long)S[i + A][j + B] - S[i + A][j] - S[i][j + B] +                         S[i][j],                   dec = (long long)TM[i][j] * A * B;         V.push_back(make_pair(sum - dec, make_pair(i, j)));       }     sort(V.begin(), V.end());     for (int i = 0; i < V.size(); i++) {       long long val = V[i].first;       int X = V[i].second.first, Y = V[i].second.second;       if (vis[X][Y]) continue;       SUM++;       Ans.push_back(make_pair(val, make_pair(X + 1, Y + 1)));       for (int i = X - A + 1; i <= X + A - 1; i++)         for (int j = Y - B + 1; j <= Y + B - 1; j++)           if (check_X(i) && check_Y(j)) vis[i][j] = 1;     }     printf( %d n , SUM);     for (int i = 0; i < Ans.size(); i++)       printf( %d %d %I64d n , Ans[i].second.first, Ans[i].second.second,              Ans[i].first);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const int maxm = 100005 * 2;   const int maxn = 100005;   const int mod = 1000000007;   struct Edge {     int v, next;   } E[maxm];   struct sw {     int v, next;   } EE[maxm];   int head[maxn], ind;   int headd[maxn], indd;   int dfs[maxn], low[maxn], clo;   int bri, cou, S[maxn], hi;   int n, m;   int f[maxn], have[maxn];   void add(int u, int v) {     E[ind].v = v, E[ind].next = head[u], head[u] = ind++;     E[ind].v = u, E[ind].next = head[v], head[v] = ind++;   }   void add1(int u, int v) {     EE[indd].v = v, EE[indd].next = headd[u], headd[u] = indd++;     EE[indd].v = u, EE[indd].next = headd[v], headd[v] = indd++;   }   void init() {     memset(head, -1, sizeof(head));     memset(headd, -1, sizeof(headd));     memset(dfs, -1, sizeof(dfs));     memset(low, -1, sizeof(low));     clo = ind = indd = 0;   }   vector<int> vvv[maxn];   void tarjan(int u, int id) {     dfs[u] = low[u] = clo++;     S[hi++] = u;     for (int i = head[u]; ~i; i = E[i].next) {       if (i == (id ^ 1)) continue;       int v = E[i].v;       if (dfs[v] == -1) {         tarjan(v, i);         low[u] = min(low[u], low[v]);         if (dfs[u] < low[v]) {           bri++;           vvv[u].push_back(v);         }       } else         low[u] = min(low[u], dfs[v]);     }     if (dfs[u] == low[u]) {       int v;       do {         v = S[--hi];         f[v] = u;         for (int j = 0; j < vvv[v].size(); j++) {           int pa = f[vvv[v][j]];           add1(u, pa);         }         have[u]++;       } while (u != v);     }   }   void work() {     hi = 0;     for (int i = 1; i <= n; i++)       if (dfs[i] == -1) {         tarjan(i, -1);       }   }   int ff[maxn][18], lev;   int dep[maxn];   long long dis[maxn];   int LCA(int x, int y) {     if (dep[x] > dep[y]) x = x ^ y, y = x ^ y, x = x ^ y;     for (int i = lev; i >= 0; i--)       if (dep[y] - dep[x] >> i & 1) y = ff[y][i];     if (x == y) return x;     for (int i = lev; i >= 0; i--)       if (ff[x][i] != ff[y][i]) x = ff[x][i], y = ff[y][i];     return ff[x][0];   }   void done(int u, int p) {     dep[u] = dep[p] + 1;     if (have[u] > 1)       dis[u] = dis[p] * 2 % mod;     else       dis[u] = dis[p];     ff[u][0] = p;     int v;     for (int i = headd[u]; ~i; i = EE[i].next) {       v = EE[i].v;       if (v != p) {         done(v, u);       }     }   }   void initLca() {     dis[0] = 1;     done(1, 0);     lev = 1;     for (; (1 << lev) <= n; lev++)       for (int i = 0; i <= n; i++)         if (f[i] == i) ff[i][lev] = ff[ff[i][lev - 1]][lev - 1];     lev--;   }   long long extend_gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long gcd = extend_gcd(b, a % b, x, y);     long long t = x;     x = y;     y = t - a / b * x;     return gcd;   }   long long Get_Inverse(long long num) {     long long x, y;     extend_gcd(num, 1000000007, x, y);     return (x % 1000000007 + 1000000007) % 1000000007;   }   int main(void) {     while (~scanf( %d%d , &n, &m)) {       init();       while (m--) {         int u, v;         scanf( %d%d , &u, &v);         add(u, v);       }       work();       initLca();       int k, a, b, fa, fb, pa;       scanf( %d , &k);       for (int i = 0; i < k; i++) {         scanf( %d%d , &a, &b);         fa = f[a];         fb = f[b];         long long ans = dis[fa] * dis[fb] % mod;         pa = LCA(fa, fb);         int need = (have[pa] > 1 ? 2 : 1);         ans = ans * Get_Inverse(dis[pa]) % mod;         ans = ans * (Get_Inverse(dis[pa] * Get_Inverse(need) % mod)) % mod;         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, a, b, i, j, k, siz, cnt = 0, p, q, s, t, z, h, po;     string str;     cin >> str;     cin >> x;     siz = str.size();     for (i = 0; i < siz; i++) {       if (str[i] !=  *  && str[i] !=  ? ) cnt++;     }     p = siz - cnt;     q = cnt - p;     if (x < q)       cout <<  Impossible  << endl;     else if (x >= q && x <= cnt) {       s = 0;       t = cnt - x;       for (i = 0; i < siz; i++) {         if (s < t && (str[i + 1] ==  ?  || str[i + 1] ==  * )) {           s++;         } else {           if (str[i] >=  a  && str[i] <=  z ) cout << str[i];         }       }     } else {       z = x - cnt;       h = 0;       for (i = 0; i < siz; i++) {         if (str[i] ==  * ) {           h++;           po = i;           break;         }       }       if (h == 0)         cout <<  Impossible  << endl;       else {         for (i = 0; i < siz; i++) {           if (i == po) {             for (j = 1; j <= z; j++) {               cout << str[i - 1];             }           } else {             if (str[i] >=  a  && str[i] <=  z ) {               cout << str[i];             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,abm,mmx,tune=native )   using namespace std;   long long gcd(long long i, long long j) {     if (j == 0)       return i;     else       return gcd(j, i % j);   }   template <typename T>   inline T getint() {     T val = 0;     char c;     bool neg = false;     while ((c = getchar()) && !(c >=  0  && c <=  9 )) {       neg |= c ==  - ;     }     do {       val = (val * 10) + c -  0 ;     } while ((c = getchar()) && (c >=  0  && c <=  9 ));     return val * (neg ? -1 : 1);   }   const long long INF = 1e9 + 100;   const int mod = 1000000007;   const long double eps = 1e-10, pi = acosl(-1);   const long long maxN = 300010, maxT = 10010, A = 179, mid = 150;   mt19937 mt_rand(time(0));   long long bp(long long et, long long b) {     b %= mod - 1;     long long res = 1;     for (int i = 30; i >= 0; --i) {       res = (res * res) % mod;       if ((b & (1 << i)) != 0) res = (res * et) % mod;     }     return res;   }   void panic() {     cout <<  -1 n ;     exit(0);   }   const int byben_size = 23;   vector<int> merge(const vector<int>& a, const vector<int>& b,                     bool want_mx = true) {     int s1 = a.size(), s2 = b.size();     int sz = min(s1 + s2, byben_size);     vector<int> r(sz);     if (!want_mx) {       int y1 = 0, y2 = 0;       int y = 0;       while (y < sz && y1 < s1 && y2 < s2) {         if (a[y1] < b[y2])           r[y++] = a[y1++];         else           r[y++] = b[y2++];       }       while (y < sz && y1 < s1) r[y++] = a[y1++];       while (y < sz && y2 < s2) r[y++] = b[y2++];     } else {       int y1 = s1 - 1, y2 = s2 - 1;       int y = sz - 1;       while (y >= 0 && y1 >= 0 && y2 >= 0) {         if (a[y1] > b[y2])           r[y--] = a[y1--];         else           r[y--] = b[y2--];       }       while (y >= 0 && y1 >= 0) r[y--] = a[y1--];       while (y >= 0 && y2 >= 0) r[y--] = b[y2--];     }     return r;   }   vector<int> t[1 << 18];   int sz = 1 << 17;   int a[maxN];   vector<int> l1[maxN], r1[maxN];   inline void add(int l, int r, int id, bool want_mx) {     for (l += sz, r += sz; l <= r; l >>= 1, r >>= 1) {       if (l & 1) {         int v = l++;         t[v].push_back(id);         int szz = t[v].size();         int rr = szz;         --szz;         while (szz > 0 && t[v][szz] < t[v][szz - 1]) {           swap(t[v][szz], t[v][szz - 1]);           --szz;         }         if (rr > byben_size) {           if (want_mx)             t[v].erase(t[v].begin());           else             t[v].pop_back();         }       }       if (~r & 1) {         int v = r--;         t[v].push_back(id);         int szz = t[v].size();         int rr = szz;         --szz;         while (szz > 0 && t[v][szz] < t[v][szz - 1]) {           swap(t[v][szz], t[v][szz - 1]);           --szz;         }         if (rr > byben_size) {           if (want_mx)             t[v].erase(t[v].begin());           else             t[v].pop_back();         }       }     }   }   vector<int> get(int v, bool want_mx) {     vector<int> r;     v |= sz;     for (v = v | sz; v; v >>= 1) {       r = merge(t[v], r, want_mx);     }     return r;   }   long double pw[maxT];   void solve() {     pw[0] = 1;     for (int i = 1; i < maxT; ++i) pw[i] = pw[i - 1] * 2;     int n = getint<int>();     for (int i = 1; i <= n; ++i) {       a[i] = getint<int>();     }     add(0, sz - 1, 0, 1);     for (int i = 1; i <= n; ++i) {       add(0, a[i], i, 1);       l1[i] = get(a[i], 1);     }     for (int i = 0; i < 2 * sz; ++i) t[i].clear();     add(0, sz - 1, n + 1, 0);     for (int i = n; i > 0; --i) {       add(0, a[i], i, 0);       r1[i] = merge({i}, get(a[i] + 1, 0), 0);     }     long double ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < l1[i].size(); ++j) {         for (int k = 0; k + 1 < r1[i].size(); ++k) {           long long cnt =               (long long)(l1[i][j] - l1[i][j - 1]) * (r1[i][k + 1] - r1[i][k]);           int pww = k + l1[i].size() - j;           if (pww > byben_size) break;           ans += (long double)cnt / pw[pww] * a[i];         }       }     }     cout << fixed << ans / n / n <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 303333, inf = 1000111222;   int n, x, y;   pair<int, int> a[max_n];   void wa() {     printf( No n );     exit(0);   }   int main() {     scanf( %d%d%d , &n, &x, &y);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i].first);       a[i].second = i + 1;     }     sort(a, a + n);     int last = -1;     for (int i = n - 1; i >= 0; --i) {       if (1LL * a[i].first * (n - i) >= y) {         last = i;         break;       }     }     if (last == -1) {       wa();     }     for (int i = 0; i < n; ++i) {       int need = (x + a[i].first - 1) / a[i].first;       if (i + need <= last) {         printf( Yes n );         printf( %d %d n , need, n - last);         for (int j = i; j < i + need; ++j) {           printf( %d  , a[j].second);         }         printf(  n );         for (int j = last; j < n; ++j) {           printf( %d  , a[j].second);         }         printf(  n );         return 0;       }     }     swap(x, y);     last = -1;     for (int i = n - 1; i >= 0; --i) {       if (1LL * a[i].first * (n - i) >= y) {         last = i;         break;       }     }     if (last == -1) {       wa();     }     for (int i = 0; i < n; ++i) {       int need = (x + a[i].first - 1) / a[i].first;       if (i + need <= last) {         printf( Yes n );         printf( %d %d n , n - last, need);         for (int j = last; j < n; ++j) {           printf( %d  , a[j].second);         }         printf(  n );         for (int j = i; j < i + need; ++j) {           printf( %d  , a[j].second);         }         printf(  n );         return 0;       }     }     wa();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void prime(long long int n, set<long long int> &s) {     if (n % 2 == 0) {       s.insert(2);       n /= 2;     }     while (n % 2 == 0) {       n /= 2;     }     for (int i = 3; i <= sqrt(n); i += 2) {       if (n % i == 0) {         s.insert(i);         n /= i;       }       while (n % i == 0) {         n /= i;       }     }     if (n > 2) s.insert(n);   }   int main() {     long long int n;     cin >> n;     set<long long int> s;     prime(n, s);     if (s.size() == 1)       cout << *(s.begin()) << endl;     else       cout << 1 << endl;     return (0);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   inline T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   inline T Bigmod(T b, T p, T m) {     if (p == 0)       return 1;     else if (!(p & 1))       return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;     else       return ((b % m) * Bigmod(b, p - 1, m)) % m;   }   template <typename T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <typename T>   inline T euclide(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclide(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclide(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclide(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <typename T>   inline T Dis(T x1, T y1, T x2, T y2) {     return sqrt((((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))));   }   template <typename T>   inline T Angle(T x1, T y1, T x2, T y2) {     return atan(double(y1 - y2) / double(x1 - x2));   }   template <typename T>   inline T DIFF(T a, T b) {     T d = a - b;     if (d < (T)0)       return -d;     else       return d;   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline long long isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   template <typename T>   inline void _in(T &x) {     register int c = getchar();     x = 0;     bool neg = 0;     for (; ((c<48 | c> 57) && c !=  - ); c = getchar())       ;     if (c ==  - ) {       neg = 1;       c = getchar();     }     for (; c > 47 && c < 58; c = getchar()) {       x = (x << 1) + (x << 3) + c - 48;     }     if (neg) x = -x;   }   template <typename T>   inline bool isLeapYear(T N) {     if (N % 4)       return 0;     else if (N % 100)       return 1;     else if (N % 400)       return 0;     else       return 1;   }   template <typename T>   inline T Set(T N, T pos) {     T A = 1;     return N = N | (A << pos);   }   template <typename T>   inline T Reset(T N, T pos) {     T A = 1;     return N = N & ~(A << pos);   }   template <typename T>   inline bool Check(T N, T pos) {     T A = 1;     return (bool)(N & (A << pos));   }   template <class T, class X>   inline T togglebit(T a, X i) {     T t = 1;     return (a ^ (t << i));   }   template <class T, class X>   inline T toInt(T &sm, X s) {     stringstream ss(s);     ss >> sm;     return sm;   }   template <typename T>   inline int cdigittoint(T ch) {     return ch -  0 ;   }   template <typename T>   inline bool isVowel(T ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   template <typename T>   inline bool isConst(T ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   inline double DEG(double x) { return (180.0 * x) / (2 * acos(0.0)); }   inline double RAD(double x) { return (x * (double)2 * acos(0.0)) / (180.0); }   int main() {     long long b1 = ({       long long a;       _in(a);       a;     }),               q = ({                 long long a;                 _in(a);                 a;               }),               l = ({                 long long a;                 _in(a);                 a;               }),               m = ({                 long long a;                 _in(a);                 a;               });     map<long long, bool> A;     for (long long i = 1; i <= m; i++)       A[({         long long a;         _in(a);         a;       })] = true;     if (abs(b1) > l) {       printf( 0 n );       return 0;     }     if (q == 0 || q == 1 || q == -1) {       if (q == 0) {         if (A[b1]) {           if (A[0] == 0)             printf( inf n );           else             printf( 0 n );         } else {           if (A[0] == 0)             printf( inf n );           else {             if (abs(b1) <= l)               printf( 1 n );             else               printf( 0 n );           }         }       } else if (q == 1) {         if (A[b1])           printf( 0 n );         else {           if (abs(b1) <= l)             printf( inf n );           else             printf( 0 n );         }       } else {         if (A[-b1] == 1 && A[b1] == 1)           printf( 0 n );         else if (A[-b1] == 1 || A[b1] == 1) {           if (abs(b1) <= l)             printf( inf n );           else             printf( 0 n );         } else {           if (abs(b1) <= l)             printf( inf n );           else             printf( 0 n );         }       }     } else {       if (b1 == 0) {         if (A[b1] == 0)           printf( inf n );         else           printf( 0 n );         return 0;       }       long long count = 0;       while (true) {         if (A[b1] == 0 && abs(b1) <= l) count++;         b1 *= q;         if (abs(b1) > l) break;       }       printf( %lld n , count);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bitset<64> f1[3610], f2[3610];   int n, m;   map<int, vector<int>> mp1, mp2;   int y[66], y2[66];   set<int> s;   vector<int> res;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> y[i], y[i] *= 2, mp1[y[i]].push_back(i);     for (int i = 1; i <= m; i++)       cin >> y2[i], y2[i] *= 2, mp2[y2[i]].push_back(i);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) res.push_back((y[i] + y2[j]) / 2);     sort(res.begin(), res.end());     res.erase(unique(res.begin(), res.end()), res.end());     for (int i = 0; i < res.size(); i++) {       int k = res[i];       for (int j = 1; j <= m; j++) {         int d = 2 * k - y2[j];         if (mp1[d].size())           for (auto xx : mp1[d]) f1[i].set(xx, 1);       }     }     for (int i = 0; i < res.size(); i++) {       int k = res[i];       for (int j = 1; j <= n; j++) {         int d = 2 * k - y[j];         if (mp2[d].size())           for (auto xx : mp2[d]) f2[i].set(xx, 1);       }     }     int ans = 0;     for (int i = 0; i < res.size(); i++)       for (int j = 0; j < res.size(); j++) {         int tmp = (f1[i] | f1[j]).count() + (f2[i] | f2[j]).count();         ans = max(ans, tmp);       }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, m, i, j, zero = 0, neg = 0, tot = 0, val = INT_MIN,                                 val2 = INT_MAX;       cin >> n >> m;       long long int b[n][m];       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) {           cin >> b[i][j];           if (b[i][j] < 0) {             neg++;             if (neg == 1)               val = b[i][j];             else if (val < b[i][j])               val = b[i][j];           } else if (b[i][j] == 0)             zero++;           else             val2 = min(val2, b[i][j]);           tot += abs(b[i][j]);         }       }       if (neg % 2 == 0 || zero != 0)         cout << tot << endl;       else {         cout << tot + 2 * max(val, -val2) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 5;   int n, dp[N][N][N][N];   char g[N][N];   int dfs(int x, int y, int h, int w) {     if (dp[x][y][h][w] != -1) return dp[x][y][h][w];     if (h == 1 && w == 1) return dp[x][y][h][w] = g[x][y] ==  # ;     if (h == 0 || w == 0) return dp[x][y][h][w] = 0;     dp[x][y][h][w] = max(h, w);     for (int i = 0; i <= h; ++i) {       dp[x][y][h][w] =           min(dp[x][y][h][w], dfs(x, y, i, w) + dfs(x + i, y, h - i, w));     }     for (int j = 0; j <= w; ++j) {       dp[x][y][h][w] =           min(dp[x][y][h][w], dfs(x, y, h, j) + dfs(x, y + j, h, w - j));     }     return dp[x][y][h][w];   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         cin >> g[i][j];       }     }     printf( %d , dfs(1, 1, n, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   const int inf = 0x3f3f3f3f;   int n, m;   int mi[maxn], cnt[maxn];   int main() {     cin >> n >> m;     memset(mi, 0x3f, sizeof(mi));     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       mi[x] = min(mi[x], (y - x + n) % n);       cnt[x]++;     }     for (int i = 1; i <= n; i++) {       long long ans = 0;       for (int j = 1; j <= n; j++)         if (cnt[j])           ans = max(ans, (j - i + n) % n + (long long)n * (cnt[j] - 1) + mi[j]);       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <class T>   void chmin(T &t, const T &f) {     if (t > f) t = f;   }   template <class T>   void chmax(T &t, const T &f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   int N, M;   int X[1000010], Y[1000010];   int bitN;   int bit[2100010];   void bitAdd(int pos, int val) {     for (int x = pos; x <= bitN; x += x & -x) bit[x] += val;   }   int bitLowerBound(int w) {     if (w <= 0) return 0;     int x = 0;     for (int k = bitN; k > 0; k /= 2) {       if (x + k <= bitN && bit[x + k] < w) {         w -= bit[x + k];         x += k;       }     }     return x + 1;   }   int perm[1000010];   int ids[2000010];   bool used[1000010];   bool solve() {     for (bitN = 2; bitN < M + N + 5; bitN <<= 1)       ;     memset(bit, 0, sizeof(bit));     memset(perm, ~0, sizeof(perm));     memset(ids, ~0, sizeof(ids));     for (int j = 1; j <= N; ++j) {       bitAdd(M + j, +1);       ids[M + j] = j;     }     for (int i = 0; i < M; ++i) {       const int pos = bitLowerBound(Y[i]);       const int j = ids[pos];       if (!~perm[j]) {         perm[j] = X[i];       }       if (perm[j] != X[i]) {         return false;       }       bitAdd(pos, -1);       bitAdd(M - i, +1);       ids[pos] = -1;       ids[M - i] = j;     }     memset(used, 0, sizeof(used));     for (int j = 1; j <= N; ++j)       if (~perm[j]) {         if (used[perm[j]]) {           return false;         }         used[perm[j]] = true;       }     int k = 1;     for (int j = 1; j <= N; ++j)       if (!~perm[j]) {         for (; used[k]; ++k)           ;         perm[j] = k;         used[k] = true;       }     return true;   }   int main() {     for (; ~scanf( %d%d , &N, &M);) {       for (int i = 0; i < M; ++i) {         X[i] = in();         Y[i] = in();       }       bool res = solve();       if (res) {         for (int j = 1; j <= N; ++j) {           if (j > 1) printf(   );           printf( %d , perm[j]);         }         puts(  );       } else {         puts( -1 );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MN = 70010;   vector<int> vs[MN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<string> vs(n);     for (int i = 0; i < n; i++) cin >> vs[i];     vector<string> ans(n);     for (int len = 1; len < 10; len++) {       map<string, set<int> > mapper;       for (int i = 0; i < n; i++)         for (int j = 0; j + len - 1 < 9; j++)           mapper[vs[i].substr(j, len)].insert(i);       for (auto &curr : mapper)         if (((int)curr.second.size()) == 1) {           int id = *curr.second.begin();           if (ans[id] ==   ) ans[id] = curr.first;         }     }     for (int i = 0; i < n; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void remax(T& A, T B) {     if (A < B) A = B;   }   template <class T>   inline void remin(T& A, T B) {     if (A > B) A = B;   }   string ToString(long long num) {     string ret;     do {       ret += ((num % 10) +  0 );       num /= 10;     } while (num);     reverse(ret.begin(), ret.end());     return ret;   }   long long ToNumber(string s) {     long long r = 0, p = 1;     for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10;     return r;   }   long long Gcd(long long a, long long b) {     while (a %= b ^= a ^= b ^= a)       ;     return b;   }   long long Power(long long base, long long power) {     long long ret = 1;     while (power) {       if (power & 1) ret *= base;       power >>= 1;       base *= base;     }     return ret;   }   long long PowerMod(long long base, long long power, long long mod) {     if (!power) return 1;     if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod;     return PowerMod((base * base) % mod, power >> 1, mod);   }   int Log(long long num, long long base) {     int ret = 0;     while (num) {       ++ret;       num /= base;     }     return ret;   }   int Count(long long mask) {     int ret = 0;     while (mask) {       if (mask & 1) ++ret;       mask >>= 1;     }     return ret;   }   inline void run() {     int arr[2000];     int n, b, ans;     scanf( %d%d , &n, &b);     for (int i = 0; i < n;) scanf( %d , arr + i++);     ans = b;     for (int i = 0; i < n; ++i)       for (int j = i + 1; j < n; ++j)         remax(ans, arr[j] * (b / arr[i]) + b % arr[i]);     printf( %d n , ans);   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long g = exgcd(b, a % b, x, y);     long long t;     t = x, x = y, y = t - (a / b) * y;     return g;   }   int main() {     long long a, b, c, x, y;     cin >> a >> b >> c;     long long t = exgcd(a, b, x, y);     if (c % t == 0)       printf( %lld %lld n , -x * c / t, -y * c / t);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int N = 1010;   int dp[N][N][2];   int bits[N];   int t, k;   long long dfs(int len, int pos, int num, bool mark) {     int maxx;     long long sum;     if (!len) {       if (num == 1) {         return true;       } else {         return false;       }     }     if (!mark && dp[len][pos][num] != -1) {       return dp[len][pos][num];     }     if (mark) {       maxx = bits[len];     } else {       maxx = 9;     }     sum = 0;     for (int i = 0; i <= maxx; i++) {       if (i == 4 || i == 7) {         sum +=             dfs(len - 1, len, (pos && pos - len <= k) | num, mark && i == maxx);       } else {         sum += dfs(len - 1, pos, num, mark && i == maxx);       }     }     sum %= MOD;     if (!mark) {       dp[len][pos][num] = sum;     }     return sum;   }   long long f(string s) {     int len;     len = 0;     for (int i = s.size() - 1; i >= 0; i--) {       len++;       bits[len] = s[i] -  0 ;     }     return dfs(len, 0, 0, 1);   }   bool check(string &s) {     int p;     p = 0;     for (int i = 1; i <= s.size(); i++) {       if (s[i - 1] ==  4  || s[i - 1] ==  7 ) {         if (!p || i - p > k) {           p = i;         } else if (i - p <= k) {           return true;         }       }     }     return false;   }   int main() {     string l, r;     long long ans;     while (scanf( %d%d , &t, &k) == 2) {       memset(dp, -1, sizeof(dp));       for (int i = 0; i < t; i++) {         cin >> l >> r;         ans = f(r) - f(l) + (check(l) ? 1 : 0);         printf( %lld n , (ans % MOD + MOD) % MOD);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[200005][3], n;   long long dp[200005][3], a[200005];   long long dfs(int x, int s) {     if (dp[x][s]) return dp[x][s];     if (vis[x][s]) return -1;     vis[x][s] = 1;     int k;     if (s)       k = x + a[x];     else       k = x - a[x];     if (k <= 0 || k > n)       dp[x][s] += a[x];     else {       dp[x][s] = dfs(k, s ^ 1);       if (dp[x][s] != -1) dp[x][s] += a[x];     }     return dp[x][s];   }   int main() {     while (scanf( %d , &n) != EOF) {       memset(vis, 0, sizeof(vis));       memset(dp, 0, sizeof(dp));       for (int i = 2; i <= n; i++) scanf( %I64d , &a[i]);       for (int i = 2; i <= n; i++) dfs(i, 0);       for (int i = 1; i < n; i++) {         if (dp[i + 1][0] == -1)           printf( -1 n );         else           printf( %I64d n , i + dp[i + 1][0]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double PI = acos(-1.0);   long long mod = 998244353;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long GCD(long long a, long long b) {     if (b == 0) return a;     return GCD(b, a % b);   }   long long prod(long long a, long long b) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1ll) res = (res + a) % mod;       a = (2ll * a) % mod;       b >>= 1ll;     }     return res;   }   long long power(long long a, long long b) {     long long res = 1ll;     while (b > 0) {       if (b % 2ll) res = (res * a) % mod;       a = (a * a) % mod;       b /= 2ll;     }     return res;   }   long long binaryExponentiation(long long a, long long b) {     long long result = 1ll;     while (b > 0) {       if (b % 2 == 1) result = (result * a) % mod;       a = (a * a) % mod;       b /= 2ll;     }     return result;   }   long long ModularInverse(long long a) {     return binaryExponentiation(a, mod - 2);   }   long long n, m;   void solve() {     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       if (a[i] >= 0) {         a[i] = -a[i] - 1;       }     }     long long x = INT_MAX, p = 0;     for (long long i = 0; i < n; i++) {       if (a[i] < x) {         x = a[i];         p = i;       }     }     if (n % 2) {       a[p] = -a[p] - 1;     }     for (auto &e : a) {       cout << e <<    ;     }     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   #define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   #define testCase    int T; cin>>T; while(T--)   #define debug(P) cout<<#P<<   <<P<<endl   #define endl   n        using namespace std;       typedef long long ll;       int main() {     testCase {      int n;      cin>>n;      string s;      cin>>s;          bool poss = true;          int t = 0;          for(char x : s) {       if(x ==  T )++t;      }          if(2*(n-t) != t) {       poss = false;      }          t = 0;          for(int i = 0; i < n; ++i) {       if(s[i] ==  T ) ++t;       else {        --t;        if(t < 0) {         poss = false;         break;        }       }      }            t = 0;          for(int i = n-1; i >= 0; --i) {       if(s[i] ==  T ) ++t;       else {        --t;        if(t < 0) {         poss = false;         break;        }       }      }          if(poss) {       cout<<  YES n ;      } else {       cout<<  NO n ;      }         }   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e6 + 10;   vector<int> a[N];   vector<int> pos[N];   string ans;   int n;   string s[N];   int m;   vector<int> cur;   int cnt[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     memset(cnt, 0, sizeof(cnt));     m = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> s[i];       int len = s[i].length();       int k;       cin >> k;       while (k--) {         int p;         cin >> p;         p--;         m = max(m, p + len);         a[p].push_back(i);         a[p + len].push_back(-i);         pos[i].push_back(p);       }     }     ans.resize(m);     for (int i = 0; i < m; i++) {       for (int x : a[i]) {         if (x > 0) {           cur.push_back(x);           cnt[x]++;         } else {           cnt[-x]--;         }       }       while (!cur.empty() && cnt[cur.back()] == 0) cur.pop_back();       if (cur.empty())         ans[i] =  a ;       else {         int id = cur.back();         auto it = upper_bound(pos[id].begin(), pos[id].end(), i);         it--;         int p = *it;         if (i - p >= (int)s[id].length()) continue;         ans[i] = s[id][i - p];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       long long l = 0, r = 100000000;       while (l <= r) {         long long t = (l + r) / 2;         long long w = b * t;         long long d = b * t;         bool ok = true;         while (d < a * c) {           if (w < a) {             ok = false;             break;           }           w -= a;           w += b;           d += b;         }         if (ok)           r = t - 1;         else           l = t + 1;       }       cout << l - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   vector<pair<int, int> > v[1000000 + 5];   int s[1000000 / 5], num = 0, last[1000000 + 5], vis[1000000 + 5],                       la[1000000 + 5], lastans = 0, n, q, mx, a[1000000 + 5],                       rt[1000000 + 5], cnt = 0, inv[1000000 + 5],                       Ans[1000000 + 5];   struct Tree {     int l, r, x;   } T[1000000 * 4 + 5];   bool b[1000000 + 5];   int Build(int l, int r) {     int x = ++cnt;     T[x].x = 1;     if (l != r) {       int mid = l + r >> 1;       T[x].l = Build(l, mid);       T[x].r = Build(mid + 1, r);     }     return x;   }   void Modify(int x, int l, int r, int lt, int rt, int v) {     if (l == lt && r == rt) {       T[x].x = 1LL * T[x].x * v % 1000000007;       return;     }     int mid = lt + rt >> 1;     if (r <= mid)       Modify(T[x].l, l, r, lt, mid, v);     else if (l > mid)       Modify(T[x].r, l, r, mid + 1, rt, v);     else       Modify(T[x].l, l, mid, lt, mid, v),           Modify(T[x].r, mid + 1, r, mid + 1, rt, v);   }   void Query(int x, int k, int lt, int rt) {     lastans = 1LL * lastans * T[x].x % 1000000007;     if (lt == rt) return;     int mid = lt + rt >> 1;     if (k <= mid)       Query(T[x].l, k, lt, mid);     else       Query(T[x].r, k, mid + 1, rt);   }   int main() {     n = read();     inv[0] = inv[1] = 1;     for (int i = 1; i <= n; ++i) mx = max(mx, a[i] = read());     q = read();     for (register int i = 2; i <= mx; ++i) {       inv[i] =           1LL * (1000000007 - 1000000007 / i) * inv[1000000007 % i] % 1000000007;       if (!b[i]) s[++num] = i, last[i] = i;       for (int j = 1; s[j] * i <= mx; ++j) {         b[s[j] * i] = 1;         last[s[j] * i] = s[j];         if (i % s[j] == 0) break;       }     }     rt[0] = Build(1, n);     for (int i = 1; i <= q; ++i) {       int l = read(), r = read();       v[r].push_back(make_pair(l, i));     }     for (register int i = 1; i <= n; ++i) {       Modify(rt[i] = rt[i - 1], 1, i, 1, n, a[i]);       for (int t = a[i]; t > 1; t /= last[t])         if (vis[last[t]] != i) {           vis[last[t]] = i;           Modify(rt[i], la[last[t]] + 1, i, 1, n,                  1LL * inv[last[t]] * (last[t] - 1) % 1000000007);           la[last[t]] = i;         }       for (int j = 0; j < v[i].size(); ++j)         lastans = 1, Query(rt[i], v[i][j].first, 1, n),         Ans[v[i][j].second] = lastans;     }     for (int i = 1; i <= q; ++i) printf( %d n , Ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const LL MOD = 998244353;   string s;   LL cal(int x) {     if (x < 10 || x > 18) return 0;     return 9 - (x - 10);   }   struct SegmentTree {     struct Node {       int L, R, l, r;       LL v[2][2];     };     vector<Node> N;     int p;     vector<int> rt;     int n;     inline void init(int _n) {       n = _n;       N.resize(n * 4);       p = 1;       rt.clear();       rt.push_back(build(0, n));     }     inline int copy(Node u) { return N[p] = u, p++; }     int build(int L, int R) {       int u = copy({L, R}), M = (L + R) >> 1;       ;       if (R - L == 1)         return N[u].v[0][0] = s[L] -  0  + 1, N[u].v[0][1] = 1, N[u].v[1][0] = 1,                N[u].v[1][1] = 0, u;       return pull(u, build(L, M), build(M, R));     }     inline int push(int u) { return u; }     inline int pull(int u, int l, int r) {       if (!l || !r) return l ? l : r;       push(N[u].l = l);       push(N[u].r = r);       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           N[u].v[i][j] =               (N[l].v[i][0] * N[r].v[0][j] +                N[l].v[i][1] * N[r].v[1][j] % MOD *                    cal((s[N[l].R - 1] -  0 ) * 10 + (s[N[r].L] -  0 ))) %               MOD;         }       }       return u;     }     int m(int L, int R, int u, int v) {       if (!u || R <= N[u].L || N[u].R <= L) return u;       push(u);       if (L <= N[u].L && N[u].R <= R) return N[u].v[0][0] = v + 1, u;       return pull(u, m(L, R, N[u].l, v), m(L, R, N[u].r, v));     }     int q(int L, int R, int u) {       if (!u || R <= N[u].L || N[u].R <= L) return 0;       if (L <= N[u].L && N[u].R <= R) return u;       push(u);       return pull(copy(N[u]), q(L, R, N[u].l), q(L, R, N[u].r));     }     inline void modify(int L, int R, int ver, int v) {       rt[ver] = m(L, R, rt[ver], v);     }     inline Node& query(int L, int R, int ver) {       p = 2 * n + 1;       return N[q(L, R, rt[ver])];     }   } solver;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, q;     cin >> n >> q;     cin >> s;     solver.init(n);     while (q--) {       int x, d;       cin >> x >> d;       x--;       s[x] =  0  + d;       solver.modify(x, x + 1, 0, d);       auto v = solver.query(0, n, 0).v;       cout << v[0][0] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> av;   int main() {     int n;     scanf( %d , &n);     for (int i = max(1, n - 100); i <= n; i++) {       int j = i, ans = i;       while (j) {         ans += j % 10;         j /= 10;       }       if (ans == n) av.push_back(i);     }     int avs = av.size();     printf( %d n , avs);     for (int i = 0; i < avs; i++) {       printf( %d n , av[i]);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   long long int n, res[200005], cnt = 0, ans[200005];   vector<long long int> g[200005];   vector<long long int> v[200005];   map<long long int, long long int> c;   queue<long long int> q;   void dfs1(long long int node, long long int color) {     c[node] = color;     for (auto it : g[node]) {       if (!c[it]) {         dfs1(it, color % 2 + 1);       }     }   }   void dfs2(long long int node, long long int p) {     for (auto it : g[node]) {       if (it != p) {         dfs2(it, node);       }     }     for (auto it : g[node]) {       if (c[it] != c[node] && res[it] == 0 && res[node] == 0) {         cnt++;         res[it] = cnt;         res[node] = cnt;         q.push(it);         q.push(node);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long int i = 1; i < n; i++) {       long long int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs1(1, 1);     dfs2(1, 1);     while (!q.empty()) {       long long int x = q.front();       q.pop();       for (auto it : g[x]) {         if (res[it] == 0) {           res[it] = res[x];           q.push(it);         }       }     }     for (long long int i = 1; i <= n; i++) {       v[res[i]].push_back(i);     }     long long int mn = 0;     for (long long int i = 1; i <= cnt; i++) {       mn += (v[i].size() - 1) * 2;       for (long long int j = 0; j < v[i].size(); j++) {         ans[v[i][j]] = v[i][(j + 1) % v[i].size()];       }     }     cout << mn <<   n ;     for (long long int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int block_size = 320;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 7;   const long double eps = 1e-9;   const double PI = atan(1) * 4;   template <typename T>   inline int sign(const T &a) {     if (a < 0) return -1;     if (a > 0) return 1;     return 0;   }   string to_string(string s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T, typename S>   inline bool upmin(T &a, const S &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T &a, const S &b) {     return a < b ? a = b, 1 : 0;   }   template <typename T>   inline void in(T &x) {     x = 0;     T f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   long long twop(int x) { return 1LL << x; }   template <typename A, typename B>   inline void in(A &x, B &y) {     in(x);     in(y);   }   template <typename A, typename B, typename C>   inline void in(A &x, B &y, C &z) {     in(x);     in(y);     in(z);   }   template <typename A, typename B, typename C, typename D>   inline void in(A &x, B &y, C &z, D &d) {     in(x);     in(y);     in(z);     in(d);   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   namespace SOLVE {   int n, q;   string s;   int nxt[100010][26];   int dp[255][255][255];   vector<int> word[3];   void solve(int i, int j, int k) {     dp[i][j][k] = inf;     if (i and dp[i - 1][j][k] <= n)       upmin(dp[i][j][k], nxt[dp[i - 1][j][k]][word[0][i]]);     if (j and dp[i][j - 1][k] <= n)       upmin(dp[i][j][k], nxt[dp[i][j - 1][k]][word[1][j]]);     if (k and dp[i][j][k - 1] <= n)       upmin(dp[i][j][k], nxt[dp[i][j][k - 1]][word[2][k]]);   }   void main() {     cin >> n >> q >> s;     for (long long i = 0; i < n; i++) s[i] -=  a ;     s =     + s;     for (long long i = 0; i < 26; i++) nxt[n][i] = inf;     for (long long i = n - 1; i >= 0; i--) {       for (long long j = 0; j < 26; j++) nxt[i][j] = nxt[i + 1][j];       nxt[i][s[i + 1]] = i + 1;     }     for (long long i = 0; i < 3; i++) word[i].push_back(0);     dp[0][0][0] = 0;     while (q--) {       string op;       cin >> op;       int id;       cin >> id;       id--;       if (op ==  + ) {         string sss;         cin >> sss;         int ch = sss[0] -  a ;         word[id].push_back(ch);         if (id == 0) {           for (long long b = 0; b < ((int)word[1].size()); b++) {             for (long long c = 0; c < ((int)word[2].size()); c++) {               solve(((int)word[0].size()) - 1, b, c);             }           }         }         if (id == 1) {           for (long long b = 0; b < ((int)word[0].size()); b++) {             for (long long c = 0; c < ((int)word[2].size()); c++) {               solve(b, ((int)word[1].size()) - 1, c);             }           }         }         if (id == 2) {           for (long long b = 0; b < ((int)word[0].size()); b++) {             for (long long c = 0; c < ((int)word[1].size()); c++) {               solve(b, c, ((int)word[2].size()) - 1);             }           }         }       } else {         word[id].pop_back();       }       cout << ((dp[((int)word[0].size()) - 1][((int)word[1].size()) - 1]                   [((int)word[2].size()) - 1] <= n)                    ?  YES                     :  NO )            << endl;     }   }   }  // namespace SOLVE   signed main() {     int t;     t = 1;     while (t--) {       SOLVE::main();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a[n];       long long int sum = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         if (!(i & 1)) sum += a[i];       }       long long int best = 0;       long long int cur = 0;       long long int z, z1;       if (n & 1)         z = n - 1;       else         z = n;       for (int i = 0; i < z; i += 2) {         cur = max(0ll, cur + a[i + 1] - a[i]);         best = max(cur, best);       }       cur = 0;       if (!(n & 1))         z1 = n - 1;       else         z1 = n;       for (int i = 1; i < z1; i += 2) {         cur = max(0ll, cur + a[i] - a[i + 1]);         best = max(cur, best);       }       cout << sum + best << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 35000 + 10;   const int MAXK = 55;   int tree[MAXN << 2], info[MAXN << 2];   int dp[MAXK][MAXN];   int nums[MAXN];   int pre[MAXN], cur[MAXN];   void build(int node, int start, int end, int i) {     if (start == end) {       tree[node] = dp[i][start - 1];       info[node] = 0;       return;     }     int mid = (start + end) >> 1;     build((node << 1), start, mid, i);     build(((node << 1) | 1), mid + 1, end, i);     tree[node] = max(tree[(node << 1)], tree[((node << 1) | 1)]);     info[node] = 0;   }   void update(int node, int start, int end, int i, int j, int val) {     if (end < i || j < start) return;     if (i <= start && end <= j) {       tree[node] += val;       info[node] += val;       return;     }     int mid = (start + end) >> 1;     if (info[node] != 0) {       update((node << 1), start, mid, start, mid, info[node]);       update(((node << 1) | 1), mid + 1, end, mid + 1, end, info[node]);       info[node] = 0;     }     update((node << 1), start, mid, i, j, val);     update(((node << 1) | 1), mid + 1, end, i, j, val);     tree[node] = max(tree[(node << 1)], tree[((node << 1) | 1)]);   }   int query(int node, int start, int end, int i, int j) {     if (end < i || j < start) return INT_MIN;     if (i <= start && end <= j) {       return tree[node];     }     int mid = (start + end) >> 1;     if (info[node] != 0) {       update((node << 1), start, mid, start, mid, info[node]);       update(((node << 1) | 1), mid + 1, end, mid + 1, end, info[node]);       info[node] = 0;     }     return max(query((node << 1), start, mid, i, j),                query(((node << 1) | 1), mid + 1, end, i, j));   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       scanf( %d , &nums[i]);       pre[i] = cur[nums[i]];       cur[nums[i]] = i;     }     for (int i = 1; i <= k; i++) {       build(1, 1, n, i - 1);       for (int j = i; j <= n; j++) {         update(1, 1, n, pre[j] + 1, j, 1);         dp[i][j] = query(1, 1, n, 1, j);       }     }     cout << dp[k][n] << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef struct {     int x;     int y;     long long z;     long long o;   } H;   long long b, g, i, j, k, sz, t, p[200040], w[200040];   int pv[200040];   H e[400005];   int C(H a, H b) { return a.x < b.x; }   void BP(void);   void S(void);   long long dfs(int v);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (cin >> t; t--;) {       S();       BP();       k++;       for (i = 0; i++ < k;) {         if (w[i] < 2 && !p[e[pv[i]].y]) {           dfs(pv[i]);           p[e[pv[i]].y] = 1;         }       }       for (b = g = i = 0; i < sz; i++) {         if (!e[i].o) {           if (w[e[i].y] < 2)             e[i].o = 1;           else             e[i].o = k - 1;         }         if (e[i].o * 2 < k || e[i].o * 2 == k && e[i].x < e[i].y) {           g += e[i].o % 2 * e[i].z;           b += e[i].o * e[i].z;         }       }       cout << g <<     << b <<   n ;       for (i = 0; i++ < k + 1;) p[i] = pv[i] = w[i] = 0;       for (i = 0; i < sz + 1; i++) e[i].o = 0;     }   }   void BP(void) {     for (int i = 0; ++i < sz;) {       if (e[i].x > e[i - 1].x) {         for (int j = e[i - 1].x; j++ < e[i].x;) {           pv[j] = i;         }       }     }     for (int j = e[sz - 1].x; j++ < k + 2;) pv[j] = sz;   }   void S(void) {     cin >> k;     k = 2 * k - 1;     for (int i = 0; i < k; i++) {       cin >> e[i].x >> e[i].y >> e[i].z;       e[i + k].x = e[i].y;       e[i + k].y = e[i].x;       e[i + k].z = e[i].z;       w[e[i].x]++;       w[e[i].y]++;     }     sz = 2 * k;     sort(e, e + sz, C);   }   long long dfs(int v) {     long long s = 0;     if (e[v].o) return e[v].o;     for (int i = pv[e[v].y]; i < pv[e[v].y + 1]; i++) {       if (e[i].y != e[v].x) s += dfs(i);     }     return e[v].o = s + 1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if ((a >= 0 && b < 0) || (a < 0 && b >= 0)) {       cout <<  -1 ;       return 0;     }     if (a == 0 && b == 0) {       cout <<  -1 ;       return 0;     }     if (a < 0 && b < 0) {       cout <<  -1 ;       return 0;     }     if (b == 0 && a > 0) {       cout <<  -1 ;       return 0;     }     if (a == b) {       cout << a;       return 0;     }     if (a > 0 && b > 0) {       if (b > a) {         cout <<  -1 ;         return 0;       } else {         int k1 = (a - b) / (2 * b);         double x1 = (double)(a - b) / (2 * k1);         int k2 = (a + b) / (2 * b);         double x2 = (double)(a + b) / (2 * k2);         cout << setprecision(10) << min(x1, x2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int fr[301][301];     int al[301];     int i, j, n;     cin >> n;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) cin >> fr[i][j];     for (i = 1; i <= n; ++i) cin >> al[i];     int k, best[301], best_time[301], cur;     for (j = 1; j <= n; ++j) {       best[j] = 301;       best_time[j] = 301;       for (i = 1; i <= n; ++i) {         if (j == 1 && i == 1) continue;         for (k = 1; k <= n; ++k)           if (al[k] <= i && al[k] != j) {             cur = al[k];             break;           }         for (k = 1; k <= n; ++k) {           if (cur == fr[j][k]) {             if (k < best[j]) {               best[j] = k;               best_time[j] = i;             }             break;           }         }       }     }     for (i = 1; i <= n; ++i) cout << best_time[i] <<   t ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 0, xi = INT_MIN, q = 0;     vector<int> v;     for (int i = 0; i < n; i++) {       int y;       cin >> y;       q = x;       v.push_back(y);       xi = max(x, v[i]);       if (x != q) x = i;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       int z = (abs(x - i) + i + x) * 2;       ans += (z * v[i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int min(int _a, int _b) { return _a < _b ? _a : _b; }   inline int max(int _a, int _b) { return _a > _b ? _a : _b; }   template <class _T>   inline void rd(_T &_a) {     int _f = 0, _ch = getchar();     _a = 0;     while (_ch <  0  || _ch >  9 ) {       if (_ch ==  - ) _f = 1;       _ch = getchar();     }     while (_ch >=  0  && _ch <=  9 ) _a = _a * 10 + _ch -  0 , _ch = getchar();     if (_f) _a = -_a;   }   const int inf = 0x3f3f3f3f;   const double eps = 1e-8;   const int mod = 1e9 + 7, N = 15;   int mp[N][N], f[N][N], ct[N], n, m, k, ans;   void dfs(int x, int y) {     if (y > m) x++, y = 1;     if (x > n) {       ans++;       ans %= mod;       return;     }     int st = f[x - 1][y] | f[x][y - 1], pre, d = -1;     if (n + m - x - y + 1 > k - __builtin_popcount(st)) return;     for (int i = 1; i <= k; i++)       if (!(st >> i - 1 & 1) && (!mp[x][y] || mp[x][y] == i)) {         f[x][y] = st | (1 << i - 1);         ct[i]++;         if (ct[i] == 1) {           if (~d)             ans += d;           else {             pre = ans;             dfs(x, y + 1);             d = ans - pre;           }         } else           dfs(x, y + 1);         ans %= mod;         ct[i]--;       }   }   int main() {     rd(n);     rd(m);     rd(k);     if (n + m - 1 > k) return puts( 0 ), 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         rd(mp[i][j]);         if (mp[i][j]) ct[mp[i][j]]++;       }     dfs(1, 1);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, n, m;   int A[100010], B[100010], L[100010];   double dis(int a, int b, int c, int d) {     return sqrt(         double((a - c + 0.0) * (a - c + 0.0) + (b - d + 0.0) * (b - d + 0.0)));   }   double getK(int y) { return 1.0 * y * a / (b * 1.0); }   int find(double xx) {     int x = xx;     return upper_bound(A, A + n, x) - A;   }   int main() {     int ll, rr, id;     double ans = 0, tmp;     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 0; i < n; i++) scanf( %d , A + i);     for (int i = 0; i < m; i++) scanf( %d , B + i);     for (int i = 0; i < m; i++) scanf( %d , L + i);     ll = rr = 0;     ans = dis(0, 0, a, A[0]) + dis(a, A[0], b, B[0]) + L[0];     for (int i = 0; i < m; i++) {       double k = getK(B[i]);       id = find(k);       id = max(0, id - 2);       for (int j = id; j < n && j <= id + 4; j++) {         tmp = dis(0, 0, a, A[j]) + dis(a, A[j], b, B[i]) + 1.0 * L[i];         if (tmp < ans) ans = tmp, ll = j, rr = i;       }     }     printf( %d %d n , ll + 1, rr + 1);   }


#include <bits/stdc++.h>   using namespace std;   long long int base(long long int n, long long int k) {     string res =   ;     long long int temp = 0, i;     while (n >= k) {       res += to_string(n % k);       n /= k;     }     res += to_string(n);     reverse(res.begin(), res.end());     for (i = 0; i < res.length(); i++) {       temp = temp * 10 + (res[i] -  0 );     }     return temp;   }   int main() {     long long int n, i, j, flag = 0;     cin >> n;     flag = 9;     for (i = 1; i <= n - 1; i++) {       for (j = 1; j <= n - 1; j++) {         cout << base(i * j, n) <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXM = 2e5 + 3, MAXN = 2e5 + 3, MAXQ = 2e5 + 3, MAXC = 2e5 + 3,             ADD = 1 << 18;   int n, m, q;   int edge_from[MAXM << 1], edge_to[MAXM << 1], edge_nex[MAXM << 1];   int cntm = 1, head[MAXN];   void link(int from, int to) {     edge_from[++cntm] = from;     edge_to[cntm] = to;     edge_nex[cntm] = head[from];     head[from] = cntm;   }   bool isb[MAXM << 1];   int edge1_to[MAXC << 1], edge1_nex[MAXC << 1];   int cntm1 = 0, head1[MAXC];   void link1(int from, int to) {     edge1_to[++cntm1] = to;     edge1_nex[cntm1] = head1[from];     head1[from] = cntm1;   }   int dfn[MAXN], low[MAXN], cntd = 0;   void tarjan(int now, int fa) {     low[now] = dfn[now] = ++cntd;     for (int i = head[now]; i; i = edge_nex[i]) {       if ((i ^ 1) == fa) continue;       if (!dfn[edge_to[i]]) {         tarjan(edge_to[i], i);         if (low[edge_to[i]] > low[now]) {           isb[i] = isb[i ^ 1] = 1;         } else {           low[now] = low[edge_to[i]];         }       } else {         low[now] = min(low[now], low[edge_to[i]]);       }     }   }   int col[MAXN], cntc = 0, Fa[MAXC][23], Deep[MAXC], cntd1 = 0;   void dfs(int now) {     col[now] = cntc;     for (int i = head[now]; i; i = edge_nex[i])       if (!col[edge_to[i]] && !isb[i]) dfs(edge_to[i]);   }   void dfs2(int now) {     for (int i = head1[now]; i; i = edge1_nex[i]) {       if (!Deep[edge1_to[i]] && edge1_to[i] != Fa[now][0]) {         Fa[edge1_to[i]][0] = now;         Deep[edge1_to[i]] = Deep[now] + 1;         dfs2(edge1_to[i]);       }     }   }   long long val1[MAXN];   long long sum1;   bool Arr[MAXN];   int ans = 1;   void dfs3(int now) {     if (!ans) return;     Arr[now] = 1;     long long in1 = sum1;     sum1 += val1[now];     for (int i = head1[now]; i; i = edge1_nex[i])       if (!Arr[edge1_to[i]] && ans) dfs3(edge1_to[i]);     in1 = sum1 - in1;     if ((in1 >> 18) && in1 - ((in1 >> 18) << 18)) ans = 0;   }   inline int lca(register int A, register int B) {     if (Deep[A] < Deep[B]) swap(A, B);     for (int i = 17; i >= 0; i--) {       if (Deep[Fa[A][i]] >= Deep[B]) A = Fa[A][i];     }     if (A == B) return A;     for (int i = 17; i >= 0; i--) {       if (Fa[A][i] != Fa[B][i]) {         A = Fa[A][i];         B = Fa[B][i];       }     }     if (Fa[A][0] == Fa[B][0] && Fa[A][0] != 0) return Fa[A][0];     return -1;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> q;     for (int i = 1, U, V; i <= m; i++) {       cin >> U >> V;       link(U, V);       link(V, U);     }     for (int i = 1; i <= n; i++)       if (!dfn[i]) tarjan(i, 0);     for (int i = 1; i <= n; i++)       if (!col[i]) {         cntc++;         dfs(i);       }     for (int i = 2; i <= cntm; i++)       if (isb[i]) link1(col[edge_from[i]], col[edge_to[i]]);     for (int i = 1; i <= cntc; i++)       if (!Deep[i]) {         Deep[i] = 1;         dfs2(i);       }     for (int i = 1; i <= 17; i++)       for (int j = 1; j <= cntc; j++) Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];     for (int i = 1, i2, i3, i4; i <= q; i++) {       cin >> i2 >> i3;       i2 = col[i2];       i3 = col[i3];       if (i2 == i3) continue;       i4 = lca(i2, i3);       if (i4 == -1) {         ans = 0;         break;       }       val1[i2] += 1;       val1[i4] -= 1;       val1[i3] += ADD;       val1[i4] -= ADD;     }     for (int i = 1; i <= cntc; i++)       if (!Arr[i]) dfs3(i);     if (ans)       cout <<  Yes ;     else       cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int adj[205][205];   int rgraph[205][205];   int n, m;   int parent[205];   bool visited[205];   int a[105];   int b[105];   bool bfs(int s, int t) {     memset(visited, 0, sizeof(visited));     queue<int> q;     q.push(s);     visited[s] = true;     parent[s] = -1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i <= 2 * n + 1; i++) {         if (!visited[i] && rgraph[u][i] > 0) {           q.push(i);           parent[i] = u;           visited[i] = true;         }       }     }     return visited[t] == true;   }   int solve(int s, int t) {     for (int i = 0; i <= 2 * n + 1; i++) {       for (int j = 0; j <= 2 * n + 1; j++) {         rgraph[i][j] = adj[i][j];       }     }     int max_flow = 0;     while (bfs(0, 2 * n + 1)) {       int path = 2000000000;       for (int i = t; i != s; i = parent[i]) {         int u = parent[i];         path = min(path, rgraph[u][i]);       }       for (int i = t; i != s; i = parent[i]) {         int u = parent[i];         rgraph[u][i] -= path;         rgraph[i][u] += path;       }       max_flow += path;     }     return max_flow;   }   int main() {     cin >> n >> m;     int suma = 0, sumb = 0;     for (int i = 1; i <= n; i++) {       cin >> a[i];       adj[0][i] = a[i];       suma += a[i];     }     for (int i = 1; i <= n; i++) {       cin >> b[i];       adj[n + i][2 * n + 1] = b[i];       sumb += b[i];       adj[i][n + i] = 1000000;     }     for (int i = 0; i < m; i++) {       int c, d;       cin >> c >> d;       adj[c][n + d] = 1000000;       adj[d][n + c] = 1000000;     }     int ans = solve(0, 2 * n + 1);     if (ans == suma && ans == sumb) {       printf( YES n );       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (rgraph[i][n + j] != 0)             printf( %d  , 1000000 - rgraph[i][n + j]);           else             printf( %d  , rgraph[i][n + j]);         }         printf(  n );       }     } else {       printf( NO n );     }   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     for (long long test = 1; test <= t; test++) {       long long n;       cin >> n;       vector<long long> a;       for (long long i = 0; i <= n - 1; i++) {         long long x;         cin >> x;         if (x != 0) a.push_back(x);       }       long long bits[61] = {0};       n = a.size();       for (long long i = 0; i <= n - 1; i++) {         long long temp = a[i];         long long j = 0;         while (temp > 0) {           if (temp & 1) bits[j]++;           temp = temp >> 1;           j++;         }       }       for (long long i = 0; i <= 60; i++)         if (bits[i] >= 3) {           cout << 3;           exit(0);         }       long long cyclec = -1;       vector<vector<long long>> adj(n);       for (long long i = 0; i < n; i++)         for (long long j = i + 1; j < n; j++)           if ((a[i] & a[j]) != 0) {             adj[i].push_back(j);             adj[j].push_back(i);           }       for (long long i = 0; i <= n - 1; i++)         if (adj[i].size() != 0) {           vector<long long> dis(n, -1);           vector<long long> par(n, -1);           queue<long long> q;           q.push(i);           dis[i] = 0;           par[i] = -1;           while (!q.empty()) {             auto x = q.front();             q.pop();             for (auto y : adj[x])               if (dis[y] == -1) {                 dis[y] = 1 + dis[x];                 par[y] = x;                 q.push(y);               } else if (y != par[x]) {                 if (cyclec == -1)                   cyclec = (dis[y] + dis[x] + 1);                 else                   cyclec = min(cyclec, dis[y] + dis[x] + 1);               }           }         }       cout << cyclec;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200001;   std::vector<long long> g[N];   long long s[N];   long long h[N];   long long a[N] = {0};   bool visited[N] = {false};   void dfs1(long long n, long long parent, long long depth) {     h[n] = depth;     for (long long v : g[n]) {       if (v != parent) {         dfs1(v, n, depth + 1);       }     }   }   void dfs2(long long n, long long parent) {     if (h[n] % 2 == 0) {       for (long long v : g[n]) {         if (v != parent) {           a[n] = s[v] - s[parent];         }       }       for (long long v : g[n]) {         if (v != parent) {           a[n] = min(s[v] - s[parent], a[n]);         }       }       s[n] = a[n] + s[parent];     } else {       a[n] = s[n] - s[parent];     }     for (long long v : g[n]) {       if (v != parent) {         dfs2(v, n);       }     }   }   int main() {     long long n;     cin >> n;     for (long long i = 2; i <= n; i++) {       long long parent;       cin >> parent;       g[parent].push_back(i);       g[i].push_back(parent);     }     for (long long i = 1; i <= n; i++) {       cin >> s[i];     }     dfs1(1, -1, 1);     a[1] = s[1];     dfs2(1, n + 1);     long long sum = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < 0) {         cout <<  -1  << endl;         return 0;       }       sum += a[i];     }     cout << sum << endl;   }


#include <bits/stdc++.h>   template <typename C>   int sz(const C &c) {     return c.size();   }   using namespace std;   int main() {     iostream::sync_with_stdio(false);     int64_t n;     cin >> n;     int k;     cin >> k;     int64_t maxV = 0;     int maxI = 1;     int64_t maxC = 0;     for (int i = 1; i <= k; ++i) {       int64_t a;       cin >> a;       if (a * (n / a) > maxV) {         maxV = a * (n / a);         maxI = i;         maxC = n / a;       }     }     cout << maxI <<     << maxC <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long a[10], rest[10];   int n, res = 1e9, pre[10], tmp, size[10], flag = 0;   vector<int> ve[10];   map<long long, long long> mp;   int count(long long x) {     if (mp[x]) return mp[x];     long long tmp = x;     long long res = 0;     for (long long i = 2; i * i <= x; i++) {       if (x % i == 0) {         while (x % i == 0) {           x /= i;           res++;         }       }     }     if (x > 1) res++;     return mp[tmp] = res;   }   bool prime(long long x) {     if (x == 2 || x == 3) return true;     for (long long i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   int isprime[10] = {0};   void cal(int now) {     tmp++;     if (size[now] == 0) {       if (!isprime[now]) tmp += count(a[now]);       return;     }     if (now) {       if (rest[now]) tmp += count(rest[now]);     }     for (int i = 0; i < size[now]; i++) {       cal(ve[now][i]);       if (flag) return;     }   }   void dfs(int pos) {     if (pos == n + 1) {       tmp = 0;       flag = 0;       for (int i = 0; i <= n; i++) {         ve[i].clear();         size[i] = 0;       }       for (int i = 1; i <= n; i++) {         size[pre[i]]++;         ve[pre[i]].push_back(i);       }       cal(0);       if (size[0] == 1) {         tmp -= 1;       }       if (flag) tmp = 1e9;       if (tmp < res) {         res = tmp;       }       return;     }     for (int i = 0; i < pos; i++) {       if (i && rest[i] % a[pos]) continue;       rest[i] = rest[i] / a[pos];       pre[pos] = i;       dfs(pos + 1);       rest[i] *= a[pos];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , a + i);     sort(a + 1, a + n + 1, greater<long long>());     for (int i = 1; i <= n; i++) {       rest[i] = a[i];       if (prime(a[i])) isprime[i] = 1;     }     dfs(1);     printf( %d n , res);   }


#include <bits/stdc++.h>   using namespace std;   int n, m, INF = 2e9;   vector<vector<int>> value;   void shift_column(int j, int k) {     vector<int> res(n);     for (int i = 0; i < n; i++) res[(i - k + n) % n] = value[i][j];     for (int i = 0; i < n; i++) value[i][j] = res[i];   }   void run() {     cin >> n >> m;     value.resize(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> value[i][j];       }     }     int ans = 0;     for (int j = 0; j < m; j++) {       map<int, int> pos;       vector<int> cnt(n);       for (int i = 0; i < n; i++) pos[1 + j + i * m] = i;       for (int i = 0; i < n; i++) {         if (pos.find(value[i][j]) == pos.end()) continue;         int shift = (i - pos[value[i][j]] + n) % n;         cnt[shift]++;       }       auto best_shift =           distance(cnt.begin(), max_element(cnt.begin(), cnt.end()));       shift_column(j, best_shift);       int best_add = INF;       for (int i = 0; i < n; i++) best_add = min(best_add, n - cnt[i] + i);       ans += best_add;     }     cout << ans;   }   signed main() {     cout.setf(ios::fixed);     cout.precision(10);     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     run();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   using namespace std;   inline void ForSpeed() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const int MAXN = int(1e5 + 5);   const int inf = 1e9 + 7;   const int MOD = 998244353;   const long long INF = (1e18 + 7);   long long b, k, a[MAXN];   int main() {     ForSpeed();     cin >> b >> k;     for (int i = 0; i < k; i++) {       cin >> a[i];     }     if (k == 1) {       if (a[0] % 2 != 0 && b % 2 != 0) {         cout <<  odd ;         return 0;       }     }     if (b % 2 == 0 && a[k - 1] % 2 == 0) {       cout <<  even ;       return 0;     } else if (b % 2 == 0 && a[k - 1] % 2 != 0) {       cout <<  odd ;       return 0;     }     long long ch = 0;     if (a[0] % 2 == 0) {       ch = 1;     }     for (int i = 1; i < k - 1; i++) {       if (ch == 0 && a[i] % 2 != 0) {         ch = 1;       } else if (ch == 1 && a[i] % 2 == 0) {         continue;       } else {         ch = 0;       }     }     if (ch == 1 && a[k - 1] % 2 == 0) {       cout <<  even ;     } else if (ch == 0 && a[k - 1] % 2 != 0) {       cout <<  even ;     } else {       cout <<  odd ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod =  1000000007;   const int LIM = 100005;   #define int long long   #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)   #define mem(a,b) memset(a,b,sizeof(a))   #define all(a) a.begin() , a.end()   #define pii pair<int,int>   #define vi vector<int>   #define endl   n    #define pb push_back   #define sp <<   <<   #define ss second   #define ff first   int power(int x, int n){       int res = 1;       while(n){             if(n&1){                   res = res * x % mod;             }             x = x * x % mod;             n>>=1;       }       return (res%mod);   }   /*bool prime[1000006];   void sieve(int n)   {         memset(prime, true, sizeof(prime));         int rootn = (int)sqrt(n);         for (int p = 2; p <= rootn; p++)               if(prime[p] == true)                     for(int i = p*p; i <= n; i += p)                           prime[i] = false;         prime[1] = 0;      }*/   /*   int fac[300005];   int ncr(int n,int r)   {         return fac[n]*((power(fac[n-r], mod-2)*power(fac[r], mod-2))%mod)%mod;   }   */   bool check(int a[],int n)   {    for(int i=1;i<n;i++)    {     if(a[i]<a[i-1])return false;    }    return true;   }      int32_t main()   {     IOS;     int tt=1,n,x,k,y,z,i,j;     cin>>tt;     while(tt--){       cin>>n>>x;     int a[n];     for(int i=0;i<n;i++)     {      cin>>a[i];     }     int ans=0;     for(int i=0;i<=n;i++)     {      if(check(a,n))break;      ans++;      for(int j=0;j<n;j++)      {       if(a[j]>x)       {        swap(a[j],x);        break;       }      }     }     if(check(a,n))cout<<ans<<endl;     else cout<<-1<<endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  RDLU ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int &x, int y, int mod = 1000000007) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et() {     puts( -1 );     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) {     long long z = y;     while (x % y != 0) {       z = x % y;       x = y;       y = z;     }     return z;   }   int h, u[100005], dp[100005];   vector<int> mp[100005];   set<pair<int, int> > cs;   void add(int x, int y) {     if (cs.count({x, y})) return;     cs.insert({x, y});     mp[x].push_back(y);   }   int dfn[100005], sta[100005], low[100005], color, ii, cnt, belong[100005];   bool ins[100005];   int sz[100005];   void tarjan(int x) {     dfn[x] = low[x] = ++ii;     sta[++cnt] = x;     ins[x] = 1;     for (auto child : mp[x]) {       if (!dfn[child]) {         tarjan(child);         low[x] = min(low[x], low[child]);       } else if (ins[child]) {         low[x] = min(low[x], dfn[child]);       }     }     if (dfn[x] == low[x]) {       ++color;       int t;       do {         t = sta[cnt];         cnt--;         ins[t] = 0;         belong[t] = color;         sz[color]++;       } while (dfn[t] != low[t]);     }   }   bool del[100005];   void fmain(int ID) {     scanf( %d%d%d , &n, &m, &h);     for (int(i) = 1; (i) <= (int)(n); (i)++) {       scanf( %d , u + i);     }     for (int(i) = 1; (i) <= (int)(m); (i)++) {       int x, y;       scanf( %d%d , &x, &y);       if ((u[x] + 1) % h == u[y]) add(x, y);       if ((u[y] + 1) % h == u[x]) add(y, x);     }     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (belong[i] == 0) tarjan(i);     for (auto p : cs) {       int x = belong[p.first], y = belong[p.second];       if (x == y) continue;       del[x] = 1;     }     int ans = -1;     for (int(i) = 1; (i) <= (int)(color); (i)++)       if (!del[i]) {         if (ans == -1 || sz[ans] > sz[i]) ans = i;       }     printf( %d n , sz[ans]);     for (int(i) = 1; (i) <= (int)(n); (i)++)       if (belong[i] == ans) printf( %d  , i);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, V = 1e5;   inline int read() {     register int x = 0, f = 0;     register char c = getchar();     while (c <  0  || c >  9 ) f |= c ==  - , c = getchar();     while (c >=  0  && c <=  9 ) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return f ? -x : x;   }   int n, tot, top;   struct point {     int x, y;   } p[N * 10], s[N * 10];   point operator-(const point &A, const point &B) {     return (point){A.x - B.x, A.y - B.y};   }   inline void add(int x, int y) {     p[++tot].x = x;     p[tot].y = y;   }   inline double accross(point A, point B) {     return (double)A.x * B.y - (double)A.y * B.x;   }   inline double dis(point A, point B) {     return (double)(A.x - B.x) * (A.x - B.x) + (double)(A.y - B.y) * (A.y - B.y);   }   inline bool cmp1(const point &A, const point &B) {     return A.x == B.x ? A.y < B.y : A.x < B.x;   }   inline bool cmp2(const point &A, const point &B) {     return A.x == B.x && A.y == B.y;   }   inline bool cmp3(const point &A, const point &B) {     double res = accross(A - p[1], B - p[1]);     if (res > 0)       return true;     else if (res == 0 && dis(A, p[1]) < dis(B, p[1]))       return true;     return false;   }   void Get_TB() {     for (int i = 2; i <= tot; ++i)       if (p[1].y > p[i].y || (p[1].y == p[i].y && p[1].x > p[i].x))         swap(p[i], p[1]);     sort(p + 2, p + tot + 1, cmp3);     s[1] = p[1];     s[2] = p[2];     top = 2;     for (int i = 3; i <= tot; ++i) {       while (top > 1 && accross(p[i] - s[top - 1], s[top] - s[top - 1]) >= 0)         top--;       s[++top] = p[i];     }     return;   }   inline double len(point &A) {     return sqrt((double)A.x * A.x + (double)A.y * A.y);   }   double calc(point A, point B, point C) {     point x = A - B, y = C - B, z = C - A;     double res = len(x) * len(y) * len(z) / (accross(y, x) * 2);     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       int x = read(), y = read(), v = read();       if (x < v)         add(0, min(V, y + v - x)), add(0, max(0, y - v + x));       else         add(x - v, y);       if (y < v)         add(max(0, x - v + y), 0), add(min(V, x + v - y), 0);       else         add(x, y - v);       if (x + v > V)         add(V, min(V, y + x + v - V)), add(V, max(0, y - x - v + V));       else         add(x + v, y);       if (y + v > V)         add(min(V, x + y + v - V), V), add(max(0, x - y - v + V), V);       else         add(x, y + v);     }     sort(p + 1, p + 1 + tot, cmp1);     tot = unique(p + 1, p + 1 + tot, cmp2) - p - 1;     Get_TB();     int id = 0;     double ans = -1e9, tmp;     s[0] = s[top];     s[top + 1] = s[1];     for (int i = 1; i <= top; ++i) {       point a = s[i - 1], b = s[i], c = s[i + 1];       if ((tmp = calc(a, b, c)) > ans) ans = tmp, id = i;     }     cout << s[id - 1].x <<     << s[id - 1].y <<   n ;     cout << s[id].x <<     << s[id].y <<   n ;     cout << s[id + 1].x <<     << s[id + 1].y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init() { freopen( input.txt ,  r , stdin); }   int abs(int x) {     if (x < 0) {       return -x;     }     return x;   }   int main() {     int n, m, x1, y1, x2, y2;     cin >> n >> m >> x1 >> y1 >> x2 >> y2;     n = abs(x1 - x2) + 1;     m = abs(y1 - y2) + 1;     if ((n >= 6) || (m >= 6)) {       cout <<  Second ;       return 0;     }     if ((n <= 4) && (m <= 4)) {       cout <<  First ;       return 0;     }     if (((n == 5) || (n == 4)) && ((m == 5) || (m == 4))) {       cout <<  Second ;       return 0;     }     cout <<  First  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(long long a, int b) {     if (a < b) {       return gcd(b, a);     }     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   class Triplet {    public:     long long gcd;     long long x;     long long y;   };   Triplet gcdExtendedEuclid(int a, int b) {     if (b == 0) {       Triplet myAns;       myAns.gcd = a;       myAns.x = 1;       myAns.y = 0;       return myAns;     }     Triplet smallAns = gcdExtendedEuclid(b, a % b);     Triplet myAns;     myAns.gcd = smallAns.gcd;     myAns.x = smallAns.y;     myAns.y = (smallAns.x - ((a / b) * (smallAns.y)));     return myAns;   }   long long modInverse(int A, int M) {     Triplet ans = gcdExtendedEuclid(A, M);     return ans.x;   }   bool check(vector<long long>& v1, long long val, long long h) {     long long ans = 0;     for (long long i = 0; i < v1.size(); i++) {       ans += v1[i] / val;       if (v1[i] % val != 0) {         ans += 1;       }     }     if (ans > h) {       return false;     }     return true;   }   void multiply(long long A[2][2], long long M[2][2]) {     long long firstValue = (A[0][0] * M[0][0] + A[0][1] * M[1][0]) % 1000000007;     long long secondValue = (A[0][0] * M[0][1] + A[0][1] * M[1][1]) % 1000000007;     long long thirdValue = (A[1][0] * M[0][0] + A[1][1] * M[1][0]) % 1000000007;     long long fourthValue = (A[1][0] * M[0][1] + A[1][1] * M[1][1]) % 1000000007;     A[0][0] = firstValue;     A[0][1] = secondValue;     A[1][0] = thirdValue;     A[1][1] = fourthValue;     return;   }   void getpow(long long A[2][2], long long n) {     if (n == 0 || n == 1) {       return;     }     getpow(A, n / 2);     multiply(A, A);     if (n % 2 != 0) {       long long first[2][2] = {{1, 1}, {1, 0}};       multiply(A, first);     }     return;   }   long long getpow1(long long n, long long m, long long b) {     if (m == 0) {       return 1;     }     long long ans = getpow1(n, m / 2, b) % b;     ans = (ans * ans) % b;     if (m % 2 != 0) {       ans = ans * n % b;     }     return ans % b;   }   long long getfib(long long n) {     if (n == 0) {       return 0;     }     long long A[2][2] = {{1, 1}, {1, 0}};     getpow(A, n);     long long first[1][2];     first[0][0] = 0;     first[0][1] = 1;     long long ans = first[0][0] * A[0][0] + first[0][1] * A[1][0];     return ans % 1000000007;   }   vector<long long>* sieve() {     bool isprime[1000001];     for (long long i = 0; i < 1000001; i++) {       isprime[i] = true;     }     vector<long long>* primes = new vector<long long>();     for (long long i = 2; i < 1000001; i++) {       if (isprime[i] == true) {         for (long long j = 2 * i; j < 1000001; j += i) {           isprime[j] = false;         }       }     }     primes->push_back(2);     for (long long i = 3; i < 1000001; i++) {       if (isprime[i] == true) {         primes->push_back(i);       }     }     return primes;   }   long long getpow2(long long a, string& b, long long m) {     long long mod = 1000000007;     long long num = 1;     for (long long i = b.size() - 1; i >= 0; i--) {       if (b[i] == 1) {         num = (num * a) % m;       } else if (b[i] == 2) {         num = ((num * a) % m * a) % m;       }       a = ((a * a) % m * a) % m;     }     return num % m;   }   long long arr[5000001];   long long res[1000001];   long long res1[1000001];   int main() {     long long k, n;     cin >> k >> n;     long long num = 0;     long long k1 = k;     while (k1 < n) {       k1 *= k;       num++;     }     if (k1 == n) {       cout <<  YES  <<   n ;       cout << num;       return 0;     }     cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   const long long mod = (long long)1e9 + 7;   const int maxn = (int)1e5 + 1;   long long inf = 1LL << 60;   using namespace std;   inline void read(int &n) {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10 * x + ch -  0 ;       ch = getchar();     }     n = x * f;   }   inline void read(long long &n) {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = 10ll * x + ch -  0 ;       ch = getchar();     }     n = x * f;   }   int a[20];   int rule[20][20];   long long dp[1 << 19][19];   int bitCount(int n) {     int count = 0;     while (n) {       count++;       n &= (n - 1);     }     return count;   }   int main() {     setlocale(LC_ALL,  Russian );     ios_base::sync_with_stdio(0);     int n, m, k;     cin >> n >> m >> k;     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < k; i++) {       int u, v, d;       cin >> u >> v >> d;       u--, v--;       rule[u][v] = d;     }     for (int i = 0; i < n; i++) dp[1 << i][i] = a[i];     for (int mask = 0; mask < 1 << n; mask++) {       for (int i = 0; i < n; i++) {         if (mask & (1 << i)) {           for (int j = 0; j < n; j++) {             if (!(mask & (1 << j))) {               int nmask = mask | (1 << j);               dp[nmask][j] = max(dp[nmask][j], dp[mask][i] + a[j] + rule[i][j]);             }           }         }       }     }     for (int mask = 0; mask < 1 << n; mask++) {       for (int i = 0; i < n; i++) {         if (bitCount(mask) == m) {           ans = max(ans, dp[mask][i]);         }       }     }     cout << ans;     return 0;   }