#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point(){};     point(int xx, int yy) {       x = xx;       y = yy;     }     point friend operator+(point a, point b) {       return point(a.x + b.x, a.y + b.y);     }     point friend operator-(point a, point b) {       return point(a.x - b.x, a.y - b.y);     }     long long friend operator*(point a, point b) {       return (long long)a.x * b.y - (long long)a.y * b.x;     }   } a[5050], s[5050];   int n, tot;   long long S;   bool cmp(point a, point b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   void put(point a) { printf( %d %d n , a.x, a.y); }   long long area(int i, int j, int k) {     return abs((s[j] - s[i]) * (s[k] - s[i]));   }   int main() {     scanf( %d%I64d , &n, &S);     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].y);     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       while (tot > 1 && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--;       s[++tot] = a[i];     }     int k = tot;     for (int i = n - 1; i > 0; i--) {       while (tot > k && (a[i] - s[tot - 1]) * (s[tot] - s[tot - 1]) <= 0) tot--;       s[++tot] = a[i];     }     tot--;     S = 0;     int ii, jj, kk;     for (int i = 1; i < tot - 1; i++) {       int tmp = i + 2;       for (int j = i + 1; j <= tot; j++) {         while (tmp < tot && area(i, j, tmp + 1) > area(i, j, tmp)) tmp++;         if (area(i, j, tmp) > S) {           S = area(i, j, tmp);           ii = i;           jj = j;           kk = tmp;         }       }     }     put(s[ii] + s[jj] - s[kk]);     put(s[jj] + s[kk] - s[ii]);     put(s[kk] + s[ii] - s[jj]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 23333;   int aa[maxn];   int p[maxn];   int main() {     int a, b, w, x, c;     scanf( %d%d%d%d%d , &a, &b, &w, &x, &c);     c -= a;     if (c <= 0) {       printf( 0 n );       return 0;     }     int m = 0, haj;     for (int i = b; !p[i];) {       p[i] = ++m;       if (i >= x) {         i -= x;         aa[m] = 1;       } else {         i = w - x + i;       }       if (p[i]) haj = p[i];     }     for (int i = 1; i < haj; ++i) {       c -= aa[i];       if (c <= 0) {         printf( %d n , i);         return 0;       }     }     long long sum = (long long)haj - 1;     int s = 0;     for (int i = haj; i <= m; ++i) s += aa[i];     sum += (long long)((c - 1) / s) * (long long)(m - haj + 1);     c -= ((c - 1) / s) * s;     for (int i = haj; i <= m && c > 0; ++i) {       c -= aa[i];       ++sum;     }     printf( %I64d n , sum);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 50;   int t, m, n;   long long su, s[maxn], cf[maxn];   int a[maxn], b[maxn], c[maxn], x, y;   int main() {     scanf( %d %d , &n, &m);     scanf( %d , a + 1);     for (int i = 2; i <= m; ++i) {       scanf( %d , a + i);       su += abs(a[i] - a[i - 1]);     }     for (int i = 1; i <= n; ++i) s[i] = su;     for (int i = 1; i <= m - 1; ++i) {       x = min(a[i], a[i + 1]), y = max(a[i], a[i + 1]);       if (x == y) continue;       s[x] += x - 1;       s[y] += 2 * x - y;       if (x + 1 == y) continue;       b[i] = x + 1;       c[i] = y - 1;     }     for (int i = 1; i <= m - 1; ++i) {       x = b[i];       y = c[i];       --cf[x];       ++cf[y + 1];     }     for (int i = 1; i <= n; i++) {       cf[i] = cf[i - 1] + cf[i];       s[i] += cf[i];     }     for (int i = 1; i <= n; ++i) printf( %lld  , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n, m;   vector<int> g[MAXN];   int max1[MAXN], max2[MAXN];   bool vis[MAXN];   void dfs(int v) {     vis[v] = true;     for (auto to : g[v]) {       if (!vis[to]) {         dfs(to);         if (max1[v] <= max1[to] + 1) {           max2[v] = max1[v];           max1[v] = max1[to] + 1;         } else if (max2[v] < max1[to] + 1) {           max2[v] = max1[to] + 1;         }       }     }   }   int ans;   int main() {     cin >> n >> m;     while (m--) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i);     for (int i = 1; i <= n; i++) ans = max(ans, max1[i] + max2[i]);     cout << ans;     return 0;   }


#include<bits/stdc++.h>   using namespace std;      #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)   #define f first   #define s second   #define for1(i,a,b) for (int i = a; i < b; i++)   #define for2(i,a,b) for (int i = a; i > b; i--)   #define arrin(a,n) for (int i = 0; i < n; i++) cin >> a[i];   #define arrout(a,n) for (int i = 0; i < n; i++) cout << a[i] <<    ; cout <<   n ;   #define arrin2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cin >> a[i][j];}   #define arrout2d(a,m,n) for (int i = 0; i < m; i++){for (int j = 0; j < n; j++) cout << a[i][j] <<    ; cout <<   n ;}   #define w(t) int t; cin >> t; while(t--)   #define strin(s) getline(cin,s)   #define pushb push_back   #define popb pop_back   #define pushf push_front   #define popf pop_front   #define mp make_pair   #define lower_bound lb   #define upper_bound ub   #define yes cout <<  YES n    #define no cout <<  NO n       typedef long long ll;   typedef long double ld;   typedef vector<int> vi;   typedef vector<ll> vll;   typedef vector<pair<int,int>> vp;   typedef vector<char> vch;   typedef vector<string> vstr;   typedef set<ll> sll;   typedef pair<int,int> pi;   typedef map<int,int> mi;   typedef map<int,char> mch;   //typedef __int128_t vvlint;      const int inf = 1e9 + 7;   /*   freopen( input.txt ,  r , stdin);   freopen( output.txt ,  w , stdout);   */      void tc()   {    int a1,a2,a3,a4,a5,c1,c2,c3;    cin >> c1 >> c2 >> c3;    cin >> a1 >> a2 >> a3 >> a4 >> a5;        if (a1 <= c1 && a2 <= c2 && a3 <= c3)    {        c1 -= a1;        c2 -= a2;        c3 -= a3;                a4 -= min(a4,c1);        a5 -= min(a5,c2);                if (a4 + a5 <= c3)            yes;        else            no;    }    else        no;   }      int main()   {    fastio;        w(t)    {     tc();     }        return 0;    }


#include <bits/stdc++.h>   int n;   char a[11][11], b[11][11], c[11][11];   void turn() {     int i, j, k, l;     for (i = n - 1, k = 0; i >= 0; --i, ++k)       for (j = 0, l = 0; j < n; ++j, ++l) c[k][l] = a[j][i];     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) a[i][j] = c[i][j];   }   int same() {     int i, j;     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j)         if (a[i][j] != b[i][j]) return 0;     return 1;   }   void p() {     int i, j;     printf(  n n );     for (i = 0; i < n; ++i) {       for (j = 0; j < n; ++j) printf( %c , a[i][j]);       printf(  n );     }     printf(  n n );   }   void f() {     int i, j;     for (i = 0; i < 3; ++i) {       if (same()) {         printf( Yes n );         return;       }       turn();     }     if (same()) {       printf( Yes n );       return;     }     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) c[i][j] = a[i][n - j - 1];     for (i = 0; i < n; ++i)       for (j = 0; j < n; ++j) a[i][j] = c[i][j];     for (i = 0; i < 3; ++i) {       if (same()) {         printf( Yes n );         return;       }       turn();     }     if (same()) {       printf( Yes n );       return;     }     printf( No n );     return;   }   int main() {     scanf( %d , &n);     int i, j;     for (i = 0; i < n; ++i) scanf( %s , a[i]);     for (i = 0; i < n; ++i) scanf( %s , b[i]);     f();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 1e6 + 6;   bool us[N], use[N];   long long a[N];   long long n, x, k, q, x1, x2, y, ibibibibbibibibiibigbabypanfewewf, y2, ans, m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> x1;     for (int I = 0; I < x1; I++) {       cin >> n;       y = 0;       ibibibibbibibibiibigbabypanfewewf = 1e9 + 7;       for (int i = 1; i <= n; i++) {         cin >> k >> q;         y = max(y, k);         ibibibibbibibibiibigbabypanfewewf =             min(ibibibibbibibibiibigbabypanfewewf, q);       }       cout << max(0ll, y - ibibibibbibibibiibigbabypanfewewf) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int n, long long int p) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result % p * x % p) % p;       x = (x % p * x % p) % p;       n = n / 2;     }     return result % p;   }   void solve() {     long long int n, m;     cin >> n >> m;     vector<long long int> cnt(1005);     for (long long int i = 0; i <= n - 1; i++) {       long long int a1;       cin >> a1;       cnt[a1] = 1;     }     for (long long int i = 0; i <= m - 1; i++) {       long long int a2;       cin >> a2;       if (cnt[a2] == 1) cnt[a2]++;     }     for (long long int i = 1; i <= 1000; i++) {       if (cnt[i] >= 2) {         cout <<  YES  << endl;         cout <<  1   << i << endl;         return;       }     }     cout <<  NO  << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, a[26], ans = 0, tot = 0;     string s;     map<pair<long long int, long long int>, long long int> mp;     for (i = 0; i < 26; i++) cin >> a[i];     cin >> s;     for (i = 0; i < s.length(); i++) {       ans += mp[{s[i] -  a , tot}];       tot += a[s[i] -  a ];       mp[{s[i] -  a , tot}]++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   using namespace std;   int main() {     cin.tie(NULL), ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a > b) {         if ((b - a) % 2 == 0)           cout << 1 <<   n ;         else           cout << 2 <<   n ;       } else if (a == b)         cout << 0 <<   n ;       else {         if ((b - a) % 2 != 0)           cout << 1 <<   n ;         else           cout << 2 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   double pi = 3.14159265359;   using namespace std;   int main() {     ios::sync_with_stdio(false);     string a, b;     cin >> a >> b;     string c(a.size(),  0 );     int count = 0;     for (unsigned int i = 0; i < a.size(); i++)       if (a[i] == b[i]) c[i] = a[i], count++;     if ((a.size() - count) % 2)       cout <<  impossible ;     else {       bool ok = 0;       for (unsigned int i = 0; i < a.size(); i++)         if (a[i] != b[i] && !ok)           c[i] = a[i], ok = 1;         else if ((a[i] != b[i] && ok))           c[i] = b[i], ok = 0;       cout << c <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul[100010], inv[100010];   const int mod = 998244353;   const int maxn = 5050;   void init() {     mul[0] = 1;     for (int i = 1; i < maxn; i++) mul[i] = (mul[i - 1] * i) % mod;     inv[0] = inv[1] = 1;     for (int i = 2; i < maxn; i++)       inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;     for (int i = 1; i < maxn; i++) inv[i] = (inv[i - 1] * inv[i]) % mod;   }   long long C(int n, int m) { return mul[n] * inv[m] % mod * inv[n - m] % mod; }   long long f(long long a, long long b) {     long long ans = 0;     for (int i = 0; i <= min(a, b); i++)       ans = (ans + C(a, i) * C(b, i) % mod * mul[i] % mod) % mod;     return ans;   }   int main() {     int a, b, c;     init();     cin >> a >> b >> c;     cout << f(a, b) * f(a, c) % mod * f(b, c) % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int rev(int n) {     int ret = 0;     while (n != 0) {       ret = (10 * ret) + (n % 10);       n /= 10;     }     return ret;   }   int main() {     int mx, my, w;     int i, j, k, t;     int ax, ay;     vector<int> v;     map<pair<int, int>, vector<int> > mp;     scanf( %d%d%d , &mx, &my, &w);     for (i = 1; i <= my; i++) {       j = rev(i);       k = gcd(i, j);       mp[make_pair(i / k, j / k)].push_back(i);     }     vector<int> vec(my + 1, 0);     vector<vector<int> > vv;     vv.push_back(v);     for (i = 1; i <= mx; i++) {       j = rev(i);       k = gcd(i, j);       v = mp[make_pair(j / k, i / k)];       for (j = 0; j < v.size(); j++) vec[v[j]]++;       vv.push_back(v);     }     long long ans = -1;     for (i = mx, j = 0, k = 0; i > 0; i--) {       if (k < w && j < my) {         do {           j++;           k += vec[j];         } while (k < w && j < my);       }       if (k >= w && (ans == -1 || ans > (long long)i * j)) {         ans = (long long)i * j;         ax = i;         ay = j;       }       for (t = 0; t < vv[i].size(); t++) {         if (vv[i][t] <= j) k--;         vec[vv[i][t]]--;       }     }     if (ans == -1)       printf( -1 n );     else       printf( %d %d n , ax, ay);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 10;   int n, a[N], b[N], c[N], p[N];   vector<int> v;   int main() {     cin >> n;     for (int i = 1; i < N; i++) p[i] = i;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (a[i] == 2) cin >> c[i];     }     for (int i = n; i >= 1; i--) {       if (a[i] == 1)         v.push_back(p[b[i]]);       else if (a[i] == 2)         p[b[i]] = p[c[i]];     }     for (int i = v.size() - 1; i >= 0; i--) printf( %d  , v[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<int> qQuit;   int ind[100000], n;   bool entered[100000];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       qLeft, qRight;   int data[100000];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       ind[temp - 1] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , data + i);       data[i]--;     }     for (int i = 0; i < n; i++) {       qQuit.push(data[i]);       if (i >= ind[data[i]])         qRight.push(make_pair(i - ind[data[i]], data[i]));       else {         qLeft.push(make_pair(ind[data[i]] - i, data[i]));         entered[data[i]] = true;       }     }     for (int i = 0; i < n; i++) {       int minVal = 99999999;       int minFrom;       if (qRight.size()) {         if (minVal > qRight.top().first - i) minFrom = qRight.top().second;         minVal = min(minVal, qRight.top().first - i);       }       while (qLeft.size() && entered[qLeft.top().second] == false) qLeft.pop();       if (qLeft.size()) {         if (minVal > qLeft.top().first + i) minFrom = qLeft.top().second;         minVal = min(minVal, qLeft.top().first + i);       }       printf( %d n , minVal);       while (qRight.size() && qRight.top().first - i == 0) {         pair<int, int> val = qRight.top();         qRight.pop();         qLeft.push(make_pair(-i, val.second));         entered[val.second] = true;       }       int toQuit = qQuit.front();       qQuit.pop();       entered[toQuit] = false;       qRight.push(make_pair(n - 1 - ind[toQuit] + (i + 1), toQuit));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dque[500005];   int s = 0, t = 0, num = 0, q, maxi;   double mean = 0;   int main() {     memset(dque, 0, sizeof(dque));     scanf( %d , &q);     while (q--) {       int type, x;       scanf( %d , &type);       if (type == 1) {         scanf( %d , &x);         if (num != 0) {           mean = (mean * num + x - maxi) / num;           dque[t++] = maxi;         } else {           mean = x;           num++;         }         maxi = x;         while (s < t && dque[s] < mean) {           mean = (mean * num + dque[s]) / (num + 1);           num++;           s++;         }       } else         printf( %.10f n , (double)maxi - mean);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     deque<int> vec(300000);     int l = 0, r = 0;     for (int i = 0; i < n; i++) {       string s;       int id;       cin >> s >> id;       if (!i) {         vec[id] = l;         l--, r++;       } else {         if (s ==  L ) {           vec[id] = l;           l--;         }         if (s ==  R ) {           vec[id] = r;           r++;         }         if (s ==  ? ) {           cout << min(abs(vec[id] - l), abs(vec[id] - r)) - 1 << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[1002];   map<long long, long long> vis;   map<pair<long long, long long>, long long> dia;   long long st[1002], en[1002];   void dfs(long long tar, long long cur, bool &found, long long mini,            long long &mini2) {     vis[cur] = 1;     if (tar == cur) {       found = true;       mini2 = min(mini, mini2);       return;     }     for (long long i = 0; i < adj[cur].size(); i++) {       if (vis[adj[cur][i]] == 0) {         dfs(tar, adj[cur][i], found, min(mini, dia[{cur, adj[cur][i]}]), mini2);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t, n, num, m, k;     cin >> n >> k;     for (long long i = 0; i < k; i++) {       long long a, b, d;       cin >> a >> b >> d;       adj[a].push_back(b);       adj[b].push_back(a);       st[a]++;       en[b]++;       dia[{a, b}] = d;       dia[{b, a}] = d;     }     vector<long long> v1, v2;     for (long long i = 1; i <= n; i++) {       if (en[i] == 0 && st[i] == 1) {         v1.push_back(i);       }       if (st[i] == 0 && en[i] == 1) {         v2.push_back(i);       }     }     cout << v1.size() <<   n ;     for (long long i = 0; i < v1.size(); i++) {       for (long long j = 0; j < v2.size(); j++) {         bool found = false;         long long mini2 = LLONG_MAX;         dfs(v2[j], v1[i], found, LLONG_MAX, mini2);         vis.clear();         if (found) {           cout << v1[i] <<     << v2[j] <<     << mini2 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mp[1001][1001];   int visit[1001][1001];   int dist[1001][1001];   int N, M;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   bool chk(int x, int y) { return 0 <= x && x < N && 0 <= y && y < M; }   void dfs(int x, int y, bool isfirst) {     visit[x][y] = 1;     if (!isfirst) dist[x][y] = 1;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (chk(nx, ny) && mp[x][y] == mp[nx][ny] && visit[nx][ny] == 0) {         dist[x][y] = 1;         dfs(nx, ny, false);       }     }   }   int main(int argc, char *argv[]) {     int Q;     scanf( %d %d %d , &N, &M, &Q);     for (int i = 0; i < N; i++) scanf( %s , mp[i]);     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (visit[i][j] == 0) dfs(i, j, true);       }     }     queue<pair<int, int> > q;     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (dist[i][j] == 1) q.push({i, j});       }     }     while (!q.empty()) {       auto [x, y] = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (chk(nx, ny) && dist[nx][ny] == 0) {           dist[nx][ny] = dist[x][y] + 1;           q.push({nx, ny});         }       }     }     while (Q--) {       long long x, y, t;       scanf( %lld %lld %lld , &x, &y, &t);       printf( %lld n , dist[x - 1][y - 1]                            ? ((mp[x - 1][y - 1] -  0 ) +                               max(t - (dist[x - 1][y - 1] - 1), 0LL)) %                                  2                            : mp[x - 1][y - 1] -  0 );     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-15;   const double pi = acos(-1.0);   const long long Mod = 1000000007;   const int N = 1e3 + 5;   int ks = 0;   int n, m, s, t;   long long dis[N], cost[N * 10], L;   int used[N], deleted[N * 10];   pair<int, int> parent[N];   vector<pair<int, int> > g[N];   struct edge {     int x, y;     long long z;     bool operator<(const edge &f) const { return z > f.z; }   } E[N * 10];   void SPFA() {     for (int i = 0; i < n; i++) {       dis[i] = LLONG_MAX;       used[i] = 0;     }     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     q.emplace(0, s);     dis[s] = 0;     while (q.size()) {       int from = q.top().second;       used[from] = 1;       q.pop();       for (auto i : g[from]) {         int to = i.first;         int id = i.second;         if (dis[from] + cost[id] < dis[to]) {           dis[to] = dis[from] + cost[id];           parent[to] = {from, id};           if (!used[to]) q.emplace(dis[to], to);         }       }     }   }   int main() {     scanf( %d%d%I64d%d%d , &n, &m, &L, &s, &t);     for (int i = 0; i < m; i++) {       scanf( %d%d%I64d , &E[i].x, &E[i].y, &E[i].z);     }     sort(E, E + m);     int last = 0;     for (int i = 0; i < m && E[i].z; i++, last++) {       cost[i] = E[i].z;       g[E[i].x].emplace_back(E[i].y, i);       g[E[i].y].emplace_back(E[i].x, i);     }     SPFA();     if (dis[t] < L) {       puts( NO );       return 0;     }     for (int i = last; i < m; i++) {       deleted[i] = cost[i] = 1;       g[E[i].x].emplace_back(E[i].y, i);       g[E[i].y].emplace_back(E[i].x, i);     }     SPFA();     if (dis[t] > L) {       puts( NO );       return 0;     }     puts( YES );     while (dis[t] < L) {       int cur = t;       while (cur != s) {         int id = parent[cur].second;         cur = parent[cur].first;         if (deleted[id]) {           cost[id] += L - dis[t];           break;         }       }       SPFA();     }     bool done[N];     memset(done, false, sizeof done);     for (int i = 0; i < n; i++) {       for (auto j : g[i]) {         if (done[j.first]) continue;         cout << i <<     << j.first <<     << cost[j.second] <<   n ;       }       done[i] = true;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int pre = INT_MIN;     int cur;     int state = 0;     for (int i = 0; i < n; i++) {       cin >> cur;       if (cur > pre) {         if (state == 0) {           pre = cur;           continue;         } else {           cout <<  NO  << endl;           return 0;         }       } else if (cur == pre) {         if (state == 1) {           pre = cur;           continue;         }         if (state == 0) {           pre = cur;           state = 1;           continue;         }         cout <<  NO  << endl;         return 0;       } else {         if (state == 2) {           pre = cur;           continue;         }         if (state < 2) {           pre = cur;           state = 2;           continue;         }         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n;     std::cin >> n;     std::string s;     std::cin >> s;     std::vector<int> v0(n);     for (int i = 0; i < n; i++) v0[i] = s[i] -  0 ;     bool add = true;     std::vector<int> v1(n);     for (int i = 0; i < n; i++) {       if (add)         v1[i] = v0[i] + 1;       else         v1[i] = v0[i];       if (v1[i] == 2) {         add = true;         v1[i] = 0;       } else         add = false;     }     int count = 0;     for (int i = 0; i < n; i++)       if (v0[i] != v1[i]) count++;     std::cout << count << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   struct node {     long long x, l, r;   } a[10005];   long long b[20005];   int is[20005][4], ed[20005][4];   int l = 2;   struct Matrix {     long long v[3][3];     Matrix() { memset(v, 0, sizeof(v)); }     Matrix operator*(const Matrix B) {       Matrix C;       for (int i = 0; i <= l; i++)         for (int j = 0; j <= l; j++)           for (int k = 0; k <= l; k++) {             C.v[i][j] = (C.v[i][j] + v[i][k] * B.v[k][j]) % mod;           }       return C;     }   };   Matrix mtpow(Matrix A, long long k) {     int i;     Matrix B;     for (int i = 0; i <= l; i++) B.v[i][i] = 1;     while (k) {       if (k & 1) B = B * A;       A = A * A;       k >>= 1;     }     return B;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i].x >> a[i].l >> a[i].r;       b[++b[0]] = a[i].l;       b[++b[0]] = a[i].r;     }     b[++b[0]] = 1, b[++b[0]] = m;     sort(b + 1, b + b[0] + 1);     b[0] = unique(b + 1, b + b[0] + 1) - b - 1;     for (int i = 1; i <= n; i++) {       a[i].l = lower_bound(b + 1, b + b[0] + 1, a[i].l) - b;       a[i].r = lower_bound(b + 1, b + b[0] + 1, a[i].r) - b;       is[a[i].l][a[i].x]++, is[a[i].r + 1][a[i].x]--;       ed[a[i].r][a[i].x]++;     }     long long x1 = 0, x2 = 1, x3 = 0;     long long x11, x22, x33;     Matrix B;     for (int i = 0; i <= l; i++) {       for (int j = 0; j <= l; j++) {         if ((i == 0 && j == 2) || (i == 2 && j == 0))           B.v[i][j] = 0;         else           B.v[i][j] = 1;       }     }     for (int i = 2; i <= b[0]; i++) {       for (int j = 1; j <= 3; j++) is[i][j] += is[i - 1][j];       long long c = b[i] - b[i - 1] - 1;       Matrix temp = B;       for (int j = 1; j <= 3; j++) {         if (is[i - 1][j] - ed[i - 1][j] >= 1)           for (int k = 0; k <= 2; k++) temp.v[j - 1][k] = 0;       }       temp = mtpow(temp, c);       x11 = (temp.v[0][0] * x1 + temp.v[0][1] * x2 + temp.v[0][2] * x3) % mod;       x22 = (temp.v[1][0] * x1 + temp.v[1][1] * x2 + temp.v[1][2] * x3) % mod;       x33 = (temp.v[2][0] * x1 + temp.v[2][1] * x2 + temp.v[2][2] * x3) % mod;       x1 = (x11 + x22) % mod, x2 = (x11 + x22 + x33) % mod,       x3 = (x33 + x22) % mod;       if (is[i][1]) x1 = 0;       if (is[i][2]) x2 = 0;       if (is[i][3]) x3 = 0;     }     cout << x2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int x = 1;     while (x <= n) {       if (x == n || x + 1 == n) {         cout << 1 <<   n ;         return 0;       }       if (x & 1) {         x = x * 2 + 2;       } else {         x = x * 2 + 1;       }     }     cout << 0 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 6;   vector<pair<int, int> > G[maxn];   int out, m, d[maxn], ans[maxn][3], leaf[maxn][2];   void add_m(int u, int v, int d) {     ans[++m][0] = u, ans[m][1] = v, ans[m][2] = d;   }   void add_link(int u, int l, int d) {     if (u == out) {       add_m(u, l, d);       return;     }     int a = l, b = leaf[u][0] == l ? leaf[u][1] : leaf[u][0], c = out;     add_m(a, c, d / 2), add_m(a, b, d / 2), add_m(b, c, -d / 2);   }   void dfs(int u, int f, int l) {     if (G[u].size() == 1 && f) {       leaf[u][0] = u;       return;     }     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i].first;       if (v != f) {         dfs(v, u, l);         if (leaf[u][0])           leaf[u][1] = leaf[v][0];         else           leaf[u][0] = leaf[v][0];       }     }     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i].first;       if (v != f) {         int d = G[u][i].second;         if (G[v].size() == 1)           add_link(u, v, G[u][i].second);         else {           add_link(u, leaf[v][0], G[u][i].second);           add_link(v, leaf[v][0], -G[u][i].second);         }       }     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v, c;       cin >> u >> v >> c;       G[u].push_back(make_pair(v, c));       G[v].push_back(make_pair(u, c));       ++d[u], ++d[v];     }     for (int i = 1; i <= n; ++i)       if (d[i] == 2) {         cout <<  NO  << endl;         return 0;       }     for (int i = 1; i <= n; ++i)       if (G[i].size() == 1) {         out = i, dfs(i, 0, i);         break;       }     cout <<  YES  << endl;     cout << m << endl;     for (int i = 1; i <= m; ++i)       cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, k, j, i, a[10001], s[1002], n1, n2, num[1002], h1, h2;     double x, sum1, sum2, l, r, m;     scanf( %d %d , &n, &k);     h1 = 1000;     h2 = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (h1 > a[i]) h1 = a[i];       if (h2 < a[i]) h2 = a[i];     }     for (i = 0; i <= h2; i++) {       s[i] = 0;       num[i] = 0;     }     for (i = 0; i < n; i++) {       for (j = a[i]; j <= h2; j++) {         s[j] += a[i];         num[j]++;       }     }     l = h1;     r = h2;     while (r - l >= 1e-9) {       m = (l + r) / 2;       sum1 = ((double)num[(int)m]) * m - (double)s[(int)m];       sum2 =           (double)(s[h2] - s[(int)m]) - (((double)(num[h2] - num[(int)m])) * m);       if (sum2 * (1 - k / 100.0) > sum1) {         l = m;       } else {         r = m;       }     }     cout.precision(6);     cout.setf(ios::fixed, ios::floatfield);     cout << (s[h2] - sum2 * (double)k / 100.0) / (double)n << endl;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   long long vectorMult(pair<int, int> a, pair<int, int> b, pair<int, int> c) {     return (c.first - a.first) * 1ll * (b.second - a.second) -            (c.second - a.second) * 1ll * (b.first - a.first);   }   bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first < b.first || a.first == b.first && a.second < b.second;   }   vector<pair<int, int> > convex_hull(vector<pair<int, int> > t) {     if (t.size() == 1) return t;     sort(t.begin(), t.end(), cmp);     vector<pair<int, int> > up, down;     auto l = t[0];     auto r = t.back();     up.push_back(t[0]);     down.push_back(t[0]);     for (int i = 1; i < t.size(); i++) {       if (vectorMult(l, r, t[i]) <= 0) {         while (up.size() >= 2 &&                vectorMult(up[up.size() - 2], up.back(), t[i]) <= 0) {           up.pop_back();         }         up.push_back(t[i]);       }       if (vectorMult(l, r, t[i]) >= 0) {         while (down.size() >= 2 &&                vectorMult(down[down.size() - 2], down.back(), t[i]) >= 0) {           down.pop_back();         }         down.push_back(t[i]);       }     }     up.insert(up.end(), down.rbegin() + 1, down.rend() - 1);     if (up.size() == 2 && up[0] == up[1]) up.pop_back();     return up;   }   int main() {     ios_base::sync_with_stdio(0);     while (true) {       int n;       cin >> n;       if (n == 0) break;       vector<string> v;       for (int i = 0; i < n; i++) {         string x;         cin >> x;         v.push_back(x);       }       for (int i = 0; i < n - i - 1; i++) {         swap(v[i], v[n - i - 1]);       }       vector<pair<int, int> > t;       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < n - 1; j++) {           if (v[i][j] >  0  && v[i][j + 1] >  0  && v[i + 1][j] >  0  &&               v[i + 1][j + 1] >  0 ) {             t.push_back(make_pair(j + 1, i + 1));           }         }       }       t = convex_hull(t);       int mn = 0;       for (int i = 1; i < t.size(); i++)         if (t[i] < t[mn]) {           mn = i;         }       vector<pair<int, int> > ans;       ans.insert(ans.end(), t.begin() + mn, t.end());       ans.insert(ans.end(), t.begin(), t.begin() + mn);       cout << ans.size() << endl;       for (auto it : ans) cout << it.first <<     << it.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5, Mod = 1e9 + 7, Lg = 27, P = 727, Sq = 350;   const long long Inf = 3e18 + 10;   long long ans;   long long gcd(long long x, long long y) {     if (x > y) swap(y, x);     if (!x) return y;     return gcd(x, y % x);   }   void solve(long long x, long long y, long long d1, long long z, long long w,              long long d2) {     long long t = y - x + 1;     long long g = gcd(d1, d2);     long long d = abs(x - z);     long long q = d / g;     if (x < z) {       x += q * g;       if (x < z) x += g;     } else {       x -= q * g;       if (x > y) x -= g;     }     if (x < z || x > w) return;     ans = max(ans, min(t, w - x + 1));   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long x, y, d1, z, w, d2;     cin >> x >> y >> d1 >> z >> w >> d2;     solve(x, y, d1, z, w, d2);     solve(z, w, d2, x, y, d1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   int main() {     for (int i = 1; i <= 35; i++) printf( l );     for (int i = 1; i <= 36; i++) printf( dsut0r );     printf( luu );     for (int i = 1; i <= 35; i++) printf( l );     for (int i = 1; i <= 36; i++) printf( usdt0r );     for (int i = 1; i <= 36; i++) printf( le );     printf( ddd );     for (int i = 1; i <= 35; i++) printf( 0r );     printf( 0uu );     for (int i = 1; i <= 33; i++) {       printf( r10ltldr01lt0utd10ut );       printf( uur01ltlldr10ltr10lt0utd10ut );       printf( lrr01ltl10rtl1rt );       printf( rrelelu10dtu10dtddlr10ltu10dtu );       printf( r10ltldr01lt0utd10ut );       printf( uur01ltlldr10ltr10lt0utd10ut );       printf( lrr01ltl10rtl1rt );       printf( l10rtd10utl10rtd10ut );       printf( uereuerererelueueledeleue );       printf( lddd10utuuur10ltd10utd10utl0rt );       printf( r10ltl01rtl1rt );       printf( rdu10dt0ut );       printf( r10ltl01rtl1rt );       printf( ru0utd10ut );       printf( r10ltl01rtl1rt );       printf( reueuerededeldeleuuu );     }     printf( ddddr );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<pair<long long, long long>, pair<long long, long long> > st1[4000000];   pair<pair<long long, long long>, pair<long long, long long> > st2[4000000];   long long arrL[600010];   long long arrR[600010];   long long dist[600010];   long long height[600010];   pair<pair<long long, long long>, pair<long long, long long> > maximize(       pair<pair<long long, long long>, pair<long long, long long> > p,       pair<pair<long long, long long>, pair<long long, long long> > q) {     pair<long long, long long> a[4];     a[0] = p.first;     a[1] = p.second;     a[2] = q.first;     a[3] = q.second;     sort(a, a + 4);     return make_pair(a[2], a[3]);   }   void build(pair<pair<long long, long long>, pair<long long, long long> > st[],              long long arr[], int node, int L, int R) {     if (L == R)       st[node] = make_pair(make_pair(arr[L], L), make_pair(-1LL << 60, -1));     else {       int mid = (R + L) / 2;       build(st, arr, node * 2, L, mid);       build(st, arr, node * 2 + 1, mid + 1, R);       st[node] = maximize(st[node * 2], st[node * 2 + 1]);     }   }   pair<pair<long long, long long>, pair<long long, long long> > query(       pair<pair<long long, long long>, pair<long long, long long> > st[],       int node, int L, int R, int i, int j) {     if (i > R || j < L)       return make_pair(make_pair(-1LL << 60, -1), make_pair(-1LL << 60, -1));     if (L >= i && R <= j) return st[node];     int mid = (L + R) / 2;     pair<pair<long long, long long>, pair<long long, long long> > qL =         query(st, node * 2, L, mid, i, j);     pair<pair<long long, long long>, pair<long long, long long> > qR =         query(st, node * 2 + 1, mid + 1, R, i, j);     return maximize(qL, qR);   }   int main() {     int N, M;     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> dist[i];       dist[i + N] = dist[i];     }     for (int i = 1; i < 2 * N - 1; i++) dist[i] += dist[i - 1];     for (int i = 0; i < N; i++) {       cin >> height[i];       height[i + N] = height[i];     }     for (int i = 0; i < 2 * N - 1; i++) {       arrL[i] = arrR[i] = 2 * height[i];       if (i) {         arrL[i] -= dist[i - 1];         arrR[i] += dist[i - 1];       }     }     build(st1, arrL, 1, 0, 2 * N - 1);     build(st2, arrR, 1, 0, 2 * N - 1);     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--, b--;       int x, y;       if (a <= b) {         x = b + 1;         y = a + N - 1;       } else {         x = b + 1;         y = a - 1;       }       pair<pair<long long, long long>, pair<long long, long long> > p =           query(st1, 1, 0, 2 * N - 1, x, y);       pair<pair<long long, long long>, pair<long long, long long> > q =           query(st2, 1, 0, 2 * N - 1, x, y);       vector<pair<long long, long long> > v1;       v1.push_back(p.first);       v1.push_back(p.second);       vector<pair<long long, long long> > v2;       v2.push_back(q.first);       v2.push_back(q.second);       vector<long long> ret;       for (int i = 0; i < int((v1).size()); i++)         for (int j = 0; j < int((v2).size()); j++)           if (v1[i].second == v2[j].second)             continue;           else             ret.push_back(v1[i].first + v2[j].first);       sort((ret).begin(), (ret).end());       cout << ret.back() << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 3e6 + 7;   const int INF = 1e9 + 9;   const int xi[] = {0, 0, +1, -1};   const int yi[] = {-1, +1, 0, 0};   const int xxi[] = {-1, +1, 0, 0, -1, +1, +1, -1};   const int yyi[] = {0, 0, -1, +1, -1, +1, -1, +1};   int n, ans;   int w[1000001], cnt[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> w[i];       cnt[w[i]]++;     }     for (int i = 0; i <= N - 1; i++) {       cnt[i + 1] += cnt[i] / 2;       cnt[i] %= 2;       ans += cnt[i];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int read(T& x) {     static char ch;     static bool neg;     for (ch = neg = 0; ch <  0  ||  9  < ch; neg |= ch ==  - , ch = getchar())       ;     for (x = 0;  0  <= ch && ch <=  9 ; (x *= 10) += ch -  0 , ch = getchar())       ;     return (x = neg ? -x : x);   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   const int N = 2e5 + 10;   int m, n, k, t;   int a[N];   struct T {     int l, r, d;   } trap[N];   int c[N];   inline bool check(int val) {     int sum = 0;     for (int i = 1; i <= k; i++) {       if (trap[i].d > val) {         c[trap[i].l]++;         c[trap[i].r + 1]--;       }     }     for (int i = 1, s = 0; i <= n + 1; i++) {       s += c[i];       if (s > 0) sum += 2;     }     for (int i = 1; i <= k; i++) {       if (trap[i].d > val) {         c[trap[i].l]--;         c[trap[i].r + 1]++;       }     }     return sum + n + 1 <= t;   }   int main(void) {     read(m);     read(n);     read(k);     read(t);     for (int i = 1; i <= m; i++) read(a[i]);     sort(a + 1, a + m + 1);     for (int i = 1; i <= k; i++) {       read(trap[i].l);       read(trap[i].r);       read(trap[i].d);     }     a[m + 1] = 1e9 + 10;     int st = 1, en = m + 1;     while (st != en) {       int md = (st + en) >> 1;       if (check(a[md]))         en = md;       else         st = md + 1;     }     printf( %d n , m - st + 1);   }


#include <bits/stdc++.h>   using namespace std;   constexpr int MAXN = 200000;   int x[MAXN + 2];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int ans = INT_MAX;     for (int i = 0; i < n / 2; i++) ans = min(ans, x[i + n / 2] - x[i]);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, q;     scanf( %d%d , &n, &k);     n = 1 << n;     printf( %d  , (n >> (k < n)) - 1), q = i = 0;     while (++i < n)       if (i < (i ^ k)) printf( %d  , i ^ q), q = i;   }


#include <bits/stdc++.h>   using namespace std;   queue<pair<int, int> > L, R;   int **M;   int ori, n, m;   bool play(pair<int, int> &p, int &ori) {     for (int i = 0; i < 2; i++) {       if (ori == 0) {         if (M[p.first + 1][p.second] > 0)           ori++;         else {           p = {p.first + 1, p.second};           return 1;         }       }       if (ori == 1) {         if (M[p.first][p.second + 1] > 0)           ori++;         else {           p = {p.first, p.second + 1};           return 1;         }       }       if (ori == 2) {         if (M[p.first - 1][p.second] > 0)           ori++;         else {           p = {p.first - 1, p.second};           return 1;         }       }       if (ori == 3) {         if (M[p.first][p.second - 1] > 0)           ori = 0;         else {           p = {p.first, p.second - 1};           return 1;         }       }     }     return 0;   }   void f(pair<int, int> l, pair<int, int> r, int oril, int orir) {     L.push(l);     if (l != r)       R.push(r);     else       return;     M[l.first][l.second] = 1;     M[r.first][r.second] = 2;     if (play(l, oril) == 0) return;     if (play(r, orir) == 0) return;     f(l, r, oril, orir);   }   int main() {     scanf( %d%d , &n, &m);     M = new int *[n + 2];     for (int i = 0; i < n + 2; i++) {       M[i] = new int[m + 2];       for (int j = 0; j < m + 2; j++) M[i][j] = 0;     }     for (int i = 0; i < n + 2; i++) M[i][0] = M[i][m + 1] = 1;     for (int i = 0; i < m + 2; i++) M[0][i] = M[n + 1][i] = 1;     f({1, 1}, {n, m}, 0, 2);     while (!L.empty()) {       printf( %d %d n , L.front().first, L.front().second);       L.pop();       if (!R.empty()) {         printf( %d %d n , R.front().first, R.front().second);         R.pop();       }     }   }


#include <bits/stdc++.h>   using namespace std;   string multiply(string num1, string num2) {     int len1 = num1.size();     int len2 = num2.size();     if (len1 == 0 || len2 == 0) return  0 ;     vector<int> result(len1 + len2, 0);     int i_n1 = 0;     int i_n2 = 0;     for (int i = len1 - 1; i >= 0; i--) {       int carry = 0;       int n1 = num1[i] -  0 ;       i_n2 = 0;       for (int j = len2 - 1; j >= 0; j--) {         int n2 = num2[j] -  0 ;         int sum = n1 * n2 + result[i_n1 + i_n2] + carry;         carry = sum / 10;         result[i_n1 + i_n2] = sum % 10;         i_n2++;       }       if (carry > 0) result[i_n1 + i_n2] += carry;       i_n1++;     }     int i = result.size() - 1;     while (i >= 0 && result[i] == 0) i--;     if (i == -1) return  0 ;     string s =   ;     while (i >= 0) s += std::to_string(result[i--]);     return s;   }   string divide(string number, int divisor) {     string ans;     int idx = 0;     int temp = number[idx] -  0 ;     while (temp < divisor) temp = temp * 10 + (number[++idx] -  0 );     while (number.size() > idx) {       ans += (temp / divisor) +  0 ;       temp = (temp % divisor) * 10 + number[++idx] -  0 ;     }     if (ans.length() == 0) return  0 ;     return ans;   }   int main() {     int spf[100000];     for (int i = 0; i < 100000; ++i) {       spf[i] = i;     }     for (int i = 4; i < 100000; i += 2) {       spf[i] = 2;     }     for (int i = 3; i * i < 100000; ++i) {       if (spf[i] == i) {         for (int j = i * i; j < 100000; j += i) {           if (spf[j] == j) {             spf[j] = i;           }         }       }     }     vector<int> primes;     for (int i = 2; i < 100000; ++i) {       if (spf[i] == i) {         primes.push_back(i);       }     }     int n;     cin >> n;     if (n == 2) {       cout <<  -1  << endl;       return 0;     }     string ans =  1 ;     for (int i = 0; i < n; ++i) {       ans = multiply(ans, to_string(primes[i]));     }     for (int i = 0; i < n; ++i) {       cout << divide(ans, primes[i]) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   int main() {     int n, q;     cin >> n >> q;     string s;     cin >> s;     string w = s;     while (q--) {       s = w;       int val[202] = {0}, del[202] = {0};       for (int i = 0; i < (int)s.size(); i++) {         if (s[i] >=  0  and s[i] <=  9 ) val[i + 1] = s[i] -  0 ;       }       s =  #  + s;       char prev =  ) ;       int pidx, freq[111] = {0};       int l, r;       cin >> l >> r;       int cp = l, dp = 1;       while (cp >= l and cp <= r) {         if (del[cp]) {           cp += dp;         } else {           if (s[cp] >=  0  and s[cp] <=  9 ) {             freq[val[cp]]++;             val[cp]--;             if (val[cp] == -1) del[cp] = 1;           } else {             if (prev ==  >  or prev ==  < ) {               del[pidx] = 1;             }             if (s[cp] ==  > )               dp = 1;             else               dp = -1;           }           prev = s[cp];           pidx = cp;           cp += dp;         }       }       for (int i = 0; i < (int)10; i++) {         if (i) printf(   );         printf( %d , freq[i]);       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   string second;   int n, k;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> second >> k;     if (second.size() < k) return cout <<  impossible n , 0;     set<char> st;     for (auto i : second) st.insert(i);     if (st.size() > k)       cout <<  0 ;     else       cout << k - st.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[60];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n);     bool aliceWins = (arr[0] < arr[n >> 1]);     cout << (aliceWins ?  Alice n  :  Bob n );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e8;   int l, r, cnt, ans1, pre1[20000005];   bitset<maxn> pre;   int max1, max2;   int main() {     cin >> l >> r;     pre[1] = pre[0] = 1;     ans1 = 1;     for (int yui = 2; yui <= r; yui++) {       if (pre[yui] == 0) {         cnt++;         pre1[cnt] = yui;         if (yui % 4 == 1) ans1++;       }       if (yui == l - 1) max1 = ans1;       if (yui == r) max2 = ans1;       for (int j = 1; j <= cnt && pre1[j] * yui <= r; j++) {         pre[yui * pre1[j]] = 1;         if (yui % pre1[j] == 0) break;       }     }     cout << max2 - max1;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 32, MAXS = 1 << 17;   const int MOD = 1e9 + 7, H = 3137;   int add(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     return a;   }   int sub(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   int mul(int a, int b) { return (int)(((long long)a * b) % MOD); }   int n, T;   string s[MAXN];   int len[MAXN];   int poz_s[MAXN];   vector<pair<int, pair<int, int> > > V[MAXS];   int __h[MAXS], pot[MAXS];   int *h = __h + 5;   int geth(int l, int ln) { return sub(h[l + ln - 1], mul(h[l - 1], pot[ln])); }   int ok(int a, int poza, int b) {     int kol = min(len[b], len[a] - poza);     return geth(poz_s[a] + poza, kol) == geth(poz_s[b], kol);   }   int slj_poz(int a, int poza, int b) {     if (!ok(a, poza, b)) return -1;     if (poza + len[b] == len[a]) return T;     if (poza + len[b] < len[a]) return poz_s[a] + poza + len[b];     return poz_s[b] + len[a] - poza;   }   char ss[MAXS];   void load() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf(  %s , ss);       s[i] = ss;       len[i] = (int)s[i].size();       poz_s[i] = !i ? 0 : (poz_s[i - 1] + len[i - 1]);       for (int j = 0; j < len[i]; j++)         h[j + poz_s[i]] = add(mul(h[j + poz_s[i] - 1], H), s[i][j]);     }     T = poz_s[n - 1] + len[n - 1];   }   void gen() {     for (int i = 0; i < n; i++) V[T].push_back({poz_s[i], pair<int, int>(i, i)});     for (int a = 0; a < n; a++) {       for (int b = 0; b < n; b++) {         for (int poza = 0; poza < len[a]; poza++) {           if (!poza && s[a] == s[b]) continue;           int tmp = slj_poz(a, poza, b);           if (tmp != -1)             V[poz_s[a] + poza].push_back(                 {tmp, pair<int, int>(min(a, b), max(a, b))});         }       }     }   }   int bio[MAXS];   int dfs(int node, int l, int r) {     if (bio[node]) return bio[node] == 1;     bio[node] = 1;     for (auto it : V[node])       if (it.second.first >= l && it.second.second <= r && dfs(it.first, l, r))         return 1;     bio[node] = 2;     return 0;   }   int nema_cik(int l, int r) {     memset(bio, 0, sizeof bio);     for (int i = 0; i < T + 1; i++)       if (!bio[i] && dfs(i, l, r)) return 0;     return 1;   }   void solve() {     int rje = 0;     gen();     for (int i = 0, j = 0; i < n; i++) {       j = max(j, i);       for (; j < n && nema_cik(i, j); j++)         ;       rje += j - i;     }     printf( %d n , rje);   }   int main() {     pot[0] = 1;     for (int i = (1); i < (MAXS); i++) pot[i] = mul(pot[i - 1], H);     load();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   int n, k;   int a[MAXN], b[MAXN];   bool f[MAXN][MAXN];   int main() {     scanf( %d%d , &n, &k);     long long sum_a = 0, sum_b = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       sum_a += a[i];       sum_b += b[i];     }     f[0][0] = true;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < k; j++) {         f[i][j] = f[i - 1][j];         for (int x = 0; x <= k; x++) {           if (x <= a[i] && (k - x) <= b[i]) {             f[i][j] = f[i][j] || f[i - 1][(j + k - x) % k];           }         }       }     }     long long ans = sum_a / k + sum_b / k;     for (int x = 1; x < k; x++) {       if (f[n][x]) {         ans = max(ans, (sum_a - x) / k + (sum_b - (k - x)) / k + 1);       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   using ll = long long;   using li = pair<ll, int>;   const int MAXK = 5000;   struct jump {     int node, prime, count;   };   int n;   vector<int> k;   int fact_node[MAXK + 1];   vector<map<int, ii>> children;   vector<int> primes;   bool not_prime[MAXK + 1];   int node_count = 0;   vector<vector<ii>> adjl;   vector<int> deg;   vector<ll> cost;   vector<int> cnt;   vector<bool> active;   int active_nodes;   void fill_primes() {     for (int i = 2; i < MAXK; ++i) {       if (not_prime[i]) continue;       primes.push_back(i);       for (int j = i * i; j < MAXK; j += i) {         not_prime[j] = true;       }     }   }   int add_node() {     children.emplace_back();     return node_count++;   }   void get_factors(int x, vector<ii> &factors) {     int pi = 0;     while (x > 1) {       if (pi == factors.size()) factors.emplace_back(primes[pi], 0);       while (x % primes[pi] == 0) {         factors[pi].second++;         x /= primes[pi];       }       ++pi;     }   }   void build_tree() {     fill_primes();     queue<jump> q;     fact_node[0] = fact_node[1] = add_node();     q.push({0, 0, 0});     vector<ii> factors;     for (int i = 2; i <= MAXK; ++i) {       get_factors(i, factors);       while (q.front().node) q.pop();       int fi = factors.size() - 1;       while (q.front().prime) {         if (q.front().prime != factors[fi].first) break;         if (q.front().count != factors[fi].second) break;         q.push(q.front());         q.pop();         --fi;       }       int node = q.front().node;       if (q.front().prime == factors[fi].first) {         int last_node = q.front().node;         int prime = factors[fi].first;         int to_add = factors[fi].second - q.front().count;         int child = children[last_node][prime].second;         int new_child = add_node();         children[child][prime] = ii(to_add, new_child);         q.push({node, prime, factors[fi].second});         node = new_child;         --fi;       }       q.pop();       while (fi >= 0) {         int prime = factors[fi].first;         int count = factors[fi].second;         int new_child = add_node();         children[node][prime] = ii(count, new_child);         q.push({node, prime, count});         node = new_child;         --fi;       }       q.push({node, 0, 0});       fact_node[i] = node;     }   }   void visit(int node) {     for (auto it : children[node]) {       int weight = it.second.first;       int child = it.second.second;       adjl[node].emplace_back(child, weight);       adjl[child].emplace_back(node, weight);       ++deg[node];       ++deg[child];       visit(child);     }   }   void build_graph() {     adjl.resize(node_count);     deg.resize(node_count, 0);     active.resize(node_count, true);     cost.resize(node_count, 0LL);     cnt.resize(node_count, 0);     active_nodes = node_count;     for (auto it : k) {       ++cnt[fact_node[it]];     }     visit(0);   }   ii get_active_neigh(int node) {     for (auto it : adjl[node]) {       if (active[it.first]) {         return it;       }     }   }   ll solve() {     priority_queue<ii> pq;     for (int i = 0; i < node_count; ++i) {       if (deg[i] == 1) {         pq.push({-cnt[i], i});       }     }     while (!pq.empty()) {       ii cur = pq.top();       pq.pop();       int node = cur.second;       if (!deg[node]) return cost[node];       active[node] = false;       --active_nodes;       ii edge = get_active_neigh(node);       int neigh = edge.first;       ll new_cost = -(ll)cur.first * edge.second;       cnt[neigh] += cnt[node];       cost[neigh] += cost[node] + new_cost;       if (--deg[neigh] == 1) {         edge = get_active_neigh(neigh);         pq.push({-cnt[neigh], neigh});       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     k.resize(n);     for (int i = 0; i < n; ++i) cin >> k[i];     build_tree();     build_graph();     cout << solve() <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int bufSize = 1e6;   inline char nc() {     return getchar();     static char buf[bufSize], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <typename T>   inline T read(T& r) {     static char c;     static int flag;     flag = 1, r = 0;     for (c = nc(); !isdigit(c); c = nc())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = nc()) r = r * 10 + c - 48;     return r *= flag;   }   const int maxn = 3e5 + 100;   const int inf = 1 << 30;   int n, m, up, cnt;   struct node {     int pos, id;   } A[maxn << 1];   inline bool cmp(const node& a, const node& b) {     return a.pos != b.pos ? a.pos < b.pos : a.id < b.id;   }   int f[1 << 9], popc[1 << 9];   int vis[15];   int main() {     read(n), read(m), read(up);     for (int i = 1, l, r; i <= n; ++i)       read(l), read(r), A[++cnt].pos = l, A[cnt].id = i, A[++cnt].pos = r + 1,                         A[cnt].id = -i;     std::sort(A + 1, A + 1 + cnt, cmp);     for (int i = 1; i < (1 << up); ++i)       f[i] = -inf, popc[i] = popc[i >> 1] ^ (i & 1);     for (int i = 1; i < cnt; ++i) {       int len = A[i + 1].pos - A[i].pos, k;       if (A[i].id > 0) {         for (int j = 0; j < 8; ++j)           if (!vis[j]) {             vis[j] = A[i].id, k = j;             break;           }         for (int j = (1 << up) - 1; j >= 0; --j)           if (j & (1 << k))             f[j] = f[j ^ (1 << k)] + len * popc[j];           else             f[j] = f[j] + len * popc[j];       } else {         for (int j = 0; j < 8; ++j)           if (vis[j] == -A[i].id) {             vis[j] = 0, k = j;             break;           }         for (int j = 0; j < (1 << up); ++j)           if (j & (1 << k))             f[j] = -inf;           else             f[j] = std::max(f[j], f[j ^ (1 << k)]) + len * popc[j];       }     }     int res = 0;     for (int i = 0; i < (1 << up); ++i) res = std::max(res, f[i]);     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     while (cin >> n >> m) {       long long num, sum = 0, minx = 1000000001;       for (long long i = 0; i < n; i++) {         cin >> num;         sum += num;         if (num < minx) minx = num;       }       if (sum < m)         cout << -1 << endl;       else if (minx < (sum - m) / n) {         cout << minx << endl;       } else         cout << (sum - m) / n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   const int P = 1048576 + 10;   const int Y = 30;   int vis[N];   int cnt;   int book[N];   int a[N];   int n;   int m;   int k;   int addis[Y][Y];   int dis[N];   int dp[P];   queue<int> q;   inline void bfs(int s) {     for (int i = 1; i <= n + 1; i++) dis[i] = 0x3f3f3f3f;     dis[s] = 0;     int nw;     int i = 1;     for (q.push(s); !q.empty();)       for (nw = q.front(), q.pop(), i = 1; i <= m; i++) {         int v1 = nw + a[i];         if (v1 <= n + 1 && dis[v1] == 0x3f3f3f3f)           dis[v1] = dis[nw] + 1, q.push(v1);         int v2 = nw - a[i];         if (v2 >= 1 && dis[v2] == 0x3f3f3f3f) dis[v2] = dis[nw] + 1, q.push(v2);       }     for (int i = 1; i <= n + 1; i++)       if (vis[i] != -1) addis[vis[s]][vis[i]] = dis[i];   }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1, t; i <= k; i++) {       scanf( %d , &t);       book[t] = 1;     }     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = n + 1; i >= 1; i--) book[i] ^= book[i - 1];     cnt = -1;     for (int i = 1; i <= n + 1; i++) vis[i] = -1;     for (int i = 1; i <= n + 1; i++)       if (book[i]) vis[i] = ++cnt;     for (int i = 1; i <= n + 1; i++)       if (book[i]) bfs(i);     for (int i = 1; i < (1 << (cnt + 1)); i++) dp[i] = 0x3f3f3f3f;     for (int i = 0; i < (1 << (cnt + 1)); i++) {       if (dp[i] == 0x3f3f3f3f) continue;       for (int j = 0; j <= cnt; j++) {         if ((i >> j) & 1) continue;         for (int k = j + 1; k <= cnt; k++)           if (((i >> k) & 1) == 0)             dp[i + (1 << j) + (1 << k)] =                 min(dp[i + (1 << j) + (1 << k)], dp[i] + addis[j][k]);       }     }     int ans = dp[(1 << (cnt + 1)) - 1];     printf( %d , (ans == 0x3f3f3f3f) ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>      using namespace std;      int t, n, m;      int main() {       ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);          cin >> t;       while(t--) {           cin >> n;           vector<int> pancake(n, 0);           for(int i = 0; i < n; i++) {               cin >> m;               if(!m)                   continue;               if(i - (m - 1) >= 0)                   pancake[i - (m - 1)] = max(pancake[i - (m - 1)], m);               else                   pancake[0] = max(pancake[0], i + 1);           }           int prev = 0;           for(int i = 0; i < n; i++) {               if(prev)                   prev--;               prev = max(prev, pancake[i]);               cout << (prev ? 1 : 0) <<    ;           }           cout <<   n ;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10010;   const double eps = 1e-12;   struct point {     int x, y, op, id;     int u, v;     long long operator*(const point &r) const {       return (long long)u * r.v - (long long)v * r.u;     }   } a[N << 1], s;   int n;   int ans[N];   inline bool cmp(point x, point y) { return x * y > 0; }   inline void solve(int l, int r) {     if (l > r) return;     for (int k = l; k <= r; k++)       if (a[k].y < a[l].y || (a[k].y == a[l].y && a[k].x < a[l].x))         swap(a[l], a[k]);     for (int k = l; k <= r; k++) {       a[k].u = a[k].x - a[l].x;       a[k].v = a[k].y - a[l].y;     }     sort(a + l + 1, a + r + 1, cmp);     int x = 0, y = 0, mid = 0;     for (int k = l; k <= r; k++) {       if (a[k].op == 0)         x++;       else         y++;       if (x == y && a[k].op != a[l].op &&           max(k - l - 1, r - k) < max(mid - l - 1, r - mid))         mid = k;     }     if (a[l].op == 0)       ans[a[l].id] = a[mid].id;     else       ans[a[mid].id] = a[l].id;     solve(l + 1, mid - 1), solve(mid + 1, r);     return;   }   int main() {     scanf( %d , &n);     for (int k = 1; k <= n; k++) {       scanf( %d%d , &a[k].x, &a[k].y);       a[k].op = 0;       a[k].id = k;     }     for (int k = 1; k <= n; k++) {       scanf( %d%d , &a[k + n].x, &a[k + n].y);       a[k + n].op = 1;       a[k + n].id = k;     }     solve(1, 2 * n);     for (int k = 1; k <= n; k++) printf( %d n , ans[k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     int a[n], b[n];     int r1 = 0, r2 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       r1 |= a[i];     }     for (int i = 0; i < n; i++) {       cin >> a[i];       r2 |= a[i];     }     cout << r1 + r2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   const int maxn = 5000 + 5;   long long cnt[maxn + 10];   long long p[maxn + 10][maxn + 10];   long long pd[maxn + 10];   int main() {     memset(cnt, 0, sizeof(cnt));     int n;     scanf( %d , &n);     for (int i = (1); i <= (n); i++) {       int u;       scanf( %d , &u);       cnt[u]++;     }     for (int i = (2); i <= (maxn); i++) {       for (int j = (1); j <= (i); j++) p[i][j] += p[i - 1][j];       int mm = sqrt(i), tem = i;       for (int j = (2); j <= (mm); j++) {         while (tem % j == 0) {           p[i][j]++;           tem /= j;         }       }       if (tem > 1) p[i][tem]++;     }     long long ans = 0, cur = 0;     for (int i = (1); i <= (maxn); i++) {       if (!cnt[i]) {         pd[i] = 1;         continue;       }       for (int j = (1); j <= (i); j++) {         ans += p[i][j] * cnt[i];         cur += p[i][j] * cnt[i];         if (p[i][j]) pd[i] = j;       }     }     while (*max_element(pd, pd + maxn + 10) > 1) {       long long f[maxn + 10];       memset(f, 0, sizeof(f));       for (int i = (1); i <= (maxn); i++) f[pd[i]] += cnt[i];       long long besp = max_element(f, f + maxn + 10) - f;       long long besg = f[besp];       if (besg * 2 <= n || besp == 1) break;       cur += n - 2 * besg;       ans = min(ans, cur);       for (int i = (1); i <= (maxn); i++) {         if (pd[i] != besp) pd[i] = 1;         if (pd[i] == 1) continue;         p[i][besp] -= 1;         while (pd[i] > 1 && p[i][pd[i]] == 0) pd[i]--;       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 20], *p1, *p2;   template <typename T>   inline void read(T &t) {     register int v =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)              ? EOF              : *p1++);     T f = 1;     t = 0;     while (!isdigit(v)) {       if (v ==  - ) f = -1;       v = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (isdigit(v)) {       t = t * 10 + v - 48;       v = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                ? EOF                : *p1++);     }     t *= f;   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   const int N = 100001;   const int M = 200010;   template <typename T>   inline T min(T x, T y) {     return x < y ? x : y;   }   template <typename T>   inline T max(T x, T y) {     return x > y ? x : y;   }   int to[M], hd[N], nxt[M], tot;   inline void add(int u, int v) {     to[++tot] = v;     nxt[tot] = hd[u];     hd[u] = tot;   }   inline void addedge(int u, int v) { add(u, v), add(v, u); }   long long son[N], siz[N], cnt[N], col[N], sum, Son, maxx, n, ans[N];   void dfs1(int u, int f) {     siz[u] = 1;     son[u] = 0;     for (int i = hd[u]; i; i = nxt[i]) {       int v = to[i];       if (v != f) {         dfs1(v, u);         siz[u] += siz[v];         if (siz[v] > siz[son[u]]) {           son[u] = v;         }       }     }   }   void add(int u, int f, int val) {     cnt[col[u]] += val;     if (cnt[col[u]] > maxx)       maxx = cnt[col[u]], sum = col[u];     else if (cnt[col[u]] == maxx)       sum += col[u];     for (int i = hd[u]; i; i = nxt[i]) {       int v = to[i];       if (v != f && v != Son) {         add(v, u, val);       }     }   }   void dfs2(int u, int f, int opt) {     for (int i = hd[u]; i; i = nxt[i]) {       int v = to[i];       if (v != f && v != son[u]) {         dfs2(v, u, 0);       }     }     if (son[u]) dfs2(son[u], u, 1), Son = son[u];     add(u, f, 1), Son = 0;     ans[u] = sum;     if (opt == 0) add(u, f, -1), sum = maxx = 0;   }   signed main() {     read(n);     for (int i = 1; i <= n; ++i) read(col[i]);     for (int i = 1; i < n; ++i) {       int x, y;       read(x, y);       addedge(x, y);     }     dfs1(1, 0);     dfs2(1, 0, 0);     for (int i = 1; i <= n; ++i) printf( %lld  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double Pi = 3.141592653;   const long long mod = 1e6 + 3;   class Graph {     map<int, vector<int>> ma;       public:     void addedge(int n, int m) {       ma[n].push_back(m);       ma[m].push_back(n);     }   };   int main() {     long long n;     cin >> n;     long long a, b, c;     cin >> a >> b >> c;     long long plastic;     if (a <= b - c and n >= a) {       plastic = n / a;       cout << plastic;       return 0;     }     long long glass = (n - c) / (b - c);     if (glass < 0) glass = 0;     long long t = n - glass * (b - c);     glass += (t / a);     cout << glass;     return 0;   }


#include <bits/stdc++.h>   char *fs, *ft, buf[1 << 20];   inline int read() {     int x = 0, f = 1;     char ch =         (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))             ? 0             : *fs++;     ;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = (fs == ft &&             (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))                ? 0                : *fs++;       ;     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = (fs == ft &&             (ft = (fs = buf) + fread(buf, 1, 1 << 20, stdin), fs == ft))                ? 0                : *fs++;       ;     }     return x * f;   }   using namespace std;   int a[1009];   int main() {     int t;     cin >> t;     while (t--) {       int n;       int z0 = 0, z1 = 0, bo = 0;       cin >> n;       cin >> a[1];       for (int i = 2; i <= n; i++) {         cin >> a[i];         if (a[i] < a[i - 1]) bo = 1;       }       for (int i = 1; i <= n; i++) {         int k;         cin >> k;         if (k == 0)           z0++;         else           z1++;       }       if (bo == 0) {         cout <<  Yes  << endl;         continue;       } else {         if (z0 == 0 || z1 == 0)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int RNG = 1000003;   const int RNGT = RNG * 4;   const int MOD1 = 1e9 + 7;   const int MOD2 = 1e9 + 87;   const double pi = 2 * acos(0.0);   inline int _Int() {     int x;     scanf( %d , &x);     return x;   }   inline long long _LLi() {     long long x;     scanf( %lld , &x);     return x;   }   void pruts() {     puts( -1 );     exit(EXIT_SUCCESS);   }   int dirX[] = {1, 0, -1, 0, 1, -1, 1, -1};   int dirY[] = {0, 1, 0, -1, 1, -1, -1, 1};   int rX[] = {1, 1, 2, 2, -1, -1, -2, -2};   int rY[] = {2, -2, 1, -1, 2, -2, 1, -1};   template <class T>   T tri_Area(T x1, T y1, T x2, T y2, T x3, T y3) {     return abs(x1 * (y2 - y3) - y1 * (x2 - x3) + (x2 * y3 - x3 * y2));   };   template <class T>   T Distance(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   };   template <class T>   T bigMod(T n, T p, T m) {     if (p == 0) return 1;     if (p & 1) return (n * bigMod(n, p - 1, m)) % m;     T x = bigMod(n, p / 2, m);     return (x * x) % m;   };   int Case;   int sset(int N, int pos) { return N = N | (1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int A[RNG], n, m, flag;   string str[600];   void Hunger() {     n = _Int();     m = _Int();     for (int i = 0; i < n; i++) cin >> str[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (str[i][j] ==  W ) {           int x = i + 1;           if (x < n && x >= 0) {             if (str[x][j] ==  . ) str[x][j] =  D ;             if (str[x][j] ==  S ) {               cout <<  No  << endl;               return;             }           }           x = i - 1;           if (x < n && x >= 0) {             if (str[x][j] ==  . ) str[x][j] =  D ;             if (str[x][j] ==  S ) {               cout <<  No  << endl;               return;             }           }           x = j + 1;           if (x < m && x >= 0) {             if (str[i][x] ==  . ) str[i][x] =  D ;             if (str[i][x] ==  S ) {               cout <<  No  << endl;               return;             }           }           x = j - 1;           if (x < m && x >= 0) {             if (str[i][x] ==  . ) str[i][x] =  D ;             if (str[i][x] ==  S ) {               cout <<  No  << endl;               return;             }           }         }       }     }     cout <<  Yes  << endl;     for (int i = 0; i < n; i++) cout << str[i] << endl;   }   int main() {     Hunger();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int cMin(T& a, T b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   inline int cMax(T& a, T b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   inline string to_str(T v) {     ostringstream os;     os << v;     return os.str();   }   const double pi = acos(-1.0);   const double eps = 1e-9;   template <class T>   inline T isqr(T v) {     return v * v;   }   template <class T>   inline T iabs(T v) {     return v < 0 ? -v : v;   }   template <class T>   inline int isgn(T v) {     return iabs(v) <= eps ? 0 : (v < 0 ? -1 : 1);   }   template <typename T>   inline T next() {     static char buf[64];     scanf( %s , buf);     istringstream is(buf);     T v;     is >> v;     return v;   }   inline int nextInt() {     int v = 0;     scanf( %d , &v);     return v;   }   const int NN = 2 * 100000 + 16;   int N, A[NN], B[NN];   int idx[NN];   int main(int argc, char* argv[]) {     scanf( %d , &N);     for (int i = 0; i < (int)(N); ++i) scanf( %d , A + i);     for (int i = 0; i < (int)(N); ++i) scanf( %d , B + i);     for (int i = 0; i < (int)(N); ++i) idx[B[i]] = i;     int n = N;     for (int i = 1; i < N; ++i) {       if (idx[A[i - 1]] > idx[A[i]]) {         n = i;         break;       }     }     printf( %d n , N - n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxm = 1e6;   int pre[maxm * 2 + 10];   bool a[maxm + 10];   int N;   int main(int argc, const char* argv[]) {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       int val;       scanf( %d , &val);       pre[val] = -1;       a[val] = true;     }     int small = 0;     int big = small;     while (big <= maxm * 2) {       while (big <= maxm * 2 && pre[big] != -1) {         big++;       }       for (int i = small + 1; i <= big; i++) {         pre[i] = small;       }       small = big;     }     int ans = 0;     for (int i = 1; i <= maxm; i++) {       if (!a[i]) continue;       for (int j = i + i; j <= maxm * 2; j += i) {         ans = max(ans, pre[j] % i);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> e[100500];   bool visited[100500];   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m != n - 1) {       cout <<  no  << endl;       return 0;     }     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       e[u].push_back(v);       e[v].push_back(u);     }     visited[0] = true;     list<int> sp;     sp.push_back(0);     while (sp.begin() != sp.end()) {       int u = sp.front();       sp.pop_front();       for (int i = 0; i < e[u].size(); i++) {         int v = e[u][i];         if (!visited[v]) sp.push_back(v);         visited[v] = true;       }     }     for (int i = 0; i < n; i++)       if (!visited[i]) {         cout <<  no  << endl;         return 0;       }     cout <<  yes  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     long long n;     cin >> n;     vector<double> gr, le;     vector<long long> gri, lei;     vector<long long> grind, leind;     for (long long i = 0; i < n; ++i) {       double t;       cin >> t;       if (t >= 0) {         gr.push_back(t);         grind.push_back(i);       } else {         le.push_back(-t);         leind.push_back(i);       }     }     long long gz = 0, lz = 0;     long long gsum = 0, lsum = 0;     for (double t : gr) {       if (floorl(t) != t) gz++;       gsum += floorl(t);       gri.push_back(floorl(t));     }     for (double t : le) {       if (floorl(t) != t) lz++;       lsum += floorl(t);       lei.push_back(floorl(t));     }     vector<long long> ans(n);     if (gsum <= lsum) {       long long add = lsum - gsum;       for (long long i = 0; i < gr.size() && add > 0; ++i) {         if (floorl(gr[i]) != gr[i]) {           add--;           gri[i]++;         }       }     } else {       long long add = gsum - lsum;       for (long long i = 0; i < le.size() && add > 0; ++i) {         if (floorl(le[i]) != le[i]) {           add--;           lei[i]++;         }       }     }     for (long long i = 0; i < gr.size(); ++i) {       ans[grind[i]] = gri[i];     }     for (long long i = 0; i < le.size(); ++i) {       ans[leind[i]] = -lei[i];     }     for (long long t : ans) cout << t <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cerr << *x, 0);   template <class c>   char dud(...);   struct debug {     template <class c>     debug& operator<<(const c&) {       return *this;     }   };   int n;   bool good(int x) {     int res = x;     while (x > 0) {       res += x % 10;       x /= 10;     }     return (res == n);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     vector<int> ans;     for (int m = n; m >= max(1, n - 100000); m--) {       if (good(m)) {         ans.emplace_back(m);       }     }     int len = ans.size();     sort(ans.begin(), ans.end());     cout << len <<   n ;     for (int i = 0; i < len; i++) {       cout << ans[i] << (i == len - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   int n, q, a[N];   int rt[N * 20], ls[N * 20], rs[N * 20], sum[N * 20], cnt = 0;   void change(int pre, int& o, int l, int r, int pos) {     o = ++cnt;     ls[o] = ls[pre];     rs[o] = rs[pre];     sum[o] = sum[pre] + 1;     if (l == r) return;     int m = (l + r) / 2;     if (pos <= m)       change(ls[pre], ls[o], l, m, pos);     else       change(rs[pre], rs[o], m + 1, r, pos);   }   int query(int pre, int o, int l, int r, int k) {     if (l == r) return l;     int m = (l + r) / 2;     if (sum[ls[o]] - sum[ls[pre]] > k) {       int res = query(ls[pre], ls[o], l, m, k);       if (res != -1) return res;     }     if (sum[rs[o]] - sum[rs[pre]] > k) {       int res = query(rs[pre], rs[o], m + 1, r, k);       if (res != -1) return res;     }     return -1;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       change(rt[i - 1], rt[i], 1, n, a[i]);     }     while (q--) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       int ans = query(rt[l - 1], rt[r], 1, n, (r - l + 1) / k);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void PrintVector(vector<int> v2, string s) {     cout << s;     for (int i = 0; i < v2.size(); i++) cout << v2[i] <<    ;     cout << endl;   }   void PrintVector(vector<int> v2) {     for (int i = 0; i < v2.size(); i++) cout << v2[i] <<    ;     cout << endl;   }   int isOdd(int x) { return (x % 2); }   int toInt(string str) {     int num;     istringstream iss(str);     iss >> num;     return num;   }   template <class T>   string toStr(T par) {     ostringstream oss;     oss << par;     return oss.str();   }   void readVector(vector<int> &vec, int len) {     for (int i = 0; i < len; i++) {       cin >> vec[i];     }   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool sortPairsCmp(const pair<int, int> &a, const pair<int, int> &b) {     return a.second > b.second;   }   multiset<int> arr;   int main() {     long long n, x, y;     long long hours = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) {       cin >> y;       arr.insert(y);     }     for (auto t : arr) {       hours += (x * t);       if (x > 1) x--;     }     cout << hours << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dirx[] = {1, -1, 0, 0, 1, 1, -1, -1}, diry[] = {0, 0, 1, -1, 1, -1, 1, -1};   bool Set(int n, int pos) { return bool(n & (1 << pos)); }   int32_t main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     string a, b;     cin >> a >> b;     int dp[n + 1][m + 1], ans = -1;     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = max(0, max(dp[i - 1][j], dp[i][j - 1]) - 1);         if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);         ans = max(ans, dp[i][j]);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  URDL ;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 998244353) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 998244353) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   vector<int> mp[200135];   int d[200135], tar;   vector<int> dp[200135];   pair<int, int> tmp;   void dfs(int x, int pa) {     d[x] = d[pa] + 1;     dp[x].clear();     for (int c : mp[x])       if (c != pa) {         dfs(c, x);         int v = dp[c][0];         if (dp[x].size() <= 1) {           dp[x].push_back(v);           if (dp[x].size() == 2 && d[dp[x][0]] < d[dp[x][1]]) {             swap(dp[x][0], dp[x][1]);           }         } else if (d[v] > d[dp[x][0]]) {           dp[x][1] = dp[x][0];           dp[x][0] = v;         } else if (d[v] > d[dp[x][1]]) {           dp[x][1] = v;         }       }     if (dp[x].empty()) dp[x].push_back(x);     if (dp[x].size() == 2) {       pair<int, int> key = {d[x], d[dp[x][0]] + d[dp[x][1]]};       if (key > tmp) {         tmp = key;         tar = x;       }     }   }   void fmain(int tid) {     scanf( %d , &n);     for (int i = 0, u, v; i < n - 1; i++) {       scanf( %d%d , &u, &v);       mp[u].push_back(v);       mp[v].push_back(u);     };     tmp = {-1, -1};     dfs(1, 0);     vector<int> ans(4);     ans[0] = dp[tar][0];     ans[2] = dp[tar][1];     tmp = {-1, -1};     dfs(tar, 0);     ans[1] = dp[tar][0];     ans[3] = dp[tar][1];     for (int(i) = 0; (i) < (int)(4); (i)++) printf( %d  , ans[i]);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   int a[55];   using namespace std;   int main() {     int n, m, k, i, t = 0, cnt;     scanf( %d%d%d , &n, &m, &k);     if (k >= m) {       printf( 0 n );       return 0;     }     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n, std::greater<int>());     a[0] += k - 1;     t = 0;     cnt = 1;     for (i = 0; i < n; i++) {       if (a[i] > 1 && t + a[i] >= m) {         printf( %d n , cnt);         return 0;       } else {         t += a[i] - 1;         cnt++;       }     }     if (i == n) printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void seif() { std::ios_base::sync_with_stdio(0); }   int xa[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};   int ya[] = {1, 0, -1, 1, 0, -1, 1, 0, -1};   int anx, any, marx, mary;   bool ok = false;   char grid[8][8];   bool valid(int x, int y) {     if (x < 0 || y < 0 || x > 7 || y > 7 || ok) return false;     return true;   }   void check(int cx, int cy, int deg) {     if (cx == 0 && cy == 7) {       cout <<  WIN ;       ok = true;     }     if (ok) return;     for (int i = 0; i < 9; i++) {       int mtx = cx + xa[i];       int mty = cy + ya[i];       if (!valid(mtx, mty)) continue;       if (mtx - deg >= 0 && grid[mtx - deg][mty] ==  S ) continue;       if (mtx - deg - 1 >= 0 && grid[mtx - deg - 1][mty] ==  S ) continue;       check(mtx, mty, deg + 1);     }     return;   }   int main() {     seif();     bool flag = false;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  S ) flag = true;       }     }     if (!flag) return cout <<  WIN , 0;     check(7, 0, 0);     if (!ok) cout <<  LOSE ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> t;     while (t--) {       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int mx, x;       mx = 0;       for (int i = 1; i < n; i++) {         if (arr[i] < arr[i - 1]) {           x = arr[i - 1] - arr[i];           if (x > mx) {             mx = x;           }           arr[i] = arr[i - 1];         }       }       int ans = 0;       while (mx != 0) {         mx = mx / 2;         ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   double eps = 1e-12;   template <class T>   void swp(T& a, T& b) {     T temp = a;     a = b;     b = temp;   }   long long ceil_div(long long a, long long b) {     return a % b == 0 ? a / b : a / b + 1;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long modex(long long x, unsigned int y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int binarySearch(int arr[], int l, int r, int x) {     if (r >= l) {       int mid = l + (r - l) / 2;       if (arr[mid] == x) return mid;       if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);       return binarySearch(arr, mid + 1, r, x);     }     return -1;   }   const long long MOD = 998244353;   const long long mod = 1e9 + 7;   void solve() {}   int main() {     long long n, m;     cin >> n >> m;     vector<long long> v(n + 2);     v[n] = 1ll;     for (long long i = n - 1; i > 0ll; --i) {       v[i] = v[i + 1];       for (long long j = 2ll; j < n + 1ll; j++) {         if (j * i > n) break;         v[i] = (v[i] + (v[j * i] - v[min(n, j * (i + 1ll) - 1ll) + 1ll])) % m;       }       v[i] = (v[i] + v[i + 1ll]) % m;     }     if (v[1] >= v[2]) {       cout << v[1] - v[2];     } else {       cout << (m + v[1] - v[2]) % m;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void ins(long long int a[], long long int n, long long int i = 0) {     for (long long int i = 0; i < n; i++) a[i] = i;   }   template <typename t>   void ins(t a[], long long int n, t b = 0) {     for (long long int i = 0; i < n; i++) a[i] = b;   }   void print(long long int a[], long long int n) {     for (long long int i = 0; i < n; i++) cout << a[i] <<    ;     ;     cout << endl;   }   template <typename t>   void print(t a[], long long int n) {     for (long long int i = 0; i < n; i++) cout << a[i] <<    ;     ;     cout << endl;   }   void po(long long int a[], long long int n) {     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }   }   template <typename t>   void po(t a[], long long int n) {     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }   }   long long int visited[100009];   vector<long long int> a[100009];   long long int n;   long long int b[100009];   long long int c[100001];   void start() {     cin >> n;     for (long long int i = 0; i < n - 1; i++) {       cin >> b[i + 1];       a[i + 2].push_back(b[i + 1]);       a[b[i + 1]].push_back(i + 2);     }     for (long long int i = 0; i < n + 3; i++) {       visited[i] = 0;       c[i] = 0;     }   }   void dfs(long long int s, long long int t) {     visited[s] = 1;     if (s != 1)       c[t + 1] += a[s].size() - 1;     else       c[t + 1] += a[s].size();     for (long long int i = 0; i < a[s].size(); i++) {       if (!visited[a[s][i]]) dfs(a[s][i], t + 1);     }   }   int main() {     start();     long long int count = 0;     dfs(1, 0);     for (long long int i = 0; i < n + 3; i++) {       if (c[i] % 2 == 1) {         count++;       }     }     cout << count + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, mi, mx;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long a[n];     for (int i = 0; i < n && cin >> a[i]; i++)       ;     cout << abs(a[0] - a[1]) <<     << abs(a[0] - a[n - 1]) << endl;     for (int i = 1; i < n - 1; i++) {       cout << min(abs((a[i]) - (a[i - 1])), abs((a[i]) - (a[i + 1]))) <<                << max(abs((a[i]) - (a[n - 1])), abs((a[i]) - (a[0]))) << endl;     }     cout << abs((a[n - 1]) - (a[n - 2])) <<     << abs(a[n - 1] - a[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, t, ts, ans;   int pos[10000005], len[10000005], tot;   inline string reverse(string s) {     string t;     t.resize(s.size());     int n = s.size();     for (int i = 0; i < n; i++) t[n - i - 1] = s[i];     return t;   }   void Duval(const string& s) {     int n = s.size();     for (int i = 0; i < n;) {       int j = i, k = i + 1;       while (s[j] <= s[k]) {         if (s[j] == s[k])           ++j;         else           j = i;         ++k;       }       len[++tot] = k - j;       while (i <= j) {         pos[tot] = i + k - j - 1;         i += k - j;       }     }   }   int p[10000005];   void Exkmp(const string& s) {     int n = s.size();     int mid = 0, mx = 0;     p[0] = n;     for (int i = 1; i < n; i++) {       if (i <= mx) p[i] = min(p[i - mid], mx - i + 1);       while (s[i + p[i]] == s[p[i]]) ++p[i];       if (i + p[i] - 1 > mx) mid = i, mx = i + p[i] - 1;     }   }   int main() {     ios::sync_with_stdio(false);     cin >> s;     t = reverse(s);     int k;     cin >> k;     if (k == 1) return cout << min(s, t), 0;     Duval(t);     pos[0] = -1;     while (k > 2 && tot) {       if (len[tot] == 1) {         while (tot && len[tot] == 1)           ans += t.substr(pos[tot - 1] + 1, pos[tot] - pos[tot - 1]), --tot;         --k;       } else         ans += t.substr(pos[tot - 1] + 1, pos[tot] - pos[tot - 1]), --k, --tot;     }     if (tot == 0) return cout << ans, 0;     if (tot == 1) {       string tmp = t.substr(0, pos[1] + 1);       tmp = min(tmp, reverse(tmp));       cout << ans + tmp;       return 0;     }     s = reverse(t = t.substr(0, pos[tot] + 1));     ts = t +  #  + s;     Exkmp(ts);     string tmp = min(s, t);     int cut = 0, n = s.size();     for (int i = 1; i < n; i++) {       int cl = min(i - cut, p[n + 1 + cut]);       if (cut + cl == i) cl += p[cl];       cl = min(cl, n - cut);       if ((cl < i - cut ? s[cut + cl] : t[cut + cl - i]) < t[cl]) cut = i;     }     tmp = min(tmp, s.substr(0, cut) + t.substr(0, n - cut));     string las = t.substr(pos[tot - 1] + 1, len[tot]);     string lass = t.substr(pos[tot - 2] + 1, len[tot]);     int st = pos[tot - 1] + 1;     string tt = t.substr(st, n - st);     string res = t.substr(0, n - tt.size());     tt += min(res, reverse(res));     tmp = min(tmp, tt);     if (las == lass) {       st = pos[tot - 2] + 1;       tt = t.substr(st, n - st);       res = t.substr(0, n - tt.size());       tt = tt + min(res, reverse(res));       tmp = min(tmp, tt);     }     cout << ans + tmp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   int upmin(T1 &x, T2 v) {     if (x > v) {       x = v;       return 1;     }     return 0;   }   template <class T1, class T2>   int upmax(T1 &x, T2 v) {     if (x < v) {       x = v;       return 1;     }     return 0;   }   const int INF = 0x3f3f3f3f;   vector<string> dict;   void init() {     for (string s; getline(cin, s);) {       dict.emplace_back(s);     }   }   int maxlen;   void preprocess() {     for (int i = 0; i < dict.size(); ++i) {       upmax(maxlen, dict[i].size());     }     for (int i = 0; i < maxlen + 2; ++i) {       cout <<  * ;       if (i + 1 == maxlen + 2) {         cout << endl;       }     }     for (int i = 0, t = 0; i < dict.size(); ++i) {       cout <<  * ;       int splen = maxlen - dict[i].size();       int ls, rs;       if (~splen & 1) {         ls = rs = splen / 2;       } else {         if (t == 0) {           ls = (splen - 1) / 2;           rs = splen - ls;         } else {           rs = (splen - 1) / 2;           ls = splen - rs;         }         t ^= 1;       }       for (int j = 0; j < ls; ++j) {         cout <<    ;       }       cout << dict[i];       for (int j = 0; j < rs; ++j) {         cout <<    ;       }       cout <<  *  << endl;     }     for (int i = 0; i < maxlen + 2; ++i) {       cout <<  * ;       if (i + 1 == maxlen + 2) {         cout << endl;       }     }   }   void solve() {}   signed main() {     ios::sync_with_stdio(0);     init();     preprocess();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long c, hr, hb, wr, wb;     cin >> c >> hr >> hb >> wr >> wb;     long long res = 0;     for (long long w = 0; w < 2; ++w) {       for (long long i = 0; i * wr <= c && i <= 10000000; ++i) {         res = max(res, i * hr + hb * ((c - i * wr) / wb));       }       swap(hb, hr);       swap(wb, wr);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     string s;     cin >> s;     int l = 0, r = s.length() - 1;     int cnt = 0;     set<int> s1;     while (l < r) {       if (s[l] ==  ( ) {         while (l < r && s[r] ==  ( ) {           r--;         }         if (s[r] ==  ) ) {           cnt = 1;           s1.insert(l + 1);           s1.insert(r + 1);         }       } else if (s[r] ==  ) ) {         while (l < r && s[l] ==  ) ) {           l++;         }         if (s[l] ==  ( ) {           cnt = 1;           s1.insert(l + 1);           s1.insert(r + 1);         }       }       l++;       r--;     }     cout << cnt <<   n ;     if (cnt) {       cout << s1.size() <<   n ;       for (auto it = s1.begin(); it != s1.end(); it++) {         cout << *it <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[500007];   int l[500007];   int r[500007];   long long ans = 0;   pair<int, int> p[500007];   void input() {     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       p[i].first = a[i];       p[i].second = i;     }     sort(p, p + n);   }   void solve() {     if (n < 3) {       printf( 0 n );       return;     }     int i;     for (i = 0; i < n; i++) {       l[i] = i - 1;       r[i] = i + 1;     }     int ind;     int x, y;     int lo = 0;     int hi = n - 1;     for (i = 0; i < n - 2; i++) {       ind = p[i].second;       if (ind == lo) {         ans += p[i].first;         lo = r[ind];         continue;       }       if (ind == hi) {         ans += p[i].first;         hi = l[ind];         continue;       }       x = l[ind];       y = r[ind];       ans += min(a[x], a[y]);       r[x] = y;       l[y] = x;     }     printf( %I64d n , ans);   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   void add(int &x, int y) { x = (x + y) % mod; }   int mul(int x, int y) { return (long long)x * y % mod; }   int pw(int x, int p) {     int r = 1;     while (p) {       if (p & 1) r = mul(r, x);       x = mul(x, x);       p >>= 1;     }     return r;   }   int fac[3602];   int rev[3602];   int nCr(int n, int r) {     if (n < r || r < 0) return 0;     return mul(fac[n], mul(rev[r], rev[n - r]));   }   int h, w, n;   int chR[3602], chC[3602];   int dpR[3602], dpC[3602];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.precision(30);     cout << fixed;     fac[0] = 1;     for (int i = 1; i <= 3601; ++i) fac[i] = mul(fac[i - 1], i);     rev[3601] = pw(fac[3601], mod - 2);     for (int i = 3601; i--;) rev[i] = mul(rev[i + 1], i + 1);     cin >> h >> w >> n;     for (int i = 0; i < n + n; ++i) {       int r, c;       cin >> r >> c;       chR[r] = 1;       chC[c] = 1;     }     chR[h + 1] = chC[w + 1] = 1;     vector<int> R, C;     int Rcnt = 0, Ccnt = 0;     for (int i = 1, p = 0; i <= h + 1; ++i) {       if (chR[i]) {         if (p) R.push_back(p);         p = 0;       } else {         ++p;         ++Rcnt;       }     }     for (int i = 1, p = 0; i <= w + 1; ++i) {       if (chC[i]) {         if (p) C.push_back(p);         p = 0;       } else {         ++p;         ++Ccnt;       }     }     dpR[0] = 1;     for (int x : R) {       for (int i = 3602; i--;) {         if (dpR[i] == 0) continue;         for (int j = 1; j + j <= x; ++j) {           ;           add(dpR[i + j], mul(dpR[i], nCr(x - j, j)));         }       }     }     dpC[0] = 1;     for (int x : C) {       for (int i = 3602; i--;) {         if (dpC[i] == 0) continue;         for (int j = 1; j + j <= x; ++j) {           add(dpC[i + j], mul(dpC[i], nCr(x - j, j)));         }       }     }     for (int i = 0; i <= 3600; ++i) {       if (dpR[i] != 0)         ;     }     for (int i = 0; i <= 3600; ++i) {       if (dpC[i] != 0)         ;     }     int ans = 0;     for (int i = 0; i <= 3600; ++i) {       for (int j = 0; j <= 3600; ++j) {         if (i + i + j > Rcnt) continue;         if (i + j + j > Ccnt) continue;         int val = mul(dpR[i], dpC[j]);         val = mul(val, nCr(Rcnt - i - i, j));         val = mul(val, nCr(Ccnt - j - j, i));         add(ans, mul(val, mul(fac[i], fac[j])));       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   char s[200001];   char pick(char a, char b) {     char c;     for (c =  a ; c == a || c == b; c++)       ;     return c;   }   char *handle(char *s) {     char *ps = s;     for (s += 1; *s; s++) {       if (*s == *(s - 1)) *s = pick(*(s - 1), *(s + 1));     }     return ps;   }   int main() {     scanf( %s , s);     printf( %s n , handle(s));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long c[N], d[N];   int main() {     long long sum = 0, ans = 0;     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %lld , &c[i]);       sum += c[i];     }     for (int i = 1; i <= k; i++) {       scanf( %lld , &d[i]);       sum -= c[d[i]];       ans += sum * c[d[i]];       c[d[i]] = 0;     }     for (int i = 2; i <= n; i++) {       ans += c[i] * c[i - 1];     }     ans += c[1] * c[n];     printf( %lld n , ans);     return 0;   }


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