#include <bits/stdc++.h>   const int MAX = 3000;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long LLINF = 0x3f3f3f3f3f3f3f3f;   const long double EPS = 1e-9;   const long double PI = acos(-1.0);   using namespace std;   bool eq(long double a, long double b) { return fabsl(a - b) <= EPS; }   struct point {     long double x, y;     int id;     point(long double x = 0, long double y = 0) : x(x), y(y) {}     point operator+(const point &o) const { return {x + o.x, y + o.y}; }     point operator-(const point &o) const { return {x - o.x, y - o.y}; }     point operator*(long double t) const { return {x * t, y * t}; }     point operator/(long double t) const { return {x / t, y / t}; }     long double operator*(const point &o) const { return x * o.x + y * o.y; }     long double operator^(const point &o) const { return x * o.y - y * o.x; }     bool operator<(const point &o) const {       if (!eq(x, o.x)) return x < o.x;       return y < o.y;     }     bool operator==(const point &o) const { return eq(x, o.x) and eq(y, o.y); }   };   long double norm(point a) { return sqrt(a * a); }   long double proj(point a, point b) { return a * b / norm(b); }   long double max(long double a, long double b) { return (a > b ? a : b); }   long double min(long double a, long double b) { return (a < b ? a : b); }   long double angle(point a, point b) {     long double ang = a * b / norm(a) / norm(b);     return acos(max(min(ang, 1), -1));   }   int ccw(point a, point b, point e) {     long double tmp = (b - a) ^ (e - a);     return (tmp > EPS) - (tmp < -EPS);   }   struct line {     point p1, p2;     line(point p1 = 0, point p2 = 0) : p1(p1), p2(p2) {}     long double a = p1.y - p2.y;     long double b = p2.x - p1.x;     long double c = -(a * p1.x + b * p1.y);     bool inside(point p) {       return eq(norm(p1 - p) + norm(p2 - p) - norm(p2 - p1), 0);     }   };   point intersect(line l1, line l2) {     long long det = l1.a * l2.b - l1.b * l2.a;     if (det == 0) return point(INF, INF);     long double x = (l1.b * l2.c - l1.c * l2.b) / det;     long double y = (l1.c * l2.a - l1.a * l2.c) / det;     return point(x, y);   }   bool check(point a[2], point b[2], point m[2]) {     if (a[0] == b[1])       swap(b[0], b[1]);     else if (a[1] == b[0])       swap(a[0], a[1]);     else if (a[1] == b[1]) {       swap(a[0], a[1]);       swap(b[0], b[1]);     } else if (!(a[0] == b[0]))       return false;     assert(a[0] == b[0]);     long double ang = angle(a[1] - a[0], b[1] - b[0]);     if (ang > PI / 2 + EPS or ang < EPS) return false;     line A = line(a[0], a[1]);     line B = line(b[0], b[1]);     line M = line(m[0], m[1]);     if (A.inside(m[0]) and B.inside(m[1])) {       if (norm(a[1] - m[0]) > 4 * norm((m[0] - a[0])) or           norm(a[0] - m[0]) > 4 * norm((m[0] - a[1])))         return false;       if (norm(b[1] - m[1]) > 4 * norm((m[1] - b[0])) or           norm(b[0] - m[1]) > 4 * norm((m[1] - b[1])))         return false;       else         return true;     } else if (A.inside(m[1]) and B.inside(m[0])) {       if (norm(a[1] - m[1]) > 4 * norm((m[1] - a[0])) or           norm(a[0] - m[1]) > 4 * norm((m[1] - a[1])))         return false;       if (norm(b[1] - m[0]) > 4 * norm((m[0] - b[0])) or           norm(b[0] - m[0]) > 4 * norm((m[0] - b[1])))         return false;       else         return true;     } else       return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, x, y;     cin >> t;     point vet[3][2];     while (t--) {       for (int i = 0; i < 3; i++)         for (int j = 0; j < 2; j++) {           cin >> x >> y;           vet[i][j] = point(x, y);         }       if (check(vet[0], vet[1], vet[2]) or check(vet[0], vet[2], vet[1]) or           check(vet[1], vet[2], vet[0]))         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j, k, l, m, n, s, t, p, q, a, b, aa, bb, d;   char c[2222222];   int main() {     t = 1;     while (gets(c) != 0) {       for (i = 0; c[i] != 0; i++)         if (c[i] !=    ) break;       if (c[i] ==  # ) {         if (t == 0) puts(  );         puts(c);         t = 1;       } else {         for (i = 0; c[i] != 0; i++)           if (c[i] !=    ) cout << c[i];         t = 0;       }     }     if (t == 0) puts(  );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     long long inf = 1000000005;     cin >> n >> m;     long long i, j, k;     bool a[n + 1][n + 1];     long long deg[n + 1];     for (i = 0; i < n + 1; i++) {       deg[i] = 0;       for (j = 0; j < n + 1; j++) a[i][j] = false;     }     long long res = inf;     for (i = 0; i < m; i++) {       cin >> j >> k;       a[j][k] = true;       a[k][j] = true;       deg[j]++;       deg[k]++;     }     for (i = 1; i < n; i++) {       for (j = i + 1; j <= n; j++) {         if (a[i][j]) {           for (k = j + 1; k <= n; k++) {             if (a[i][k] && a[j][k]) res = min(res, deg[i] + deg[j] + deg[k]);           }         }       }     }     if (res == inf)       cout << -1 << endl;     else       cout << res - 6 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int t;     cin >> t;     for (int i = 0; i < n; ++i) {       int a, b;       cin >> a >> b;       int d[7] = {0};       d[a] = 1;       d[7 - a] = 1, d[b] = 1, d[7 - b] = 1;       d[t] = 1;       int cn = 0;       for (int j = 1; j < 7; ++j) {         if (d[j] == 0) {           t = 7 - j;           cn++;         }       }       if (cn == 2) return (cout <<  NO , 0);     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int a[N];   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> nrs;     for (int i = 0; i < n; ++i) nrs.push_back(a[i]);     for (int i = 1; i < 32; ++i) {       vector<int> counts(32, 0);       vector<int> cur;       for (int j = 0; j < n; ++j) {         if (not(a[j] & (1 << i))) continue;         cur.push_back(a[j]);         for (int k = 0; k < 32; ++k) {           if (a[j] & (1 << k)) ++counts[k];         }       }       if (cur.empty()) continue;       bool ok = true;       for (int j = 0; j < i; ++j) {         ok &= counts[j] < counts[i];       }       if (ok) nrs = cur;     }     cout << nrs.size() <<   n ;     for (int i = 0; i < (int)nrs.size(); ++i) {       if (i > 0) cout <<    ;       cout << nrs[i];     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d , &(n)), scanf( %d , &(m));     int a[(100000 + 10)][2];     for (int i(0), _n(n); i < _n; ++i) {       scanf( %d , &a[i][1]);       if (a[i][1] > 0)         a[i][0] =  + ;       else         a[i][0] =  - , a[i][1] = -a[i][1];     }     int yes[(100000 + 10)], no[(100000 + 10)];     memset((yes), 0, sizeof(yes));     memset((no), 0, sizeof(no));     for (int i(0), _n(n); i < _n; ++i) {       if (a[i][0] ==  + )         yes[a[i][1]]++;       else         no[a[i][1]]++;     }     int sno = 0;     for (int i(1), _h(n); i <= _h; ++i) sno += no[i];     bool may[(100000 + 10)];     memset((may), false, sizeof(may));     int cnt = 0;     for (int i(1), _h(n); i <= _h; ++i)       if (yes[i] + sno - no[i] == m) {         may[i] = true;         cnt++;       }     for (int i(0), _n(n); i < _n; ++i) {       if (a[i][0] ==  + ) {         if (may[a[i][1]] && cnt == 1)           puts( Truth );         else if (may[a[i][1]])           puts( Not defined );         else           puts( Lie );       } else {         if (may[a[i][1]] && cnt == 1)           puts( Lie );         else if (may[a[i][1]])           puts( Not defined );         else           puts( Truth );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200010], b[200010], n, m, q;   vector<pair<int, int> > e[200010];   long long T[800010], d[800010];   long long f[200010];   void push(int id) {     T[id << 1] += d[id];     T[id << 1 | 1] += d[id];     d[id << 1] += d[id];     d[id << 1 | 1] += d[id];     d[id] = 0;     return;   }   void upd(int x, int y, long long dx, int id = 1, int l = 0, int r = n) {     if (x >= r || l >= y) return;     if (x <= l && r <= y) {       T[id] += dx;       d[id] += dx;       return;     }     push(id);     upd(x, y, dx, id << 1, l, l + r >> 1);     upd(x, y, dx, id << 1 | 1, l + r >> 1, r);     T[id] = min(T[id << 1], T[id << 1 | 1]);     return;   }   void build() {     for (int i = 0; i < n; i++) upd(i, i + 1, b[i]);     for (int i = 0; i < n; i++) {       for (auto p : e[i]) {         int to, cost;         tie(to, cost) = p;         upd(0, to + 1, cost);       }       f[i] = T[1];     }     memset(T, 0, sizeof(T));     memset(d, 0, sizeof(d));     for (int i = 0; i < n; i++) upd(i, i + 1, a[i] + f[i]);     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> q;     for (int i = 0; i < n - 1; i++) cin >> a[i] >> b[i + 1];     for (int i = 0, u, v, w; i < m; i++) {       cin >> u >> v >> w;       e[--u].push_back((make_pair((--v), (w))));     }     build();     cout << T[1] << endl;     while (q--) {       int x, w;       cin >> x >> w;       upd(x - 1, x, w - a[x - 1]);       a[x - 1] = w;       cout << T[1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int N = 2e5 + 7;   int n, m, i, j, a, b;   int check(int x, int y) {     int dis1 = abs(x - i);     int dis2 = abs(y - j);     if (dis1 % a == 0 && dis2 % b == 0) {       int p = dis1 / a;       int q = dis2 / b;       if (p == q) return q;       if ((p + q) & 1) return inf;       if (p < q) {         if (i + a > n && i - a < 1) return inf;       } else {         if (j + b > m && j - b < 1) return inf;       }       return max(p, q);     } else       return inf;   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &i);     scanf( %d , &j);     scanf( %d , &a);     scanf( %d , &b);     int ans = inf;     ans = min(ans, check(1, 1));     ans = min(ans, check(n, 1));     ans = min(ans, check(1, m));     ans = min(ans, check(n, m));     if (ans == inf)       puts( Poor Inna and pony! );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long long N = 2e6 + 10;   const long long dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},                   dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};   bool TC = 0;   long long binpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * 1LL * a;       a = a * 1LL * a;       b >>= 1;     }     return res;   }   long long s(long long n) {     long long res = 0;     while (n) {       res += n % 10;       n /= 10;     }     return res;   }   void test_case() {     long long a, b, c;     cin >> a >> b >> c;     vector<long long> v;     for (long long i = 1; i <= 81; i++) {       long long var = b * ((long long)binpow(i, a)) + c;       if (s(var) == i && var < 1e9) v.push_back(var);     }     cout << (long long)((v).size()) <<   n ;     for (long long i = 0; i < (long long)((v).size()); i++) {       cout << v[i] <<    ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (TC) {       long long T;       cin >> T;       while (T--) test_case();     } else       test_case();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long pow_[20];   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n % 2 == 1) {         res = (a * res) % mod;       }       a = (a * a) % mod;       n /= 2;     }     return res;   }   long long C(long long n, long long k) {     long long res = 1;     n = n % mod;     for (long long i = n; i >= n - k + 1; i--) {       res = (res * i) % mod;     }     for (long long i = 1; i <= k; i++) {       res = (res * pow_[i]) % mod;     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     for (long long i = 1; i <= 19; i++) {       pow_[i] = binpow(i, mod - 2);     }     long long n, s;     cin >> n >> s;     vector<long long> f(n);     for (long long i = 0; i < n; i++) cin >> f[i];     long long res = 0;     for (long long mask = 0; mask < (1 << n); mask++) {       long long t = 0;       for (long long i = 0; i < n; i++) {         if (mask & (1 << i)) t++;       }       long long cur;       if (t % 2 == 0)         cur = 1;       else         cur = -1;       long long sum = 0;       for (long long i = 0; i < n; i++) {         if (mask & (1 << i)) sum += (f[i] + 1);       }       if (s - sum + n - 1 < n - 1) continue;       cur = (cur * C(s - sum + n - 1, n - 1) + mod) % mod;       res = (res + cur) % mod;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long int k;   long long int a[100001];   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n / 2; i++) {       long long int c = (a[i + 1] - a[i] + a[n - i + 1] - a[n - i]) * i;       if (c <= k)         k -= c;       else {         cout << a[n - i + 1] - a[i] - k / i;         return 0;       }     }     cout << 0;     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 n;   pair<pair<int, int>, pair<int, int> > a = {{0, 0}, {0, 0}},                                         b = {{0, 0}, {0, 0}};   pair<pair<int, int>, pair<int, int> > solve(int x, int y, int x1, int y1) {     pair<pair<int, int>, pair<int, int> > ans;     ans.first = {x, y};     ans.second = {x1, y1};     int l = x + 1, r = x1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << mid <<     << y <<     << x1 <<     << y1 << endl;       int ok;       cin >> ok;       if (ok == 0) {         r = mid - 1;       } else {         l = mid + 1;         ans.first.first = mid;       }     }     l = y + 1, r = y1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << mid <<     << x1 <<     << y1 << endl;       int ok;       cin >> ok;       if (ok == 0) {         r = mid - 1;       } else {         l = mid + 1;         ans.first.second = mid;       }     }     l = y, r = y1 - 1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << y <<     << x1 <<     << mid << endl;       int ok;       cin >> ok;       if (ok == 0) {         l = mid + 1;       } else {         r = mid - 1;         ans.second.second = mid;       }     }     l = x, r = x1 - 1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << y <<     << mid <<     << y1 << endl;       int ok;       cin >> ok;       if (ok == 0) {         l = mid + 1;       } else {         r = mid - 1;         ans.second.first = mid;       }     }     return ans;   }   pair<pair<int, int>, pair<int, int> > solve1(int x, int y, int x1, int y1) {     pair<pair<int, int>, pair<int, int> > ans;     ans.first = {x, y};     ans.second = {x1, y1};     int l = x + 1, r = x1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << mid <<     << y <<     << x1 <<     << y1 << endl;       int ok;       cin >> ok;       if (mid <= a.first.first && y <= a.first.second && x1 >= a.second.first &&           y1 >= a.second.second)         ok--;       if (ok == 0) {         r = mid - 1;       } else {         l = mid + 1;         ans.first.first = mid;       }     }     l = y + 1, r = y1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << mid <<     << x1 <<     << y1 << endl;       int ok;       cin >> ok;       if (x <= a.first.first && mid <= a.first.second && x1 >= a.second.first &&           y1 >= a.second.second)         ok--;       if (ok == 0) {         r = mid - 1;       } else {         l = mid + 1;         ans.first.second = mid;       }     }     l = y, r = y1 - 1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << y <<     << x1 <<     << mid << endl;       int ok;       cin >> ok;       if (x <= a.first.first && y <= a.first.second && x1 >= a.second.first &&           mid >= a.second.second)         ok--;       if (ok == 0) {         l = mid + 1;       } else {         r = mid - 1;         ans.second.second = mid;       }     }     l = x, r = x1 - 1;     while (l <= r) {       int mid = (l + r) >> 1;       cout <<  ?   << x <<     << y <<     << mid <<     << y1 << endl;       int ok;       cin >> ok;       if (x <= a.first.first && y <= a.first.second && mid >= a.second.first &&           y1 >= a.second.second)         ok--;       if (ok == 0) {         l = mid + 1;       } else {         r = mid - 1;         ans.second.first = mid;       }     }     return ans;   }   int main() {     cin >> n;     int l = 1, r = n;     int ans = 1;     pair<pair<int, int>, pair<int, int> > ha = {{0, 0}, {0, 0}};     while (l <= r) {       int mid = ((l + r) >> 1);       cout <<  ?   << mid <<     << 1 <<     << n <<     << n << endl;       int x;       cin >> x;       if (x == 2) {         ans = mid;         l = mid + 1;       } else {         if (x == 0) {           r = mid - 1;         } else {           ha = {{mid, 1}, {n, n}};           break;         }       }     }     if (ha.first.second != 0) {       a = solve(ha.first.first, ha.first.second, ha.second.first,                 ha.second.second);       b = solve1(1, 1, n, n);     } else {       l = 1, r = n;       int anss = 1;       ha = {{0, 0}, {0, 0}};       while (l <= r) {         int mid = ((l + r) >> 1);         cout <<  ?   << ans <<     << mid <<     << n <<     << n << endl;         int x;         cin >> x;         if (x == 2) {           anss = mid;           l = mid + 1;         } else {           if (x == 0) {             r = mid - 1;           } else {             ha = {{ans, mid}, {n, n}};             break;           }         }       }       a = solve(ha.first.first, ha.first.second, ha.second.first,                 ha.second.second);       b = solve1(1, 1, n, n);     }     cout <<  !   << a.first.first <<     << a.first.second <<              << a.second.first <<     << a.second.second <<     << b.first.first          <<     << b.first.second <<     << b.second.first <<              << b.second.second << endl;   }


#include<bits/stdc++.h>   #define ls i<<1   #define rs i<<1|1   #define fi first   #define se second   #define pb push_back   #define mp make_pair   using namespace std;   typedef long long ll;   typedef vector<int> vct;   typedef pair<int,int> pii;   const int N=2E5+1;   const int inf=1<<30;   ll read()   {       ll a=0;       char b=1,c;       do if((c=getchar())==45)b=-1;while(c<48||c>57);       do a=(a<<3)+(a<<1)+(c&15);while((c=getchar())>47&&c<58);       return a*b;   }   void write(ll x,char c)   {       if(x<0)putchar(45),x=-x;       char a[20],s=0;       do a[++s]=x%10|48;while(x/=10);       do putchar(a[s]);while(--s);       putchar(c);   }   const int p=1E9+7;   int n,l,r;   int fac[N],inv[N];   vct a,ans;   int solve(int u,int v)   {       for(int i=0;i<n;++i)       {           int y=u-max(l+a[i]-1,0),z=v-max(n-r+a[i],0);           if(y<0||z<0)ans[i]=0;           else ans[i]=(fac[y+z]*1LL*inv[y]%p*inv[z]%p);       }       int res=0;       for(int i=0;i<n;++i)res=(res+(ans[i]-ans[i+1]+p)*1LL*a[i])%p;       return res;   }   int main()   {       fac[0]=fac[1]=inv[0]=inv[1]=1;       for(int i=2;i<N;++i)inv[i]=(p-p/i)*1LL*inv[p%i]%p;       for(int i=2;i<N;++i)       {           fac[i]=fac[i-1]*1LL*i%p;           inv[i]=inv[i-1]*1LL*inv[i]%p;       }       for(int x=read();x--;)       {           n=read(),l=read(),r=read();           a.resize(n);           ans.resize(n);           ans.pb(0);           iota(a.begin(),a.end(),min(1-l,r-n));           int m=n>>1;           if(n&1)write((solve(m,n-m)+solve(n-m,m))%p,  n );           else write(solve(m,m),  n );       }   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int main() {     int i, j, n, m, t;     string s;     cin >> t;     int cnt = 0;     for (i = 0; i < t; i++) {       cin >> s;       int len = s.size();       string ans;       int chk = 1;       while (chk == 1) {         ans.clear();         chk = 0;         len = s.size();         for (j = 0; j < len - 1; j++) {           if (s[j] ==  o  && s[j + 1] ==  o ) {             ans.push_back( u );             j++;             chk = 1;           } else if (s[j] ==  k  && s[j + 1] ==  h ) {             ans.push_back( h );             j++;             chk = 1;           } else if (s[j] ==  u  && s[j + 1] ==  o ) {             s[j] =  o ;             s[j + 1] =  u ;             chk = 1;             ans.push_back( o );           } else             ans.push_back(s[j]);         }         if (j == len - 1) ans.push_back(s[j]);         s = ans;       }       if (mp[ans] == 0) {         cnt++;       }       mp[ans]++;     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int ans = 0;   vector<int> vx[200005];   bool vu[200005];   int n, k;   int dfs(int v, int p) {     int aa = 0, aa2 = 0;     for (int i = 0; i < vx[v].size(); i++) {       if (vx[v][i] == p) continue;       int pr = dfs(vx[v][i], v);       aa += pr;       aa2 += min(pr, 2 * k - pr);     }     ans += aa2;     if (vu[v]) aa++;     return aa;   }   int main() {     for (int i = 0; i < 200005; i++) vu[i] = 0;     cin >> n >> k;     int u, v;     for (int i = 0; i < k; i++) {       cin >> u >> v;       vu[u] = vu[v] = 1;     }     for (int i = 1; i < n; i++) {       cin >> u >> v;       vx[u].push_back(v);       vx[v].push_back(u);     }     dfs(1, -1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     double x, y;     Point() {}     Point(double _x, double _y) {       x = _x;       y = _y;     }     Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }     double operator^(const Point &b) const { return x * b.y - y * b.x; }     double operator*(const Point &b) const { return x * b.x + y * b.y; }     void transXY(double B) {       double tx = x, ty = y;       x = tx * cos(B) - ty * sin(B);       y = tx * sin(B) + ty * cos(B);     }   };   struct Line {     Point s, e;     Line() {}     Line(Point _s, Point _e) {       s = _s;       e = _e;     }   };   Point PointToLine(Point P, Line L) {     Point result;     double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s));     result.x = L.s.x + (L.e.x - L.s.x) * t;     result.y = L.s.y + (L.e.y - L.s.y) * t;     return result;   }   Point ver[1010];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> ver[i].x >> ver[i].y;     ver[0] = ver[n];     ver[n + 1] = ver[1];     double ans = 1e12;     for (int i = 1; i <= n; ++i) {       Line l;       l.s = ver[i - 1];       l.e = ver[i + 1];       Point p = PointToLine(ver[i], l);       double len = sqrt((ver[i].x - p.x) * (ver[i].x - p.x) +                         (ver[i].y - p.y) * (ver[i].y - p.y));       ans = min(ans, len / 2);     }     printf( %.010lf n , ans);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T __sqr(const T x) {     return x * x;   }   template <class T, class X>   inline T __pow(T a, X y) {     T z = 1;     for (int i = 1; i <= y; i++) {       z *= a;     }     return z;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     if (!b) return a;     return __gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / __gcd(a, b)) * b;   }   inline bool ispow2(int x) { return (x != 0 && (x & (x - 1)) == 0); }   template <class T>   void UpdateMin(T &x, T y) {     if (y < x) {       x = y;     }   }   template <class T>   void UpdateMax(T &x, T y) {     if (x < y) {       x = y;     }   }   template <class T, class X, class Y>   inline T bigmod(T n, X m, Y mod) {     unsigned long long ret = 1, a = n % mod;     while (m) {       if (m & 1) ret = (ret * a) % mod;       m >>= 1;       a = (a * a) % mod;     }     ret %= mod;     return (T)ret;   }   template <class T, class Y>   inline T modinv(T n, Y mod) {     return bigmod(n, mod - 2, mod);   }   template <class T, class X>   int getbit(T s, X i) {     return (s >> i) & 1;   }   template <class T, class X>   T onbit(T s, X i) {     return s | (T(1) << i);   }   template <class T, class X>   T offbit(T s, X i) {     return s & (~(T(1) << i));   }   template <class T>   inline void read(T &n) {     char c;     for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar())       ;     n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;   }   void extended_euclid(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return;     }     long long first, second;     extended_euclid(b, a % b, first, second);     x = second;     y = first - (a / b) * second;   }   pair<long long, pair<long long, long long> > extendedEuclid(long long a,                                                               long long b) {     long long x = 1, y = 0;     long long xLast = 0, yLast = 1;     long long q, r, m, n;     while (a != 0) {       q = b / a;       r = b % a;       m = xLast - q * x;       n = yLast - q * y;       xLast = x, yLast = y;       x = m, y = n;       b = a, a = r;     }     return make_pair(b, make_pair(xLast, yLast));   }   const long long mod[] = {0,          1000000007, 1000000009,                            1000000021, 1000000033, 1000000097,                            1000000093, 1000000097, 1000000103};   const long long base[] = {0,       1000003, 1000033, 1000037, 1000039,                             1000081, 1000099, 1000117, 1000121};   char s[(300000 + 20)], ans[(300000 + 20)];   vector<int> cnt[50];   int fnd[50];   int main() {     int m, n;     scanf( %d , &m);     scanf( %s , s);     n = strlen(s);     int tot = 0;     int cov = -1;     for (int i = 0; i < n; i++) {       fnd[s[i] -  a ]++;       cnt[s[i] -  a ].push_back(i);       if (i == (cov + m)) {         for (int j = 0; j < 26; j++) {           if (cnt[j].empty()) continue;           if (cnt[j].back() <= (i - m)) continue;           ans[tot++] = s[cnt[j].back()];           fnd[s[cnt[j].back()] -  a ]--;           cov = cnt[j].back();           break;         }       }     }     ans[tot] =   0 ;     sort(ans, ans + tot);     int g = tot;     for (int i = 0; i < (ans[g - 1] -  a ); i++) {       for (int j = 0; j < fnd[i]; j++) {         ans[tot++] =  a  + i;       }     }     ans[tot] =   0 ;     sort(ans, ans + tot);     puts(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int a, b;     node() { a = b = 0; }   } node[10005];   int main() {     int n, v;     cin >> n >> v;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       node[a].a += b;     }     int ans = 0;     for (int i = 1; i <= 3001; i++) {       int vv = v;       if (vv < node[i].b) {         ans += vv;         node[i + 1].b += node[i].a;       } else {         ans += node[i].b;         vv -= node[i].b;         if (vv >= node[i].a) {           ans += node[i].a;         } else {           ans += vv;           node[i + 1].b += node[i].a - vv;         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 100;   const long long inf = (1LL << 30 - 1);   pair<int, int> A[maxn];   int fa[maxn], X[maxn], Y[maxn], Hx[maxn], Hy[maxn], ans[maxn];   int FindSet(int x) { return fa[x] == x ? x : fa[x] = FindSet(fa[x]); }   void UnionSet(int u, int v) {     u = FindSet(u);     v = FindSet(v);     if (u != v) fa[u] = v;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n * m; i++) {       fa[i] = i;       scanf( %d , &A[i].first);       A[i].second = i;     }     sort(A, A + n * m);     int j = -1;     memset(X, 0, sizeof(X));     memset(Y, 0, sizeof(Y));     for (int i = 0; i < n * m; i++) {       if (i != n * m - 1 && A[i].first == A[i + 1].first) continue;       for (int k = j + 1; k <= i; k++) {         int p = A[k].second;         int x = A[k].second / m, y = A[k].second % m;         Hx[x] = p;         Hy[y] = p;       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second;         int x = A[k].second / m, y = A[k].second % m;         UnionSet(Hx[x], p);         UnionSet(Hy[y], p);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second;         int x = A[k].second / m, y = A[k].second % m;         int pa = FindSet(p);         ans[pa] = max(ans[pa], max(X[x], Y[y]) + 1);       }       for (int k = j + 1; k <= i; k++) {         int p = A[k].second;         int x = A[k].second / m, y = A[k].second % m;         int pa = FindSet(p);         X[x] = max(X[x], ans[pa]);         Y[y] = max(Y[y], ans[pa]);       }       j = i;     }     for (int i = 0; i < n * m; i++) {       printf( %d , ans[FindSet(i)]);       if ((i + 1) % m == 0)         printf(  n );       else         printf(   );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> num(n + 1);     for (int i = 1; i <= n; i++) cin >> num[i];     if (num[1] % 2 == 0 || n % 2 == 0 || num[n] % 2 == 0) {       cout <<  No ;       return 0;     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using std::cin;   using std::cout;   const int N = 17;   char ch[N];   int n, r[N], b[N];   int sr, sb, red[1 << N], blue[1 << N], f[1 << N][123];   int main() {     std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> ch[i] >> r[i] >> b[i];       sr += r[i];       sb += b[i];     }     for (int i = 0; i < (1 << n); ++i) {       for (int j = 1; j <= n; ++j) {         if (i & (1 << (j - 1))) {           if (ch[j] ==  R )             ++red[i];           else             ++blue[i];         }       }     }     memset(f, -1, sizeof(f));     f[0][0] = 0;     for (int i = 0; i < (1 << n); ++i) {       for (int j = 0; j <= 121; ++j) {         if (f[i][j] == -1) continue;         for (int k = 1; k <= n; ++k) {           if (i & (1 << (k - 1))) continue;           int T = i | (1 << (k - 1));           f[T][j + std::min(r[k], red[i])] =               std::max(f[T][j + std::min(r[k], red[i])],                        f[i][j] + std::min(b[k], blue[i]));         }       }     }     int res = 1e9;     for (int i = 0; i <= 121; ++i) {       if (f[(1 << n) - 1][i] == -1) continue;       res = std::min(res, std::max(sr - i, sb - f[(1 << n) - 1][i]));     }     cout << res + n <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<string, int> table;     table.insert(pair<string, int>( void , 0));     while (n--) {       string cmd;       cin >> cmd;       if (cmd ==  typedef ) {         string from, to, raw;         cin >> from >> to;         int depth = 0, i = 0, j = from.size() - 1;         for (; i < j; ++i) {           if (from[i] !=  & ) {             break;           }           --depth;         }         for (; i < j; --j) {           if (from[j] !=  * ) {             break;           }           ++depth;         }         raw = from.substr(i, j - i + 1);         map<string, int>::iterator it = table.find(raw);         if (it == table.end()) {           table[to] = -1;         } else if (it->second < 0 || it->second + depth < 0) {           table[to] = -1;         } else {           table[to] = it->second + depth;         }       } else if (cmd ==  typeof ) {         string type, raw;         cin >> type;         int depth = 0, i = 0, j = type.size() - 1;         for (; i < j; ++i) {           if (type[i] !=  & ) {             break;           }           --depth;         }         for (; i < j; --j) {           if (type[j] !=  * ) {             break;           }           ++depth;         }         raw = type.substr(i, j - i + 1);         map<string, int>::iterator it = table.find(raw);         if (it == table.end()) {           cout <<  errtype  << endl;         } else if (it->second < 0 || it->second + depth < 0) {           cout <<  errtype  << endl;         } else {           cout <<  void  << string(it->second + depth,  * ) << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long MAX = pow(2, 32) - 1;     int n;     cin >> n;     stack<int> fors;     long long val = 0;     long long num = 1;     int i = 0;     while (i != n) {       string str;       cin >> str;       if (str ==  add ) {         val += num;       } else if (str ==  for ) {         int j;         cin >> j;         num *= j;         fors.push(j);       } else {         num /= fors.top();         fors.pop();       }       if (val > MAX) {         cout <<  OVERFLOW!!!  << endl;         return 0;       }       if (num > MAX) {         int end = 1;         while (end != 0) {           string s;           cin >> s;           if (s ==  add ) {             cout <<  OVERFLOW!!!  << endl;             return 0;           } else if (s ==  for ) {             int k;             cin >> k;             end++;           } else {             end--;           }           i++;         }         num /= fors.top();         fors.pop();       }       i++;     }     cout << val << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2005;   const long long mod = 1e9 + 7;   const long long INF = 1e18 + 1;   long long goal, n, m;   long long umbrella[N], rain[N], cache[N][N];   pair<long long, long long> a[N], b[N];   long long dp(long long x, long long y) {     if (x == goal) return 0;     long long &ans = cache[x][y];     if (ans != -1) return ans;     ans = INF;     if (umbrella[x]) ans = dp(x, x);     if (rain[x] and y == goal + 1) return ans;     if (rain[x]) {       ans = min(ans, umbrella[y] + min(dp(x + 1, y), dp(x + 1, goal + 1)));     } else       ans = min({ans, dp(x + 1, goal + 1),                  umbrella[y] + min(dp(x + 1, y), dp(x + 1, goal + 1))});     return ans;   }   void solve() {     memset(cache, -1, sizeof(cache));     cin >> goal >> n >> m;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i].first >> a[i].second;       for (long long j = a[i].first; j < a[i].second; j++) rain[j] = 1;     }     for (long long i = 1; i < m + 1; i++) {       cin >> b[i].first >> b[i].second;       if (umbrella[b[i].first] == 0)         umbrella[b[i].first] = b[i].second;       else         umbrella[b[i].first] = min(b[i].second, umbrella[b[i].first]);     }     sort(a + 1, a + n + 1);     sort(b + 1, b + m + 1);     if (a[1].first < b[1].first) {       cout << -1;       return;     }     cout << dp(0, goal + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, cnt;   vector<int> e[N];   vector<pair<int, int> > ans;   void init() {     scanf( %d , &n);     for (int i = 1, x, y; i < n; ++i) {       scanf( %d %d , &x, &y);       e[x].push_back(y);       e[y].push_back(x);     }   }   void dfs(int x, int father, int last_idx) {     int pre = last_idx;     for (int i = 0; i < e[x].size(); ++i)       if (e[x][i] != father) {         printf( 2 %d %d n , x, e[x][i]);         cnt++;         if (pre != -1) ans.push_back(make_pair(pre, cnt));         pre = cnt;         dfs(e[x][i], x, cnt);       }   }   void solve() {     printf( %d n , n - 1);     cnt = 0;     dfs(1, -1, -1);     for (int i = 0; i < ans.size(); ++i)       printf( %d %d n , ans[i].first, ans[i].second);   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b, c;   long long x, y, z, n;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     cin >> n;     a = 1234567;     b = 123456;     c = 1234;     for (int i = 0; i * a <= n; i++) {       for (int j = 0; i * a + j * b <= n; j++) {         if ((n - i * a - j * b) % c == 0) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   const int NUM = 200005;   const int MAXV = 1e6 + 100;   int blen, n, t, l, r, val;   int a[NUM], vcnt[MAXV];   long long int ans[NUM], answer;   struct query {     int l, r, ind;   } qs[NUM];   bool query_cmp(query a, query b) {     if (a.l / blen != b.l / blen) return a.l < b.l;     return a.r < b.r;   }   int main() {     int i;     std::scanf( %d%d , &n, &t);     blen = std::ceil(std::sqrt(n));     for (i = 0; i < n; ++i) std::scanf( %d , &a[i]);     for (i = 0; i < t; ++i) {       std::scanf( %d%d , &l, &r);       qs[i].l = l - 1;       qs[i].r = r;       qs[i].ind = i;     }     std::sort(qs, qs + t, query_cmp);     int ql, qr, cl, cr;     cl = 0;     cr = 0;     answer = 0;     for (i = 0; i < t; ++i) {       ql = qs[i].l;       qr = qs[i].r;       while (cl > ql) {         cl--;         val = a[cl];         answer -= (long long int)vcnt[val] * vcnt[val] * val;         vcnt[val]++;         answer += (long long int)vcnt[val] * vcnt[val] * val;       }       while (cl < ql) {         val = a[cl];         answer -= (long long int)vcnt[val] * vcnt[val] * val;         vcnt[val]--;         answer += (long long int)vcnt[val] * vcnt[val] * val;         cl++;       }       while (cr < qr) {         val = a[cr];         answer -= (long long int)vcnt[val] * vcnt[val] * val;         vcnt[val]++;         answer += (long long int)vcnt[val] * vcnt[val] * val;         cr++;       }       while (cr > qr) {         cr--;         val = a[cr];         answer -= (long long int)vcnt[val] * vcnt[val] * val;         vcnt[val]--;         answer += (long long int)vcnt[val] * vcnt[val] * val;       }       ans[qs[i].ind] = answer;     }     for (i = 0; i < t; ++i) printf( %I64d n , ans[i]);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int inf;   const double eps = 1e-8;   const double pi = acos(-1.0);   template <class T, class T2>   int chkmin(T &a, T2 b) {     return a > b ? a = b, 1 : 0;   }   template <class T, class T2>   int chkmax(T &a, T2 b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   T sqr(T a) {     return a * a;   }   template <class T, class T2>   T mmin(T a, T2 b) {     return a < b ? a : b;   }   template <class T, class T2>   T mmax(T a, T2 b) {     return a > b ? a : b;   }   template <class T>   T aabs(T a) {     return a < 0 ? -a : a;   }   template <class T>   int dcmp(T a, T b) {     return a > b;   }   template <int *a>   int cmp_a(int first, int second) {     return a[first] < a[second];   }   struct __INIT__ {     __INIT__() {       fill((unsigned char *)(&inf), (unsigned char *)(&inf) + sizeof(inf), 0x3f);     }   } __INIT___;   namespace io {   const int SIZE = (1 << 21) + 1;   char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,                                          qu[55];   int f, qr;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char first) {     *oS++ = first;     if (oS == oT) flush();   }   template <typename A>   inline bool read(A &first) {     for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                               : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - )         f = -1;       else if (c == EOF)         return 0;     for (first = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       first = first * 10 + (c & 15);     first *= f;     return 1;   }   inline bool read(char &first) {     while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                  (iS == iT ? EOF : *iS++))                               : *iS++)) ==     ||            first ==   n  || first ==   r )       ;     return first != EOF;   }   inline bool read(char *first) {     while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                   (iS == iT ? EOF : *iS++))                                : *iS++)) ==   n  ||            *first ==     || *first ==   r )       ;     if (*first == EOF) return 0;     while (!(*first ==   n  || *first ==     || *first ==   r  || *first == EOF))       *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                              : *iS++);     *first = 0;     return 1;   }   template <typename A, typename... B>   inline bool read(A &first, B &...second) {     return read(first) && read(second...);   }   template <typename A>   inline bool write(A first) {     if (!first) putc( 0 );     if (first < 0) putc( - ), first = -first;     while (first) qu[++qr] = first % 10 +  0 , first /= 10;     while (qr) putc(qu[qr--]);     return 0;   }   inline bool write(char first) {     putc(first);     return 0;   }   inline bool write(const char *first) {     while (*first) {       putc(*first);       ++first;     }     return 0;   }   inline bool write(char *first) {     while (*first) {       putc(*first);       ++first;     }     return 0;   }   template <typename A, typename... B>   inline bool write(A first, B... second) {     return write(first) || write(second...);   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_flusher_;   }  // namespace io   using io ::putc;   using io ::read;   using io ::write;   bitset<1005> l[1005], a, hv;   unsigned w[31], lw[1005];   int k, c, n;   void Insert() {     unsigned s = 0;     for (int i = n; i; --i)       if (a[i]) {         if (hv[i]) {           s ^= lw[i];           a ^= l[i];         } else {           s |= 1 << k;           ++k;           lw[i] = s;           l[i] = a;           hv[i] = 1;           for (int j = 1; j < i; ++j)             if (l[i][j]) {               l[i] ^= l[j];               lw[i] ^= lw[j];             }           for (int j = i + 1; j <= n; ++j)             if (l[j][i]) {               l[j] ^= l[i];               lw[j] ^= lw[i];             }           return;         }       }     w[c] = s;     ++c;   }   int get() {     unsigned s = 0;     for (int i = n; i; --i)       if (a[i]) {         if (hv[i]) {           s ^= lw[i];           a ^= l[i];         } else           return -1;       }     return s;   }   unsigned v[1 << 15 | 5];   int dis[1 << 15 | 5];   int q[1 << 15 | 5];   void bfs() {     for (int i = 0; i < (1 << k); ++i) dis[i] = inf;     int *l = q, *r = q;     *q = 0;     dis[0] = 0;     for (; l <= r; ++l) {       for (int i = 0; i < c; ++i)         if (chkmin(dis[*l ^ w[i]], dis[*l] + 1)) {           *(++r) = *l ^ w[i];         }     }   }   signed main() {     int s, q;     read(n, s, q);     for (int i = 1; i <= s; ++i) {       int m, first;       read(m);       a.reset();       for (int j = 1; j <= m; ++j) {         read(first);         a[first] = 1;       }       Insert();     }     if (k <= 15) {       bfs();       for (; q; --q) {         int m, first;         read(m);         a.reset();         for (int j = 1; j <= m; ++j) {           read(first);           a[first] = 1;         }         int w = get();         if (w < 0)           write( -1 n );         else {           int ans = inf;           for (int j = 0; j < (1 << k); ++j)             chkmin(ans, __builtin_popcount(j ^ w) + dis[j]);           write(ans,   n );         }       }     } else {       for (int i = 0; i < c; ++i) {         v[1 << i] = w[i];       }       for (int i = 1; i < (1 << c); ++i)         if (i & (i - 1)) v[i] = v[i & (i - 1)] ^ v[i & (-i)];       for (; q; --q) {         int m, first;         read(m);         a.reset();         for (int j = 1; j <= m; ++j) {           read(first);           a[first] = 1;         }         int w = get();         if (w < 0)           write( -1 n );         else {           int ans = inf;           for (int j = 0; j < (1 << c); ++j)             chkmin(ans, __builtin_popcount(j) + __builtin_popcount(w ^ v[j]));           write(ans,   n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int k = 0;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  a ) {         k++;       }     }     if (2 * k <= s.length()) {       cout << 2 * k - 1;     } else {       cout << s.length();     }   }


#include <bits/stdc++.h>   using namespace std;   void _fill_int(int* p, int val, int rep) {     int i;     for (i = 0; i < rep; i++) p[i] = val;   }   int GETi() {     int i;     scanf( %d , &i);     return i;   }   template <class T>   T sqr(T val) {     return val * val;   }   int W, H;   int TX[2][100001];   int TY[2][100001];   int CT = 0;   void solve() {     int f, r, i, j, k, l, x, y, cur, tar, dx, dy, sx, sy;     char st[4];     H = GETi();     W = GETi();     sy = GETi() - 1;     sx = GETi() - 1;     scanf( %s , st);     ;     dx = (st[1] ==  R ) ? 1 : -1;     dy = (st[0] ==  U ) ? -1 : 1;     for (x = 0; x < W; x++) {       if (((sx + sy) % 2) == (x % 2)) {         TX[0][x]++;         CT++;       }       if (((sx + sy) % 2) == ((x + H - 1) % 2)) {         TX[1][x]++;         CT++;       }     }     for (y = 0; y < H; y++) {       if (((sx + sy) % 2) == (y % 2)) {         TY[0][y]++;         CT++;       }       if (((sx + sy) % 2) == ((y + W - 1) % 2)) {         TY[1][y]++;         CT++;       }     }     signed long long res = 1;     for (i = 0; i < 1000000; i++) {       if (sx == 0 && TY[0][sy]) {         TY[0][sy] = 0;         CT--;       }       if (sx == W - 1 && TY[1][sy]) {         TY[1][sy] = 0;         CT--;       }       if (sy == 0 && TX[0][sx]) {         TX[0][sx] = 0;         CT--;       }       if (sy == H - 1 && TX[1][sx]) {         TX[1][sx] = 0;         CT--;       }       if (CT == 0) {         cout << res << endl;         return;       }       if (sx == 0) dx = 1;       if (sx == W - 1) dx = -1;       if (sy == 0) dy = 1;       if (sy == H - 1) dy = -1;       int ml = 1000000;       if (dx > 0) ml = min(ml, W - 1 - sx);       if (dx < 0) ml = min(ml, sx);       if (dy > 0) ml = min(ml, H - 1 - sy);       if (dy < 0) ml = min(ml, sy);       res += ml;       sx += ml * dx;       sy += ml * dy;     }     printf( -1 n );     return;   }   int main(int argc, char** argv) {     if (argc > 1) freopen(argv[1],  r , stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void optimizeIO() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   const int nmax = 150005;   const long long LINF = 1e17;   int ara[110];   set<int> SET;   int main() {     optimizeIO();     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ara[i];       SET.insert(ara[i]);     }     int siz = SET.size();     if (siz > 3) {       cout << -1;       return 0;     }     if (siz == 3) {       vector<int> v;       for (auto x : SET) v.push_back(x);       int a = v[2] - v[1];       int b = v[1] - v[0];       if (a != b) {         cout << -1;         return 0;       }       if (a == b) {         cout << a << endl;         return 0;       }     }     if (siz == 2) {       vector<int> v;       for (auto x : SET) v.push_back(x);       int a = v[1] - v[0];       if (a % 2 == 1) {         cout << a << endl;         return 0;       }       if (a % 2 == 0) {         cout << a / 2 << endl;         return 0;       }     }     if (siz == 1) {       cout << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void getre() {     int x = 0;     printf( %d n , 1 / x);   }   void gettle() {     int res = 1;     while (1) res <<= 1;     printf( %d n , res);   }   template <typename T, typename S>   inline bool upmin(T &a, const S &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T, typename S>   inline bool upmax(T &a, const S &b) {     return a < b ? a = b, 1 : 0;   }   template <typename N, typename PN>   inline N flo(N a, PN b) {     return a >= 0 ? a / b : -((-a - 1) / b) - 1;   }   template <typename N, typename PN>   inline N cei(N a, PN b) {     return a > 0 ? (a - 1) / b + 1 : -(-a / b);   }   template <typename N>   N gcd(N a, N b) {     return b ? gcd(b, a % b) : a;   }   template <typename N>   inline int sgn(N a) {     return a > 0 ? 1 : (a < 0 ? -1 : 0);   }   inline void gn(long long &x) {     int sg = 1;     char c;     while (((c = getchar()) <  0  || c >  9 ) && c !=  - )       ;     c ==  -  ? (sg = -1, x = 0) : (x = c -  0 );     while ((c = getchar()) >=  0  && c <=  9 ) x = x * 10 + c -  0 ;     x *= sg;   }   inline void gn(int &x) {     long long t;     gn(t);     x = t;   }   inline void gn(unsigned long long &x) {     long long t;     gn(t);     x = t;   }   inline void gn(double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gn(long double &x) {     double t;     scanf( %lf , &t);     x = t;   }   inline void gs(char *s) { scanf( %s , s); }   inline void gc(char &c) {     while ((c = getchar()) > 126 || c < 33)       ;   }   inline void pc(char c) { putchar(c); }   inline long long sqr(long long a) { return a * a; }   inline double sqrf(double a) { return a * a; }   const int inf = 0x3f3f3f3f;   const double pi = 3.14159265358979323846264338327950288L;   const double eps = 1e-6;   const int TREE_MAXV = 100000 + 5;   struct edge {     int v, next;   } e[TREE_MAXV * 2];   int g[TREE_MAXV], etot;   int n;   void ae(int u, int v) {     e[etot].v = v;     e[etot].next = g[u];     g[u] = etot++;   }   int dfn[TREE_MAXV], rig[TREE_MAXV], pre[TREE_MAXV], h[TREE_MAXV];   int seq[TREE_MAXV], up[TREE_MAXV], sz[TREE_MAXV];   void build_hld(int rt) {     static int qu[TREE_MAXV], son[TREE_MAXV];     int p = 0, q = 0;     qu[q++] = rt;     pre[rt] = 0;     h[rt] = 0;     while (p != q) {       int u = qu[p++];       sz[u] = 1, son[u] = 0;       for (int i = g[u]; ~i; i = e[i].next)         if (e[i].v != pre[u])           qu[q++] = e[i].v, pre[e[i].v] = u, h[e[i].v] = h[u] + 1;     }     sz[0] = 0;     for (int i = q - 1; i >= 1; i--) {       sz[pre[qu[i]]] += sz[qu[i]];       if (sz[qu[i]] > sz[son[pre[qu[i]]]]) son[pre[qu[i]]] = qu[i];     }     for (int j = 0; j < q; j++)       if (!son[qu[j]]) {         int s = qu[j];         while (son[pre[s]] == s) s = pre[s];         int t = s;         while (t) up[t] = s, t = son[t];       } else {         int u = qu[j], v = son[u];         if (e[g[u]].v != v) {           for (int i = g[u], j; ~i; j = i, i = e[i].next)             if (e[i].v == v) {               e[j].next = e[i].next;               e[i].next = g[u];               g[u] = i;               break;             }         }       }     static int stk[TREE_MAXV], cur[TREE_MAXV];     int top = 0, ind = 0;     stk[++top] = rt;     cur[top] = g[rt];     while (top) {       int u = stk[top];       if (cur[top] == g[u]) {         dfn[u] = ++ind;         seq[ind] = u;       }       if (cur[top] == -1) {         rig[u] = ind;         top--;       } else {         int v = e[cur[top]].v;         cur[top] = e[cur[top]].next;         if (v == pre[u]) continue;         stk[++top] = v;         cur[top] = g[v];       }     }   }   void work(int a, int b) {     int l1, r1;     while (up[a] != up[b]) {       if (h[up[a]] < h[up[b]]) swap(a, b);       l1 = dfn[up[a]], r1 = dfn[a];       a = pre[up[a]];     }     if (h[a] > h[b]) swap(a, b);     l1 = dfn[a] + 1, r1 = dfn[b];     if (a != b) {     }   }   int lca(int a, int b) {     while (up[a] != up[b]) {       if (h[up[a]] < h[up[b]]) swap(a, b);       a = pre[up[a]];     }     if (h[a] > h[b]) swap(a, b);     return a;   }   void tree_init() {     static bool ini = 0;     if (!ini) {       ini = 1;       memset(g, -1, sizeof(g));     } else {       for (int i = 0; i <= n; i++) g[i] = -1;     }     etot = 0;   }   int rt;   void readedge() {     for (int i = 1; i <= n; i++) {       int x, y;       gn(x);       gn(y);       if (x == 0)         rt = y;       else         ae(x, y);     }   }   int lis[111111];   int ansquer[3333333];   int quetot = 0;   struct quer {     int l, r;     int x;     int id;   } que1[3333333], que0[3333333];   int que1tot = 0, que0tot = 0;   int operator<(const quer &a, const quer &b) { return a.x < b.x; }   void addque(int l, int r, int x, int bo) {     int id = ++quetot;     quer tmp = (quer){l, r, x, id};     if (bo)       que1[++que1tot] = tmp;     else       que0[++que0tot] = tmp;   }   int poptot = 0;   int popque() {     int id = ++poptot;     return ansquer[id];   }   const int SEG_MAXN = 100000 + 5;   int seg[SEG_MAXN * 4];   inline void segpu(int x) { seg[x] = max(seg[x << 1], seg[x << 1 | 1]); }   void seginit_in(int l, int r, int x) {     if (l == r) {       seg[x] = -inf;     } else {       int mid = l + r >> 1;       seginit_in(l, mid, x << 1);       seginit_in(mid + 1, r, x << 1 | 1);       segpu(x);     }   }   int l1, r1, I;   int sans;   bool ans_bo;   int stag;   void segupd_in(int l, int r, int x) {     if (l == r) {       seg[x] = max(seg[x], stag);     } else {       int mid = l + r >> 1;       if (I <= mid)         segupd_in(l, mid, x << 1);       else         segupd_in(mid + 1, r, x << 1 | 1);       segpu(x);     }   }   void segque_in(int l, int r, int x) {     if (l1 <= l && r <= r1) {       if (!ans_bo)         ans_bo = 1, sans = seg[x];       else         sans = max(sans, seg[x]);     } else {       int mid = l + r >> 1;       if (l1 <= mid) segque_in(l, mid, x << 1);       if (r1 > mid) segque_in(mid + 1, r, x << 1 | 1);     }   }   int segn;   void segupd(int i, int v) {     stag = v, I = i;     segupd_in(1, segn, 1);   }   int segque(int l, int r) {     if (l > r) return -inf;     ans_bo = 0, l1 = l, r1 = r;     segque_in(1, segn, 1);     return sans;   }   void seginit(int n) {     segn = n;     seginit_in(1, segn, 1);   }   int ord[111111];   int cmpsz(int i, int j) { return sz[i] < sz[j]; }   void gaoxunwen() {     sort(que1 + 1, que1 + que1tot + 1);     sort(que0 + 1, que0 + que0tot + 1);     for (int i = (1), _ed = (n + 1); i < _ed; i++) ord[i] = i;     sort(ord + 1, ord + 1 + n, cmpsz);     seginit(n);     int cur = 1;     for (int i = (1), _ed = (que0tot + 1); i < _ed; i++) {       int va = que0[i].x;       while (cur <= n && sz[ord[cur]] <= va) {         segupd(dfn[ord[cur]], sz[ord[cur]]);         cur++;       }       ansquer[que0[i].id] = segque(que0[i].l, que0[i].r);     }     seginit(n);     cur = n;     for (int i = (que1tot + 1) - 1, _ed = (1); i >= _ed; i--) {       int va = que1[i].x;       while (cur >= 1 && sz[ord[cur]] >= va) {         segupd(dfn[ord[cur]], -sz[ord[cur]]);         cur--;       }       ansquer[que1[i].id] = -segque(que1[i].l, que1[i].r);     }   }   struct quj {     int l, r;   } qq[111];   int cmpqj(const quj &a, const quj &b) { return a.l < b.l; }   void getque(int nrt, int u, int val, int bo) {     if (nrt != rt) {       addque(dfn[nrt], rig[nrt], val, bo);     } else {       int qjtot = 0;       int del = sz[u];       qq[++qjtot] = (quj){dfn[u], rig[u]};       int v = pre[u];       while (v) {         qq[++qjtot] = (quj){dfn[up[v]], dfn[v]};         v = pre[up[v]];       }       sort(qq + 1, qq + 1 + qjtot, cmpqj);       qq[0].r = 0, qq[qjtot + 1].l = n + 1;       for (int i = (0), _ed = (qjtot + 1); i < _ed; i++) {         if (qq[i].r + 1 <= qq[i + 1].l - 1)           addque(qq[i].r + 1, qq[i + 1].l - 1, val, bo);       }       v = pre[u];       while (v) {         addque(dfn[up[v]], dfn[v], val + del, bo);         v = pre[up[v]];       }     }   }   int gotque(int nrt, int u, int val, int bo) {     if (nrt != rt) {       return popque();     } else {       int ret;       if (bo == 0)         ret = -inf;       else         ret = inf;       int qjtot = 0;       int del = sz[u];       qq[++qjtot] = (quj){dfn[u], rig[u]};       int v = pre[u];       while (v) {         qq[++qjtot] = (quj){dfn[up[v]], dfn[v]};         v = pre[up[v]];       }       sort(qq + 1, qq + 1 + qjtot, cmpqj);       qq[0].r = 0, qq[qjtot + 1].l = n + 1;       for (int i = (0), _ed = (qjtot + 1); i < _ed; i++) {         if (qq[i].r + 1 <= qq[i + 1].l - 1) {           int goo = popque();           if (bo == 0)             upmax(ret, goo);           else             upmin(ret, goo);         }       }       v = pre[u];       while (v) {         int goo = popque() - del;         if (bo == 0)           upmax(ret, goo);         else           upmin(ret, goo);         v = pre[up[v]];       }       return ret;     }   }   void prework(int u) {     int tot = 0;     for (int i = g[u]; ~i; i = e[i].next) lis[++tot] = sz[e[i].v];     if (u != rt) {       lis[++tot] = n - sz[u];     }     sort(lis + 1, lis + 1 + tot);     int masz = lis[tot];     int nrt = rt;     for (int i = g[u]; ~i; i = e[i].next)       if (sz[e[i].v] == masz) {         nrt = e[i].v;       }     if (tot == 0) return;     if (tot == 1) return;     if (tot == 2) {       int a = lis[1], c = lis[2];       getque(nrt, u, cei(c - a, 2), 1);       getque(nrt, u, (c - a) / 2, 0);       return;     } else {       int a = lis[1], b = lis[tot - 1], c = lis[tot];       getque(nrt, u, cei(c - a, 2), 1);       getque(nrt, u, (c - a) / 2, 0);       getque(nrt, u, c - b, 1);       return;     }   }   int work(int u) {     int tot = 0;     for (int i = g[u]; ~i; i = e[i].next) lis[++tot] = sz[e[i].v];     if (u != rt) {       lis[++tot] = n - sz[u];     }     sort(lis + 1, lis + 1 + tot);     int masz = lis[tot];     int nrt = rt;     for (int i = g[u]; ~i; i = e[i].next)       if (sz[e[i].v] == masz) {         nrt = e[i].v;       }     if (tot == 0) return 0;     if (tot == 1) return lis[1];     if (tot == 2) {       int a = lis[1], c = lis[2];       int d1 = gotque(nrt, u, cei(c - a, 2), 1);       int d2 = gotque(nrt, u, (c - a) / 2, 0);       return min(lis[2], min(max(c - d1, a + d1), max(c - d2, a + d2)));     } else {       int a = lis[1], b = lis[tot - 1], c = lis[tot];       int d1 = gotque(nrt, u, cei(c - a, 2), 1);       int d2 = gotque(nrt, u, (c - a) / 2, 0);       int d3 = gotque(nrt, u, c - b, 1);       int ans = lis[tot];       upmin(ans, max(max(a + d1, b), c - d1));       upmin(ans, max(max(a + d2, b), c - d2));       upmin(ans, max(max(a + d3, b), c - d3));       return ans;     }   }   int main() {     gn(n);     tree_init();     readedge();     build_hld(rt);     for (int u = (1), _ed = (n + 1); u < _ed; u++) prework(u);     gaoxunwen();     for (int u = (1), _ed = (n + 1); u < _ed; u++) printf( %d n , work(u));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 30;   long long n, a[N], ans, limit = 1e9 + 10;   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     for (int i = 0; i < n; i++) {       ans += min(a[i], limit);       limit = min(limit - 1, a[i] - 1);       if (limit <= 0) break;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, q, a[200005], b[200005], f[200005], g[200005], h[200005],       minn[800005], rev[200005];   vector<int> pos[200005], pos2[200005];   void build(int o, int l, int r) {     if (l == r) {       minn[o] = (g[l] == -1) ? 1E9 : g[l];       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     minn[o] = min(minn[o << 1], minn[o << 1 | 1]);   }   int query(int o, int l, int r, int nl, int nr) {     if (nl <= l && r <= nr) return minn[o];     int mid = (l + r) >> 1, ans = 1E9;     if (nl <= mid) ans = min(ans, query(o << 1, l, mid, nl, nr));     if (mid < nr) ans = min(ans, query(o << 1 | 1, mid + 1, r, nl, nr));     return ans;   }   signed main() {     n = Read(), m = Read(), q = Read();     for (int i = 1; i <= n; i++) a[i] = Read(), rev[a[i]] = i;     for (int i = 1; i <= m; i++) b[i] = Read(), pos[b[i]].push_back(i);     memset(f, -1, sizeof(f));     memset(g, -1, sizeof(g));     memset(h, -1, sizeof(h));     for (int i = n; i >= 1; i--) {       if (i == n) {         for (int j = 0; j < pos[a[i]].size(); j++) f[pos[a[i]][j]] = pos[a[i]][j];         continue;       }       for (int j = 0; j < pos[a[i]].size(); j++) {         vector<int>::iterator it =             lower_bound(pos[a[i + 1]].begin(), pos[a[i + 1]].end(), pos[a[i]][j]);         if (it == pos[a[i + 1]].end()) continue;         f[pos[a[i]][j]] = f[*it];       }     }     for (int i = 1; i <= n; i++) {       if (i == 1) {         for (int j = 0; j < pos[a[i]].size(); j++) h[pos[a[i]][j]] = pos[a[i]][j];         continue;       }       for (int j = 0; j < pos[a[i]].size(); j++) {         vector<int>::iterator it =             lower_bound(pos[a[i - 1]].begin(), pos[a[i - 1]].end(), pos[a[i]][j]);         if (it == pos[a[i - 1]].begin()) continue;         --it;         h[pos[a[i]][j]] = h[*it];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < pos[a[i]].size(); j++)         pos2[a[i]].push_back(h[pos[a[i]][j]]);     }     for (int i = 1; i <= m; i++) {       int ff = rev[b[i]];       if (ff == 1) {         g[i] = f[i];         continue;       }       if (f[i] == -1) continue;       vector<int>::iterator it =           lower_bound(pos2[a[ff - 1]].begin(), pos2[a[ff - 1]].end(), f[i]);       if (it == pos2[a[ff - 1]].end()) continue;       int Pos = it - pos2[a[ff - 1]].begin();       g[i] = pos[a[ff - 1]][Pos];     }     build(1, 1, m);     for (int i = 1; i <= q; i++) {       int l = Read(), r = Read();       int mpos = query(1, 1, m, l, r);       if (mpos <= r)         putchar( 1 );       else         putchar( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     for (auto v : V) os << v <<    ;     return cout <<   ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> S) {     for (auto s : S) os << s <<    ;     return cout <<   ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os << P.first <<     << P.second;   }   const long long mod = 1e9 + 7;   long long inv(long long i) {     if (i == 1) return 1;     return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long pwr(long long a, long long b) {     a %= mod;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T = 1;     cin >> T;     while (T--) {       int n, c0, c1, h, x = 0, y = 0;       cin >> n >> c0 >> c1 >> h;       string s;       cin >> s;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           x++;         else           y++;       }       if (c0 >= c1 + h) {         cout << x * h + n * c1 <<   n ;       } else if (c1 >= c0 + h) {         cout << y * h + n * c0 <<   n ;       } else {         cout << x * c0 + y * c1 <<   n ;       }     }   }


#include <bits/stdc++.h>   long long n, m, k, a[11111], kq;   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   int main() {     scanf( %lld %lld %lld , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     if (n % 2 == 0)       printf( 0 );     else {       kq = a[1];       for (int i = 3; i <= n; i += 2) kq = min(kq, a[i]);       kq = min(kq, (m / ((n + 1) / 2)) * k);       printf( %lld , kq);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 7;   const int M = 32;   const long long base = 1e18;   const int mod = 999983;   const int inf = 1e9 + 7;   const double pi = acos(-1);   const int maxn = N * 2;   const double PI = acos(-1);   const double ep = 1e-9;   int n, m, s, e;   int a[N], b[N];   int last[N];   map<int, int> st;   vector<int> all[N];   int dp[2][N];   int getPos(int x) {     if (st.count(x))       return st[x];     else       return st[x] = st.size();   }   void solve() {     cin >> n >> m >> s >> e;     for (int i = (0); i < (n); i++) scanf( %d , a + i);     for (int j = (0); j < (m); j++) {       scanf( %d , b + j);       all[getPos(b[j])].push_back(j);     }     last[0] = -1;     for (int i = (1); i < (N); i++) last[i] = inf;     int C = s / e;     int ans = 0;     for (int i = (0); i < (n); i++) {       if (st.count(a[i])) {         int c = st[a[i]];         for (int j = C - 1; j >= 0; j--) {           typeof(all[c].begin()) it =               lower_bound(all[c].begin(), all[c].end(), last[j] + 1);           if (it != all[c].end()) {             if ((j + 1) * e + (i + 1 + (*it) + 1) <= s) {               ans = max(ans, j + 1);             }             last[j + 1] = min(last[j + 1], *it);           }         }       }     }     cout << ans;   }   int main() {     int T = 1;     for (int i = (1); i < (T + 1); i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt;     cin >> tt;     unordered_map<string, string> mp;     unordered_set<string> s;     for (int i = 0; i < tt; i++) {       string s1;       string s2;       cin >> s1 >> s2;       if (s.find(s1) == s.end()) {         mp.insert({s1, s2});         s.insert(s2);       } else {         for (auto &it : mp) {           if (s1 == it.second) {             it.second = s2;             s.insert(s2);           }         }       }     }     cout << mp.size() << endl;     for (auto it : mp) {       cout << it.first <<     << it.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[3], y[3];   bool is_between(int a, int b, int c) {     return min(a, b) <= c && c <= max(a, b);   }   bool check(int i, int j, int k) {     return (x[k] == x[i] || x[k] == x[j]) && is_between(y[i], y[j], y[k]) ||            (y[k] == y[i] || y[k] == y[j]) && is_between(x[i], x[j], x[k]);   }   int main() {     for (int i = 0; i < 3; i++) {       cin >> x[i] >> y[i];     }     if (x[0] == x[1] && x[1] == x[2] || y[0] == y[1] && y[1] == y[2]) {       cout << 1 << endl;     } else if (check(0, 1, 2) || check(0, 2, 1) || check(1, 2, 0)) {       cout << 2 << endl;     } else {       cout << 3 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int main() {     cin >> n >> k;     cout << k * (6 * n - 1) << endl;     for (int i = 1; i <= n; i++) {       int x = (i - 1) * 6 + 1;       cout << k * x <<     << k * (x + 1) <<     << k * (x + 2) <<                << k * (x + 4) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long getint() {     long long ssum = 0, ff = 1;     char ch;     for (ch = getchar(); !isdigit(ch) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) ff = -1, ch = getchar();     for (; isdigit(ch); ch = getchar()) ssum = ssum * 10 + ch -  0 ;     return ssum * ff;   }   const long long M = 1e6 + 5, mod = 1e9 + 7;   long long ans, f[M], g[M];   long long n, t[3];   signed main() {     cin >> n;     for (long long i = 1; i <= n; i++) t[getint()]++;     f[0] = 1;     f[1] = 1;     for (long long i = 2; i <= t[1]; i++)       (f[i] = f[i - 1] + f[i - 2] * (i - 1)) %= mod;     g[0] = f[t[1]];     for (long long i = 1; i <= t[2]; i++) (g[i] = g[i - 1] * (t[1] + i)) %= mod;     cout << g[t[2]] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, t;     cin >> n;     t = 2 * n;     long long a[t], I;     for (I = 0; I < t; I++) cin >> a[I];     sort(a, a + t);     long long ans = (a[0] - a[n - 1]) * (a[n] - a[2 * n - 1]);     for (I = 1; I < n; I++)       ans = min(ans, (a[I] - a[I + n - 1]) * (a[0] - a[2 * n - 1]));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   inline int read() {     int n = 0, ch = getchar();     for (; !isdigit(ch); ch = getchar())       ;     for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + (ch ^ 48);     return n;   }   int main() {     int T = read();     while (T--) {       int ans[3] = {0, 0, 0};       int n = read();       while (n--) ++ans[read() % 3];       int A = ans[0];       if (ans[1] < ans[2])         A += ans[1] + (ans[2] - ans[1]) / 3;       else         A += ans[2] + (ans[1] - ans[2]) / 3;       printf( %d n , A);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   inline void read(t& res) {     char ch;     while (ch = getchar(), !isdigit(ch))       ;     res = ch ^ 48;     while (ch = getchar(), isdigit(ch)) res = res * 10 + (ch ^ 48);   }   template <class t>   inline void print(t x) {     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   const int e = 3e5 + 5, z1 = 29, z2 = 31, h1 = 1e9 + 7, h2 = 1e9 + 9;   struct node {     int s1, s2, len;     node() {}     node(int _s1, int _s2, int _len) : s1(_s1), s2(_s2), len(_len) {}   } up[e], down[e];   vector<int> a[e], b[e], g[e];   int n, top[e], son[e], m, f[20][e], dep[e], mx[e];   int p1[e], p2[e], fa[e], dfn[e], id[e << 1], tim, logn[e << 1], c[21][e << 1];   int q1[e], q2[e], inv1, inv2;   char s[e];   inline bool operator==(node a, node b) { return a.s1 == b.s1 && a.s2 == b.s2; }   inline node operator+(node a, node b) {     return node(((long long)a.s1 * p1[b.len] + b.s1) % h1,                 ((long long)a.s2 * p2[b.len] + b.s2) % h2, a.len + b.len);   }   inline int ksm(int x, int y, int mod) {     int res = 1;     while (y) {       if (y & 1) res = (long long)res * x % mod;       y >>= 1;       x = (long long)x * x % mod;     }     return res;   }   inline void dfs1(int u, int pa) {     int i;     fa[u] = pa;     dep[u] = dep[pa] + 1;     mx[u] = dep[u];     s[u] -=  a  - 1;     dfn[u] = ++tim;     id[tim] = u;     for (i = 0; i < 18; i++) f[i + 1][u] = f[i][f[i][u]];     node a = down[pa], b = up[pa];     down[u] = node(((long long)z1 * a.s1 + s[u]) % h1,                    ((long long)z2 * a.s2 + s[u]) % h2, a.len + 1);     up[u] = node((b.s1 + (long long)p1[b.len] * s[u]) % h1,                  (b.s2 + (long long)p2[b.len] * s[u]) % h2, b.len + 1);     for (auto v : g[u])       if (v != pa) {         f[0][v] = u;         dfs1(v, u);         if (mx[v] > mx[u]) mx[u] = mx[v], son[u] = v;         id[++tim] = u;       }   }   inline void dfs2(int u, int pa, int fi) {     top[u] = fi;     if (son[u]) dfs2(son[u], u, fi);     for (auto v : g[u])       if (v != pa && v != son[u]) dfs2(v, u, v);   }   inline int cmp(int x, int y) { return dep[x] < dep[y] ? x : y; }   inline void init() {     int i, j;     logn[0] = -1;     for (i = 1; i <= tim; i++) logn[i] = logn[i >> 1] + 1, c[0][i] = id[i];     for (j = 1; (1 << j) <= tim; j++)       for (i = 1; i + (1 << j) - 1 <= tim; i++)         c[j][i] = cmp(c[j - 1][i], c[j - 1][i + (1 << j - 1)]);   }   inline int lca(int l, int r) {     l = dfn[l];     r = dfn[r];     if (l > r) swap(l, r);     int k = logn[r - l + 1];     return cmp(c[k][l], c[k][r - (1 << k) + 1]);   }   inline int anc(int x, int k) {     if (!k) return x;     int y = logn[k], to;     x = f[y][x];     k -= (1 << y);     to = top[x];     if (dep[to] <= dep[x] - k)       return b[to][dep[x] - k - dep[to]];     else       return a[to][dep[to] - dep[x] + k];   }   inline int sub1(int x, int y) {     (x -= y) < 0 && (x += h1);     return x;   }   inline int sub2(int x, int y) {     (x -= y) < 0 && (x += h2);     return x;   }   inline node query_up(int x, int y) {     node a = up[x], b = up[y];     return node((long long)sub1(a.s1, b.s1) * q1[b.len] % h1,                 (long long)sub2(a.s2, b.s2) * q2[b.len] % h2, a.len - b.len);   }   inline node query_down(int x, int y) {     node a = down[y], b = down[x];     return node(sub1(a.s1, (long long)b.s1 * p1[a.len - b.len] % h1),                 sub2(a.s2, (long long)b.s2 * p2[a.len - b.len] % h2),                 a.len - b.len);   }   inline node calc(int x, int y, int z, int len) {     int d1 = dep[x] - dep[z] + 1, d2 = dep[x] + dep[y] - 2 * dep[z] + 1;     if (len <= d1) {       int u = anc(x, len - 1);       return query_up(x, fa[u]);     } else {       int u = anc(y, d2 - len);       return query_up(x, fa[z]) + query_down(z, u);     }   }   inline int query(int x, int y, int u, int v) {     int z = lca(x, y), w = lca(u, v), res = 0, l = 1,         r = min(dep[x] + dep[y] - 2 * dep[z], dep[u] + dep[v] - 2 * dep[w]) + 1;     while (l <= r) {       int mid = l + r >> 1;       if (calc(x, y, z, mid) == calc(u, v, w, mid))         res = mid, l = mid + 1;       else         r = mid - 1;     }     return res;   }   int main() {     read(n);     int i, x, y, u, v, j;     scanf( %s , s + 1);     for (i = 1; i < n; i++) {       read(x);       read(y);       g[x].emplace_back(y);       g[y].emplace_back(x);     }     inv1 = ksm(z1, h1 - 2, h1);     inv2 = ksm(z2, h2 - 2, h2);     p1[0] = p2[0] = q1[0] = q2[0] = 1;     for (i = 1; i <= n; i++) {       p1[i] = (long long)p1[i - 1] * z1 % h1;       p2[i] = (long long)p2[i - 1] * z2 % h2;       q1[i] = (long long)q1[i - 1] * inv1 % h1;       q2[i] = (long long)q2[i - 1] * inv2 % h2;     }     dfs1(1, 0);     dfs2(1, 0, 1);     init();     for (i = 1; i <= n; i++)       if (top[i] == i) {         int x = i;         for (j = 0; j <= mx[i] - dep[i]; j++) a[i].emplace_back(x), x = fa[x];         x = i;         while (x) b[i].emplace_back(x), x = son[x];       }     read(m);     while (m--) {       read(x);       read(y);       read(u);       read(v);       print(query(x, y, u, v));       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   #include <algorithm>   using namespace std;       #define int long long   #define ll long long   #define rep(i,a,b) for (int i = a; i < b; ++i)   #define mod 1000000007   #define F first   #define S second   #define printer(v) for(auto f: v) cout<<f<<      #define pb push_back   #define mp make_pair   #define all(c) c.begin(), c.end()   #define ipair pair<int,int>   #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)       int bin_power(int x, unsigned int y){   // Modular Exponentiation (Power in Modular Arithmetic)       int temp;       if( y == 0)           return 1;       temp = bin_power(x, y / 2);       if (y % 2 == 0)           return (temp * temp)%mod;       else           return (x * temp * temp)%mod;          // ll res = 1;        // while(y){       //     if(y & 1) res = (res * x)%mod;        //     y >>= 1;        //     x = (x * x)%mod;       // }       // return res;   }      int inverse_mod(int a){       return bin_power(a, mod-2);   }      vector<bool> isPrime_Seive_Of_Erastothenes(long n){       vector<bool> prime(n+1,true);       prime[0] = prime[1] = false;       for(long i=2;i*i<=n;i++){           if(prime[i]){               for(long j=i*i;j<=n;j+=i){                   prime[j] = false;               }           }       }       return prime;   }      bool is_integer(float k){     return std::floor(k) == k;   }      int fact(int n);      int nCr(int n, int r) {       if(r > n - r) r = n - r;       int ans = 1;       int i;       for(i = 1; i <= r; i++) {           ans *= n - r + i;           ans /= i;       }       return ans;   }      int fact(int n){       int res = 1;       for (int i = 2; i <= n; i++){           res = res * i;           res = res;       }       return res;   }      unsigned int gcd(unsigned int u, unsigned int v){       // Basic Euclidean Algorithm for GCD        int shift;       if (u == 0) return v;       if (v == 0) return u;       shift = __builtin_ctz(u | v);       u >>= __builtin_ctz(u);       do {           v >>= __builtin_ctz(v);           if (u > v) {               unsigned int t = v;               v = u;               u = t;           }             v = v - u;       } while (v != 0);       return u << shift;   }      int gcdExtended(int a, int b, int *x, int *y){      // Extended Euclidean Algorithm       if (a == 0){           *x = 0;           *y = 1;           return b;       }       int x1, y1;       int gcd = gcdExtended(b%a, a, &x1, &y1);       *x = y1 - (b/a) * x1;       *y = x1;       return gcd;   }      int binarySearch(int l, int r, int k){       if(l == r) return l;       int mid = l + (r - l) / 2;       cout<< ? <<   <<l+1<<   <<mid+1<<  n ;       cout.flush();       int sum;       cin>>sum;       int x = mid - l + 1;       if (x - sum >= k){           return binarySearch(l, mid, k);       }       else{           k -= (x - sum);           return binarySearch(mid+1, r, k);       }   }      bool isPrime(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;   }      int nextPrime(int N)   {       if (N <= 1)           return 2;       int prime = N;       bool found = false;       while (!found) {           prime++;           if (isPrime(prime))               found = true;       }       return prime;   }      signed main(){    ios_base::sync_with_stdio(false);       cin.tie(NULL); cout.tie(NULL);    int T;       cin>>T;       while(T--){           int n;           cin>>n;           vector<int> A(n);           int ans = INT_MAX;           int index = 0;           for (int i = 0; i < n; ++i){               cin>>A[i];               if(A[i] < ans){                   ans = A[i];                   index = i;               }           }           cout<<n - 1<<endl;           for(int i = 0; i < index; i++){               A[i] = ans + abs(index - i);               cout<<i + 1<<   <<index + 1<<   <<A[i]<<   <<ans<<endl;           }           for(int i = index + 1; i < n; i++){               A[i] = ans + abs(index - i);               cout<<i + 1<<   <<index + 1<<   <<A[i]<<   <<ans<<endl;           }       }       return 0;   }


#include <bits/stdc++.h>   #include <vector>   #include <set>   #include <string>   #include <map>   #include <cmath>   #include <algorithm>   typedef long long int ll;   #define f first   #define s second   #define vi vector<int>   #define ld long double   #define pb push_back   #define mp make_pair   #define pii pair<int, int>   #define floop(count,a, n) for(int count{a}; count < n; ++count)   #define tr(c, it) for(auto it{c.begin()}; it != c.end(); ++it)   #define lb lower_bound   #define ub upper_bound   #define bs binary_search   #define newl   n             using namespace std;      const int MOD = 1e9+7;   const ld PI = acos(-1);   const ld EPS = 1e-9;   const ll INF = 1e18;             int main(){          ios::sync_with_stdio(0);       cin.tie(0); cout.tie(0);           #ifndef ONLINE_JUDGE                  freopen( input.txt ,  r , stdin);                                                freopen( output.txt ,  w , stdout);                                  #endif           int cas;cin>>cas;           while(cas--){               int n;               cin>>n;               int a = sqrt(n);               if(a*a == n)                   cout<<a<<  n ;               else                   cout<<a + 1<<  n ;                 }       cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC <<  ms n ;          return 0;    }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     if (r - l < 2) {       printf( -1 );       return 0;     }     if (l & 1) l++;     if (l + 2 > r) {       printf( -1 );       return 0;     }     cout << l <<     << l + 1 <<     << l + 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 18;   const int MOD = 1000000007;   char c[MAX];   int r[MAX], b[MAX];   int dp[1 << 16][125];   int red[1 << 16], blue[1 << 16];   void precalc(int n) {     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (!(i & (1 << j))) {           continue;         }         if (c[j] ==  R ) {           red[i]++;         } else {           blue[i]++;         }       }     }   }   int main() {     for (int i = 0; i < 1 << 16; i++) {       for (int j = 0; j < 125; j++) {         dp[i][j] = -MOD;       }     }     dp[0][0] = 0;     long long rt = 0, bt = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf(  %c %d %d , &c[i], &r[i], &b[i]);       rt += r[i];       bt += b[i];     }     precalc(n);     long long maxi = 1000000000000000000;     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < 125; j++) {         for (int k = 0; k < n; k++) {           if (i & (1 << k)) {             continue;           }           int res = i | (1 << k);           int jnew = j + min(red[i], r[k]);           dp[res][jnew] = max(dp[res][jnew], dp[i][j] + min(blue[i], b[k]));         }         maxi = min(maxi, max(rt - j, bt - dp[i][j]));       }     }     printf( %lld n , n + maxi);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T Bitcnt(T a) {     int sum = 0;     while (a) {       if (a & 1) sum++;       a /= 2;     }     return sum;   }   template <class T>   T Max3(T a, T b, T c) {     return max(a, max(b, c));   }   template <class T>   T Lcm(T a, T b) {     T tmp = __gcd(a, b);     return (a / tmp) * b;   }   template <class T>   T Pow(T a, T b) {     T ans = 1;     T base = a;     while (b) {       if (b & 1) ans = (ans * base);       base = (base * base);       b /= 2;     }     return ans;   }   long long Bigmod(long long a, long long b) {     long long res = 1;     long long pw = a % 1000000007LL;     while (b > 0) {       if (b & 1) res = (res * pw) % 1000000007LL;       pw = (pw * pw) % 1000000007LL;       b /= 2;     }     return res;   }   int a_x[] = {1, -1, 0, 0};   int a_y[] = {0, 0, 1, -1};   long long X, Y;   void extend_euclid(long long a, long long b) {     if (b == 0) {       X = a;       Y = 0;       return;     }     extend_euclid(b, a % b);     long long x, y;     x = Y;     y = X - (a / b) * Y;     X = x;     Y = y;   }   long long inverse_modulo(long long a, long long b) {     extend_euclid(a, b);     return (X + 1000000007LL) % 1000000007LL;   }   int main() {     long long x;     cin >> x;     if (x == 2) {       cout << -1;       return 0;     }     if (x % 2 == 0) {       long long b = (x / 2) * (x / 2) - 1;       long long c = b + 2;       cout << b <<     << c;       return 0;     } else {       long long b = (x * x - 1) / 2;       long long c = (x * x + 1) / 2;       if (b <= 0 || c <= 0) {         cout << -1;         return 0;       }       cout << b <<     << c << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int freq[300];   string s;   const int maxN = 2000;   int primes[maxN];   int equs[maxN];   char result[maxN];   set<pair<int, char> > lets;   int n;   void sieve() {     for (int i = 2; i < maxN; i++) {       primes[i] = 1;     }     for (long long i = 2; i * i < maxN; i++) {       if (primes[i] == 1) {         for (long long j = i * i; j < maxN; j += i) {           primes[j] = 0;         }       }     }   }   int main(int argc, char const *argv[]) {     cin >> s;     sieve();     n = s.length();     for (int i = 0; i < n; i++) {       freq[s[i]]++;     }     int tot = 0;     for (int i = 0; i <= n; i++) {       if (primes[i] == 1 && i * 2 <= n) {         for (int j = i; j <= n; j += i) {           if (equs[j] == 0) {             tot++;           }           equs[j] = 1;         }       }     }     for (int i = 0; i < 300; i++) {       if (freq[i] != 0) {         lets.insert(make_pair(-freq[i], i));       }     }     if (-lets.begin()->first < tot) {       cout <<  NO  << endl;       return 0;     }     for (int i = 1; i <= n; i++) {       if (equs[i] == 1) {         result[i] = lets.begin()->second;       }     }     pair<int, char> tmp = *lets.begin();     tmp.first += tot;     lets.erase(lets.begin());     lets.insert(tmp);     for (int i = 1; i <= n; i++) {       if (equs[i] == 0) {         if (lets.begin()->first == 0) {           lets.erase(lets.begin());           i--;           continue;         }         result[i] = lets.begin()->second;         tmp = *lets.begin();         tmp.first++;         lets.erase(lets.begin());         lets.insert(tmp);       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) {       cout << result[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void rd(Tp &x) {     x = 0;     int fh = 1;     char ch = 1;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     x *= fh;   }   template <typename Tp>   inline void bird(Tp &x) {     x = 0;     int fh = 1;     char ch = 1;     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) fh = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 2 + ch -  0 , ch = getchar();     x *= fh;   }   template <typename Tp>   inline void smax(Tp &x, Tp y) {     if (x < y) x = y;   }   const int maxn = 100000 + 7;   const int maxm = 200000 + 7;   const int mod = 1000000007;   int n, m;   int Head[maxn], to[maxm], Next[maxm], w[maxm], tot;   void add(int x, int y, int z) {     to[++tot] = y, Next[tot] = Head[x], Head[x] = tot, w[tot] = z;   }   inline void Init(void) {     rd(n);     rd(m);     for (int i = 1, x, y, z; i <= m; i++) {       rd(x);       rd(y);       rd(z);       add(x, y, z);       add(y, x, z);     }   }   bool vis[maxn];   int c[maxn];   void dfs(int x, int f, int col) {     if (vis[x]) {       if (c[x] != col) {         puts( 0 );         exit(0);       }       return;     }     vis[x] = true;     c[x] = col;     for (int i = Head[x]; i; i = Next[i]) {       int y = to[i];       if (y == f) continue;       if (w[i])         dfs(y, x, col);       else         dfs(y, x, 3 - col);     }   }   int fpow(long long x, int p) {     long long res = 1ll;     while (p) {       if (p & 1) res = res * x % mod;       p >>= 1;       x = x * x % mod;     }     return res;   }   inline void Work(void) {     long long ans = 1ll;     for (int i = 1; i <= n; i++) {       if (vis[i] == false) {         dfs(i, 0, 1);         ans = ans * 2 % mod;       }     }     ans = ans * fpow(2, mod - 2) % mod;     printf( %lld n , ans);   }   signed main(void) {     Init();     Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 20;   inline int read() {     int ans = 0;     char last =    , ch = getchar();     while (ch< 0  | ch>  9 ) last = ch, ch = getchar();     while (ch >=  0  && ch <=  9 ) ans = ans * 10 + ch -  0 , ch = getchar();     if (last ==  - ) ans = -ans;     return ans;   }   int n, k;   vector<int> save[maxn];   int a[maxn], color[maxn], cnt[maxn], ls[maxn];   void solve() {     n = read(), k = read();     for (int i = 0; i <= n; i++) save[i].clear(), color[i] = 0;     for (int i = 0; i <= n - 1; i++) a[i] = read(), save[a[i]].push_back(i);     int kd = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= min(k, (int)(save[i].size())) - 1; j++) {         color[save[i][j]] = kd + 1;         ls[kd + 1] = save[i][j];         kd++;         kd %= k;       }     }     for (int i = 1; i <= kd; i++) color[ls[i]] = 0;     for (int i = 0; i <= n - 1; i++) cout << color[i] <<    ;     cout <<   n ;   }   int main() {     int _t;     _t = read();     while (_t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 201001;   const int MAXK = 51;   const double inf = 1e100;   const double eps = 1e-10;   int K, N;   int tab[MAXN];   long long sum[MAXN];   double res[MAXN];   double odw[MAXN];   double dp[MAXK][MAXN];   struct Pt {     double x, y;   };   int ccw(const Pt& a, const Pt& b, const Pt& c) {     double w = 0;     w += a.x * (b.y - c.y);     w += b.x * (c.y - a.y);     w += c.x * (a.y - b.y);     return w < -eps ? -1 : w > eps;   }   int main() {     scanf( %d %d , &N, &K);     for (int i = (1); i <= (N); ++i) {       scanf( %d , &tab[i]);       sum[i] = sum[i - 1] + tab[i];       odw[i] = odw[i - 1] + 1. / tab[i];       res[i] = res[i - 1] + (double)sum[i] / tab[i];     }     for (int i = (1); i <= (N); ++i) dp[1][i] = res[i];     for (int k = (2); k <= (K); ++k) {       vector<Pt> v;       for (int i = (k - 1); i <= (N); ++i) {         Pt pt = {-1. * sum[i], dp[k - 1][i] - res[i] + sum[i] * odw[i]};         while (v.size() >= 2 && ccw(v[((int)((v).size())) - 2], v.back(), pt) > 0)           v.pop_back();         v.push_back(pt);       }       int p = 0;       for (int i = (k); i <= (N); ++i) {         while (p + 1 < ((int)((v).size())) &&                v[p].x * odw[i] + v[p].y > v[p + 1].x * odw[i] + v[p + 1].y)           ++p;         dp[k][i] = v[p].x * odw[i] + v[p].y + res[i];       }     }     printf( %.10lf n , dp[K][N]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105, INF = 1 << 30, MOD = 1e9 + 7;   int n, k;   vector<int> adj[N];   long long cnt[N][N];   long long ans = 0, F[N];   long long sumOfProducts(vector<int>& arr, int n, int k) {     long long dp[n + 1][n + 1];     memset(dp, 0, sizeof(dp));     long long cur_sum = 0;     for (int i = 1; i <= n; i++) {       dp[1][i] = arr[i - 1];       (cur_sum += arr[i - 1]) %= MOD;     }     for (int i = 2; i <= k; ++i) {       long long temp_sum = 0;       for (int j = 1; j <= n; j++) {         (cur_sum -= dp[i - 1][j]) %= MOD;         dp[i][j] = (arr[j - 1] * cur_sum) % MOD;         (temp_sum += dp[i][j]) %= MOD;       }       cur_sum = temp_sum;     }     return (cur_sum + MOD) % MOD;   }   void dfs(int u, int root, int p, int d) {     ++cnt[root][d];     for (int v : adj[u]) {       if (v == p) continue;       dfs(v, root, u, d + 1);     }   }   void solve(int u) {     memset(cnt, 0, sizeof(cnt));     if (adj[u].size() < k) return;     for (int v : adj[u]) {       dfs(v, v, u, 0);     }     for (int i = 0; i < n; ++i) {       int CNT = 0;       for (int v : adj[u])         if (cnt[v][i]) ++CNT;       if (CNT < k) break;       vector<int> C;       for (int v : adj[u])         if (cnt[v][i]) C.push_back(cnt[v][i]);       (ans += sumOfProducts(C, CNT, k)) %= MOD;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     F[0] = 1;     for (int i = 1; i < N; ++i) F[i] = (F[i - 1] * i) % MOD;     int t;     cin >> t;     while (t--) {       ans = 0;       cin >> n >> k;       for (int i = 0; i < n; ++i) adj[i].clear();       for (int i = 0; i < n - 1; ++i) {         int u, v;         cin >> u >> v;         adj[--u].push_back(--v);         adj[v].push_back(u);       }       if (k == 2)         cout << n * (n - 1) / 2 <<   n ;       else {         for (int i = 0; i < n; ++i) solve(i);         cout << ans % MOD <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXn = 1e5 + 10, MAXx = 4 * MAXn;   struct salar {     int l, r, max1, leftchild, rightchild, id;     long long sum;     salar() { sum = id = l = r = max1 = leftchild = rightchild = 0; }     void idit(int v) {       id = v;       leftchild = 2 * v;       rightchild = 2 * v + 1;     }   };   salar seg[MAXx];   int ar[MAXn], n, m;   void build(int v, int l, int r) {     seg[v].l = l, seg[v].r = r;     seg[v].idit(v);     if (r - l == 1) {       seg[v].sum = ar[l];       seg[v].max1 = ar[l];       return;     }     int med = (l + r) / 2;     build(seg[v].leftchild, l, med);     build(seg[v].rightchild, med, r);     seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;     seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);   }   long long get(int v, int l, int r) {     if (max(l, seg[v].l) >= min(r, seg[v].r)) return 0;     if (l <= seg[v].l && seg[v].r <= r) {       return seg[v].sum;     }     return get(seg[v].leftchild, l, r) + get(seg[v].rightchild, l, r);   }   void domodule(int v, int l, int r, int x) {     if (seg[v].max1 < x) return;     if (max(l, seg[v].l) >= min(r, seg[v].r)) return;     if (seg[v].r - seg[v].l == 1) {       ar[seg[v].l] %= x;       seg[v].sum = ar[seg[v].l];       seg[v].max1 = ar[seg[v].l];       return;     }     domodule(seg[v].leftchild, l, r, x);     domodule(seg[v].rightchild, l, r, x);     seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;     seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);   }   void change(int v, int l, int x) {     if (l < seg[v].l || l >= seg[v].r) return;     if (seg[v].r - seg[v].l == 1) {       ar[seg[v].l] = x;       seg[v].sum = ar[seg[v].l];       seg[v].max1 = ar[seg[v].l];       return;     }     change(seg[v].leftchild, l, x);     change(seg[v].rightchild, l, x);     seg[v].sum = seg[seg[v].leftchild].sum + seg[seg[v].rightchild].sum;     seg[v].max1 = max(seg[seg[v].leftchild].max1, seg[seg[v].rightchild].max1);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar[i];     build(1, 0, n);     for (int i = 0; i < m; i++) {       int type;       cin >> type;       if (type == 1) {         int l, r;         cin >> l >> r;         l--;         cout << get(1, l, r) << endl;       } else if (type == 2) {         int l, r, x;         cin >> l >> r >> x;         l--;         domodule(1, l, r, x);       } else {         int l, x;         cin >> l >> x;         l--;         change(1, l, x);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005];   long long b[100005], dpMax[100005], dpMin[100005], ans = (1ll << 63);   void setup() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) b[i] = abs(a[i] - a[i + 1]);     n--;   }   void xuly() {     for (int i = n; i >= 1; i--) {       dpMax[i] = -min(dpMin[i + 1], 0ll) + b[i];       dpMin[i] = -max(dpMax[i + 1], 0ll) + b[i];       ans = max(ans, dpMax[i]);     }     cout << ans;   }   int main() {     iostream::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     setup();     xuly();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       for (int t = 0; t < n - 1; t++) {         if (a[t] > a[t + 1]) {           int j = t + 1;           cout << t + 1 <<     << j + 1 << endl;           int q = a[t];           a[t] = a[j];           a[j] = q;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long a, b, c, i, j, k, l, m, t, x, y, n, z;     string s;     map<long long, long long> mp;     map<long long, long long>::iterator it;     cin >> a >> s;     n = s.size();     long long a1[n + 1];     a1[0] = 0;     for (i = 1; i < n + 1; i++) a1[i] = s[i - 1] -  0  + a1[i - 1];     for (i = 0; i < n + 1; i++) {       for (j = i + 1; j < n + 1; j++) {         mp[a1[j] - a1[i]]++;       }     }     c = 0;     if (!a) c = (mp[0] * (n * (n + 1) - mp[0]));     if (!a) {       cout << c << endl;       return 0;     }     for (i = 0; i < n + 1; i++) {       for (j = i + 1; j < n + 1; j++) {         if (a1[j] - a1[i] != 0)           if (a % (a1[j] - a1[i]) == 0) {             it = mp.find(a / (a1[j] - a1[i]));             if (it != mp.end()) c = c + mp[a / (a1[j] - a1[i])];           }       }     }     cout << c << endl;     return 0;   }