#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1E-15;   const int inf = int(1e9) + 7;   const int maxN = 1000 + 5;   int in[maxN], to[maxN], cs[maxN];   int n, m;   int main() {     scanf( %d%d , &n, &m);     int a, b, c;     for (int(i) = 0; (i) < (m); ++(i)) {       scanf( %d%d%d , &a, &b, &c);       to[a] = b;       in[b] = 1;       cs[a] = c;     }     int tot = 0;     for (int(i) = (1); (i) < (n + 1); ++(i))       if (in[i] == 0 && to[i] != 0) tot++;     printf( %d n , tot);     for (int(i) = (1); (i) < (n + 1); ++(i))       if (in[i] == 0 && to[i] != 0) {         int x = i, ans = inf;         while (to[x]) {           ans = min(ans, cs[x]);           x = to[x];         }         printf( %d %d %d n , i, x, ans);       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6001;   int n, m, k, a, b, x[N], y[N], z[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) scanf( %d , &y[i]);     scanf( %d , &k);     for (int i = 1; i <= k; i++) scanf( %d , &z[i]);     scanf( %d%d , &a, &b);     sort(x + 1, x + 1 + n);     sort(y + 1, y + 1 + m);     sort(z + 1, z + 1 + k);     double p2 = z[1];     double r1 = x[n];     double res = 0;     for (int i = 1; i <= m; i++) {       double p1 = y[i];       double cur = (p1 * b * r1 * r1) / (p1 * b + p2 * a);       cur = sqrt(cur);       if (cur - res > 1e-6) res = cur;     }     printf( %.7f n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const MAX_N = 1e5 + 10;   int n, p, l[MAX_N], r[MAX_N];   int get_count(int l, int r) {     int ans = 0;     if (l % p == 0) ++ans;     l -= l % p;     r -= r % p;     ans += (r - l) / p;     return ans;   }   double get_prob(int a, int b) {     long long count = 0;     count +=         1LL * get_count(l[a], r[a]) * (r[b] - l[b] + 1 - get_count(l[b], r[b]));     count +=         1LL * get_count(l[b], r[b]) * (r[a] - l[a] + 1 - get_count(l[a], r[a]));     count += 1LL * get_count(l[a], r[a]) * get_count(l[b], r[b]);     return count * 1.0 / (1LL * (r[a] - l[a] + 1) * (r[b] - l[b] + 1));   }   int main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(12);     cin >> n >> p;     for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];     double ret = 0;     for (int i = 0; i < n; ++i) {       int j = (i + 1) % n;       ret += 2000.0 * get_prob(i, j);     }     cout << ret << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     long double u;     cin >> n >> u;     vector<long double> e(n);     for (int i = 0; i < n; i++) cin >> e[i];     long double ans = 0;     bool fl = 0;     for (int i = 2; i < n; i++) {       if (e[i] - e[i - 2] <= u) fl = 1;     }     if (!fl) {       cout <<  -1  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       int tmp = upper_bound(e.begin(), e.end(), e[i] + u) - e.begin() - 1;       if (tmp - i < 2) continue;       ans = max(ans, (e[tmp] - e[i + 1]) / (e[tmp] - e[i]));     }     cout << fixed << setprecision(13) << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, e[10][10] = {}, a, b;     scanf( %d , &m);     while (m--) {       scanf( %d%d , &a, &b);       e[a][b] = e[b][a] = 1;     }     for (int i = 1; i <= 5; i++)       for (int j = i + 1; j <= 5; j++)         for (int k = j + 1; k <= 5; k++)           if (e[i][j] == e[j][k] && e[j][k] == e[k][i]) {             puts( WIN );             return 0;           }     puts( FAIL );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   struct node {     long long x, y;   } po[100000];   inline long long dis(node a, node b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   bool cmp(const node &a, const node &b) {     return (a.y == b.y ? a.x < b.x : a.y < b.y);   }   long long solve(long long ll, long long rr) {     if (ll == rr) return (long long)2e18;     if (ll + 1 == rr) return dis(po[ll], po[rr]);     if (ll + 2 == rr)       return min(dis(po[ll], po[rr]),                  min(dis(po[ll], po[ll + 1]), dis(po[ll + 1], po[rr])));     long long mid = (ll + rr) >> 1;     long long res = min(solve(ll, mid), solve(mid + 1, rr));     sort(po + ll, po + rr + 1, cmp);     for (long long i = ll; i <= rr; ++i) {       for (long long j = i + 1; j <= rr && j <= i + 8; ++j)         res = min(res, dis(po[i], po[j]));     }     return res;   }   int main() {     scanf( %I64d , &n);     for (long long i = 1; i <= n; ++i)       scanf( %I64d , &po[i].y), po[i].y += po[i - 1].y, po[i].x = i;     printf( %I64d n , solve(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   template <class T>   T gcd(T a, T b) {     return !b ? a : gcd(b, a % b);   }   template <class T>   inline void cmin(T &x, T y) {     x = x < y ? x : y;   }   template <class T>   inline void cmax(T &x, T y) {     x = x > y ? x : y;   }   const int N = 100010;   int n, q, head[N], nxt[N], v[N], cnt, son[N], top[N], si[N], wp[N], totw, id[N],       fa[N];   inline void add(int x, int y) {     nxt[++cnt] = head[x];     head[x] = cnt;     v[cnt] = y;   }   struct seg {     int l, r, sum, sufma, al;   } t[N << 2];   void dfs(int now) {     int mx = -1;     si[now] = 1;     for (register int i = head[now]; i; i = nxt[i]) {       dfs(v[i]);       si[now] += si[v[i]];       if (si[v[i]] > mx) son[now] = v[i];     }   }   void _dfs(int now, int tf) {     top[now] = tf;     wp[now] = ++totw;     id[totw] = now;     if (!son[now]) return;     _dfs(son[now], tf);     for (register int i = head[now]; i; i = nxt[i]) {       if (son[now] != v[i]) _dfs(v[i], v[i]);     }   }   void merge(seg &a, seg b, seg c) {     a.sum = b.sum + c.sum;     a.sufma = max(c.sufma, c.sum + b.sufma);   }   void build(int p, int l, int r) {     t[p].l = l;     t[p].r = r;     if (l == r) {       t[p].sum = t[p].sufma = -1;       return;     }     int mid = (l + r) >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     merge(t[p], t[p << 1], t[p << 1 | 1]);   }   void pushdown(int p) {     if (t[p].al != 0) {       t[p << 1].al = t[p << 1 | 1].al = t[p].al;       t[p << 1].sum = (t[p << 1].r - t[p << 1].l + 1) * t[p << 1].al;       t[p << 1 | 1].sum =           (t[p << 1 | 1].r - t[p << 1 | 1].l + 1) * t[p << 1 | 1].al;       t[p << 1].sufma = t[p << 1 | 1].sufma = -1;       t[p].al = 0;     }   }   void change(int p, int x, int dt) {     if (t[p].l == t[p].r) {       t[p].sufma += dt;       t[p].sum += dt;       return;     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     if (x <= mid)       change(p << 1, x, dt);     else       change(p << 1 | 1, x, dt);     merge(t[p], t[p << 1], t[p << 1 | 1]);   }   void modify(int p, int l, int r, int dt) {     if (t[p].l >= l && t[p].r <= r) {       t[p].al = dt;       t[p].sum = (t[p].r - t[p].l + 1) * t[p].al;       t[p].sufma = -1;       return;     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     if (l <= mid) modify(p << 1, l, r, dt);     if (r > mid) modify(p << 1 | 1, l, r, dt);     merge(t[p], t[p << 1], t[p << 1 | 1]);   }   seg maxsuf(int p, int l, int r) {     if (t[p].l >= l && t[p].r <= r) {       return t[p];     }     pushdown(p);     int mid = (t[p].l + t[p].r) >> 1;     if (r <= mid) return maxsuf(p << 1, l, r);     if (l > mid) return maxsuf(p << 1 | 1, l, r);     seg tmp;     merge(tmp, maxsuf(p << 1, l, r), maxsuf(p << 1 | 1, l, r));     return tmp;   }   int query(int x) {     seg res = maxsuf(1, wp[top[x]], wp[x]);     x = fa[top[x]];     while (x) {       merge(res, maxsuf(1, wp[top[x]], wp[x]), res);       x = fa[top[x]];     }     return res.sufma;   }   int main() {     read(n);     read(q);     for (register int i = (2); i <= (n); i++) {       read(fa[i]);       add(fa[i], i);     }     dfs(1);     _dfs(1, 1);     build(1, 1, n);     for (register int i = (1); i <= (q); i++) {       int opt, x;       read(opt);       read(x);       if (opt == 1) {         change(1, wp[x], 1);       } else if (opt == 2) {         modify(1, wp[x], wp[x] + si[x] - 1, -1);         change(1, wp[x], -(query(x) + 1));       } else {         if (query(x) >= 0) {           printf( black n );         } else {           printf( white n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char c[200010];   int main() {     int n;     while (scanf( %d , &n) != EOF) {       memset(c, 0, sizeof c);       scanf( %s , c);       int ans = 0;       for (int i = 0; i < n; i++) {         if (c[i] ==  < )           ans++;         else           break;       }       for (int i = n - 1; i >= 0; i--) {         if (c[i] ==  > )           ans++;         else           break;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int a[N];   int z[2][N][N];   int main() {     int n, bl, bugs, md;     scanf( %d %d %d %d , &n, &bl, &bugs, &md);     for (int i = 0; i < int(n); i++) scanf( %d , &a[i]);     z[0][0][0] = 1;     for (int it = 1; it <= n; it++) {       int i = it & 1;       for (int j = 0; j <= bl; j++) {         for (int k = 0; k <= bugs; k++) {           z[i][j][k] = z[i ^ 1][j][k];           if (j > 0 && k >= a[it - 1]) z[i][j][k] += z[i][j - 1][k - a[it - 1]];           z[i][j][k] %= md;         }       }     }     int ans = 0;     for (int i = 0; i <= bugs; i++) {       ans += z[n & 1][bl][i];       ans %= md;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( omit-frame-pointer )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <class T>   void debug(vector<T> vec) {     for (int i = 0; i < vec.size(); i++) cerr << vec[i] <<    ;     cerr <<   n ;   }   template <class T>   void debug(vector<vector<T> > vec) {     for (int i = 0; i < vec.size(); i++) {       for (int ii = 0; ii < vec[i].size(); ii++) cerr << vec[i][ii] <<    ;       cerr <<   n ;     }   }   void solve() {     int T;     int i;     cin >> T;     for (int i = 0; i < T; i++) {       int n;       string s;       cin >> n;       cin >> s;       if (s.size() == 1) {         cout <<  YES               <<   n ;         continue;       } else if (s.size() == 2) {         if (abs(s[0] - s[1]) > 2 || abs(s[0] - s[1]) == 1)           cout <<  NO                 <<   n ;         else           cout <<  YES                 <<   n ;         continue;       }       int x;       bool possible = true;       for (int x = 0; x < n / 2; x++) {         if (abs(s[x] - s[n - x - 1]) > 2 || abs(s[x] - s[n - x - 1]) == 1) {           possible = false;           cout <<  NO                 <<   n ;           break;         }       }       if (possible == true)         cout <<  YES               <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     cin.tie(NULL);     int testcases = 1;     while (testcases-- != 0) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1E-9;   int cnt;   double a, b, m, vx, vy, vz, t, f;   double ansx, ansz;   int main() {     scanf( %lf%lf%lf , &a, &b, &m);     scanf( %lf%lf%lf , &vx, &vy, &vz);     t = -m / vy;     ansx = a / 2 + t * vx;     ansz = t * vz;     while (ansx < 0) ansx += a;     while (ansz < 0) ansz += b;     while (ansx + eps > a) ansx -= a;     while (ansz + eps > b) ansz -= b;     cnt = (int)(fabs(t / (b / vz)) + eps);     if (cnt % 2) ansz = b - ansz;     cnt = 0;     if (t + eps > fabs((a / 2) / vx)) {       cnt = 1;       t -= fabs(a / 2 / vx);     }     cnt += (int)(fabs(t / (a / vx)) + eps);     if (cnt % 2) ansx = a - ansx;     printf( %.10lf %.10lf n , ansx, ansz);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T& first) {     return first * first;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 5e-12;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void input(int& a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = 10 * a + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(int a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[10];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   char can[8][8];   bool check(const vector<int>& a) {     for (int i : a)       for (int j : a)         if (!can[i][j]) return false;     return true;   }   int main() {     long long n;     cin >> n;     long long tri = 1;     while (n % tri == 0) tri *= 3;     cout << (n + tri - 1) / tri << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const double eps = 1e-12;   const double PI = acos(-1.0);   const int mod = 998244353;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int ar[100050];   void solve() {     int n, k;     cin >> n >> k;     bool exi = false, gp = false;     for (int i = 1; i <= n; i++) {       cin >> ar[i];       if (ar[i] == k) exi = true;     }     for (int i = 1; i < n; i++) {       if (ar[i] >= k && (ar[i + 1] >= k || i < n - 1 && ar[i + 2] >= k)) {         gp = true;         break;       }     }     if (n == 1 && ar[1] == k || exi && gp)       cout <<  yes n ;     else       cout <<  no n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     for (int t = 1; t <= T; t++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   vector<long long int> prime;   void sieve(long long int n) {     bool bakh[n + 1];     memset(bakh, true, sizeof(bakh));     for (long long int p = 2; p * p <= n; p++) {       if (bakh[p] == true) {         for (long long int i = p * p; i <= n; i += p) bakh[i] = false;       }     }     for (long long int p = 2; p <= n; p++)       if (bakh[p]) prime.push_back(p);   }   long long int eulertotient(long long int z) {     long long int fac = z;     for (long long int i = 0; prime[i] * prime[i] <= z; i++) {       if (z % prime[i] == 0) {         fac -= (fac / prime[i]);         while (z % prime[i] == 0) z /= prime[i];       }     }     if (z > 1) fac -= (fac / z);     return fac;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int lcm(long long int a, long long int b) {     long long int g = gcd(a, b);     long long int ans = (a * b) / g;     return ans;   }   long long int modInverse(long long int a, long long int m) {     long long int hvf = gcd(a, m);     if (hvf == 1) return power(a, m - 2, m);     return -1;   }   void multiply(long long int F[2][2], long long int M[2][2]) {     long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0];     long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1];     long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0];     long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1];     F[0][0] = x;     F[0][1] = y;     F[1][0] = z;     F[1][1] = w;   }   void powermat(long long int F[2][2], long long int n) {     if (n == 0 || n == 1) return;     long long int M[2][2] = {{1, 1}, {1, 0}};     powermat(F, n / 2);     multiply(F, F);     if (n % 2 != 0) multiply(F, M);   }   long long int fib(long long int n) {     long long int F[2][2] = {{1, 1}, {1, 0}};     if (n == 0) return 0;     powermat(F, n - 1);     return F[0][0];   }   vector<long long int> merge(vector<long long int> v1,                               vector<long long int> v2) {     vector<long long int> temp;     long long int i = 0, j = 0;     while (i < v1.size() && j < v2.size()) {       if (v1[i] < v2[j])         temp.push_back(v1[i]), i++;       else         temp.push_back(v2[j]), j++;     }     while (i < v1.size()) temp.push_back(v1[i]), i++;     while (j < v2.size()) temp.push_back(v2[j]), j++;     return temp;   }   long long int mp[2][300005], n;   long long int ar[2][300005], dp[2][300005], pre[2][300005];   long long int fun(long long int id, long long int curr) {     if (id == n + 1) return 0;     if (mp[curr][id] != -1) return mp[curr][id];     long long int t = 2 * (id - 1), a = 0;     if (id % 2 == 1) {       if (curr == 0)         a = max(ar[curr][id] * t + fun(id, 1), dp[curr][id] + t * pre[curr][id]);       else         a = ((t + 1) * ar[curr][id]) + fun(id + 1, curr);     } else {       if (curr == 1)         a = max(ar[curr][id] * t + fun(id, 0),                 dp[curr][id] + t * (pre[curr][id]));       else         a = (ar[curr][id] * (t + 1)) + fun(id + 1, curr);     }     return mp[curr][id] = a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n;     for (long long int i = 1; i <= n; i++) cin >> ar[0][i];     for (long long int i = 1; i <= n; i++) cin >> ar[1][i];     memset(dp, 0, sizeof(dp));     memset(pre, 0, sizeof(pre));     for (long long int i = n; i >= 1; i--) {       dp[0][i] = dp[0][i + 1] + pre[0][i + 1] + ar[1][i] * (2 * (n - i + 1) - 1);       dp[1][i] = dp[1][i + 1] + pre[1][i + 1] + ar[0][i] * (2 * (n - i + 1) - 1);       pre[0][i] = pre[0][i + 1] + ar[0][i] + ar[1][i];       pre[1][i] = pre[1][i + 1] + ar[0][i] + ar[1][i];     }     memset(mp, -1, sizeof(mp));     long long int ans = fun(1, 0);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5255;   long long n, m;   long long a[N], b[N];   long long ans[N], rec[N];   inline long long gt(long long u) {     long long flg = u < 0 ? -1 : 1;     u = u * flg;     for (long long i = 2; i * i <= u; ++i) {       while (u % (i * i) == 0) u = u / (i * i);     }     return u * flg;   }   signed main() {     cin >> n;     for (long long i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       a[i] = b[i] = gt(a[i]);     }     sort(b + 1, b + n + 1);     m = unique(b + 1, b + n + 1) - b - 1;     for (long long i = 1; i <= n; ++i) {       if (a[i] != 0) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b + 1;     }     for (long long i = 1; i <= n; ++i) {       long long cnt = 0;       bool flag = 1;       memset(rec, 0, sizeof(rec));       for (long long j = i; j <= n; ++j) {         if (flag == 0) {           if (a[j] == 0)             ;           else {             if (rec[a[j]] == 0) cnt++;           }         } else {           if (i == j) {             if (a[j] != 0)               flag = 0, cnt++;             else               cnt++;           } else {             if (a[j] != 0)               flag = 0;             else               ;           }         }         rec[a[j]] = 1;         ans[cnt]++;       }     }     for (long long i = 1; i <= n; ++i) {       printf( %lld  , ans[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200000 + 10;   const long long M = 1000000 + 10;   const long long INF = (long long)1e9 + 10;   long long n, m;   long long tl[N], tr[N];   map<long long, long long> toX;   pair<long long, long long> a[N];   pair<pair<long long, long long>, pair<long long, int> > b[N];   long long preMax[M], sufMin[M], midMax[M];   long long queryMax(long long *c, long long p) {     long long ret = 0;     for (p++; p; p -= p & -p) {       ret = max(ret, c[p]);     }     return ret;   }   long long queryMin(long long p) {     long long ret = INF;     for (p++; p; p -= p & -p) {       ret = min(ret, sufMin[p]);     }     return ret;   }   void addMax(long long *c, long long p, long long value) {     for (p++; p < M; p += p & -p) {       c[p] = max(c[p], value);     }   }   void addMin(long long p, long long value) {     for (p++; p < M; p += p & -p) {       sufMin[p] = min(sufMin[p], value);     }   }   void solve() {     cin >> n >> m;     vector<long long> values;     for (long long i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       tl[i] = x;       tr[i] = y;       a[i].first = x;       a[i].second = y;       values.push_back(a[i].first);       values.push_back(a[i].second);     }     for (long long i = 0; i < m; ++i) {       int x, y, d;       scanf( %d%d%d , &x, &y, &d);       b[i].first.first = x;       b[i].first.second = y;       b[i].second.first = d;       b[i].second.second = i;       values.push_back(b[i].first.first);       values.push_back(b[i].first.second);     }     sort(values.begin(), values.end());     values.erase(unique(values.begin(), values.end()), values.end());     for (long long i = 0; i < values.size(); ++i) {       toX[values[i]] = i;     }     fill(preMax, preMax + M, -1);     fill(sufMin, sufMin + M, INF);     fill(midMax, midMax + M, 0);     for (long long i = 0; i < n; ++i) {       long long l = toX[a[i].first];       long long r = toX[a[i].second];       addMax(preMax, l, a[i].second);       addMin(M - r - 100, a[i].first);     }     sort(a, a + n);     sort(b, b + m);     long long ret = 0;     long long ptr = n - 1;     int rc = -1, rcc;     for (long long i = m - 1; i >= 0; --i) {       for (; ptr >= 0 && a[ptr].first >= b[i].first.first; ptr--) {         addMax(midMax, toX[a[ptr].second], a[ptr].second - a[ptr].first);       }       long long maxLen = 0;       maxLen = queryMax(midMax, toX[b[i].first.second]);       maxLen =           max(maxLen, queryMax(preMax, toX[b[i].first.first]) - b[i].first.first);       maxLen = max(           maxLen, b[i].first.second - queryMin(M - toX[b[i].first.second] - 100));       maxLen = min(maxLen, b[i].first.second - b[i].first.first);       if (ret < maxLen * b[i].second.first) {         ret = maxLen * b[i].second.first;         rc = b[i].second.second;         rcc = i;       }     }     cout << ret << endl;     if (ret == 0) {       return;     }     for (int i = 0; i < n; ++i) {       long long nl = max(tl[i], b[rcc].first.first);       long long nr = min(tr[i], b[rcc].first.second);       if (nl > nr) continue;       if ((nr - nl) * b[rcc].second.first == ret) {         cout << i + 1 <<     << rc + 1 << endl;         return;       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d;     cin >> n >> d;     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       if (x + y - d >= 0 && x - y - d <= 0 && x - y + d >= 0 &&           x + y - 2 * n + d <= 0) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T = 1;     while (T--) {       long long a, b, s;       cin >> a >> b >> s;       s = s - abs(a) - abs(b);       if (s % 2 == 0 && s >= 0)         cout <<  Yes ;       else         cout <<  No ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long quickpow(long long x, long long y) {     long long res = 1;     for (; y; y >>= 1, x *= x, x %= 1000003)       if (y & 1) res *= x, res %= 1000003;     return res;   }   int main() {     scanf( %I64d %I64d , &n, &k);     if (n < 62 && k > (1LL << n))       printf(  1 1 n );     else {       long long A = 1, t = quickpow(2, n), cnt = n;       for (int y = 1; y < 62; y++) cnt += (k - 1) / (1LL << y);       if (k < 1000003) {         for (long long i = 1; i <= k; i++)           A = A * (t - i + 1000003 + 1) % 1000003;         A = A * quickpow(quickpow(2, 1000003 - 2), cnt) % 1000003;       } else         A = 0;       long long B = quickpow(quickpow(2, n), k) *                     quickpow(quickpow(2, 1000003 - 2), cnt) % 1000003;       printf( %I64d %I64d n , (B - A + 1000003) % 1000003, B);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int x[100005], y[100005], num_, num;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       if (x[i] > 0) {         num++;       } else {         num_++;       }     }     if (num == 1 || num_ == 1 || num == 0 || num_ == 0) {       cout <<  Yes  << endl;       return 0;     } else {       cout <<  No  << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   int _runtimeTerror_() {     long long n;     cin >> n;     long long i, a[n], b[n];     for (i = 0; i < n; ++i) cin >> a[i];     for (i = 0; i < n; ++i) cin >> b[i];     long long ans = 0;     long long arr[n];     for (i = 0; i < n; ++i) {       arr[i] = a[i] * (i + 1) * (n - i);     }     sort(arr, arr + n, greater<long long>());     sort(b, b + n);     for (i = 0; i < n; ++i) {       ans += (b[i] * (arr[i] % 998244353)) % 998244353;       ans %= 998244353;     }     cout << ans <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) _runtimeTerror_();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f(long long n) {     long long t = n;     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) {         t = t / i * (i - 1);         while (n % i == 0) n /= i;       }     if (n > 1) t = t / n * (n - 1);     return t;   }   int main() {     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= k && n > 1; i += 2) n = f(n);     printf( %I64d n , n % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string parse(string str) {     string returnme;     for (int i = 0; i < str.length(); i++) {       if (str[i] ==  _  || str[i] ==  ;  || str[i] ==  - ) {       } else {         returnme.push_back(tolower(str[i]));       }     }     return returnme;   }   int main() {     string con1, con2, con3;     cin >> con1 >> con2 >> con3;     con1 = parse(con1);     con2 = parse(con2);     con3 = parse(con3);     int n;     cin >> n;     vector<string> con;     con.push_back(con1 + con2 + con3);     con.push_back(con1 + con3 + con2);     con.push_back(con3 + con2 + con1);     con.push_back(con2 + con3 + con1);     con.push_back(con2 + con1 + con3);     con.push_back(con3 + con1 + con2);     for (int i = 0; i < n; i++) {       string str;       cin >> str;       str = parse(str);       bool acc = false;       for (int j = 0; j < 6; j++) {         if (str == con[j]) {           cout <<  ACC  << endl;           acc = true;           break;         }       }       if (acc == false) {         cout <<  WA  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int foot = 0;     int inch = 0;     int q, o;     if (n < 35) {       if (n == 2) {         inch++;       } else         for (int e = 1; e < n; e = e + 3) {           inch++;         }     } else if (n == 35 || n == 36) {       foot++;     } else if (n > 36) {       if (n == 37) {         inch = 0;       } else if (n == 38) {         inch++;       } else if (n > 38) {         for (int z = 36; z <= n; z = z + 36) {           foot++;           if (z - n == 2 || z - n == 1) {             ;           }           q = z;           o = n - q;         }         for (int i = 3; i <= o; i = i + 3) {           inch++;           if (o - i == 2) {             inch++;           }         }       }     }     if (inch == 12) {       inch = 0;       foot++;     }     cout << foot <<     << inch;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int FFTMOD = 1007681537;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return val < a ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }   inline int sign(long double x, long double y) { return sign(x - y); }   const int maxn = 50 + 5;   int n, p;   int c[maxn];   int f[maxn][maxn];   int p2[maxn];   int dp[maxn][maxn][maxn][2];   int calc(int pos, int u, int v, int fa) {     if (pos == n) return fa == p;     int& res = dp[pos][u][v][fa];     if (~res) return res;     res = 0;     for (int i = (0); i < (2); ++i) {       int num = c[pos] == -1 || c[pos] == i;       if (!num) continue;       int ar[] = {u, v};       for (int j = (0); j < (ar[i ^ 1] + 1); ++j) {         int add = j + 1 & 1;         ar[i] += add;         int nfa = fa + j + 1 & 1;         addmod(res,                mult(p2[pos - ar[i ^ 1]],                     mult(f[j][ar[i ^ 1]], calc(pos + 1, ar[0], ar[1], nfa))));         ar[i] -= add;       }     }     return res;   }   void chemthan() {     for (int i = (0); i < (maxn); ++i) f[0][i] = 1;     for (int i = (1); i < (maxn); ++i)       for (int j = (1); j < (maxn); ++j)         f[i][j] = (f[i][j - 1] + f[i - 1][j - 1]) % MOD;     for (int i = (0); i < (maxn); ++i) p2[i] = fpow(2, i);     cin >> n >> p;     for (int i = (0); i < (n); ++i) cin >> c[i];     memset(dp, -1, sizeof(dp));     cout << calc(0, 0, 0, 0) <<   n ;   }   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(0), cin.tie(0);     if (argc > 1) {       assert(freopen(argv[1],  r , stdin));     }     if (argc > 2) {       assert(freopen(argv[2],  wb , stdout));     }     chemthan();     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mx = 3e5 + 66;   const long long mod = 1e9 + 7;   const long long inf = 8e18 + 66;   const int llg = 25;   const long long mxk = 31700000;   long long power(long long a, long long b, long long md) {     if (b == 0) return 1;     long long c = power(a, b / 2, md);     if (b % 2)       return c * c % md * a % md;     else       return c * c % md;   }   int n, a[mx], la[mx], ra[mx], rmq[2][llg][mx], val[2][mx], lga[mx], l[llg][mx],       r[llg][mx];   int cmx(int x, int y, int b) {     if (val[b][x] < val[b][y]) return y;     return x;   }   void build(int b) {     for (int i = 1; i < 3 * n + 1; i++) {       rmq[b][0][i] = i;       if (b == 0)         val[b][i] = -la[i];       else         val[b][i] = ra[i];     }     for (int i = 1; i < lga[3 * n] + 1; i++)       for (int j = 1; j + (1 << i) - 1 <= 3 * n; j++) {         rmq[b][i][j] =             cmx(rmq[b][i - 1][j], rmq[b][i - 1][j + (1 << (i - 1))], b);       }   }   int maxq(int x, int y, int b) {     int k = lga[y - x + 1];     return cmx(rmq[b][k][x], rmq[b][k][y - (1 << k) + 1], b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (int i = 2; i < mx; i++) {       lga[i] = lga[i / 2] + 1;     }     cin >> n;     if (n == 1) {       cout << 0;       return 0;     }     for (int i = 1; i < n + 1; i++) {       cin >> a[i];       a[i + n * 2] = a[i + n] = a[i];     }     for (int i = 1; i < 3 * n + 1; i++) {       la[i] = max(1, i - a[i]);       ra[i] = min(3 * n, a[i] + i);     }     for (int i = 0; i < lga[3 * n] + 1; i++) {       l[i][1] = 1;       r[i][3 * n] = 3 * n;     }     for (int i = 1; i < 3 * n + 1; i++) {       l[0][i] = la[i];       r[0][i] = ra[i];     }     build(0);     build(1);     for (int i = 1; i < lga[n * 3] + 1; i++) {       for (int j = 1; j < 3 * n + 1; j++) {         int al = maxq(l[i - 1][j], r[i - 1][j], 0);         int ar = maxq(l[i - 1][j], r[i - 1][j], 1);         l[i][j] = min(l[i - 1][al], l[i - 1][ar]);         r[i][j] = max(r[i - 1][al], r[i - 1][ar]);       }     }     for (int i = n + 1; i < 2 * n + 1; i++) {       int ans = 1, u = i, v = i;       for (int j = lga[3 * n]; j >= 0; j--) {         if (max(r[j][u], r[j][v]) - min(l[j][u], l[j][v]) < n - 1) {           int al = maxq(l[j][u], r[j][v], 0);           int ar = maxq(l[j][u], r[j][v], 1);           u = al, v = ar, ans += (1 << j);         }       }       cout << ans <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int sizes = 200001;   int main() {     long long int i, j, k, l, m, n, o, p, q, r, s, t, a[sizes], b[sizes],         booked[1001];     cin >> n;     o = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       o = max(o, a[i]);     }     sort(a, a + n);     memset(b, -1, sizeof(b));     for (i = 0; i < n; i++) {       b[a[i]] = i;     }     long long int ans = 1;     for (i = 2 * 1; i <= 2 * o; i++) {       memset(booked, 0, sizeof(booked));       p = 0;       for (j = 0; j < n; j++) {         if (booked[j] == 0) {           if ((i - a[j] > 0) && b[i - a[j]] != -1) {             if (booked[b[i - a[j]]] == 0 && j != b[i - a[j]]) {               booked[j] = 1;               booked[b[i - a[j]]] = 1;               p++;             }           }         }       }       ans = max(ans, p);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e3 + 10;   long long inf = 1e18;   set<pair<long long, pair<int, int> > > s;   vector<pair<pair<int, int>, long long> > vec;   long long dp[2][maxn][maxn], arr[maxn][maxn];   long long ps[maxn][maxn];   int n, m, a, b;   bool mark[maxn][maxn];   void input() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m >> a >> b;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> arr[i][j];   }   void cal_ps() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         ps[i + 1][j + 1] = ps[i][j + 1] + ps[i + 1][j] - ps[i][j] + arr[i][j];   }   void cal_dp() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) dp[0][i][j] = dp[1][i][j] = inf;     for (int j = 0; j < m; j++) {       deque<int> dq;       for (int i = 0; i < a; i++) {         while (!dq.empty() && arr[dq.back()][j] >= arr[i][j]) dq.pop_back();         dq.push_back(i);       }       dp[0][a - 1][j] = arr[dq.front()][j];       for (int i = a; i < n; i++) {         while (!dq.empty() && arr[dq.back()][j] >= arr[i][j]) dq.pop_back();         dq.push_back(i);         if (dq.front() == i - a) dq.pop_front();         dp[0][i][j] = arr[dq.front()][j];       }     }     for (int i = 0; i < n; i++) {       deque<int> dq;       for (int j = 0; j < b; j++) {         while (!dq.empty() && dp[0][i][dq.back()] >= dp[0][i][j]) dq.pop_back();         dq.push_back(j);       }       dp[1][i][b - 1] = dp[0][i][dq.front()];       for (int j = b; j < m; j++) {         while (!dq.empty() && dp[0][i][dq.back()] >= dp[0][i][j]) dq.pop_back();         dq.push_back(j);         if (dq.front() == j - b) dq.pop_front();         dp[1][i][j] = dp[0][i][dq.front()];       }     }   }   void init() {     for (int i = a - 1; i < n; i++)       for (int j = b - 1; j < m; j++) {         long long sum = ps[i + 1][j + 1] - ps[i + 1][j + 1 - b] -                         ps[i + 1 - a][j + 1] + ps[i + 1 - a][j + 1 - b] -                         a * b * dp[1][i][j];         s.insert({sum, {i - a + 1, j - b + 1}});       }   }   bool valid(int x, int y) {     if (mark[x][y]) return false;     int xx = max(0, x - a + 1), yy = max(0, y - b + 1);     for (int i = x + a - 1; i >= xx; i--)       for (int j = y + b - 1; j >= yy; j--) mark[i][j] = true;     return true;   }   int main() {     input();     cal_ps();     cal_dp();     init();     while (!s.empty()) {       auto tmp = *s.begin();       int x = tmp.second.first, y = tmp.second.second;       long long p = tmp.first;       if (valid(x, y)) vec.push_back({{x, y}, p});       s.erase(tmp);     }     cout << vec.size() <<   n ;     for (auto tmp : vec) {       cout << tmp.first.first + 1 <<     << tmp.first.second + 1 <<                << tmp.second <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, X = 2000010, P = 1000000007;   int n, pc, ind;   bool vis[X], chose[N];   int a[N], l[X], pr[N], fc[X];   int tag[X];   void apply(int x) {     int lst = 0, cnt = 0;     while (x != 1) {       int pp = fc[x];       x /= pp;       if (pp == lst) {         ++cnt;       } else {         if (cnt >= l[lst]) {           l[lst] = cnt;           tag[lst] = ind;         }         cnt = 1;         lst = pp;       }     }     if (cnt >= l[lst]) {       l[lst] = cnt;       tag[lst] = ind;     }   }   int main() {     for (int x = 2; x < X; ++x) {       if (!vis[x]) {         fc[x] = x;         pr[++pc] = x;       }       for (int i = 1; x * pr[i] < X; ++i) {         vis[x * pr[i]] = true;         fc[x * pr[i]] = pr[i];         if (x % pr[i] == 0) break;       }     }     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1, greater<int>());     for (int i = 1; i <= n; ++i) {       ind = i;       if (!l[a[i]])         apply(a[i]);       else         apply(a[i] - 1);     }     int ans = 1;     for (int i = 1; i <= pc; ++i)       while (l[pr[i]]--) ans = ans * (long long)pr[i] % P;     for (int x = 1; x < X; ++x) chose[tag[x]] = true;     ans = (ans + (count(chose + 1, chose + n + 1, true) != n)) % P;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) {       long long int m, n, k, t, i;       cin >> m >> n >> k >> t;       vector<long long int> sol(m);       for (i = 0; i < m; i++) cin >> sol[i];       sort((sol).begin(), (sol).end());       vector<pair<long long int, pair<long long int, long long int>>> traps(k);       for (i = 0; i < k; i++) {         cin >> traps[i].first >> traps[i].second.first >> traps[i].second.second;       }       sort((traps).begin(), (traps).end());       long long int l, r, mid;       l = 0;       r = 200005;       long long int ans = r;       while (l <= r) {         mid = (l + r) / 2;         long long int tm = n + 1;         long long int donest = -1;         long long int doneend = -1;         for (auto x : traps) {           if (x.second.second > mid) {             if (donest == -1) {               donest = x.first;               doneend = x.second.first;             } else if (x.first <= doneend) {               doneend = max(doneend, x.second.first);             } else {               tm += 2 * (doneend - donest + 1);               donest = x.first;               doneend = x.second.first;             }           }         }         if (donest != -1) {           tm += 2 * (doneend - donest + 1);         }         if (tm <= t) {           r = mid - 1;           ans = min(ans, mid);         } else           l = mid + 1;       }       ans = lower_bound((sol).begin(), (sol).end(), ans) - sol.begin();       cout << m - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c, d, a, b, i;     cin >> n >> a >> b;     c = b, d = c;     for (i = 2; i <= n; i++) {       cin >> a >> b;       c = max(c, d - a + b);       d = d - a + b;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000, MD = 1000000007;   char aa[N + 1], bb[N + 1], cc[N * 3];   int zz[N * 3];   void mult(int aa[][2], int bb[][2], int cc[][2]) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         long long c = 0;         for (int k = 0; k < 2; k++) c += (long long)aa[i][k] * bb[k][j];         cc[i][j] = c % MD;       }   }   void power(int aa[][2], int pp[][2], int tt[][2], int k) {     if (k == 0) {       pp[0][0] = 1, pp[0][1] = 0;       pp[1][0] = 0, pp[1][1] = 1;       return;     }     if (k & 1) {       power(aa, pp, tt, k >> 1);       mult(pp, pp, tt);       mult(tt, aa, pp);     } else {       power(aa, tt, pp, k >> 1);       mult(tt, tt, pp);     }   }   int main() {     int k;     cin >> aa >> bb >> k;     int n = strlen(aa);     for (int i = 0; i < n; i++) {       cc[i] = bb[i];       cc[n + i] = cc[n + n + i] = aa[i];     }     for (int l = 0, r = 0, i = 1; i < n * 3; i++)       if (i + zz[i - l] < r)         zz[i] = zz[i - l];       else {         l = i;         if (r < l) r = l;         while (r < n * 3 && cc[r] == cc[r - l]) r++;         zz[i] = r - l;       }     int a = 0;     for (int i = n; i < n + n; i++)       if (zz[i] >= n) a++;     int b = n - a;     int aa[2][2], pp[2][2], tt[2][2];     aa[0][0] = a - 1, aa[0][1] = a;     aa[1][0] = b, aa[1][1] = b - 1;     power(aa, pp, tt, k);     int ans = zz[n] >= n ? pp[0][0] : pp[0][1];     if (ans < 0) ans += MD;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   const int inf = 1e9 + 5;   const int mod = 1e9 + 7;   vector<int> v[M];   int hx2[2 * M];   int hx[M];   int nxt[M];   int n, m;   int KMP() {     memset(nxt, 0, sizeof(nxt));     int la, lb;     la = n;     lb = m;     int j, k;     j = 0;     k = -1;     nxt[0] = -1;     while (j < la) {       if (k == -1 || hx[j] == hx[k]) {         j++;         k++;         nxt[j] = k;       } else {         k = nxt[k];       }     }     int ans = 0;     j = 0;     k = 0;     while (k < lb) {       if (j == -1 || hx[j] == hx2[k]) {         j++;         k++;       } else {         j = nxt[j];       }       if (j == la) {         j = nxt[j];         ans++;       }     }     return ans;   }   int main() {     int k;     scanf( %d%d , &n, &k);     m = 2 * n;     for (int i = 0; i < k; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a > b) swap(a, b);       v[a].push_back(min(b - a, n - b + a));       v[b].push_back(min(b - a, n - b + a));     }     for (int i = 0; i < n; i++) {       sort(v[i + 1].begin(), v[i + 1].end());       for (int j = 0; j < v[i + 1].size(); j++) {         hx[i] = hx[i] * n + v[i + 1][j];       }     }     for (int i = 0; i < n; i++) {       hx2[i] = hx[i];       hx2[i + n] = hx[i];     }     if (KMP() <= 2) {       printf( No n );     } else {       printf( Yes n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, B, Q;   int a[200005];   vector<int> adj[200005];   void init() {     B = sqrt(N);     for (int i = 1; i <= N; i++) {       a[i] = i;       adj[i / B].push_back(i);     }   }   long long work(int l, int r) {     if (l == r) return 0;     int idx, idy, x, y, k;     x = a[l];     y = a[r];     idx = l / B;     k = find(adj[idx].begin(), adj[idx].end(), x) - adj[idx].begin();     adj[idx][k] = y;     sort(adj[idx].begin(), adj[idx].end());     idy = r / B;     k = find(adj[idy].begin(), adj[idy].end(), y) - adj[idy].begin();     adj[idy][k] = x;     sort(adj[idy].begin(), adj[idy].end());     int ans = 0, f;     if (x > y)       f = -1, swap(x, y);     else       f = 1;     if (idx == idy) {       for (int i = l + 1; i <= r - 1; i++) {         if (x < a[i] && a[i] < y) ++ans;       }     } else {       for (int i = l + 1; i < (idx + 1) * B; i++) {         if (x < a[i] && a[i] < y) ++ans;       }       for (int id = idx + 1; id < idy; id++) {         ans += upper_bound(adj[id].begin(), adj[id].end(), y) -                lower_bound(adj[id].begin(), adj[id].end(), x);       }       for (int i = idy * B; i < r; i++) {         if (x < a[i] && a[i] < y) ++ans;       }     }     swap(a[l], a[r]);     return (2 * ans + 1) * f;   }   int main() {     scanf( %d%d , &N, &Q);     init();     int l, r;     long long ans = 0;     while (Q--) {       scanf( %d%d , &l, &r);       if (l > r) swap(l, r);       ans += work(l, r);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], pre[N];   int n;   long long check(int p, int len) {     return pre[p] - pre[p - len - 1] + pre[n] - pre[n - len];   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];     int p = 1, len = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       int l = 1, r = min(i - 1, n - i), mid;       while (r >= l) {         mid = l + r >> 1;         if ((long long)check(i, mid) * (mid * 2 - 1) >=             (long long)check(i, mid - 1) * (mid * 2 + 1)) {           l = mid + 1;           if ((long long)check(i, mid) * (len * 2 + 1) -                   a[i] * (len * 2 + 1) * (mid * 2 + 1) >               (long long)ans * (mid * 2 + 1) -                   a[p] * (len * 2 + 1) * (mid * 2 + 1))             ans = check(i, mid), p = i, len = mid;         } else           r = mid - 1;       }     }     printf( %d n , len * 2 + 1);     for (int i = p - len; i <= p; i++) printf( %d  , pre[i] - pre[i - 1]);     for (int i = n - len + 1; i <= n; i++) printf( %d  , pre[i] - pre[i - 1]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[110], b[110], n;   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       for (register int i = 1; i <= n; i++) cin >> a[i];       for (register int i = 1; i <= n; i++) cin >> b[i];       sort(a + 1, a + n + 1);       sort(b + 1, b + n + 1);       for (register int i = 1; i <= n; i++) cout << a[i] <<    ;       puts(  );       for (register int i = 1; i <= n; i++) cout << b[i] <<    ;       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double EPS = 1e-9;   int INF = 2000000000;   long long INFF = 8000000000000000000LL;   double PI = acos(-1);   string IntToString(int a) {     char x[100];     sprintf(x,  %d , a);     string s = x;     return s;   }   int StringToInt(string a) {     char x[100];     strcpy(x, a.c_str());     int res;     sscanf(x,  %d , &res);     return res;   }   int spaces = 0;   char c[5];   int main() {     while (scanf( %c , &c[0]) != EOF && c[0] !=   n ) {       scanf( %c%c , &c[1], &c[2]);       if (c[2] ==  > ) {         spaces += 2;         for (int(i) = (1); (i) <= (spaces - 2); (i)++) printf(   );         for (int(i) = (0); (i) <= (2); (i)++) printf( %c , c[i]);         puts(  );       } else {         scanf( %c , &c[3]);         spaces -= 2;         for (int(i) = (1); (i) <= (spaces); (i)++) printf(   );         for (int(i) = (0); (i) <= (3); (i)++) printf( %c , c[i]);         puts(  );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000 + 100;   const int maxk = 45;   const int mod = 1000000007;   int dp[maxk][maxn];   int cnt[maxk][maxn];   void input_output() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n, k;       cin >> n >> k;       if (k < maxk)         cout << dp[k][n] << endl;       else         cout << 0 << endl;     }   }   void dpp() {     for (int i = 0; i < maxn; i++) dp[0][i] = 1, cnt[0][i] = i + 1;     for (int i = 1; i < 45; i++) {       for (int j = i; j < maxn; j++) {         dp[i][j] = (dp[i][j - i] + (long long)i * cnt[i - 1][j - i]) % mod;         cnt[i][j] = (cnt[i][j - 1] + dp[i][j]) % mod;       }     }   }   int main() {     dpp();     input_output();   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 3e5 + 5;   const int oo = 1e9 + 7;   vector<pair<pair<int, int>, int> > X, Y;   pair<int, int> operator+(pair<int, int> x, pair<int, int> y) {     return {x.first + y.first, x.second + y.second};   }   bool pos() {     for (int i = 0; i < 4; i++) {       pair<int, int> a, b;       cin >> a.first >> a.second;       cin >> b.first >> b.second;       if (a == b) return 0;       if (a.first == b.first) {         if (b < a) swap(a, b);         Y.push_back({a, b.second - a.second});       } else if (a.second == b.second) {         if (b < a) swap(a, b);         X.push_back({a, b.first - a.first});       } else         return 0;     }     if (X.size() != 2) return 0;     if (Y.size() != 2) return 0;     sort(X.begin(), X.end());     sort(Y.begin(), Y.end());     if (X[0].second != X[1].second or X[0].first.first != X[1].first.first)       return 0;     if (Y[0].second != Y[1].second or Y[0].first.second != Y[1].first.second)       return 0;     if (X[0].first != Y[0].first) return 0;     if (X[0].first + make_pair(0, Y[0].second) != X[1].first) return 0;     if (Y[0].first + make_pair(X[0].second, 0) != Y[1].first) return 0;     return 1;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cout << (pos() ?  YES n  :  NO n );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6 + 10;   int z[MAXN];   void Zvalue(const string &s) {     z[0] = s.size();     int l = 0, r = 0, x;     for (int i = 1; i < s.size(); i++) {       if (r < i || z[i - l] >= r - i + 1) {         r < i ? x = i : x = r + 1;         while (x < s.size() && s[x] == s[x - i]) x++;         z[i] = x - i;         if (i < x) {           l = i;           r = x - 1;         };       } else         z[i] = z[i - l];     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       string s;       cin >> s;       int p;       for (p = 0; p < s.size() - 1 - p; p++)         if (s[p] != s[s.size() - 1 - p]) break;       string smid = s.substr(p, s.size() - p * 2);       string revsmid = smid;       reverse(revsmid.begin(), revsmid.end());       Zvalue(smid +  $  + revsmid);       int ls = 0, rs = 0;       for (int i = 1; i <= smid.size(); i++)         if (i == z[smid.size() * 2 + 1 - i]) ls = i;       Zvalue(revsmid +  $  + smid);       for (int i = 1; i <= smid.size(); i++)         if (i == z[smid.size() * 2 + 1 - i]) rs = i;       if (ls > rs)         cout << s.substr(0, p + ls) + s.substr(s.size() - p, p) <<   n ;       else         cout << s.substr(0, p) + s.substr(s.size() - p - rs, p + rs) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   long long a[100005];   int get_bit(long long x) {     int ans = 0;     while (x) {       ans++;       x >>= 1;     }     return ans;   }   int main() {     int i, j;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (i = 1; i <= n; i++) scanf( %lld , &a[i]);       int ans = 0, last = a[1];       for (i = 2; i <= n; i++) {         if (a[i] >= last) {           last = a[i];           continue;         }         ans = max(ans, get_bit(last - a[i]));       }       printf( %d n , ans);     }     return 0;   }


// Jai Shree Ram      #include<bits/stdc++.h>   typedef long long int ll;   #define pb push_back   #define max2(a,b) (a>b)?a:b   #define mi2(a,b) (a<=b)?a:b   #define fori(i,n) for(ll i=0;i<(ll)n;i++)   #define ford(i,n) for(ll i=n;i>=0;i--)   #define pll pair<ll,ll>   #define mod 1000000007   #define ff first   #define ss second   using namespace std;   #define MAXI 1e15   #define MAX_LIMIT 500001         void solve()   {              ll n;       cin>>n;       vector<ll> v(n),neg;       ll pos=MAXI;       bool fl=0;       fori(i,n)       {           cin>>v[i];           if(v[i]<=0)           {               neg.pb(v[i]);           }           else if(v[i]>0)           {               fl=1;               pos=min(pos,v[i]);           }       }       sort(neg.begin(),neg.end(),greater<ll>());       ll ans=neg.size();       if(fl==0)       {                      cout<<ans<<  n ;           return;       }       else       {              ll mini=MAXI;           for(int i=1;i<neg.size();i++)           {               ll val=abs(neg[i]-neg[i-1]);               mini=min(mini,val);           }                                        if(mini>=pos)               {                   ans++;               }                                              cout<<ans<<  n ;           return;                     }                                  }              int main()   {                      ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);                          ll T;       T=1;       cin>>T;              fori(_,T)       {                      solve();                  }                                   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int k, a, b;     cin >> k >> a >> b;     string s;     cin >> s;     int l = s.length();     double c = (double)l / k;     int c1 = floor(c);     int c2 = ceil(c);     int flag1 = 0, flag2 = 0;     if ((l - (c1 * (k - 1))) > b || (l - (c1 * (k - 1))) < a) {       flag1 = 1;     }     if ((l - (c2 * (k - 1))) > b || (l - (c2 * (k - 1))) < a) {       flag2 = 1;     }     if ((flag1 == 1 || c1 < a || c1 > b) && (flag2 == 1 || c2 < a || c2 > b)) {       cout <<  No solution ;       return;     }     if (flag1 == 0) {       int i1 = 0;       int kk = 0;       while (i1 <= l) {         kk++;         for (long long int i = i1; i < min(i1 + c1, l); i++) {           cout << s[i];         }         i1 += c1;         if (kk == k) {           for (long long int i = i1; i < l; i++) {             cout << s[i];           }           return;         }         printf(  n );       }     } else {       int i1 = 0;       int kk = 0;       while (i1 <= l) {         kk++;         for (long long int i = i1; i < min(i1 + c2, l); i++) {           cout << s[i];         }         i1 += c2;         if (kk == k) {           for (long long int i = i1; i < l; i++) {             cout << s[i];           }         }         printf(  n );       }     }   }   int main() { solve(); }


#include <bits/stdc++.h>   using namespace std;   long long rt(long long a) {     long long p = 0, q = a;     while (p < q) {       long long s = (p + q + 1) / 2;       long long sv = s * (s + 1) / 2;       if (sv < a) p = s;       if (sv > a) q = s - 1;       if (sv == a) return s;     }     if (p * (p + 1) / 2 == a) return p;     return -1;   }   long long a, b, c, d;   bool possible(long long z, long long j) {     long long n = z + j;     if (a + b + c + d != n * (n - 1) / 2) {       return 0;     }     return 1;   }   bool solve(long long z, long long j) {     if (!possible(z, j)) {       return 0;     }     long long n = z + j;     if (j == 0) {       for (int i = 0; i < n; i++) cout <<  0 ;       return 1;     }     if (z == 0) {       for (int i = 0; i < n; i++) cout <<  1 ;       return 1;     }     long long ord[5];     ord[0] = b / j;     ord[2] = (ord[0] * j != b);     ord[3] = b - ord[0] * j;     ord[4] = z - ord[0] - ord[2];     ord[1] = j - ord[3];     for (int i = 0; i < 5; i++) {       for (int k = 0; k < ord[i]; k++) {         cout << (i % 2);       }     }     return 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> a >> b >> c >> d;     if (a + b + c + d == 0) {       cout <<  1 n ;       return 0;     }     long long z = rt(a);     long long j = rt(d);     if (z == -1 || j == -1) {       cout <<  Impossible n ;       return 0;     }     ++z;     ++j;     if (z == 1 && j == 1) {       if (solve(0, 0)) return 0;       if (solve(0, 1)) return 0;       if (solve(1, 0)) return 0;       if (solve(1, 1)) return 0;       cout <<  Impossible n ;       return 0;     }     if (z == 1) {       if (solve(0, j)) return 0;       if (solve(1, j)) return 0;       cout <<  Impossible n ;       return 0;     }     if (j == 1) {       if (solve(z, 0)) return 0;       if (solve(z, 1)) return 0;       cout <<  Impossible n ;       return 0;     }     if (solve(z, j)) return 0;     cout <<  Impossible n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   long long arr[100003];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &arr[i]);     if (n == 1 || n == 2)       printf( 0 n );     else {       long long res = INF;       for (int i = -1; i <= 1; i++) {         for (int j = -1; j <= 1; j++) {           long long a = arr[0] + i;           long long b = (arr[1] + j) - (arr[0] + i);           long long cnt = abs(i) + abs(j);           for (int k = 2; k < n; k++) {             if (abs(a + (k * b) - arr[k]) > 1)               cnt = INF;             else               cnt += abs(a + (k * b) - arr[k]);           }           res = min(res, cnt);         }       }       if (res <= 1e9)         printf( %lld n , res);       else         printf( -1 n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y;     cin >> x >> y;     for (long long int i = 0; i < x.size(); i++) {       if (x[i] == y[i])         cout << 0;       else         cout << 1;     }   }


#include <bits/stdc++.h>   template <class T>   T _diff(T a, T b) {     return (a < b ? b - a : a - b);   }   template <class T>   T _abs(T a) {     return (a < 0 ? -a : a);   }   template <class T>   T _max(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T _min(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T max3(T a, T b, T c) {     return (_max(a, b) > c ? _max(a, b) : c);   }   template <class T>   T min3(T a, T b, T c) {     return (_min(a, b) < c ? _min(a, b) : c);   }   template <class T>   T GCD(T a, T b) {     a = _abs(a);     b = _abs(b);     T tmp;     while (a % b) {       tmp = a % b;       a = b;       b = tmp;     }     return b;   }   template <class T>   T LCM(T a, T b) {     a = _abs(a);     b = _abs(b);     return (a / GCD(a, b)) * b;   }   using namespace std;   long long n, k, mul;   int main() {     cin >> n >> k;     mul = (n * (n - 1)) / 2;     if (mul <= k)       cout <<  no solution n ;     else {       for (int i = 0; i < n; i++) {         cout << 0 <<     << i << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   vector<int> adj[300016];   int id[300016], lo[300016];   int par[300016], rnk[300016], dist[300016];   vector<int> tadj[300016];   vector<pair<int, int> > br;   int nxt = 0;   int fin(int x) { return par[x] == x ? x : par[x] = fin(par[x]); }   void uni(int x, int y) {     if (rnk[x] < rnk[y]) {       par[x] = y;     } else {       par[y] = x;       rnk[x] = max(rnk[x], rnk[y] + 1);     }   }   void dfs(int u, int p = 0) {     id[u] = lo[u] = ++nxt;     for (int v : adj[u]) {       if (!id[v]) {         dfs(v, u);         lo[u] = min(lo[u], lo[v]);         if (lo[v] > id[u]) {           br.emplace_back(u, v);         } else {           int ru = fin(u), rv = fin(v);           if (ru != rv) uni(ru, rv);         }       } else if (v != p) {         lo[u] = min(lo[u], lo[v]);       }     }   }   int bfs(int s, int n) {     queue<int> q;     int r = 0;     fill_n(dist + 1, n, 1010101);     dist[s] = 0;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       r = u;       for (int v : tadj[u]) {         if (dist[u] + 1 < dist[v]) {           dist[v] = dist[u] + 1;           q.push(v);         }       }     }     return r;   }   int main() {     canhazfast();     int n, m, t;     cin >> n >> m;     for (int i = 1; i <= n; ++i) par[i] = i;     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1);     for (pair<int, int> e : br) {       int a = fin(e.first), b = fin(e.second);       tadj[a].push_back(b);       tadj[b].push_back(a);     }     t = bfs(fin(1), n);     t = bfs(t, n);     cout << dist[t];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INFLL = 1e18;   const int MAXN = 1e6 + 100;   const long long INF = 1e9;   const long long mod1 = 1e9 + 7;   const long long mod2 = 2e9 + 11;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long a, b;       cin >> a >> b;       if (a == b)         cout << 0 <<   n ;       else {         if (b < a) {           if ((a - b) % 2 == 0)             cout << 1 <<   n ;           else             cout << 2 <<   n ;         } else {           if ((a - b) % 2 == 0)             cout << 2 <<   n ;           else             cout << 1 <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double long EPS = 1e-10;   struct wor {     double long x = 0, y = 0;   };   double long dist(wor a, wor b) {     double long answer =         sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));     return answer;   }   pair<vector<double long>, vector<long long>> djkstra(       long long from, long long n,       vector<vector<pair<double long, long long>>> &adj) {     vector<bool> used(n);     vector<double long> d(n, 1e15);     vector<long long> f(n);     d[from] = 0;     f[from] = from;     for (int i = 0; i < n; i++) {       long long mi = -1;       for (int i = 0; i < n; i++) {         if (!used[i]) {           mi = i;           break;         }       }       for (int j = 0; j < n; j++) {         if (!used[j] && d[j] < d[mi]) {           mi = j;         }       }       used[mi] = true;       for (auto e : adj[mi]) {         if (!used[e.second] && d[mi] + e.first < d[e.second]) {           d[e.second] = d[mi] + e.first;           f[e.second] = mi;         }       }     }     return {d, f};   }   struct Kun1 {     long long n;     vector<vector<long long>> adj;     vector<long long> used;     vector<bool> is_l;     vector<long long> mt;     Kun1(long long n) {       this->n = n;       adj.resize(n);       used.resize(n);       mt.resize(n);       is_l.resize(n);     }     void add_edge(long long u, long long v) {       adj[u].push_back(v);       adj[v].push_back(u);     }     void make_left(long long v) { is_l[v] = true; }     bool try_kun(long long v, long long cur) {       if (used[v] == cur) return false;       used[v] = cur;       for (auto e : adj[v]) {         if (mt[e] == -1 || try_kun(mt[e], cur)) {           mt[e] = v;           return true;         }       }       return false;     }     long long max_matching() {       vector<bool> usel(n);       for (int i = 0; i < n; i++) {         if (!is_l[i]) mt[i] = -1;       }       long long answer = 0;       for (int i = 0; i < n; i++) {         if (is_l[i]) {           for (auto e : adj[i]) {             if (mt[e] == -1) {               mt[e] = i;               answer++;               usel[i] = true;               break;             }           }         }       }       long long z = 1;       for (int i = 0; i < n; i++) {         if (is_l[i] && !usel[i] && try_kun(i, z++)) answer++;       }       return answer;     }   };   struct MCMF {     struct edge {       long long from, to, flow, cap, cost;     };     vector<edge> edges;     vector<vector<long long>> adj;     vector<long long> d;     vector<long long> p;     deque<long long> q;     vector<long long> state;     const long long levit_inf = 2e9;     long long n, s, t;     MCMF(long long _n, long long _s, long long _t) {       n = _n;       s = _s;       t = _t;       adj.resize(n);       d.resize(n);       p.resize(n);       state.resize(n);     }     void add_edge(long long from, long long to, long long cap, long long cost) {       edge e1 = {from, to, 0, cap, cost};       edge e2 = {to, from, 0, 0, -cost};       adj[from].push_back(edges.size());       edges.push_back(e1);       adj[to].push_back(edges.size());       edges.push_back(e2);     }     void relax(long long v, long long dist, long long from) {       if (d[v] <= dist) {         return;       }       d[v] = dist;       p[v] = from;       if (state[v] == 0 || (!q.empty() && d[q.front()] > d[v])) {         q.push_front(v);         state[v] = 1;       } else if (state[v] == 2) {         q.push_back(v);         state[v] = 1;       }     }     bool levit() {       fill(d.begin(), d.end(), levit_inf);       fill(p.begin(), p.end(), -1);       fill(state.begin(), state.end(), 0);       relax(s, 0, 0);       while (!q.empty()) {         long long v = q.front();         q.pop_front();         state[v] = 2;         for (auto i = 0; i < adj[v].size(); i++) {           auto e = adj[v][i];           if (edges[e].flow < edges[e].cap) {             relax(edges[e].to, d[v] + edges[e].cost, e);           }         }       }       return d[t] < levit_inf;     }     pair<long long, long long> max_flow() {       long long flow = 0;       long long cost = 0;       while (levit()) {         long long ed = p[t];         long long mi_fl = edges[ed].cap - edges[ed].flow;         while (edges[ed].from != s) {           mi_fl = min(mi_fl, edges[ed].cap - edges[ed].flow);           ed = p[edges[ed].from];         }         mi_fl = min(mi_fl, edges[ed].cap - edges[ed].flow);         ed = p[t];         while (edges[ed].from != s) {           edges[ed].flow += mi_fl;           edges[ed ^ 1].flow -= mi_fl;           cost += edges[ed].cost * mi_fl;           ed = p[edges[ed].from];         }         edges[ed].flow += mi_fl;         edges[ed ^ 1].flow -= mi_fl;         cost += edges[ed].cost * mi_fl;         flow += mi_fl;       }       return {cost, flow};     }   };   struct MCMF1 {     struct edge {       long long from, to, cap, flow, cost;     };     vector<edge> edges;     vector<vector<long long>> adj;     vector<long long> p;     vector<long long> d;     vector<long long> state;     const long long lenin_inf = 2e9;     long long n, s, t;     MCMF1(long long _n, long long _s, long long _t) {       n = _n;       s = _s;       t = _t;       p.resize(n);       d.resize(n);       state.resize(n);       adj.resize(n);     }     void add_edge(long long from, long long to, long long cap, long long cost) {       edge e1 = {from, to, cap, 0, cost};       edge e2 = {to, from, 0, 0, -cost};       adj[from].push_back(edges.size());       edges.push_back(e1);       adj[to].push_back(edges.size());       edges.push_back(e2);     }     deque<long long> q;     void relax(long long v, long long dist, long long from) {       if (d[v] <= dist) return;       d[v] = dist;       p[v] = from;       if (state[v] == 0 || (!q.empty() && d[v] < d[q.front()])) {         q.push_front(v);         state[v] = 1;       } else if (state[v] == 2) {         q.push_back(v);         state[v] = 1;       }     }     bool lenin() {       fill(p.begin(), p.end(), -1);       fill(d.begin(), d.end(), lenin_inf);       fill(state.begin(), state.end(), 0);       relax(s, 0, 0);       while (!q.empty()) {         long long v = q.front();         q.pop_front();         state[v] = 2;         for (auto e : adj[v]) {           if (edges[e].cap - edges[e].flow == 0) continue;           relax(edges[e].to, d[v] + edges[e].cost, e);         }       }       return d[t] < lenin_inf;     }     pair<long long, long long> max_flow() {       long long cost = 0;       long long flow = 0;       while (lenin()) {         long long ed = p[t];         long long ma = edges[ed].cap - edges[ed].flow;         while (edges[ed].from != s) {           ma = min(ma, edges[ed].cap - edges[ed].flow);           ed = p[edges[ed].from];         }         ma = min(ma, edges[ed].cap - edges[ed].flow);         flow += ma;         ed = p[t];         while (edges[ed].from != s) {           edges[ed].flow += ma;           edges[ed ^ 1].flow -= ma;           cost += ma * edges[ed].cost;           ed = p[edges[ed].from];         }         edges[ed].flow += ma;         edges[ed ^ 1].flow -= ma;         cost += ma * edges[ed].cost;       }       return {cost, flow};     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string t;     cin >> t;     long long n;     cin >> n;     vector<pair<string, long long>> arr(n);     vector<vector<long long>> num(n);     long long sum = 0;     long long z = n + 1;     for (int i = 0; i < n; i++) {       cin >> arr[i].first >> arr[i].second;       for (int j = 0; j < arr[i].first.length(); j++) {         num[i].push_back(z++);       }       sum += arr[i].first.length();     }     MCMF1 mcmf(2 + t.length() + n + sum, 0, 2 + t.length() + n + sum - 1);     for (int i = 0; i < n; i++) {       mcmf.add_edge(0, i + 1, arr[i].second, 0);     }     for (int i = 1; i <= n; i++) {       for (auto e : num[i - 1]) {         mcmf.add_edge(i, e, 1, 0);       }     }     vector<long long> tn;     for (int i = 0; i < t.length(); i++) {       tn.push_back(z++);     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < arr[i - 1].first.length(); j++) {         for (int z = 0; z < t.length(); z++) {           if (t[z] == arr[i - 1].first[j]) {             mcmf.add_edge(num[i - 1][j], tn[z], 1, i);           }         }       }     }     for (auto e : tn) {       mcmf.add_edge(e, 2 + t.length() + n + sum - 1, 1, 0);     }     auto e = mcmf.max_flow();     if (e.second != t.length()) {       cout << -1;     } else {       cout << e.first;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <class U, class V>   ostream& operator<<(ostream& os, const pair<U, V>& p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   template <class U, class V>   istream& operator>>(istream& in, pair<U, V>& p) {     in >> p.first >> p.second;     return in;   }   vector<vector<long long> > al;   long long n;   bool bfs(long long s, long long fr, long long* col) {     bool mark[n];     memset(mark, 0, sizeof(mark));     ;     mark[s] = 1;     queue<long long> q;     for (long long v : al[s]) {       if (v != fr) {         q.push(v);       }     }     while (!q.empty()) {       long long u = q.front();       q.pop();       if (col[u] != col[s]) {         return false;       }       mark[u] = 1;       for (long long v : al[u]) {         if (!mark[v]) {           q.push(v);           mark[v] = 1;         }       }     }     return true;   }   int main() {     scanf( %lld , &n);     ;     al = vector<vector<long long> >(n);     long long c[n];     vector<pair<long long, long long> > inp;     for (long long i = 0; i < n - 1; i++) {       long long u, v;       scanf( %lld %lld , &u, &v);       ;       u--, v--;       al[u].push_back(v);       al[v].push_back(u);       inp.push_back(make_pair(u, v));     }     for (long long i = 0; i < n; i++) {       scanf( %lld , &c[i]);       ;     }     for (auto& e : inp) {       if (c[e.first] != c[e.second]) {         bool f = 0;         for (long long v : al[e.first]) {           if (!bfs(v, e.first, c)) {             f = 1;             break;           }         }         if (!f) {           puts( YES );           printf( %lld n , e.first + 1);           ;           return 0;         }         for (long long v : al[e.second]) {           if (!bfs(v, e.second, c)) {             puts( NO );             return 0;           }         }         puts( YES );         printf( %lld n , e.second + 1);         ;         return 0;       }     }     puts( YES );     printf( %lld n , (long long)1);     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long k, l;   int main() {     cin >> k >> l;     long long K = k;     int res = 0;     while (K < l) {       K *= k;       res++;     }     if (K == l) {       cout <<  YES  << endl;       cout << res << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct sgmnt {     long long L, R;     int mxL, mxR, w;     sgmnt() {}     sgmnt(long long L, int mxL, long long R, int mxR, int w)         : L(L), mxL(mxL), R(R), mxR(mxR), w(w) {}   };   const int MAXN = 3 * 1000 * 100 + 10;   long long arr[MAXN];   sgmnt seg[MAXN * 4];   sgmnt merge(sgmnt a, sgmnt b, int s, int m, int e) {     sgmnt c = sgmnt(a.L, a.mxL, b.R, b.mxR, max(a.w, b.w));     if ((a.R > 0 && b.L != 0) || (a.R < 0 && b.L < 0)) {       if (a.mxL == m - s) c.mxL = a.mxL + b.mxL;       if (b.mxR == e - m) c.mxR = b.mxR + a.mxR;       c.w = max(c.w, a.mxR + b.mxL);     }     c.w = max({c.w, c.mxR, c.mxL});     return c;   }   void add(int p, int v, int s, int e) {     if (e - s <= 1) {       seg[v] = sgmnt(arr[s], 1, arr[s], 1, 1);       return;     }     int m = (s + e) / 2;     if (p < m)       add(p, v * 2, s, m);     else       add(p, v * 2 + 1, m, e);     seg[v] = merge(seg[v * 2], seg[v * 2 + 1], s, m, e);   }   int main() {     int n, b;     scanf( %d %d , &n, &b);     n--;     for (int i = 0; i < n; i++) {       int a;       scanf( %d , &a);       arr[i] = a - b;       add(i, 1, 0, n);       b = a;     }     int q;     scanf( %d , &q);     while (q--) {       int l, r, d;       scanf( %d %d %d , &l, &r, &d);       l--;       if (!n) {         cout << 1 << endl;         continue;       }       if (l != 0) {         arr[l - 1] += d;         add(l - 1, 1, 0, n);       }       if (r != n + 1) {         arr[r - 1] -= d;         add(r - 1, 1, 0, n);       }       printf( %d n , seg[1].w + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int l[N], r[N], n, len, posl, posr;   char a[N], b[N];   int ans, ans1, ans2;   vector<int> vec[30];   int main() {     for (int i = 0; i < 30; ++i) vec[i].push_back(1);     scanf( %s%s , a + 1, b + 1);     n = strlen(a + 1);     len = strlen(b + 1);     for (int i = 1; i <= n; ++i) vec[a[i] -  a ].push_back(i);     for (int i = 1; i <= len; ++i) {       int c = b[i] -  a ;       int& pos = vec[c][0];       while (pos <= vec[c].size() - 1 && vec[c][pos] <= l[i - 1]) {         pos++;       }       if (pos > vec[c].size() - 1)         l[i] = n + 1;       else         l[i] = vec[c][pos++];     }     for (int i = 0; i < 30; ++i) vec[i][0] = vec[i].size() - 1;     r[len + 1] = n + 1;     for (int i = len; i >= 1; --i) {       int c = b[i] -  a ;       int& pos = vec[c][0];       while (pos && vec[c][pos] > r[i + 1]) {         pos--;       }       if (pos == 0)         r[i] = 0;       else         r[i] = vec[c][pos--];     }     for (int i = 1; i <= len; ++i)       if (l[i] > l[i - 1] && l[i] <= n)         posl = i;       else         break;     posr = len + 1;     for (int i = len; i >= 1; --i)       if (r[i] < r[i + 1] && r[i] != 0)         posr = i;       else         break;     if (ans < posl) {       ans = posl;       ans1 = posl;       ans2 = len + 1;     }     if (ans < len - posr + 1) {       ans = len - posr + 1;       ans1 = 0;       ans2 = posr;     }     for (int i = posr; i <= len; ++i) {       int tmp = r[i];       int pos = lower_bound(l + 1, l + posl + 1, tmp) - l;       pos--;       if (pos >= i) pos = i - 1;       int val = len - i + 1 + pos;       if (ans < val) {         ans = val;         ans1 = pos;         ans2 = i;       }     }     if (ans == 0)       puts( - );     else {       for (int i = 1; i <= ans1; ++i) putchar(b[i]);       for (int i = ans2; i <= len; ++i) putchar(b[i]);       puts(  );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   long long int ch(long long int x, long long int y) {     if (abs(x - y) % 2 == 0) {       return 0;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int q;     cin >> q;     while (q--) {       long long int x, y, k;       cin >> x >> y >> k;       if (k < max(x, y)) {         cout <<  -1 n ;       } else {         long long int temp = k - max(x, y);         if (temp % 2 == 0) {           if (ch(x, y)) {             cout << k - 1 <<   n ;           } else {             cout << k <<   n ;           }         } else {           if (ch(x, y)) {             cout << k - 1 <<   n ;           } else {             cout << k - 2 <<   n ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   struct node {     double x, y, vx, vy;   } a[maxn];   bool ck(double a, double b) {     if (a - b > 1e-50 || (fabs(a - b) <= 1e-50))       return true;     else       return false;   }   int main() {     int n;     scanf( %d , &n);     double lx, ly, rx, ry;     scanf( %lf%lf%lf%lf , &lx, &ly, &rx, &ry);     double tl = 0, tr = 0x3f3f3f3f3f;     for (int i = 0; i < n; ++i)       scanf( %lf%lf%lf%lf , &a[i].x, &a[i].y, &a[i].vx, &a[i].vy);     for (int i = 0; i < n; ++i) {       double x = a[i].x, y = a[i].y, vx = a[i].vx, vy = a[i].vy;       double tmpl = 0, tmpr = 0x3f3f3f3f3f;       if (ck(x, rx) && ck(vx, 0)) {         return 0 * printf( -1 n );       } else if (ck(y, ry) && vy >= 0) {         return 0 * printf( -1 n );       } else if (ck(lx, x) && vx <= 0) {         return 0 * printf( -1 n );       } else if (ck(ly, y) && vy <= 0) {         return 0 * printf( -1 n );       }       double tt = 0;       if (vx >= 0 && vy >= 0) {         if (x <= lx) {           tt = max(tt, (lx - x + 1e-50) / vx);         }         if (y <= ly) {           tt = max(tt, (ly - y + 1e-50) / vy);         }         if (ck(x + vx * tt, rx) || ck(y + vy * tt, ry)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((rx - x + 1e-50) / vx, (ry - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx >= 0 && vy <= 0) {         if (x <= lx) {           tt = max(tt, (lx - x + 1e-50) / vx);         }         if (y >= ry) {           tt = max(tt, (ry - y + 1e-50) / vy);         }         if (ck(x + vx * tt, rx) || ck(ly, y + vy * tt)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((rx - x + 1e-50) / vx, (ly - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx <= 0 && vy >= 0) {         if (x >= rx) {           tt = max(tt, (rx - x + 1e-50) / vx);         }         if (y <= ly) {           tt = max(tt, (ly - y + 1e-50) / vy);         }         if (ck(lx, x + vx * tt) || ck(y + vy * tt, ry)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((lx - x + 1e-50) / vx, (ry - y + 1e-50) / vy);         tr = min(tr, tt);       } else if (vx <= 0 && vy <= 0) {         if (x >= rx) {           tt = max(tt, (rx - x + 1e-50) / vx);         }         if (y >= ry) {           tt = max(tt, (ry - y + 1e-50) / vy);         }         if (ck(lx, x + vx * tt) || ck(ly, y + vy * tt)) return 0 * printf( -1 n );         tl = max(tl, tt);         tt = 0;         tt = min((lx - x + 1e-50) / vx, (ly - y + 1e-50) / vy);         tr = min(tr, tt);       }     }     if (!ck(tl, tr))       printf( %.20f n , tl);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   int l[N][N], r[N][N], u[N][N], z[N][N];   int v[N][N];   void swap_left(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(l[fi][fj], l[gi][gj]);     int ai = l[fi][fj] / N;     int aj = l[fi][fj] % N;     int bi = l[gi][gj] / N;     int bj = l[gi][gj] % N;     swap(r[ai][aj], r[bi][bj]);   }   void swap_right(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(r[fi][fj], r[gi][gj]);     int ai = r[fi][fj] / N;     int aj = r[fi][fj] % N;     int bi = r[gi][gj] / N;     int bj = r[gi][gj] % N;     swap(l[ai][aj], l[bi][bj]);   }   void swap_up(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(u[fi][fj], u[gi][gj]);     int ai = u[fi][fj] / N;     int aj = u[fi][fj] % N;     int bi = u[gi][gj] / N;     int bj = u[gi][gj] % N;     swap(z[ai][aj], z[bi][bj]);   }   void swap_down(int f, int g) {     int fi = f / N;     int fj = f % N;     int gi = g / N;     int gj = g % N;     swap(z[fi][fj], z[gi][gj]);     int ai = z[fi][fj] / N;     int aj = z[fi][fj] % N;     int bi = z[gi][gj] / N;     int bj = z[gi][gj] % N;     swap(u[ai][aj], u[bi][bj]);   }   int main() {     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         if (j) {           int c = i * N + j - 1;           l[i][j] = c;         }         if (j + 1 < N) {           int c = i * N + j + 1;           r[i][j] = c;         }         if (i) {           int c = (i - 1) * N + j;           u[i][j] = c;         }         if (i + 1 < N) {           int c = (i + 1) * N + j;           z[i][j] = c;         }       }     }     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &v[i][j]);       }     }     while (q--) {       int a, b, c, d, h, w;       scanf( %d %d %d %d %d %d , &a, &b, &c, &d, &h, &w);       int f = 0, g = 0;       for (int i = 0; i < a; i++) f = z[f / N][f % N];       for (int i = 0; i < b; i++) f = r[f / N][f % N];       for (int i = 0; i < c; i++) g = z[g / N][g % N];       for (int i = 0; i < d; i++) g = r[g / N][g % N];       for (int i = 0; i < h; i++) {         swap_left(f, g);         if (i + 1 < h) {           f = z[f / N][f % N];           g = z[g / N][g % N];         }       }       for (int i = 0; i < w; i++) {         swap_down(f, g);         if (i + 1 < w) {           f = r[f / N][f % N];           g = r[g / N][g % N];         }       }       for (int i = 0; i < h; i++) {         swap_right(f, g);         if (i + 1 < h) {           f = u[f / N][f % N];           g = u[g / N][g % N];         }       }       for (int i = 0; i < w; i++) {         swap_up(f, g);         if (i + 1 < w) {           f = l[f / N][f % N];           g = l[g / N][g % N];         }       }     }     for (int i = 1; i <= n; i++) {       int now = r[i][0];       while (now % N <= m) {         int a = now / N;         int b = now % N;         printf( %d  , v[a][b]);         now = r[a][b];       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int head[100005], nxt[200005], v[200005], w[200005], tot = 0;   int fa[100005], rk[100005];   int p[100005], k[100005], n, m;   long long d[100005];   struct node {     int a, b, c;     long long len;   } e[100005];   queue<int> q;   inline int read() {     int x = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x;   }   inline void add(int a, int b, int c) {     tot++;     nxt[tot] = head[a];     head[a] = tot;     v[tot] = b;     w[tot] = c;   }   inline bool cmp(node a, node b) { return a.len < b.len; }   int getf(int a) {     if (a == fa[a]) return a;     return fa[a] = getf(fa[a]);   }   int main() {     int i, num;     n = read();     m = read();     for (i = 1; i <= m; i++) {       e[i].a = read();       e[i].b = read();       e[i].c = read();       add(e[i].a, e[i].b, e[i].c);       add(e[i].b, e[i].a, e[i].c);     }     num = read();     memset(d, 0x3f, sizeof(d));     memset(p, -1, sizeof(p));     for (i = 1; i <= num; i++) {       k[i] = read();       d[k[i]] = 0;       p[k[i]] = k[i];       q.push(k[i]);     }     while (!q.empty()) {       int t = q.front();       q.pop();       for (i = head[t]; i; i = nxt[i]) {         if (d[v[i]] > d[t] + w[i]) {           d[v[i]] = d[t] + w[i];           p[v[i]] = p[t];           q.push(v[i]);         }       }     }     for (i = 1; i <= n; i++) {       fa[i] = i;       rk[i] = 1;     }     for (i = 1; i <= m; i++) {       e[i].len = d[e[i].a] + d[e[i].b] + e[i].c;       e[i].a = p[e[i].a];       e[i].b = p[e[i].b];     }     sort(e + 1, e + m + 1, cmp);     long long ans = d[1];     for (i = 1; i <= m; i++) {       int faa = getf(e[i].a), fab = getf(e[i].b);       if (faa == fab) {         continue;       }       ans += e[i].len;       if (rk[faa] > rk[fab]) {         fa[fab] = faa;       } else {         fa[faa] = fab;       }       if (rk[faa] == rk[fab]) rk[fab]++;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   using vll = vector<long long>;   using vii = vector<pair<int, int>>;   const int N = 105;   int matrix[N][N];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &matrix[i][j]);     int score = 0, replace = 0;     for (int j = 0; j < m; j++) {       int best = 0, chop = 0, one = 0;       for (int i = 0; i < n; i++) {         if (matrix[i][j] == 0) continue;         int tmp = 0;         for (int x = 0; x < k && i + x < n; x++) tmp += matrix[i + x][j];         if (tmp > best) {           best = tmp;           chop = one;         }         ++one;       }       score += best;       replace += chop;     }     printf( %d %d n , score, replace);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     while (q--) {       long long c, m, x;       cin >> c >> m >> x;       long long a = min(c, m);       long long left = m - a + x + c - a;       if (left >= a) {         cout << a << endl;       } else {         long long t;         t = x;         c -= x;         m -= x;         if (c == m) {           t += (c + m) / 3;         } else {           if (c > m) {             t += c - m;             long long x = c - m;             c = c - (2 * x);             m = m - x;             t += (c + m) / 3;           } else {             t += m - c;             long long x = m - c;             m = m - (2 * x);             c = c - x;             t += (c + m) / 3;           }         }         cout << t << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<double, double> midpoint(double x1, double y1, double x2, double y2) {     return {(x1 + x2) / 2, (y1 + y2) / 2};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     map<pair<double, double>, int> mp;     pair<double, double> pr[n + 5];     for (int i = 0; i < n; i++) {       cin >> pr[i].first >> pr[i].second;       mp[pr[i]]++;     }     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (mp.find(midpoint(pr[i].first, pr[i].second, pr[j].first,                              pr[j].second)) != mp.end())           ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getFldsFromLine(char *line, std::vector<char *> &res,                       const char *sep =    t n v f r );   int main(int argc, char **argv) {     FILE *infile = stdin;     char *line;     line = (char *)calloc(5000000, sizeof(char));     if (line == NULL) {       fprintf(stderr,  Couldn t allocate space for  %s  nBye! n ,  line );       exit(-1);     };     std::vector<char *> flds;     int numFlds, numCases, caseNum = 0;     {       char *feabeqav = fgets(line, 5000000, infile);       numFlds = getFldsFromLine(line, flds);     };     int k = atoi(flds[0]);     if (k != 2) k = 1;     cout << k << endl;     return (0);     return (0);   }   int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep) {     res.clear();     char *tok = strtok(line, sep);     while (tok) {       res.push_back(tok);       tok = strtok(0, sep);     }     return res.size();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, r[1000], c[1000], min[1000], sum = 0;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> r[i] >> c[i];       min[i] = 9999999999;     }     for (int i = 0; i < n; i++)       if (min[r[i] - 1] > c[i]) min[r[i] - 1] = c[i];     for (int i = 0; i < m; i++) sum += min[i];     if (sum > k)       cout << k;     else       cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int n, s, f;   int m;   long long a[2 * 100005];   long long duc = 1e10;   inline long long get(long long pos) {     if (pos <= s)       return s - pos + 1;     else {       return n - pos + s + 1;     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     cin >> s >> f;     m = f - s;     long long ans = 0;     long long now = 0;     for (int i = 1; i <= m; i++) {       now += a[i];     }     ans = now;     long long opt = 1;     int l = 1, r = m;     while (l <= n) {       now -= a[l];       now += a[r + 1];       if (ans <= now) {         if (ans < now)           duc = get(l + 1);         else           duc = min(duc, get(l + 1));         ans = now;       }       l++;       r++;     }     cout << duc;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, mod2 = 998244353;   unsigned long long base = 131;   const int w = 5e5 + 5;   long long n, m;   struct node {     int x, y, z;   } s[w];   int cmp(node x, node y) {     if (x.x != y.x)       return x.x > y.x;     else       return x.y > y.y;   }   int main() {     long long i, j, t;     cin >> n;     cout << n / 2 + 1 << endl;     for (i = 1; i <= n; i++) scanf( %d , &s[i].x), s[i].z = i;     for (i = 1; i <= n; i++) scanf( %d , &s[i].y);     sort(s + 1, s + 1 + n, cmp);     cout << s[1].z <<    ;     for (i = 2; i <= n; i += 2) {       if (s[i].y > s[i + 1].y)         cout << s[i].z <<    ;       else         cout << s[i + 1].z <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 1;   int a[6];   int n;   int b[MAXN];   int ptr[MAXN];   int f[MAXN][6];   int main() {     for (int i = 0; i < 6; ++i) cin >> a[i];     cin >> n;     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < 6; ++j) {         f[i][j] = b[i] - a[j];       }       sort(f[i], f[i] + 6);     }     fill(ptr, ptr + n, 0);     priority_queue<pair<int, int>, vector<pair<int, int>>,                    greater<pair<int, int>>>         pq;     int maxv = -1;     for (int i = 0; i < n; ++i) {       pq.push(make_pair(f[i][ptr[i]], i));       maxv = max(maxv, f[i][ptr[i]]);     }     int minv = -1;     int mini = -1;     int diff = 1e9;     pair<int, int> top;     while (true) {       top = pq.top();       pq.pop();       minv = top.first;       diff = min(diff, maxv - minv);       mini = top.second;       if (ptr[mini] == 5) {         break;       }       ++ptr[mini];       pq.push(make_pair(f[mini][ptr[mini]], mini));       maxv = max(maxv, f[mini][ptr[mini]]);     }     cout << diff << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxi = 2000000000;   const int maxq = 1000000000;   const double eps = 1e-10;   const double pi = acos(-1);   const double inf = 1e+18;   const int mo = 1000000007;   using namespace std;   char s[111111], s1[111111];   int main() {     gets(s);     gets(s1);     int n = strlen(s);     int m = strlen(s1);     int kol = 0;     int kol1 = 0;     int sum = 0;     int ans = 0;     for (int i = 0; i < n; i++)       if (s[i] ==  4 ) kol++;     for (int i = 0; i < n; i++)       if (s1[i] ==  4 ) kol1++;     for (int i = 0; i < n; i++) {       if (kol < kol1 && s[i] ==  7  && s1[i] ==  4 ) {         s[i] =  4 ;         ans++;         kol++;       }       if (kol > kol1 && s[i] ==  4  && s1[i] ==  7 ) {         s[i] =  7 ;         ans++;         kol--;       }     }     for (int i = 0; i < n; i++)       if (s[i] != s1[i]) sum++;     cout << ans + sum / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e6 + 3;   long long fastexp(long long a, long long b, long long n) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % n;       a = a * a % n;       b >>= 1;     }     return res;   }   int main() {     vector<long long> p(11), re(mod);     for (long long i = 1; i < mod; i++) {       re[i] = fastexp(i, mod - 2, mod);     }     for (int i = 0; i < 11; i++) {       cout <<  ?   << i << endl;       cin >> p[i];       if (p[i] == -1) {         return 0;       }       if (p[i] == 0) {         cout <<  !   << i << endl;         return 0;       }     }     for (int i = 0; i < 11; i++) {       for (int j = 0; j < 11; j++) {         if (j == i) continue;         p[i] = p[i] * re[(i - j + mod) % mod] % mod;       }     }     for (int x = 11; x < mod; x++) {       long long val = 0;       for (int i = 0; i < 11; i++) {         val += p[i] * re[x - i];       }       if (val % mod == 0) {         cout <<  !   << x << endl;         return 0;       }     }     cout <<  ! -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(0);   const long long MAXN = 2e6 + 1, MOD = 998244353, M = 1000000001;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (; t--;) {       long long n, m;       cin >> n >> m;       long long l = (n - m) / (m + 1);       long long k = n - m - (m + 1) * l;       long long ans = l * (l + 1) * (m + 1 - k) / 2 + k * (l + 1) * (l + 2) / 2;       cout << n * (n + 1) / 2 - ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   int main() {     long long int t, n, i, j, m, d, k, q, y, z, l, r, a, b, c;     cin >> t;     while (t--) {       string str;       cin >> str;       n = str.length();       z = 0;       int p = 0;       m = 0;       int x = 0;       for (i = 0; i < (n); ++i) {         z++;         if (str[i] ==  + )           p++;         else           m++;         if (x + p - m < 0) {           x++;           z += (i + 1);         }       }       cout << z <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[150500];   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     vector<long long> ans;     for (int f = 0; f < t; f++) {       long long n, m;       cin >> n >> m;       vector<long long> l;       l.push_back(m % 10);       for (long long i = m + m; l[0] != i % 10; i += m) l.push_back(i % 10);       long long c = n / m / l.size() * accumulate(l.begin(), l.end(), 0);       for (int i = 0; i < n / m % l.size(); i++) c += l[i];       ans.push_back(c);     }     for (auto i : ans) cout << i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum(int a) {     int s = 0;     while (a > 0) {       s += (a % 10);       a = a / 10;     }     return s;   }   int main() {     int n, a, b;     cin >> n;     while (sum(n) % 4 != 0) {       n++;     }     cout << n << endl;     return 0;   }