#include <bits/stdc++.h>   using namespace std;   map<long long int, long long int>::iterator it;   vector<pair<long long int, long long int> > v;   map<long long int, long long int> mp;   int main() {     long long int n;     scanf( %lld , &n);     for (long long int i = 0; i < n; i++) {       long long int l, r;       scanf( %lld%lld , &l, &r);       mp[l]++, mp[r + 1]--;     }     for (it = mp.begin(); it != mp.end(); it++) {       v.push_back(make_pair(it->first, it->second));     }     sort(v.begin(), v.end());     long long int sum = 0;     for (long long int i = 0; i < v.size(); i++) {       sum += v[i].second;       if (sum > 2) {         printf( NO n );         return 0;       }     }     printf( YES n );   }


#include <bits/stdc++.h>   using namespace std;   struct fast_ios {     fast_ios() {       cin.tie(nullptr), ios::sync_with_stdio(false),           cout << fixed << setprecision(20);     };   } fast_ios_;   string solve(string S) {     const int N = S.length();     int L = N;     while (L % 2 == 0) L /= 2;     while (L < N) {       for (int i = 0; i < N; i += L * 2) {         if (S.substr(i, L) > S.substr(i + L, L)) {           for (int j = (0), j_end_ = (L); j < j_end_; j++)             swap(S[i + j], S[i + j + L]);         }       }       L *= 2;     }     return S;   }   int main() {     string A, B;     cin >> A >> B;     cout << (solve(A) == solve(B) ?  YES  :  NO ) <<   n ;   }


#include <bits/stdc++.h>   #include <climits>   #define F first   #define S second   #define all(v) v.begin(),v.end()   #define li long int   #define lli long long int   #define pb push_back   #define loop(a,b,i) for(lli i=a ; i<b ; i++)   #define rev_loop(a,b,i) for(lli i=a ; i>=b ; i--)   #define MAX(a,b) (a>b)?a:b   #define lele(arr, n) loop(0,n,i) cin>>arr[i];   #define VAL 10005   #define N 1005      using namespace std;      void solve(){       int n;       cin>>n;       long int arr[2*n], mx=0;       loop(0, 2*n, i){            cin>>arr[i];           if(arr[i] > arr[mx]) mx = i;       }       int i;       bool flag;       for(i=0 ; i<2*n ; i++){                      // O(n)           if(i == mx) continue;           multiset<int> tmp;           loop(0, 2*n, j){                        // O(n)               if(j == i || j == mx) continue;               tmp.insert(arr[j]);           }           long int lastMx = arr[mx], curMx;           flag=true;           while(!tmp.empty()){               curMx = *tmp.rbegin();               tmp.erase(tmp.find(curMx));               if(tmp.find(lastMx - curMx) == tmp.end()){                   flag = false;                   break;               }               tmp.erase(tmp.find(lastMx - curMx));               lastMx = curMx;           }           if(flag) break;       }       if(!flag){            cout<< NO n ;           return;       }       cout<< YES n ;       cout<<arr[mx] + arr[i]<<endl;       cout<<arr[mx]<<   <<arr[i]<<endl;       multiset<int> tmp;       loop(0, 2*n, j){                        // O(n)           if(j == i || j == mx) continue;           tmp.insert(arr[j]);       }       long int lastMx = arr[mx];       while(!tmp.empty()){           long int x = *tmp.rbegin(), y = *tmp.find(lastMx - x);           cout<<x<<   <<y<<  n ;           tmp.erase(tmp.find(x));           tmp.erase(tmp.find(lastMx - x));           lastMx = x;       }       return;   }      int main()    {        int t;       cin>>t;       while(t--){           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int f = 1, x = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -1LL;     } while (ch <  0  || ch >  9 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f * x;   }   template <class T>   inline void chmax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void chmin(T &a, T b) {     if (a > b) a = b;   }   inline void swap(int &a, int &b) {     int c = a;     a = b;     b = c;   }   using namespace std;   const int N = 233;   const int P = 1e9 + 7;   const int mod = 1e9 + 7;   inline long long qpow(long long a, long long b) {     long long q = 1;     while (b) {       if (b & 1) q = q * a % P;       a = a * a % P;       b >>= 1;     }     return q;   }   inline long long gtinv(long long x) { return qpow(x, P - 2); }   long long a[N][N];   int e[N][N];   inline long long sub(long long a, long long b) {     if (a < b) return a - b + P;     return a - b;   }   long long det(int n) {     long long ans = 1;     for (int i = (1); i <= (n); ++i) {       bool fg = 0;       for (int j = (i); j <= (n); ++j)         if (a[j][i] != 0) {           for (int k = (i); k <= (n); ++k) swap(a[i][k], a[j][k]);           if (j != i) ans = -ans;           fg = 1;           break;         }       if (!fg) return 0;       for (int j = (i + 1); j <= (n); ++j) {         long long tmp = -a[j][i] * qpow(a[i][i], P - 2) % P;         for (int k = (i); k <= (n); ++k) a[j][k] = (a[j][k] + tmp * a[i][k]) % P;       }     }     for (int i = (1); i <= (n); ++i) ans = ans * a[i][i] % P;     if (ans < 0) ans += P;     return ans;   }   int n;   long long ans[N], inv[N], g[N], w[N];   long long c[N];   int main() {     n = read();     for (int i = (1); i <= (n - 1); ++i) {       int u = read(), v = read();       e[u][v] = e[v][u] = 1;     }     for (int x = (0); x <= (n); ++x) {       for (int i = (0); i <= (n); ++i) a[i][i] = 0;       for (int i = (1); i <= (n); ++i) {         for (int j = (1); j <= (n); ++j) {           if (i == j) continue;           a[i][j] = e[i][j] ? -x : -1;           a[i][i] -= a[i][j];         }       }       ans[x] = det(n - 1);     }     inv[0] = inv[1] = 1;     for (int i = 2; i <= n; i++) inv[i] = mod - (inv[mod % i] * (mod / i)) % mod;     g[0] = g[1] = 1;     for (int i = 2; i <= n; i++) g[i] = g[i - 1] * inv[i] % mod;     for (int i = 0; i <= n; i++) w[i] = qpow(i, n);     for (int i = n; i >= 0; i--) {       for (int j = 0; j <= i; j++) {         if (j & 1) {           c[i] -= g[j] * g[i - j] % mod * ans[i - j] % mod;           if (c[i] < 0) c[i] += mod;         } else {           c[i] += g[j] * g[i - j] % mod * ans[i - j] % mod;           if (c[i] >= mod) c[i] -= mod;         }       }       for (int j = 1; j <= n; j++) {         ans[j] -= c[i] * w[j] % mod;         if (ans[j] < 0) ans[j] += mod;         w[j] = w[j] * inv[j] % mod;       }     }     for (int i = (0); i <= (n - 1); ++i) printf( %lld  , c[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[200002] = {0};   void fill() {     for (int i = 0; i < 200002; i++) ans[i] = 1e7;   }   int main() {     fill();     int n;     cin >> n;     int arr[200002];     queue<int> q;     stack<int> st;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 0) q.push(i), st.push(i);     }     for (int i = 0; i < n; i++) {       if (q.size() != 0) {         if (q.front() >= i)           ans[i] = q.front() - i;         else {           q.pop();           if (q.size() != 0) ans[i] = q.front() - i;         }       }     }     for (int i = n - 1; i >= 0; i--) {       if (st.size() != 0) {         if (st.top() <= i)           ans[i] = min(ans[i], i - st.top());         else {           st.pop();           if (st.size() != 0) ans[i] = min(ans[i], i - st.top());         }       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   long long n, m, l, r;   long long binpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res % mod;   }   long long inv(long long a) { return binpow(a, mod - 2); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n >> m >> l >> r;     long long sz = n * m;     if (sz & 1) {       cout << binpow(r - l + 1, sz);     } else {       cout << (inv(2) * (binpow(r - l + 1, sz) + (((r - l + 1) % 2) ? 1 : 0))) %                   mod;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   void solve() {     long long int n, x, ans = 1, p = -1, q = -1, c;     cin >> n;     set<long long int> s;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i], s.insert(a[i]);     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < 32; j++) {         c = 1;         if (s.find(a[i] - (1 << j)) != s.end()) {           q = a[i] - (1 << j);           c++;         }         if (s.find(a[i] + (1 << j)) != s.end()) {           q = a[i] + (1 << j);           c++;         }         if (c == 3) {           cout << 3 <<   n ;           cout << a[i] - (1 << j) <<     << a[i] <<     << a[i] + (1 << j);           return;         }         if (c == 2) p = a[i];         ans = max(ans, c);       }     }     cout << ans <<   n ;     if (ans == 2) cout << p <<     << q;     if (ans == 1) cout << a[0];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int hh, mm, h, d, c, n;     cin >> hh >> mm;     cin >> h >> d >> c >> n;     float a;     if (h % n == 0)       a = (h / n) * c;     else       a = (h / n + 1) * c;     float b;     int tim = hh * 60 + mm;     if (tim <= 1200) {       h += (1200 - tim) * d;       float rate = (float)c * 4 / 5;       if (h % n == 0) {         b = (h / n) * rate;       } else         b = (h / n + 1) * rate;     } else {       float rate = (float)c * 4 / 5;       if (h % n == 0)         b = (h / n) * rate;       else         b = (h / n + 1) * rate;     }     cout << fixed << setprecision(4) << min(a, b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, m, d, x, ans;     cin >> n >> k >> m >> d;     ans = m;     for (int i = 2; i <= d && (k * i - k + 1) <= n; i++) {       x = (n / ((i * k) - (k - 1)));       x = min(x, m);       ans = max(ans, x * i);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, num[64];   string s[64];   int number(string s1, string s2) {     if (s1 == s2) return 0;     for (int i = 1; i < s1.length(); i++) {       string tail = s1.substr(0, i);       string head = s1.substr(i, s1.length() - i);       if (head + tail == s2) return i;     }     return -1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     int mn = 2e9;     for (int i = 1; i <= n; i++) {       int ans = 0;       for (int j = 1; j <= n; j++) {         int num = number(s[j], s[i]);         if (num == -1) {           cout << -1;           return 0;         }         ans += num;       }       mn = min(mn, ans);     }     cout << mn;   }


#include <bits/stdc++.h>   using namespace std;   long long k = 1000003;   long long exp(long long p, long long q) {     if (q == 1) return (long long)p;     if (q == 0) return 1;     long long temp = (long long)(exp(p, q / 2) % k);     if (q % 2 == 0) {       return (long long)((temp) * (temp)) % k;     } else {       return (long long)((((temp) * (temp)) * p) % k);     }   }   int main() {     string str;     getline(cin, str);     int bin[str.size() + 1];     bin[0] = 0;     for (int i = 0; i < str.size(); i++) {       int k = (int)str[i];       int val = 0;       long long bina = 0;       while (k > 0) {         bina += k % 2;         k /= 2;         bina *= (long long)10;       }       int count = 0;       int u = log10(bina);       if ((int)str[i] < 64) bina *= 10;       while (bina > 0) {         long long t = bina % 10;         val += t * pow((double)2, count);         bina /= 10;         count++;       }       int prev = bin[i];       int s = bin[i] - val;       bin[i + 1] = val;       while (s < 0) s += 256;       cout << s << endl;     }     return 0;   }


//#include  bits/stdc++.h       #define _USE_MATH_DEFINES   #include<cstdio>   #include <cstring>   #include <cmath>   #include <cstdlib>   #include <deque>   #include <algorithm>   #include <functional>   #include <iostream>   #include <list>   #include <map>   #include <array>   #include <unordered_map>   #include<unordered_set>   #include <numeric>   #include <queue>   #include <set>   #include <sstream>   #include <stack>   #include <string>   #include <utility>   #include <vector>   #include <iterator>   #include<iomanip>   #include<complex>   #include<fstream>   #include<assert.h>      #include<stdio.h>      using namespace std;      #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)   #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)   #define all(c) begin(c),end(c)      #define int ll   #define SZ(x) ((int)(x).size())   #define pb push_back   #define mp make_pair      //typedef unsigned long long ull;   typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef pair<ll, int> pli;   typedef pair<int, double> pid;   typedef pair<double, int> pdi;   typedef pair<double, double> pdd;   typedef vector< vector<int> > mat;      template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }   template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }      const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;   const int MOD = (int)1e9 + 7;      const double EPS = 1e-9;      signed main()   {    cin.tie(0);    ios::sync_with_stdio(false);       int N, K, Q;    cin >> N >> K >> Q;       vector<int> A(N);    rep(i, 0, N)cin >> A[i];       vector<vector<int>> WAY(N, vector<int>(K + 1, 0));    vector<vector<int>> DP(N, vector<int>(K + 1, 0));    rep(i, 0, N)DP[i][K] = 1;    rep(i, 0, N)WAY[i][0] = 1;       rrep(k, 1, K + 1)    {     rep(i, 0, N)     {      if (0 < i)      {       DP[i - 1][k - 1] += DP[i][k];       DP[i - 1][k - 1] %= MOD;      }      if (i < N - 1)      {       DP[i + 1][k - 1] += DP[i][k];       DP[i + 1][k - 1] %= MOD;      }     }    }    rep(k, 0, K)    {     rep(i, 0, N)     {      if (0 < i)      {       WAY[i - 1][k + 1] += WAY[i][k];       WAY[i - 1][k + 1] %= MOD;      }      if (i < N - 1)      {       WAY[i + 1][k + 1] += WAY[i][k];       WAY[i + 1][k + 1] %= MOD;      }     }    }       vector<int> CNT(N,0);       int ans = 0;    rep(i, 0, N)    {     rep(k, 0, K + 1)     {      CNT[i] += (DP[i][k] * WAY[i][k]) % MOD;      CNT[i] %= MOD;     }     ans += (CNT[i] * A[i])%MOD;     ans %= MOD;    }       int x, y;    rep(i, 0, Q)    {     cin >> x >> y;     x--;     ans = (ans - ((CNT[x] * A[x]) % MOD) + MOD) % MOD;     A[x] = y;     ans = (ans + ((CNT[x] * A[x]) % MOD)) % MOD;     cout << ans << endl;    }       return 0;   }


#include <cstdio>   #include <iostream>   #include <cstring>   #include <queue>   using namespace std;   const int M = 2005;   const int inf = 0x3f3f3f3f;   #define int long long   int read()   {    int x=0,f=1;char c;    while((c=getchar())< 0  || c> 9 ) {if(c== - ) f=-1;}    while(c>= 0  && c<= 9 ) {x=(x<<3)+(x<<1)+(c^48);c=getchar();}    return x*f;   }   int n,m,k,t,mx,a[M],b[M],d[M],del[M];   int tot,S,T,f[M],dis[M],dp[55][55],pre[55][55];   struct edge   {    int v,c,next;   }e[2*M];   void add(int u,int v,int c)   {    e[++tot]=edge{v,c,f[u]},f[u]=tot;    e[++tot]=edge{u,0,f[v]},f[v]=tot;   }   int bfs()   {    for(int i=S;i<=T;i++) dis[i]=0;    queue<int> q;    q.push(S);dis[S]=1;    while(!q.empty())    {     int u=q.front();q.pop();     if(u==T) return 1;     for(int i=f[u];i;i=e[i].next)     {      int v=e[i].v;      if(e[i].c>0 && !dis[v])      {       dis[v]=dis[u]+1;       q.push(v);      }     }    }    return 0;   }   int dfs(int u,int ept)   {    if(u==T) return ept;    int flow=0,tmp=0;    for(int i=f[u];i;i=e[i].next)    {     int v=e[i].v;     if(e[i].c>0 && dis[v]==dis[u]+1)     {      tmp=dfs(v,min(e[i].c,ept));      if(!tmp) continue;      ept-=tmp;      e[i].c-=tmp;      e[i^1].c+=tmp;      flow+=tmp;      if(!ept) break;     }    }    return flow;   }   int get()   {    S=0;T=2*n+1;tot=1;    for(int i=S;i<=T;i++) f[i]=0;    for(int i=1;i<=m;i++)    {     int u=a[i],v=b[i];     add(u+n,v,1);//x is in / x+n is out;    }    for(int i=1;i<=n;i++)       {           if(!del[i+n]) add(S,i+n,1);           if(!del[i]) add(i,T,1);       }    int res=0;    while(bfs()) res+=dfs(S,inf);    return res;   }   void print(int x,int y)   {    if(!x) return ;    print(x-1,pre[x][y]);    for(int i=pre[x][y]+1;i<=y;i++)    {     if(d[i]>n) printf( %lld  ,d[i]-n);     else printf( %lld  ,-d[i]);    }    printf( 0  );   }   signed main()   {    n=read();m=read();k=read();    for(int i=1;i<=m;i++)     a[i]=read(),b[i]=read();    mx=get();    for(int i=1;i<=mx;i++)     for(int j=1;j<=2*n;j++)      if(!del[j])      {       del[j]=1;       if(get()==mx-i)//we can delete j to reduce the maxmatch       {        d[++t]=j;        break;       }       del[j]=0;      }    memset(dp,-0x3f,sizeof dp);    dp[0][0]=0;    for(int i=1;i<=k;i++)    {     int x=read(),y=read();     for(int j=0;j<=t;j++)     {      if(i-j>=n-mx) continue;//illegal      for(int k=0;k<=j;k++)//we choose k now       if(dp[i][j]<dp[i-1][j-k]+max(0ll,x-k*y))       {        dp[i][j]=dp[i-1][j-k]+max(0ll,x-k*y);        pre[i][j]=j-k;       }     }    }    int p=0;    for(int i=0;i<=t;i++)     if(dp[k][i]>dp[k][p])      p=i;    printf( %lld n ,k+p);    print(k,p);   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, modu = 1e9 + 7, prod = 1, sum = 0;   long long int power(long long int x, long long int y) {     if (y == 0) return 1;     if (y & 1) return (x * power((x * x) % modu, y >> 1)) % modu;     return power((x * x) % modu, y >> 1);   }   long long int combine(long long int n, long long int r) {     long long int p1 = 1, p2 = 1;     for (int i = 1; i <= n; i++) p1 = (p1 * i) % modu;     for (int i = 1; i <= r; i++) p2 = (p2 * i) % modu;     for (int i = 1; i <= (n - r); i++) p2 = (p2 * i) % modu;     return (p1 * (power(p2, modu - 2))) % modu;   }   int main() {     cin >> n >> m;     int prev = 0;     vector<int> aa;     for (int i = 0; i < m; i++) {       long long int x;       cin >> x;       aa.push_back(x);     }     sort(aa.begin(), aa.end());     for (int i = 0; i < m; i++) {       long long int a = aa[i];       long long int c = a;       a = a - prev - 1;       if (a > 0) {         sum += a;         if (i > 0 && i <= m - 1) prod = (prod * power(2, a - 1)) % modu;         prod = (prod * combine(sum, a)) % modu;       }       prev = c;     }     if (n - prev > 0) {       sum += (n - prev);       prod = (prod * (combine(sum, n - prev))) % modu;     }     cout << prod << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 1000000;   int a[mxN];   void solve() {     int n, k;     cin >> n >> k;     int idx = ceil((double)n / 2);     int sub = (n - idx) + 1;     for (int i = 0; i < n * k; i++) {       cin >> a[i];     }     long long ans = 0, cnt = 0;     for (int i = n * k - sub; cnt < k; i -= sub) {       ans += a[i];       cnt++;     }     cout << ans <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   inline void print(int x) {     if (x < 0) putchar( - ), x = ~x + 1;     if (x >= 10) print(x / 10);     putchar((x % 10) | 48);   }   int n;   int c, d;   long long ans;   int t[100010];   char tp[100010];   int main() {     n = read();     c = read(), d = read();     for (int i = 1; i <= n; ++i) {       t[i] = read();       char c = getchar();       while (c !=  P  && c !=  W ) c = getchar();       tp[i] = c;     }     t[n + 1] = read();     tp[n + 1] =  A ;     ans = 1ll * d * n;     long long sum = 0;     int last = t[n + 1];     for (int i = n; i >= 1; --i) {       ans = min(ans, 1ll * c * (t[n + 1] - t[i]) + sum + 1ll * d * (i - 1));       if (tp[i - 1] == tp[i]) {         sum += min(d, c * (last - t[i]));       } else {         last = t[i];       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <typename T>   void read(T &a) {     T x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     a = x * f;   }   template <typename T>   void print(T x) {     if (!x) return;     if (x < 0) putchar( - ), x = -x;     print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T, typename... Args>   void read(T &t, Args &...args) {     read(t);     read(args...);   }   long long n, a[200005 << 1], res = 0, las[200005 << 1];   map<long long, long long> mp;   signed main() {     read(n);     for (long long i = 1; i <= n; i++) read(a[i]), mp[a[i]]++;     long long maxid, maxx = -1;     for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();          it++) {       if (maxx < it->second) {         maxx = it->second;         maxid = it->first;       }     }     for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();          it++) {       if (it->first == maxid) continue;       long long sum = n;       memset(las, -1, sizeof(las));       las[n] = 0;       for (long long i = 1; i <= n; i++) {         if (a[i] == it->first) sum--;         if (a[i] == maxid) sum++;         if (las[sum] != -1)           res = max(res, i - las[sum]);         else           las[sum] = i;       }     }     printf( %lld n , res);     return 0;   }


/**    *  created: 25/03/2021, 15:47:17    *  pause: 16:11 - 16:18   **/      #include <bits/stdc++.h>      using namespace std;      const int max_n = 200222, inf = 1000111222;   const int max_x = 2 * max_n;      vector<long long> all;      struct node {       int cnt;       long long sum, sum_l, sum_r;          friend ostream& operator << (ostream &os, const node &nd) {           os <<  (cnt =   << nd.cnt <<  , s =   << nd.sum <<  , sl =   << nd.sum_l <<  , sr =   << nd.sum_r <<  ) ;           return os;       }   };      node combine(const node &a, const node &b) {       return {a.cnt + b.cnt,               a.sum + b.sum,               a.sum_l + b.sum_l + a.sum * b.cnt,               a.sum_r + b.sum_r + b.sum * a.cnt};   }      struct segment_tree {       node a[4 * max_x];          void build(int v, int l, int r, int cnt[]) {           if (l == r) {               a[v] = {cnt[l], cnt[l] * all[l], cnt[l] * all[l], cnt[l] * all[l]};               //cout << v <<  : [  << l <<     << r <<  ], nd =   << a[v] << endl;               return;           }           int mid = (l + r) / 2;           build(2 * v, l, mid, cnt);           build(2 * v + 1, mid + 1, r, cnt);           a[v] = combine(a[2 * v], a[2 * v + 1]);           //cout << v <<  : [  << l <<     << r <<  ], nd =   << a[v] << endl;       }          void update(int v, int l, int r, int x, int value) {           if (l == r) {               a[v] = {value, value * all[l], value * all[l], value * all[l]};               return;           }           int mid = (l + r) / 2;           if (x <= mid) {               update(2 * v, l, mid, x, value);           } else {               update(2 * v + 1, mid + 1, r, x, value);           }           a[v] = combine(a[2 * v], a[2 * v + 1]);       }          node get_sum(int v, int tl, int tr, int l, int r) {           if (tl == l && tr == r) {               return a[v];           }           int mid = (tl + tr) / 2;           if (r <= mid) {               return get_sum(2 * v, tl, mid, l, r);           } else if (l > mid) {               return get_sum(2 * v + 1, mid + 1, tr, l, r);           }           return combine(get_sum(2 * v, tl, mid, l, mid), get_sum(2 * v + 1, mid + 1, tr, mid + 1, r));       }          long long get_sum_left(int v, int tl, int tr, int k) {           if (tl == tr) {               if (k == 1) {                   return a[v].sum;               }               return 0;           }           int mid = (tl + tr) / 2;           if (k <= a[2 * v].cnt) {               return get_sum_left(2 * v, tl, mid, k);           }           return a[2 * v].sum + get_sum_left(2 * v + 1, mid + 1, tr, k - a[2 * v].cnt);       }          long long get_sum_right(int v, int tl, int tr, int k) {           if (tl == tr) {               if (k == 1) {                   return a[v].sum;               }               return 0;           }           int mid = (tl + tr) / 2;           if (k <= a[2 * v + 1].cnt) {               return get_sum_right(2 * v + 1, mid + 1, tr, k);           }           return a[2 * v + 1].sum + get_sum_right(2 * v, tl, mid, k - a[2 * v + 1].cnt);       }          node get_node_left(int v, int tl, int tr, int k) {           if (tl == tr) {               return a[v];           }           int mid = (tl + tr) / 2;           if (k <= a[2 * v].cnt) {               return get_node_left(2 * v, tl, mid, k);           }           return combine(a[2 * v], get_node_left(2 * v + 1, mid + 1, tr, k - a[2 * v].cnt));       }          node get_node_right(int v, int tl, int tr, int k) {           if (tl == tr) {               return a[v];           }           int mid = (tl + tr) / 2;           if (k <= a[2 * v + 1].cnt) {               return get_node_right(2 * v + 1, mid + 1, tr, k);           }           return combine(get_node_right(2 * v, tl, mid, k - a[2 * v + 1].cnt), a[2 * v + 1]);       }   };      int n, q, tp[max_n], cnt[max_x];   long long a[max_n], b[max_n];   segment_tree st;      int compress(long long x) {       return lower_bound(all.begin(), all.end(), x) - all.begin();   }      long long solve() {       //cout <<  #  << st.a[1] << endl;       long long res = st.a[1].sum_r - st.a[1].sum_l;       const int k = st.a[1].cnt;       if (k >= 3) {           int pos = (k + 1) / 2 - 2;           long long sr = st.get_sum_right(1, 0, all.size() - 1, pos + 1);           long long sl = st.get_sum_left(1, 0, all.size() - 1, pos + 2);           if (sr > sl) {               int l = pos, r = k - 1;               while (r - l > 1) {                   int mid = (l + r) / 2;                   long long sr = st.get_sum_right(1, 0, all.size() - 1, mid + 1);                   long long sl = st.get_sum_left(1, 0, all.size() - 1, mid + 2);                   if (sr > sl) {                       l = mid;                   } else {                       r = mid;                   }               }               int to = l;               l = -1;               r = pos;               while (r - l > 1) {                   int mid = (l + r) / 2;                   long long sr = st.get_sum_right(1, 0, all.size() - 1, mid + 1);                   long long sl = st.get_sum_left(1, 0, all.size() - 1, mid + 2);                   if (sr > sl) {                       r = mid;                   } else {                       l = mid;                   }               }               int from = r;               res -= st.get_node_right(1, 0, all.size() - 1, to + 1).sum_r;               if (from) {                   res += st.get_node_right(1, 0, all.size() - 1, from).sum_r;               }               res += st.get_node_left(1, 0, all.size() - 1, to + 2).sum_l;               res -= st.get_node_left(1, 0, all.size() - 1, from + 1).sum_l;               /*for (int i = from; i <= to; ++i) {                   //res -= st.get_sum_right(1, 0, all.size() - 1, i + 1) - st.get_sum_left(1, 0, all.size() - 1, i + 2);                   res += st.get_sum_left(1, 0, all.size() - 1, i + 2);               }*/           }       }       return res;   }      int main() {       //freopen( input.txt ,  r , stdin);       //freopen( output.txt ,  w , stdout);       scanf( %d%d , &n, &q);       for (int i = 0; i < n; ++i) {           scanf( %lld , &a[i]);       }       for (int i = 0; i < q; ++i) {           scanf( %d%lld , &tp[i], &b[i]);       }       for (int i = 0; i < n; ++i) {           all.push_back(a[i]);       }       for (int i = 0; i < q; ++i) {           all.push_back(b[i]);       }       sort(all.begin(), all.end());       all.erase(unique(all.begin(), all.end()), all.end());       for (int i = 0; i < n; ++i) {           cnt[compress(a[i])] = 1;       }       st.build(1, 0, all.size() - 1, cnt);       printf( %lld n , solve());       for (int i = 0; i < q; ++i) {           if (tp[i] == 1) {               st.update(1, 0, all.size() - 1, compress(b[i]), 1);           } else {               st.update(1, 0, all.size() - 1, compress(b[i]), 0);           }           printf( %lld n , solve());       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int a[MAXN], b[MAXN], pos[MAXN];   map<int, int> zoom;   bool vis[MAXN];   int main() {     ios::sync_with_stdio(false);     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) {       zoom[b[i]] = i;       b[i] = i;     }     for (int i = 1; i <= n; i++) {       a[i] = zoom[a[i]];       pos[a[i]] = i;     }     vector<vector<int>> res;     for (int i = 1; i <= n; i++) {       if (!vis[pos[i]]) {         vector<int> cur;         for (int j = pos[i]; !vis[j]; j = pos[j]) {           cur.push_back(j);           vis[j] = true;         }         res.push_back(cur);       }     }     cout << res.size() <<   n ;     for (auto v : res) {       cout << v.size() <<    ;       for (auto x : v) {         cout << x <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     double n;     long int sum = 0;     for (int i = 0; i < q; i++) {       cin >> n;       long long int a;       for (int j = 0; j < n; j++) {         cin >> a;         sum += a;       }       cout << fixed << setprecision(0) << ceill((sum / n)) << endl;       sum = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5, MOD = 1e9 + 7;   long long k, p, q;   string ans;   set<long long> s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> k;     if (k < 25) {       cout << -1 << endl;       return 0;     }     char str[5] = { a ,  e ,  i ,  o ,  u };     for (long long i = 1; i * i <= k; i++) {       if (k % i == 0) {         if (i >= 5 && k / i >= 5) {           p = i;           q = k / i;           break;         }       }     }     if (p == 0 && q == 0) {       cout << -1 << endl;       return 0;     }     for (long long i = 0; i < p; i++) {       for (long long j = 0; j < q; j++) cout << str[(i + j) % 5];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long long a[100];     long long b[100];     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) cin >> b[i];     long long ans = 1000000000000000000LL;     for (int i = 1; i <= n; i++) {       long long mn = -1000000000000000000LL;       for (int j = 1; j <= m; j++)         for (int k = 1; k <= n; k++) {           if (k == i) continue;           mn = max(mn, a[k] * b[j]);         }       ans = min(ans, mn);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   const int mod = 1e9 + 7;   const int inf = INT_MAX;   vector<string> l = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                        y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                        z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     ld x, y, z;     cin >> x >> y >> z;     if (x < 1 and y < 1 and z < 1) {       ld ans = pow(x, pow(y, z));       int cur = 0;       if (pow(x, pow(z, y)) > ans) {         ans = pow(x, pow(z, y));         cur = 1;       }       if (pow(x, y * z) > ans) {         ans = pow(x, y * z);         cur = 2;       }       if (pow(y, pow(x, z)) > ans) {         ans = pow(y, pow(x, z));         cur = 4;       }       if (pow(y, pow(z, x)) > ans) {         ans = pow(y, pow(z, x));         cur = 5;       }       if (pow(y, x * z) > ans) {         ans = pow(y, x * z);         cur = 6;       }       if (pow(z, pow(x, y)) > ans) {         ans = pow(z, pow(x, y));         cur = 8;       }       if (pow(z, pow(y, x)) > ans) {         ans = pow(z, pow(y, x));         cur = 9;       }       if (pow(z, x * y) > ans) {         ans = pow(z, x * y);         cur = 10;       }       cout << l[cur] <<   n ;       return 0;     }     ld ans = 0;     int cur = 0;     if (x < 1)       ans = -1e18;     else if (x == 1)       ans = -1000;     else       ans = z * log(y) + log(log(x));     if (x > 1 and y * log(z) + log(log(x)) > ans) {       ans = y * log(z) + log(log(x));       cur = 1;     }     if (x > 1 and log(y) + log(z) + log(log(x)) > ans) {       ans = log(y) + log(z) + log(log(x));       cur = 2;     }     if (y == 1 and ans < -1000) {       ans = -1000;       cur = 4;     }     if (y > 1 and z * log(x) + log(log(y)) > ans) {       ans = z * log(x) + log(log(y));       cur = 4;     }     if (y > 1 and x * log(z) + log(log(y)) > ans) {       ans = x * log(z) + log(log(y));       cur = 5;     }     if (y > 1 and log(x) + log(z) + log(log(y)) > ans) {       ans = log(x) + log(z) + log(log(y));       cur = 6;     }     if (z == 1 and ans < -1000) {       ans = -1000;       cur = 8;     }     if (z > 1 and y * log(x) + log(log(z)) > ans) {       ans = y * log(x) + log(log(z));       cur = 8;     }     if (z > 1 and x * log(y) + log(log(z)) > ans) {       ans = x * log(y) + log(log(z));       cur = 9;     }     if (z > 1 and log(x) + log(y) + log(log(z)) > ans) {       ans = log(x) + log(y) + log(log(z));       cur = 10;     }     cout << l[cur];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n;     string s;     cin >> t;     while (t--) {       cin >> n >> s;       long long ans = 0, o = 0, ans1 = 0;       for (long long i = 0; i < n; i++) {         if ((s[i] - 48) % 2 == 1) {           ans = (ans * 10) + (s[i] - 48);           ans1 += ans;           if (ans1 % 2 == 0) {             o = 1;             break;           }         }       }       if (o == 0)         cout << -1 <<   n ;       else         cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, pos, num[100005];     cin >> n;     for (i = 1; i <= n; i++) scanf( %d , &num[i]);     pos = upper_bound(num + 1, num + 1 + n, 5e5) - num;     if (pos > n)       cout << num[n] - 1 << endl;     else if (pos <= 1)       cout << 1e6 - num[1] << endl;     else {       cout << max((int)1e6 - num[pos], num[pos - 1] - 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int suspect[100000];   int justify[100000];   bool killer[100000];   pair<int, int> a[100000];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 0; i < n; i++) {       killer[i] = false;       char x;       int k;       scanf( %d , &k);       if (k < 0) {         x =  - ;         k *= -1;       } else         x =  + ;       k--;       if (x ==  + ) {         suspect[k]++;         a[i].second = 1;       } else {         a[i].second = 0;         justify[k]++;         cnt++;       }       a[i].first = k;     }     int cntkiller = 0;     for (int i = 0; i < n; i++)       if (suspect[i] + cnt - justify[i] == m) {         killer[i] = true;         cntkiller++;       }     for (int i = 0; i < n; i++) {       if (a[i].second == 1 && killer[a[i].first] && cntkiller == 1)         printf( Truth n );       else if (a[i].second == 0 && killer[a[i].first] && cntkiller == 1)         printf( Lie n );       else if (a[i].second == 1 && killer[a[i].first])         printf( Not defined n );       else if (a[i].second == 1 && !killer[a[i].first])         printf( Lie n );       else if (a[i].second == 0 && !killer[a[i].first])         printf( Truth n );       else         printf( Not defined n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, k, l, a, b, c, d, m, s, f;     cin >> n >> m;     c = 0;     for (i = 1; i <= n; i++) {       c++;       if (i % m == 0) {         n++;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Dx[] = {1, -1, 0, 0};   int Dy[] = {0, 0, 1, -1};   double x, y, n, mn = 10000000.0, a, b, i;   bool ok(int m) {     if (x * i > m * y) return 1;     return 0;   }   int main() {     cin >> x >> y >> n;     for (i = 1; i <= n; i++) {       int s = 0, e = 1e9;       while (s < e) {         int m = (e + s + 1) / 2;         if (ok(m))           s = m;         else           e = m - 1;       }       double z = abs(x / y - s / i), zz = abs((s + 1) / i - x / y);       if (z < mn)         mn = z, a = s, b = i;       else if (z == mn && s < a)         a = s;       if (zz < mn)         mn = zz, a = s + 1, b = i;       else if (zz == mn && s + 1 < a)         a = s + 1;     }     cout << a <<  /  << b << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   vector<int> v;   struct mmp {     int to, next, len;     mmp() {}     mmp(int a, int b, int c) { to = a, next = b, len = c; }   } e[maxn << 1];   int vis[maxn], st, ed, cnt, head[maxn], val[maxn], len;   void add(int u, int v, int len) {     e[++cnt] = mmp(v, head[u], len);     head[u] = cnt;   }   void add(int x) {     for (int i = 0; i < (int)v.size(); i++) {       x = min(x, x ^ v[i]);     }     if (x) v.push_back(x);   }   void dfs(int x, int now) {     vis[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       int to = e[i].to;       if (vis[to])         add(val[to] ^ now ^ e[i].len);       else {         val[to] = now ^ e[i].len;         dfs(to, val[to]);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &st, &ed, &len);       add(st, ed, len);       add(ed, st, len);     }     dfs(1, 0);     for (int i = 0; (int)i < v.size(); i++) {       val[n] = min(val[n], val[n] ^ v[i]);     }     return 0 * printf( %d , val[n]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     cin >> n >> b;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     vector<int> s;     for (int i = 0; i < n - 1; i++) {       if (arr[i] <= b) {         int m = INT_MIN;         for (int j = i + 1; j < n; j++) m = max(m, arr[j]);         if (arr[i] < m) s.push_back(b + (m - arr[i]) * (b / arr[i]));       }     }     if (!s.empty())       cout << *max_element(s.begin(), s.end()) << endl;     else       cout << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1000 + 5;   int n, m, W;   int w[NMAX];   int b[NMAX];   vector<int> graph[NMAX];   int comp[NMAX];   void dfs(int node, int cmp) {     comp[node] = cmp;     for (auto it : graph[node])       if (!comp[it]) dfs(it, cmp);   }   vector<pair<int, int> > groups[NMAX];   int dp[NMAX][NMAX];   int main() {     cin >> n >> m >> W;     for (int i = 1; i <= n; ++i) cin >> w[i];     for (int i = 1; i <= n; ++i) cin >> b[i];     for (int i = 1; i <= m; ++i) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     int cmp = 0;     for (int i = 1; i <= n; ++i)       if (!comp[i]) dfs(i, ++cmp);     for (int i = 1; i <= n; ++i) groups[comp[i]].push_back(make_pair(w[i], b[i]));     for (int i = 1; i <= cmp; ++i) {       int sumW = 0;       int sumB = 0;       for (auto it : groups[i]) {         sumW += it.first;         sumB += it.second;       }       groups[i].push_back(make_pair(sumW, sumB));     }     for (int i = 1; i <= cmp; ++i) {       for (int j = 1; j <= W; ++j) {         dp[i][j] = dp[i - 1][j];         for (auto it : groups[i])           if (j - it.first >= 0)             dp[i][j] = max(dp[i][j], dp[i - 1][j - it.first] + it.second);       }     }     cout << dp[cmp][W] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pkt {     int x, y;   };   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<string> p(n);     for (int i = 0; i < n; ++i) cin >> p[i];     vector<vector<int> > a(n, vector<int>(m, -1));     for (int k = 0; k < n; ++k) {       for (int l = 1; l < m; ++l) {         if (p[k][l - 1] !=  . )           a[k][l] = l - 1;         else           a[k][l] = a[k][l - 1];       }     }     vector<vector<int> > b(n, vector<int>(m, -1));     for (int k = 0; k < n; ++k) {       for (int l = m - 2; l >= 0; --l) {         if (p[k][l + 1] !=  . )           b[k][l] = l + 1;         else           b[k][l] = b[k][l + 1];       }     }     vector<vector<int> > c(n, vector<int>(m, -1));     for (int l = 0; l < m; ++l) {       for (int k = 1; k < n; ++k) {         if (p[k - 1][l] !=  . )           c[k][l] = k - 1;         else           c[k][l] = c[k - 1][l];       }     }     vector<vector<int> > d(n, vector<int>(m, -1));     for (int l = 0; l < m; ++l) {       for (int k = n - 2; k >= 0; --k) {         if (p[k + 1][l] !=  . )           d[k][l] = k + 1;         else           d[k][l] = d[k + 1][l];       }     }     vector<vector<int> > L, P, G, D;     L = a;     P = b;     G = c;     D = d;     int odp = 0, il = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (p[i][j] ==  . ) continue;         int dl = 1;         pkt akt = {i, j};         vector<pkt> z;         while (true) {           pkt nast;           if (p[akt.x][akt.y] ==  L )             nast = {akt.x, L[akt.x][akt.y]};           else {             if (p[akt.x][akt.y] ==  R )               nast = {akt.x, P[akt.x][akt.y]};             else {               if (p[akt.x][akt.y] ==  U )                 nast = {G[akt.x][akt.y], akt.y};               else {                 if (p[akt.x][akt.y] ==  D ) nast = {D[akt.x][akt.y], akt.y};               }             }           }           if (nast.x == -1 || nast.y == -1) break;           ++dl;           pkt le = {akt.x, L[akt.x][akt.y]};           pkt pr = {akt.x, P[akt.x][akt.y]};           if (le.x != -1 && le.y != -1) P[le.x][le.y] = pr.y;           if (pr.x != -1 && pr.y != -1) L[pr.x][pr.y] = le.y;           pkt go = {G[akt.x][akt.y], akt.y};           pkt dol = {D[akt.x][akt.y], akt.y};           if (dol.x != -1 && dol.y != -1) G[dol.x][dol.y] = go.x;           if (go.x != -1 && go.y != -1) D[go.x][go.y] = dol.x;           akt = nast;           z.push_back(le);           z.push_back(pr);           z.push_back(go);           z.push_back(dol);         }         if (dl > odp) {           odp = dl;           il = 1;         } else {           if (dl == odp) ++il;         }         for (int k = 0; k < z.size(); ++k) {           if (z[k].x == -1 || z[k].y == -1) continue;           L[z[k].x][z[k].y] = a[z[k].x][z[k].y];           P[z[k].x][z[k].y] = b[z[k].x][z[k].y];           G[z[k].x][z[k].y] = c[z[k].x][z[k].y];           D[z[k].x][z[k].y] = d[z[k].x][z[k].y];         }       }     }     cout << odp <<     << il;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pt {     double x, y;   };   pt a[1005];   long long n;   double kv(double g) { return g * g; }   double dist(pt a, pt b) { return sqrt(kv(a.x - b.x) + kv(a.y - b.y)); }   double visina(pt a, pt b, pt c) {     return abs((b.y - a.y) * c.x - (b.x - a.x) * c.y + b.x * a.y - b.y * a.x) /            (dist(a, b));   }   int main() {     cout.precision(15);     cout << fixed;     cin >> n;     for (long i = 0; i < n; i++) {       cin >> a[i].x >> a[i].y;     }     double d = 1e17;     for (long i = 0; i < n; i++) {       pt x = a[i], y = a[(i + 1) % n], z = a[(i + 2) % n];       d = min(d, visina(x, y, z));       d = min(d, visina(y, z, x));       d = min(d, visina(z, x, y));     }     cout << d / 2 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6;   int pref[MAXN + 1];   string S;   int n, k;   void fast_io() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   pair<int, int> query(int s) {     int lo = s, hi = n;     int res = -1;     while (lo <= hi) {       int mid = (lo + hi) >> 1;       if (pref[mid] - pref[s - 1] >= k)         res = mid, hi = mid - 1;       else         lo = mid + 1;     }     if (res == -1 or (pref[res] - pref[s - 1]) != k) return make_pair(-1, -1);     pair<int, int> p = make_pair(res, -1);     lo = res, hi = n;     res = -1;     while (lo <= hi) {       int mid = (lo + hi) >> 1;       if (pref[mid] - pref[s - 1] <= k)         res = mid, lo = mid + 1;       else         hi = mid - 1;     }     p.second = res;     return p;   }   int main() {     fast_io();     cin >> k >> S;     n = S.length();     S =  $  + S;     for (int i = 1; i <= n; i++) {       pref[i] = (S[i] -  0 ) + pref[i - 1];     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       pair<int, int> p = query(i);       if (p.first == -1) continue;       ans += (p.second - p.first + 1);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void display(T a[], int size) {     for (int i = 0; i < size; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void display(vector<pair<int, int> > a) {     for (int i = 0; i < a.size(); i++) {       cout <<  (  << a[i].first <<  ,  << a[i].second <<  )             <<    ;     }     cout << endl;   }   void display(vector<int> a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i];       if (i == a.size() - 1)         cout << endl;       else         cout <<    ;     }   }   template <typename T>   void initialise(T a[], T value, int length) {     for (int i = 0; i < length; i++) a[i] = value;   }   template <typename T>   void initialise(vector<T>& a, T value) {     for (int i = 0; i < a.size(); i++) a[i] = value;   }   bool compare(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second < b.second;   }   int max(int a[], int n) {     int max = -1000000000;     for (int i = 0; i < n; i++) {       if (a[i] > max) max = a[i];     }     return max;   }   bool find(string a[], string s, int n) {     int left = 0;     int right = n - 1;     while (left < right) {       int mid = (left + right) / 2;       if (s.compare(a[mid]) == 0)         return true;       else if (s.compare(a[mid]) < 0) {         right = mid;       } else {         left = mid + 1;       }     }     return false;   }   void factor(int a[], int base, int num, int n) {     for (int i = n - 1; i >= 0; i--) {       a[i] = num % base;       num = num / base;     }   }   int findLength(int n, int base) {     int i = 0;     while (n > 0) {       i++;       n = n / base;     }     return i;   }   int gcd(int a, int b) {     while (a % b != 0 && b % a != 0) {       if (b > a) {         b = b % a;       } else if (a > b) {         a = a % b;       }     }     if (a <= b)       return a;     else       return b;   }   int main() {     int n, m;     cin >> n >> m;     list<int> son[n];     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       son[u - 1].push_back(v - 1);       son[v - 1].push_back(u - 1);     }     int side[n];     initialise(side, -1, n);     for (int i = 0; i < n; i++) {       if (side[i] != -1) continue;       queue<int> q;       q.push(i);       side[i] = 0;       while (!q.empty()) {         int current = q.front();         q.pop();         for (auto fil : son[current]) {           if (side[fil] == -1) {             side[fil] = 1 - side[current];             q.push(fil);           } else if (side[fil] == side[current]) {             cout << -1 << endl;             return 0;           } else             continue;         }       }     }     vector<int> zero;     vector<int> one;     for (int i = 0; i < n; i++) {       if (side[i] == 0)         zero.push_back(i + 1);       else         one.push_back(i + 1);     }     cout << zero.size() << endl;     for (int i = 0; i < zero.size(); i++) {       cout << zero[i];       if (i == zero.size() - 1)         cout << endl;       else         cout <<    ;     }     cout << one.size() << endl;     for (int i = 0; i < one.size(); i++) {       cout << one[i];       if (i == one.size() - 1)         cout << endl;       else         cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long ans = 0x3f3f3f3f3f3f, a[510];   void calc(long long val) {     if (!val) return;     long long res = 0;     for (int i = 1; i <= n; i++) {       long long p = a[i] / val, q = a[i] % val;       if (p < q) return;       res += p - (p - q) / (val + 1);     }     ans = min(ans, res);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + n);     for (long long i = 1; i * i <= a[1]; i++)       calc(i), calc(a[1] / i), calc(a[1] / i - 1);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sqr(const T &a) {     return a * a;   }   int a, b, x, ans;   int main() {     scanf( %d%d , &a, &b);     while (1) {       ans += a;       x += a;       if (x / b == 0) break;       a = x / b;       x -= (x / b) * b;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int z = 0, f = 0, n, a;     cin >> n;     while (n--) {       cin >> a;       a == 0 ? z++ : f++;     }     if (z > 0 && f > 8) {       f -= f % 9;       while (f--) cout <<  5 ;       while (z--) cout <<  0 ;       cout << endl;     } else if (z > 0)       cout <<  0 n ;     else       cout <<  -1 n ;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> s;       n = s.length();       int m = n, M = -1;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) {           m = min(m, i);           M = max(M, i);         }       }       if (m > M) {         cout << 0 << endl;       } else {         int cnt = 0;         for (int i = m; i < M; i++) {           cnt += (s[i] ==  0 );         }         cout << cnt << endl;       }     }   }


#include <bits/stdc++.h>   using ll = long long;   using namespace std;   int n, m;   int const N = 3e5 + 2;   int const M = (1 << 21);   struct Triple {     int fi;     int se;     int th;     Triple(int f, int s, int t) : fi(f), se(s), th(t) {}   };   struct Compare {     bool operator()(const Triple& f, const Triple& g) {       if (f.th != g.th)         return (f.th < g.th);       else         return pair<int, int>{f.fi, f.se} < pair<int, int>{g.fi, g.se};     }   };   vector<Triple> seg;   int t[M];   int lazy[M];   int const INF = 1e9;   void push(int v) {     t[v * 2] += lazy[v];     lazy[v * 2] += lazy[v];     t[v * 2 + 1] += lazy[v];     lazy[v * 2 + 1] += lazy[v];     lazy[v] = 0;   }   int query(int v, int l, int r, int tl, int tr) {     if (r < l) return INF;     if (l == tl && r == tr)       return t[v];     else {       push(v);       int mid = (tl + tr) / 2;       int qw1 = query(v * 2, l, min(mid, r), tl, mid);       int qw2 = query(v * 2 + 1, max(mid + 1, l), r, mid + 1, tr);       return min(qw1, qw2);     }   }   void update(int v, int l, int r, int tl, int tr, int val) {     if (r < l) return;     if (l == tl && r == tr) {       t[v] += val;       lazy[v] += val;     } else {       push(v);       int mid = (tl + tr) >> 1;       update(v << 1, l, min(mid, r), tl, mid, val);       update((v << 1) + 1, max(mid + 1, l), r, mid + 1, tr, val);       t[v] = min(t[v << 1], t[(v << 1) + 1]);     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = (1); i <= (n); i++) {       int l, r, w;       scanf( %d %d %d , &l, &r, &w);       seg.push_back(Triple({l, r, w}));     }     sort(seg.begin(), seg.end(), Compare());     int mu = 0;     int lb = seg[0].th;     int rb = seg[0].th;     int ans = INF;     for (int i = (1); i <= (n); i++) {       update(1, seg[i - 1].fi, seg[i - 1].se - 1, 1, m - 1, 1);       rb = seg[i - 1].th;       while (query(1, 1, m - 1, 1, m - 1) > 0) {         ans = min(ans, rb - lb);         update(1, seg[mu].fi, seg[mu].se - 1, 1, m - 1, -1);         mu++;         if (mu != n) lb = seg[mu].th;       }     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 11;   const long long mod = 1e9 + 7;   int n, m, k;   long long a[N], ans;   int par[N], sz[N];   pair<long long, pair<int, int> > b[N];   vector<pair<int, int> > v;   vector<int> cur;   bool u[N];   int find_set(int v) {     if (v == par[v]) return v;     return par[v] = find_set(par[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (sz[a] < sz[b]) swap(a, b);       par[b] = a;       sz[a] += sz[b];     }   }   long long binpow(int n) {     long long a = 2, res = 1;     while (n) {       if (n % 2 == 0) {         n /= 2;         a = (a * a) % mod;       } else {         n--;         res = (res * a) % mod;       }     }     return res;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &b[i].second.first, &b[i].second.second);       b[i].first = a[b[i].second.first] ^ a[b[i].second.second];     }     sort(b + 1, b + m + 1);     int l = 0;     int uniq = 0, comp;     for (int i = 1; i <= m; i++) {       if (b[i].first == b[i + 1].first) continue;       comp = 0;       for (int j = l + 1; j <= i; j++) v.push_back(b[j].second);       for (auto i : v) {         par[i.first] = i.first;         par[i.second] = i.second;         sz[i.first] = sz[i.second] = 1;       }       for (auto i : v) {         if (!u[i.first]) cur.push_back(i.first);         if (!u[i.second]) cur.push_back(i.second);         u[i.first] = u[i.second] = true;       }       for (auto i : v) union_sets(i.first, i.second);       for (auto i : cur)         if (find_set(i) == i) comp++;       ans = (ans + binpow(n - (int)cur.size() + comp)) % mod;       for (auto i : cur) {         u[i] = false;       }       cur.clear();       v.clear();       l = i;       uniq++;     }     long long p = ((1ll << k) - uniq) % mod;     p = (p * binpow(n)) % mod;     ans = (ans + p) % mod;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100100;   int N, M;   long long h[MAX_N], p[MAX_N];   inline long long calc(long long start, long long from, long long to) {     if (to <= start) return start - from;     if (from >= start) return to - start;     long long left = start - from, right = to - start;     long long mn = min(left, right), mx = max(left, right);     return 2 * mn + mx;   }   inline bool check(long long dist) {     int firstTrack = 1, lastTrack;     for (int i = 1; i <= N; i += 1) {       if (abs(p[firstTrack] - h[i]) > dist) {         continue;       }       lastTrack = firstTrack;       while (lastTrack < M &&              calc(h[i], p[firstTrack], p[lastTrack + 1]) <= dist) {         lastTrack += 1;       }       if (lastTrack == M) {         return true;       }       firstTrack = lastTrack + 1;     }     return false;   }   int main() {     cin >> N >> M;     for (int i = 1; i <= N; i += 1) {       cin >> h[i];     }     for (int i = 1; i <= M; i += 1) {       cin >> p[i];     }     long long answer = -1;     for (long long bit = (1LL << 40); bit > 0; bit /= 2) {       if (!check(answer + bit)) {         answer += bit;       }     }     cout << answer + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   namespace in {   char buf[1 << 21], *p1 = buf, *p2 = buf;   inline int getc() {     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <typename T>   inline void read(T &t) {     t = 0;     int f = 0;     char ch = getc();     while (!isdigit(ch)) {       if (ch ==  - ) f = 1;       ch = getc();     }     while (isdigit(ch)) {       t = t * 10 + ch - 48;       ch = getc();     }     if (f) t = -t;   }   template <typename T, typename... Args>   inline void read(T &t, Args &...args) {     read(t);     read(args...);   }   char getC() {     char c = getc();     while (!isdigit(c) && !isalpha(c) && c !=  (  && c !=  )  && c !=  ? )       c = getc();     return c;   }   }  // namespace in   namespace out {   char buffer[1 << 21];   int p1 = -1;   const int p2 = (1 << 21) - 1;   inline void flush() { fwrite(buffer, 1, p1 + 1, stdout), p1 = -1; }   inline void putc(const char &x) {     if (p1 == p2) flush();     buffer[++p1] = x;   }   template <typename T>   void write(T x) {     static char buf[15];     static int len = -1;     if (x >= 0) {       do {         buf[++len] = x % 10 + 48, x /= 10;       } while (x);     } else {       putc( - );       do {         buf[++len] = -(x % 10) + 48, x /= 10;       } while (x);     }     while (len >= 0) putc(buf[len]), --len;   }   void puts(char *str) {     int now = 0;     while (str[now] != 0) putc(str[now++]);     putc(  n );   }   }  // namespace out   namespace Game {   unsigned long long p1[64][3200], p2[64][3200];   inline void make(unsigned long long arr[64][3200], int pos) {     int th = std::min(63, pos);     for (int i = 0; i <= th; i++)       arr[i][(pos - i) >> 6] |= 1ull << ((pos - i) & 63);   }   void solve(int n, int m, int q, char *s1, char *s2, int *qx, int *qy, int *qlen,              unsigned int *ans) {     for (int i = 0; i < n; i++)       if (s1[i] -  0 ) make(p1, i);     for (int i = 0; i < m; i++)       if (s2[i] -  0 ) make(p2, i);     for (int i = 0; i < q; i++) {       unsigned int res1 = 0, res2 = 0, res3 = 0, res4 = 0, res5 = 0, res6 = 0,                    res7 = 0, res8 = 0;       int x = qx[i], y = qy[i], l = qlen[i];       unsigned int block = l >> 6, c;       unsigned long long *arr1 = p1[x & 63] + (x >> 6);       unsigned long long *arr2 = p2[y & 63] + (y >> 6);       for (c = 0; c + 8 < block; c += 8, arr1 += 8, arr2 += 8) {         res1 += __builtin_popcountll(arr1[0] ^ arr2[0]);         res2 += __builtin_popcountll(arr1[1] ^ arr2[1]);         res3 += __builtin_popcountll(arr1[2] ^ arr2[2]);         res4 += __builtin_popcountll(arr1[3] ^ arr2[3]);         res5 += __builtin_popcountll(arr1[4] ^ arr2[4]);         res6 += __builtin_popcountll(arr1[5] ^ arr2[5]);         res7 += __builtin_popcountll(arr1[6] ^ arr2[6]);         res8 += __builtin_popcountll(arr1[7] ^ arr2[7]);       }       int res = res1 + res2 + res3 + res4 + res5 + res6 + res7 + res8;       for (; c < block; c++, arr1++, arr2++)         res += __builtin_popcountll(arr1[0] ^ arr2[0]);       ans[i] = res + __builtin_popcountll((arr1[0] ^ arr2[0]) &                                           ((1ull << (l & 63)) - 1));       out::write(ans[i]);       out::putc(  n );     }   }   void main() {     char *s1 = new char[200000 + 1];     char *s2 = new char[200000 + 1];     int n, m;     s1[n = 0] = in::getC();     while (isdigit(s1[n])) s1[++n] = in::getc();     s2[m = 0] = in::getC();     while (isdigit(s2[m])) s2[++m] = in::getc();     int q;     in::read(q);     unsigned int *anss = new unsigned int[q];     int *q_x = new int[q];     int *q_y = new int[q];     int *q_len = new int[q];     for (int i = 0; i < q; i++) in::read(q_x[i], q_y[i], q_len[i]);     solve(n, m, q, s1, s2, q_x, q_y, q_len, anss);   }   }  // namespace Game   int main() {     Game::main();     out::flush();     return 0;   }


#include<bits/stdc++.h>   #define N 200100   #define ll long long   using namespace std;   const ll inf=9223372036854775807;   ll n,m;   ll T;   ll a[N];   ll maxx=-inf;   ll ans;   ll anss;   int main(){    cin>>T;    while(T--){     ans=0;     maxx=-inf;     cin>>n;     scanf( %lld ,&a[1]);     for(int i=2;i<=n;i++){      scanf( %lld ,&a[i]);      //maxx=max(maxx,abs(a[i]-a[i-1]));      ans+=abs(a[i]-a[i-1]);     }     anss=ans;     anss=min(anss,ans-abs(a[2]-a[1]));     anss=min(anss,ans-abs(a[n]-a[n-1]));     for(int i=2;i<=n-1;i++){      anss=min(anss,ans-abs(a[i+1]-a[i])-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1]));      //anss=min(anss,ans-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1]));     }     cout<<anss<<endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long n, s1, v1, s2, v2;   long long i, j, k, ans, p, q, m, num;   inline long long cal_1() { return i * v1 + (n - i * s1) / s2 * v2; }   inline long long cal_2() { return i * v2 + (n - i * s2) / s1 * v1; }   inline long long maxn(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   int main() {     cin >> n >> v1 >> v2 >> s1 >> s2;     m = lcm(s1, s2);     num = n / m;     if (num > 0) num--;     if (v1 * s2 >= v2 * s1) {       num = m / s1 * num;       p = (n - num * s1) / s2;       ans = num * v1 + p * v2;       if (s1 >= s2) {         for (i = num; i * s1 <= n; i++) ans = maxn(ans, cal_1());       } else {         for (i = p; i >= 0; i--) ans = maxn(ans, cal_2());       }     } else {       num = m / s2 * num;       p = (n - num * s2) / s1;       ans = num * v2 + p * v1;       if (s2 >= s1) {         for (i = num; i * s2 <= n; i++) ans = maxn(ans, cal_2());       } else {         for (i = p; i >= 0; i--) ans = maxn(ans, cal_1());       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<int, int> arr[100000 + 5];   int main() {     cin >> n;     int L = 0, R = 0;     for (int i = 1; i <= n; i++) {       cin >> arr[i].first >> arr[i].second;       L += arr[i].first;       R += arr[i].second;     }     int ans = abs(L - R);     int id = 0;     for (int i = 1; i <= n; i++) {       if (ans < abs(L - R + 2 * (arr[i].second - arr[i].first))) {         ans = abs(L - R + 2 * (arr[i].second - arr[i].first));         id = i;       }     }     cout << id << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, p;   long long w, d;   int main() {     cin >> n >> p >> w >> d;     long long x, y = -1, z = -1;     for (long long i = p / w; i >= max(p / w - d, (long long)0); i--) {       x = i;       if (p - x * w >= 0 && (p - x * w) % d == 0) {         y = (p - x * w) / d;       }       if (n - x - y >= 0) {         z = n - x - y;       }       if (y != -1 && z != -1) break;     }     if (y != -1 && z != -1 && x + y + z == n)       cout << x <<     << y <<     << z << endl;     else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   #define pb push   #define speed ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)   using namespace std;   typedef long long ll;   typedef long double ld;   typedef vector <ll> vll;   typedef pair<ll,ll> pll;   typedef vector <pair<ll,ll>> vpll;   typedef vector <vll> vvll;   ll n;      int get(int x,int y)   {       int val;       cout<< ?  <<x<<   <<y<<endl;       cin>>val;       return val;   }      int main()   {       speed;       cin>>n;       ll l,h,m,midx,i;       midx=get(1,n);              if(midx>1 && get(1,midx)==midx)       {           l=1;           h=midx-1;                      while(l<h)           {               m=(l+h+1)/2;               i=get(m,midx);               if(i==midx)                   l=m;               else                    h=m-1;           }           cout<< !  <<l<<endl;       }       else       {           l=midx+1;           h=n;                      while(l<h)           {               m=(l+h)/2;               i=get(midx,m);               if(i!=midx)                   l=m+1;               else                   h=m;           }           cout<< !  <<l<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     a %= b;     return gcd(b, a);   }   long long power(long long x, long long y, long long md = 1000000007) {     long long res = 1;     x %= md;     while (y > 0) {       if (y & 1) res = (res * x) % md;       x = (x * x) % md;       y = y >> 1;     }     return res % md;   }   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.second < b.second);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long sum = 0, arr[n];     for (long long i = 0; i < n; i++) {       cin >> arr[i];       sum += arr[i];     }     if (arr[0] > sum / 2) {       cout << 1 <<   n ;       cout << 1 <<   n ;       return 0;     }     long long sum1 = arr[0];     std::vector<long long> v;     v.push_back(1);     for (long long i = 1; i < n; i++) {       if (arr[0] >= (2 * arr[i])) {         sum1 += arr[i];         v.push_back(i + 1);       }     }     if (sum1 > (sum / 2)) {       cout << v.size() <<   n ;       for (long long j = 0; j < v.size(); j++) {         cout << v[j] <<    ;       }       cout <<   n ;     } else {       cout << 0 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   bool check(int n, int l, int v1, int v2, int k, double mid) {     double t0 = (l - v2 * mid) / (v1 - v2);     if (t0 < -eps) return 0;     double tb = mid - t0;     if (tb < -eps) return 0;     double tback = (v2 - v1) * tb / (v2 + v1) + tb;     if (tback + eps < tb) return 0;     return (n - 1) / k * tback + tb < mid + eps &&            (n - 1) / k * (tb - tback) * v2 + tb * v2 < l + eps;   }   int main() {     int n, l, v1, v2, k;     scanf( %d%d%d%d%d , &n, &l, &v1, &v2, &k);     double ll = 0, rr = 1. * l / v1;     for (int i = 1; i <= 100000; i++) {       double mid = (ll + rr) / 2;       if (check(n, l, v1, v2, k, mid))         rr = mid;       else         ll = mid;     }     printf( %.10f , ll);   }


#include <bits/stdc++.h>   using namespace std;   struct LCA {     int logn;     vector<int> depth;     vector<vector<int> > lca;     vector<vector<int> > *edges;     LCA(int n, vector<vector<int> > *edges) {       logn = log(n) / log(2) + 1;       depth.resize(n + 1, 0);       lca.resize(n + 1, vector<int>(logn, 0));       this->edges = edges;       build();     }     void dfs(int u, int p) {       lca[u][0] = p;       for (int i = 1; i < logn; i++) {         lca[u][i] = lca[lca[u][i - 1]][i - 1];       }       depth[u] = depth[p] + 1;       for (auto &v : (*edges)[u]) {         if (p != v) {           dfs(v, u);         }       }     }     int parent(int v, int h) {       for (int i = logn - 1; i >= 0; i--) {         if (h & (1 << i)) {           v = lca[v][i];         }       }       return v;     }     int lessParent(int u, int p) { return parent(u, depth[u] - depth[p] - 1); }     int get(int u, int v) {       if (depth[u] > depth[v]) {         swap(u, v);       }       int h = depth[v] - depth[u];       v = parent(v, h);       if (u == v) {         return u;       }       for (int i = logn - 1; i >= 0; i--) {         if (lca[u][i] != lca[v][i]) {           u = lca[u][i];           v = lca[v][i];         }       }       return lca[u][0];     }     void build() { dfs(1, 0); }   } * lca;   struct GraphBuilder {     enum DIRECT {       UP = 0,       DOWN,     };     int n;     int k;     vector<vector<int> > *e;     vector<pair<int, int> > edges;     set<pair<int, int> > cache;     vector<vector<int> > addedVertices;     vector<vector<int> > deletedVertices;     LCA *lca;     struct Node {       int id;       Node *leftChild;       Node *rightChild;       Node(int v, Node *l, Node *r) {         id = v;         leftChild = l;         rightChild = r;       }     };     vector<pair<Node *, Node *> > root;     GraphBuilder(int m, vector<vector<int> > *e) {       k = 2 * m - 1;       n = 2 * m - 1;       this->e = e;       lca = new LCA(e->size() - 1, e);       addedVertices.resize(e->size());       deletedVertices.resize(e->size());       for (int i = 0; i < m; i++) {         for (int j = 0; j < 2; j++) {           int u, v;           scanf( %d %d , &u, &v);           int p = lca->get(u, v);           if (u != p) {             addedVertices[u].push_back((i << 1) | j);             deletedVertices[lca->lessParent(u, p)].push_back((i << 1) | j);           }           if (v != p) {             addedVertices[v].push_back((i << 1) | j);             deletedVertices[lca->lessParent(v, p)].push_back((i << 1) | j);           }         }       }       root.resize(e->size(), {0, 0});       dfs(1, 0);     }     void dfs(int u, int p) {       for (auto &v : (*e)[u]) {         if (v != p) {           dfs(v, u);           root[u].first = merge(root[u].first, root[v].first, DOWN);           root[u].second = merge(root[u].second, root[v].second, UP);         }       }       for (auto &x : addedVertices[u]) {         if (root[u].first) {           add(x, root[u].first->id);         }         int a = 0;         root[u].first = addVertex(0, n, root[u].first, (x ^ 1), DOWN);         if (root[u].second) {           add(root[u].second->id, (x ^ 1));         }         root[u].second = addVertex(0, n, root[u].second, x, UP);       }       for (auto &x : deletedVertices[u]) {         root[u].first = delVertex(0, n, root[u].first, (x ^ 1), DOWN);         root[u].second = delVertex(0, n, root[u].second, x, UP);         if (root[u].first) {           add(x, root[u].first->id);         }         if (root[u].second) {           add(root[u].second->id, (x ^ 1));         }       }     }     void add(int u, int v) { edges.push_back({u, v}); }     void addEdge(Node *p, int direct) {       if (direct == DOWN) {         if (p->leftChild) {           add(p->id, p->leftChild->id);         }         if (p->rightChild) {           add(p->id, p->rightChild->id);         }       } else {         if (p->leftChild) {           add(p->leftChild->id, p->id);         }         if (p->rightChild) {           add(p->rightChild->id, p->id);         }       }     }     Node *addVertex(int l, int r, Node *p, int v, int direct) {       if (!p) {         p = new Node(0, 0, 0);       }       if (l == r) {         return new Node(v, 0, 0);       } else {         int mid = (l + r) >> 1;         Node *newNode = new Node(++k, p->leftChild, p->rightChild);         if (v <= mid) {           newNode->leftChild = addVertex(l, mid, p->leftChild, v, direct);         } else {           newNode->rightChild = addVertex(mid + 1, r, p->rightChild, v, direct);         }         addEdge(newNode, direct);         return newNode;       }     }     Node *delVertex(int l, int r, Node *p, int v, int direct) {       if (l == r) {         return 0;       } else {         int mid = (l + r) >> 1;         Node *newNode = new Node(++k, p->leftChild, p->rightChild);         if (v <= mid) {           newNode->leftChild = delVertex(l, mid, p->leftChild, v, direct);         } else {           newNode->rightChild = delVertex(mid + 1, r, p->rightChild, v, direct);         }         if (!newNode->leftChild && !newNode->rightChild) {           return 0;         }         addEdge(newNode, direct);         return newNode;       }     }     Node *merge(Node *p1, Node *p2, int direct) {       if (!p1 || !p2) {         return p1 ? p1 : p2;       } else {         Node *left = merge(p1->leftChild, p2->leftChild, direct);         Node *right = merge(p1->rightChild, p2->rightChild, direct);         Node *newNode = new Node(++k, left, right);         addEdge(newNode, direct);         return newNode;       }     }   };   struct SAT {     int n;     vector<int> st;     vector<int> mark;     vector<int> group;     vector<vector<int> > edges;     vector<vector<int> > revEdges;     SAT(int n, vector<pair<int, int> > &e) {       this->n = n + 1;       mark.resize(n + 1, 0);       group.resize(n + 1, 0);       edges.resize(n + 1);       revEdges.resize(n + 1);       for (auto &p : e) {         addEdge(p.first, p.second);       }     }     void addEdge(int u, int v) {       edges[u].push_back(v);       revEdges[v].push_back(u);     }     void dfs1(int u) {       mark[u] = 1;       for (auto &v : edges[u]) {         if (mark[v] == 0) {           dfs1(v);         }       }       st.push_back(u);     }     void dfs2(int u, int k) {       group[u] = k;       for (auto &v : revEdges[u]) {         if (group[v] == 0) {           dfs2(v, k);         }       }     }     void solve() {       for (int i = 0; i < n; i++) {         if (mark[i] == 0) {           dfs1(i);         }       }       int k = 0;       for (int i = st.size() - 1; i >= 0; i--) {         int u = st[i];         if (group[u] == 0) {           k++;           dfs2(u, k);         }       }     }     void answer(int m) {       for (int i = 0; i < 2 * m; i += 2) {         if (group[i] == group[i | 1]) {           printf( NO );           return;         }       }       printf( YES n );       for (int i = 0; i < 2 * m; i += 2) {         printf( %d n , (group[i] > group[i | 1]) ? 1 : 2);       }     }     void print() {       cout <<   nst n ;       for (int x : st) {         cout << x <<     << group[x] <<   n ;       }       cout <<   n ;       for (int i = 0; i < n; i++) {         cout << i <<   :  ;         for (int j : edges[i]) {           cout << j <<    ;         }         cout <<   n ;       }     }   };   int main() {     int n;     scanf( %d , &n);     vector<vector<int> > edges(n + 1);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     int m;     scanf( %d , &m);     GraphBuilder builder(m, &edges);     SAT solver(builder.k, builder.edges);     solver.solve();     solver.answer(m);   }


#include <bits/stdc++.h>   int main() {     int N, L, i, count = 0, vivos = 0;     int vet[1000000];     scanf( %d , &N);     for (i = N - 1; i >= 0; i--) {       scanf( %d , &vet[i]);     }     for (i = 0; i < N; i++) {       if (count == 0) {         count = vet[i];         vivos++;       } else {         count--;         if (vet[i] > count) {           count = vet[i];         }         if (count == 0) {           count = vet[i];         }       }     }     printf( %d n , vivos);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int q, n, m;     cin >> q;     while (q--) {       cin >> n >> m;       string s;       cin >> s;       long long int a[n + 1], b[n + 1], zero = 0, one = 0;       a[0] = 0;       b[0] = 0;       for (long long int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           zero++;         } else {           one++;         }         a[i + 1] = zero;         b[i + 1] = one;       }       set<long long int> se;       long long int f = 1;       for (long long int i = 0; i < n; i++) {         long long int a1 = m + i - 2 * a[i];         long long int k = (zero - one);         if (k == 0) {           if (a1 == 0) f = 0;         } else if (a1 % k == 0) {           long long int a2 = a1 / k;           long long int len = n * a2 + i;           if (len >= 0) se.insert(len);         }       }       if (f) {         cout << se.size() << endl;       } else {         cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       string ch;       cin >> ch;       long long int ans = 0;       int x = 0, y = 0;       set<pair<pair<int, int>, pair<int, int>>> s;       pair<int, int> prev = {0, 0};       for (int i = 0; i < (int)ch.size(); i++) {         if (ch[i] ==  N )           y++;         else if (ch[i] ==  S )           y--;         else if (ch[i] ==  W )           x--;         else           x++;         bool check = false;         if (s.count({prev, {x, y}}) || s.count({{x, y}, prev}))           ans++;         else {           s.insert({prev, {x, y}});           s.insert({{x, y}, prev});           ans += 5;         }         prev = {x, y};       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, x, y, z, A[(1 << 17)], B[(1 << 17)], C[(1 << 17)],       mmp[(1 << 17)], Comb[18][18];   long long O[(1 << 17)], Ans[4][(1 << 17)], S[4][(1 << 17)];   long long powmod(long long x, long long y = 998244353 - 2,                    long long p = 998244353) {     x %= p;     y = (y % (p - 1) + (p - 1)) % (p - 1);     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % p;       x = x * x % p;       y >>= 1;     }     return ans;   }   signed main() {     scanf( %lld%lld%lld%lld%lld , &n, &k, &x, &y, &z);     for (long long i = 0; i < n; i++) {       scanf( %lld%lld%lld , &A[i], &B[i], &C[i]);       B[i] ^= A[i];       C[i] ^= A[i];     }     for (long long i = 0; i <= k; i++)       for (long long j = 0; j <= i; j++)         Comb[i][j] = !j ? 1 : Comb[i - 1][j - 1] + Comb[i - 1][j];     mmp[0] = 1;     for (long long i = 1; i <= k; i++) {       mmp[i] = 1 - (i % 2);       for (long long j = 0; j < i; j++) mmp[i] -= Comb[i][j] * mmp[j];     }     for (long long b1 = 0; b1 < 2; b1++)       for (long long b2 = 0; b2 < 2; b2++) {         memset(O, 0, sizeof O);         for (long long i = 0; i < n; i++) O[(B[i] * b1) ^ (C[i] * b2)]++;         for (long long i = 1; i < (1 << k); i *= 2)           for (long long j = 0; j < (1 << k); j += i + i)             for (long long k = j; k < j + i; k++) O[k] = (O[k] + O[k + i]);         for (long long i = 0; i < (1 << k); i++)           O[i] *= mmp[__builtin_popcount(i)], O[i];         for (long long i = 1; i < (1 << k); i *= 2)           for (long long j = 0; j < (1 << k); j += i + i)             for (long long k = j; k < j + i; k++) O[k + i] = (O[k + i] + O[k]);         memcpy(Ans[b1 * 2 + b2], O, sizeof O);       }     S[0][1] = x - y - z;     S[1][1] = x - y + z;     S[2][1] = x + y - z;     S[3][1] = x + y + z;     for (long long i = 0; i < 4; i++) {       S[i][0] = 1;       for (long long j = 2; j <= n; j++)         S[i][j] = S[i][j - 1] * S[i][1] % 998244353;     }     for (long long i = 0; i < (1 << k); i++) {       long long _00 = Ans[0][i], _01 = Ans[1][i], _10 = Ans[2][i],                 _11 = Ans[3][i];       long long __00 = (_01 + _10 + _11 - _00) / 2;       long long __11 = _11 - __00;       long long __01 = _10 - __00;       long long __10 = _01 - __00;       O[i] = S[0][__11] * S[1][__10] % 998244353 * S[2][__01] % 998244353 *              S[3][__00] % 998244353;     }     long long tot = 0;     for (long long i = 0; i < n; i++) tot ^= A[i];     for (long long i = 1; i < (1 << k); i *= 2)       for (long long j = 0; j < (1 << k); j += i + i)         for (long long k = j; k < j + i; k++) {           long long A = O[k], B = O[k + i];           O[k] = (A + B);           O[k + i] = (A - B);         }     long long r = powmod(1 << k);     for (long long i = 0; i < (1 << k); i++)       printf( %lld  ,              (O[i ^ tot] % 998244353 * r % 998244353 + 998244353) % 998244353);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[1042], cc[1042];   vector<pair<int, int> > path;   vector<pair<int, int> > ans;   map<pair<long long, long long>, pair<int, int> > m;   long long base = 1031, mod = 1000000007LL, mod2 = 1000000009LL;   long long pows[1042] = {1};   pair<long long, long long> h(int a[]) {     long long ret = 0, ret2 = 0;     for (int i = 0; i < n; i++) {       ret *= base;       ret2 *= base;       ret += a[i];       ret2 += a[i];       ret %= mod;       ret2 %= mod2;     }     return make_pair(ret, ret2);   }   bool ok() {     if (m.find(h(arr)) != m.end()) {       return 1;     }     return 0;     for (int i = 1; i <= n; i++) {       if (arr[i - 1] != i) {         return 0;       }     }     return 1;   }   bool f = 0;   void get(int ck) {     if (ans.size()) {       return;     }     if (ck == 2) {       if (ok()) {         ans = path;         ans.push_back(m[h(arr)]);       }       return;     }     for (int s = 0; s < n; s++) {       if (s != 0 && abs(arr[s] - arr[s - 1]) == 1 && s != 1 &&           abs(arr[s - 2] - arr[s - 1]) == 1) {         continue;       }       for (int f = s; f < n; f++) {         if (f != n - 1 && abs(arr[f] - arr[f + 1]) == 1 && f != n - 2 &&             abs(arr[f + 1] - arr[f + 2]) == 1) {           continue;         }         path.push_back(make_pair(s, f));         reverse(arr + s, arr + f + 1);         get(ck + 1);         reverse(arr + s, arr + f + 1);         path.pop_back();         if (ans.size()) {           return;         }       }     }   }   long long ss[1042], ff[1042], revHs[1042][1042];   long long ss2[1042], ff2[1042], revHs2[1042][1042];   long long pows2[1042];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     pows[0] = 1;     pows2[0] = 1;     for (int i = 1; i <= n; i++) {       pows[i] = pows[i - 1] * base % mod;       pows2[i] = pows2[i - 1] * base % mod2;     }     for (int i = 0; i < n; i++) {       cin >> arr[i];       cc[i] = i + 1;     }     ss[0] = 0;     ss2[0] = 0;     for (int i = 1; i <= n; i++) {       ss[i] = ss[i - 1] + i * pows[n - i];       ss2[i] = ss2[i - 1] + i * pows2[n - i];       ss[i] %= mod;       ss2[i] %= mod2;     }     ff[n - 1] = 0;     ff2[n - 1] = 0;     for (int i = n - 2; i >= 0; i--) {       ff[i] = ff[i + 1] + (i + 2) * pows[n - i - 2];       ff2[i] = ff2[i + 1] + (i + 2) * pows2[n - i - 2];       ff[i] %= mod;       ff2[i] %= mod2;     }     for (int s = 0; s < n; s++) {       revHs[s][s] = s + 1;       revHs2[s][s] = s + 1;       for (int f = s + 1; f < n; f++) {         revHs[s][f] = revHs[s][f - 1] + (f + 1) * pows[f - s];         revHs2[s][f] = revHs2[s][f - 1] + (f + 1) * pows2[f - s];         revHs[s][f] %= mod;         revHs2[s][f] %= mod2;       }     }     for (int s = 0; s < n; s++) {       for (int f = s; f < n; f++) {         long long c = ss[s] + revHs[s][f] * pows[n - f - 1] + ff[f];         long long c2 = ss2[s] + revHs2[s][f] * pows2[n - f - 1] + ff2[f];         c %= mod;         c2 %= mod2;         m[make_pair(c, c2)] = make_pair(s, f);       }     }     get(0);     reverse(ans.begin(), ans.end());     path = ans;     int kk = 0;     for (int j = 0; j < path.size(); j++) {       if (path[j].first == path[j].second) {         continue;       }       kk++;     }     cout << kk <<   n ;     for (int j = 0; j < path.size(); j++) {       if (path[j].first == path[j].second) {         continue;       }       cout << path[j].first + 1 <<     << path[j].second + 1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5 + 100000;   int n, m, len_behind, len_front;   struct TREE {     int fg;     int M11[3];   } T[maxn * 4];   inline int L(int &x) { return x << 1; }   inline int R(int &x) { return x << 1 | 1; }   void f_maintain(int root, int len) {     int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1;     T[root].M11[0] = T[a].M11[0];     if (T[root].M11[0] == lena) T[root].M11[0] += T[b].M11[0];     T[root].M11[1] = T[b].M11[1];     if (T[root].M11[1] == lenb) T[root].M11[1] += T[a].M11[1];     T[root].M11[2] = max(T[a].M11[2], T[b].M11[2]);     T[root].M11[2] = max(T[root].M11[2], T[L(root)].M11[1] + T[R(root)].M11[0]);   }   void f_build(int root, int le, int ri) {     T[root].fg = -1;     T[root].M11[0] = T[root].M11[1] = T[root].M11[2] = ri - le + 1;     if (le == ri) return;     int mid = (le + ri) >> 1;     f_build(L(root), le, mid);     f_build(R(root), mid + 1, ri);   }   void f_giveson(int fg, int son, int len) {     T[son].fg = fg;     T[son].M11[0] = T[son].M11[1] = T[son].M11[2] = fg * len;   }   void f_pushdown(int root, int len) {     if (len == 1) return;     int a = L(root), b = R(root), lena = (len + 1) >> 1, lenb = len >> 1;     if (T[root].fg != -1) {       f_giveson(T[root].fg, a, lena);       f_giveson(T[root].fg, b, lenb);       T[root].fg = -1;     }   }   void f_update(int root, int le, int ri, int Mle, int Mri, int fg) {     if (Mle <= le && ri <= Mri) {       f_giveson(fg, root, ri - le + 1);       return;     }     f_pushdown(root, ri - le + 1);     int mid = (le + ri) >> 1;     if (Mle <= mid) f_update(L(root), le, mid, Mle, Mri, fg);     if (Mri > mid) f_update(R(root), mid + 1, ri, Mle, Mri, fg);     f_maintain(root, ri - le + 1);   }   int f_query(int root, int le, int ri, int x) {     if (le == ri) return le;     f_pushdown(root, ri - le + 1);     int mid = (le + ri) >> 1;     if (T[L(root)].M11[2] >= x)       return f_query(L(root), le, mid, x);     else if (T[L(root)].M11[1] + T[R(root)].M11[0] >= x)       return mid - T[L(root)].M11[1] + 1;     return f_query(R(root), mid + 1, ri, x);   }   int one[2][105];   int main() {     char ss[33];     while (scanf( %d %d %d %d , &n, &len_behind, &len_front, &m) + 1) {       f_build(1, 1, n);       memset(one, -1, sizeof one);       int e, t, newlen, leaveid;       for (e = 1; e <= m; e++) {         scanf( %d , &t);         if (t == 1) {           scanf( %d , &newlen);           if ((T[1].M11[0] == n && n >= newlen) ||               (T[1].M11[0] >= newlen + len_front)) {             puts( 0 );             f_update(1, 1, n, 1, newlen, 0);             one[0][e] = 1;             one[1][e] = newlen;             continue;           }           if (T[1].M11[2] >= newlen + len_behind + len_front) {             int x = f_query(1, 1, n, newlen + len_behind + len_front);             printf( %d n , x - 1 + len_behind);             f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0);             one[0][e] = x + len_behind;             one[1][e] = x + len_behind + newlen - 1;             continue;           }           if (T[1].M11[1] >= newlen + len_behind) {             int x = n + 1 - T[1].M11[1];             printf( %d n , x - 1 + len_behind);             f_update(1, 1, n, x + len_behind, x + len_behind + newlen - 1, 0);             one[0][e] = x + len_behind;             one[1][e] = x + len_behind + newlen - 1;             continue;           }           puts( -1 );         } else {           scanf( %d , &leaveid);           if (one[0][leaveid] != -1) {             f_update(1, 1, n, one[0][leaveid], one[1][leaveid], 1);             one[0][leaveid] = one[1][leaveid] = -1;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool SR(int &x) { return scanf( %d , &x) == 1; }   bool SR(long long &x) { return scanf( %lld , &x) == 1; }   bool SR(double &x) { return scanf( %lf , &x) == 1; }   bool SR(char *s) { return scanf( %s , s) == 1; }   bool RI() { return true; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   void SP(const int x) { printf( %d , x); }   void SP(const long long x) { printf( %lld , x); }   void SP(const double x) { printf( %.16lf , x); }   void SP(const char *s) { printf( %s , s); }   void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   const int maxn = 3e3 + 3;   const int second = 200;   struct Node {     static Node mem[maxn], *pmem;     int dep;     Node *fail, *to[2];     int who;     Node() : dep(-1), fail(0), to{NULL, NULL}, who(-1) {}     Node(int _d, int _w) : dep(_d), fail(0), to{NULL, NULL}, who(_w) {}   } Node::mem[maxn], *Node::pmem = Node::mem;   struct AC {     AC() { root = new (Node::pmem++) Node(-1, -1); }     Node *root;     void add(const string &s, int id) {       Node *pt = root;       for (int i = 0; i < int(((int)(s).size())); i++) {         if (!pt->to[s[i] -  a ])           pt->to[s[i] -  a ] = new (Node::pmem++) Node(1 + pt->dep, -1);         pt = pt->to[s[i] -  a ];       }       pt->who = id;     }     void build() {       queue<Node *> q;       q.push(root);       root->fail = root;       while (((int)(q).size())) {         Node *pt = q.front();         q.pop();         for (int i = 0; i < int(2); i++)           if (pt->to[i]) q.push(pt->to[i]);         if (pt->dep == -1) {           for (int i = 0; i < int(2); i++)             if (pt->to[i]) pt->to[i]->fail = root;           for (int i = 0; i < int(2); i++)             if (!pt->to[i]) pt->to[i] = root;         } else {           for (int i = 0; i < int(2); i++)             if (pt->to[i]) {               Node *&cur = pt->to[i]->fail;               for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail)                 ;               if (cur->to[i]) cur = cur->to[i];             }           for (int i = 0; i < int(2); i++)             if (!pt->to[i]) {               Node *&cur = pt->to[i];               for (cur = pt->fail; cur != root && !cur->to[i]; cur = cur->fail)                 ;               if (cur->to[i]) cur = cur->to[i];             }         }       }     }   } ac;   int n, m;   string s[maxn];   void read() {     RI(n, m);     for (int i = 0; i < int(m); i++) {       static char in[maxn];       RI(in);       s[i] = in;     }   }   const int MOD = 1e9 + 7;   string os[maxn];   int sig;   int f[maxn][maxn];   int _c[2][maxn][maxn / second + 1];   int (*prv)[maxn / second + 1], (*cur)[maxn / second + 1];   int big;   int om;   void build() {     om = m;     for (int i = 0; i < int(m); i++) os[i] = s[i];     sort(s, s + m);     m = unique(s, s + m) - s;     sort(s, s + m, [&](const string &a, const string &b) {       return make_pair(((int)(a).size()), a) > make_pair(((int)(b).size()), b);     });     for (big = 0; big < m && ((int)(s[big]).size()) > second; big++)       ;     for (int i = 0; i < int(m); i++) ac.add(s[i], i);     ac.build();     sig = Node::pmem - Node::mem;   }   int ans[maxn];   void sol_big() {     for (int i = 0; i < int(sig); i++) f[1][i] = Node::mem[i].to[0] - Node::mem;     for (int i = 0; i < int(sig); i++) f[2][i] = Node::mem[i].to[1] - Node::mem;     for (int i = (3); i <= int(n); i++)       for (int j = 0; j < int(sig); j++) f[i][j] = f[i - 2][f[i - 1][j]];     prv = _c[0];     cur = _c[1];     for (int i = 0; i < int(sig); i++)       for (int j = 0; j < int(big); j++) {         Node *pt = Node::mem + i;         for (pt = pt->to[0]; pt->who != j && pt->dep != -1; pt = pt->fail)           ;         prv[i][j] = (pt->who == j);       }     for (int i = 0; i < int(sig); i++)       for (int j = 0; j < int(big); j++) {         Node *pt = Node::mem + i;         for (pt = pt->to[1]; pt->who != j && pt->dep != -1; pt = pt->fail)           ;         cur[i][j] = (pt->who == j);       }     for (int _ = (3); _ <= int(n); _++) {       static int tmp[maxn][maxn / second + 1];       auto &m1 = cur, &m2 = prv;       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++)           tmp[i][j] = m1[i][j] + m2[f[_ - 1][i]][j];       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++)           if (tmp[i][j] >= MOD) tmp[i][j] -= MOD;       swap(prv, cur);       for (int i = 0; i < int(sig); i++)         for (int j = 0; j < int(big); j++) cur[i][j] = tmp[i][j];     }     for (int i = 0; i < int(big); i++) ans[i] = cur[0][i];   }   string h[maxn], t[maxn];   int ap[maxn][maxn];   void merge(const string &p, const string &q, int res[]) {     for (int i = 0; i < int(((int)(p).size())); i++) {       Node *pt = ac.root;       for (int j = (i); j <= int(((int)(p).size()) - 1); j++)         pt = pt->to[p[j] -  a ];       for (int j = 0; j < int(((int)(q).size())); j++) {         pt = pt->to[q[j] -  a ];         if (big <= pt->who && pt->who < m &&             pt->dep == (((int)(p).size()) - i) + j)           res[pt->who]++;       }     }     for (int i = (big); i <= int(m - 1); i++)       if (res[i] >= MOD) res[i] -= MOD;   }   void sol_small() {     h[1] =  a ;     h[2] =  b ;     for (int i = (3); i <= int(15); i++) h[i] = h[i - 1] + h[i - 2];     for (int i = (1); i <= int(15); i++) t[i] = h[i];     if (n <= 15) {       for (int j = (big); j <= int(m - 1); j++)         for (size_t o = h[n].find(s[j]); ~o; o = h[n].find(s[j], o + 1)) ans[j]++;     } else {       for (int i = (14); i <= int(15); i++)         for (int j = (big); j <= int(m - 1); j++)           for (size_t o = h[i].find(s[j]); ~o; o = h[i].find(s[j], o + 1))             ap[i][j]++;       for (int i = (14); i <= int(15); i++)         h[i].resize(second), t[i].erase(t[i].begin(), t[i].end() - second);       for (int i = (16); i <= int(n); i++) {         for (int j = (big); j <= int(m - 1); j++)           ap[i][j] = ap[i - 1][j] + ap[i - 2][j];         for (int j = (big); j <= int(m - 1); j++)           if (ap[i][j] >= MOD) ap[i][j] -= MOD;         h[i] = h[i - 1];         t[i] = t[i - 2];         merge(t[i - 1], h[i - 2], ap[i]);       }       for (int i = (big); i <= int(m - 1); i++) ans[i] = ap[n][i];     }   }   void sol() {     sol_big();     sol_small();     for (int i = 0; i < int(om); i++) {       int id = lower_bound(s, s + m, os[i],                            [&](const string &a, const string &b) {                              return make_pair(((int)(a).size()), a) >                                     make_pair(((int)(b).size()), b);                            }) -                s;       PL(ans[id]);     }   }   int main() {     read();     build();     sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string zbor1, zbor2;     cin >> zbor1;     int n, i, j;     n = zbor1.length();     if (n < 10) {       cout <<  NO ;       return 0;     }     for (i = n - 1; i >= n - 10; i--) {       zbor2 = zbor2 + zbor1[i];     }     if (zbor2 ==  SECROFEDOC ) {       cout <<  YES ;       return 0;     }     zbor2.clear();     for (i = 0; i < 10; i++) {       zbor2 = zbor2 + zbor1[i];     }     if (zbor2 ==  CODEFORCES ) {       cout <<  YES ;       return 0;     }     for (i = 0; i < 10; i++) {       zbor2.clear();       for (j = 0; j <= i; j++) {         zbor2 = zbor2 + zbor1[j];       }       for (j = n - 9 + i; j < n; j++) {         zbor2 = zbor2 + zbor1[j];       }       if (zbor2 ==  CODEFORCES ) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int abs(long long int a, long long int b) {     if (a < b) {       return -1 * (a - b);     }     return (a - b);   }   bool comp(long long int a, long long int b) {     if (a > b) {       return true;     }     return false;   }   int main() {     int n, a, b;     cin >> n >> a >> b;     vector<long long int> v;     for (int i = 0; i < n; i++) {       long long int t;       cin >> t;       v.push_back(t);     }     sort(v.begin(), v.end(), comp);     long long int ans = abs(v[n - b], v[n - b - 1]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i, j;     int max = INT_MIN;     cin >> n;     int a[n];     int b[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (j = n - 1; j >= 0; j--) {       if (a[j] <= max) {         b[j] = max + 1 - a[j];       } else {         b[j] = 0;       }       if (max < a[j]) {         max = a[j];       }     }     for (i = 0; i < n; i++) {       cout << b[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1E9 + 7, INF = 2E18 + 5;   const double PI = 2 * acos(0.0);   const long double EPS = 1.0E-14;   long long arr[1000005], arrFreq[1000005], arrAns[1000005];   vector<long long> vec;   int main() {     long long n, m, lcm = 1, sz = 0;     cin >> n >> m;     for (int i = 0; i < n; i++) {       scanf( %lld , &arr[i]);       if (arr[i] <= m) {         arrFreq[arr[i]]++;       }     }     for (int i = 1; i <= m; i++) {       if (!arrFreq[i]) continue;       for (int j = i; j <= m; j += i) {         arrAns[j] += arrFreq[i];       }     }     for (int i = 1; i <= m; i++) {       if (arrAns[i] > sz) {         sz = arrAns[i];         lcm = i;       }     }     for (int i = 0; i < n; i++) {       if (lcm % arr[i] == 0) {         vec.push_back(i + 1);       }     }     cout << lcm <<     << vec.size() <<   n ;     for (int i = 0; i < vec.size(); i++) {       printf( %lld  , vec[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100000;   int n, m;   char a[MAXN], b[MAXN];   int s[MAXN], t[MAXN];   inline int id(int x, int y) {     if (x < 1 || x > n || y < 1 || y > m) return 0;     return (x - 1) * m + y;   }   bool check(int k) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (i - k >= 1 && i + k <= n && j - k >= 1 && j + k <= m &&             s[id(i + k, j + k)] - s[id(i - k - 1, j + k)] -                     s[id(i + k, j - k - 1)] + s[id(i - k - 1, j - k - 1)] ==                 0)           b[id(i, j)] =  X ;         else           b[id(i, j)] =  . ;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         t[id(i, j)] = t[id(i - 1, j)] + t[id(i, j - 1)] - t[id(i - 1, j - 1)] +                       (b[id(i, j)] ==  X );     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int l1 = max(i - k, 1), r1 = min(i + k, n);         int l2 = max(j - k, 1), r2 = min(j + k, m);         if (a[id(i, j)] ==  X  && t[id(r1, r2)] - t[id(l1 - 1, r2)] -                                           t[id(r1, l2 - 1)] +                                           t[id(l1 - 1, l2 - 1)] ==                                       0)           return 0;       }     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %s , a + (i - 1) * m + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         s[id(i, j)] = s[id(i - 1, j)] + s[id(i, j - 1)] - s[id(i - 1, j - 1)] +                       (a[id(i, j)] !=  X );     int l = 0, r = min(n, m);     while (l < r) {       int mid = l + r + 1 >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     printf( %d n , l);     check(l);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) putchar(b[id(i, j)]);       putchar(  n );     }     return 0;   }