#include <bits/stdc++.h>   using namespace std;   int visit[210000];   int ans[210000];   queue<int> q;   int a[210000];   int n;   vector<int> g[210000];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       if (a[i] & 1) {         q.push(i);         visit[i] = 1;       }       if (i - a[i] >= 1) g[i - a[i]].push_back(i);       if (i + a[i] <= n) g[i + a[i]].push_back(i);     }     while (!q.empty()) {       int pos = q.front();       q.pop();       for (auto p : g[pos])         if (!visit[p]) {           q.push(p);           ans[p] = visit[p] = visit[pos] + 1;         }     }     memset((visit), (0), sizeof(visit));     for (int i = 1; i <= n; i++)       if (!(a[i] & 1)) {         q.push(i);         visit[i] = 1;       }     while (!q.empty()) {       int pos = q.front();       q.pop();       for (auto p : g[pos])         if (!visit[p]) {           q.push(p);           ans[p] = visit[p] = visit[pos] + 1;         }     }     for (int i = 1; i <= n; i++) cout << ans[i] - 1 <<    ;     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   const int P = 998244353, INF = 0x3f3f3f3f;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long qpow(long long a, long long n) {     long long r = 1 % P;     for (a %= P; n; a = a * a % P, n >>= 1)       if (n & 1) r = r * a % P;     return r;   }   long long inv(long long first) {     return first <= 1 ? 1 : inv(P % first) * (P - P / first) % P;   }   inline int rd() {     int first = 0;     char p = getchar();     while (p <  0  || p >  9 ) p = getchar();     while (p >=  0  && p <=  9 ) first = first * 10 + p -  0 , p = getchar();     return first;   }   const int N = 1e6 + 10;   int n, m, a[N], w[N], s1, s0;   int in[N];   int dp[55][55][55];   int solve(int a, int w) {     memset(dp, 0, sizeof dp);     dp[0][0][0] = 1;     int ans = 0;     if (a) {       for (int i = 1; i <= m + 1; ++i)         for (int j = 0; j <= i - 1; ++j)           for (int k = 0; k <= j; ++k)             if (dp[i - 1][j][k]) {               int &r = dp[i - 1][j][k];               int now = w + k, tot = s1 + s0 + j - (i - 1 - j),                   p = (long long)now * in[tot] % P;               dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] + (long long)p * r) % P;               now = s1 - w + j - k, p = (long long)now * in[tot] % P;               dp[i][j + 1][k] = (dp[i][j + 1][k] + (long long)p * r) % P;               now = s0 - (i - 1 - j), p = (long long)now * in[tot] % P;               dp[i][j][k] = (dp[i][j][k] + (long long)p * r) % P;               if (i - 1 == m) ans = (ans + (long long)(w + k) * r) % P;             }       return ans;     }     for (int i = 1; i <= m + 1; ++i)       for (int j = 0; j <= i - 1; ++j)         for (int k = 0; k <= min(w, j); ++k)           if (dp[i - 1][j][k]) {             int &r = dp[i - 1][j][k];             int now = w - k, tot = s0 + s1 - j + (i - 1 - j),                 p = (long long)now * in[tot] % P;             dp[i][j + 1][k + 1] = (dp[i][j + 1][k + 1] + (long long)p * r) % P;             now = s1 + (i - 1 - j), p = (long long)now * in[tot] % P;             dp[i][j][k] = (dp[i][j][k] + (long long)p * r) % P;             now = s0 - w - j + k, p = (long long)now * in[tot] % P;             dp[i][j + 1][k] = (dp[i][j + 1][k] + (long long)p * r) % P;             if (i - 1 == m) ans = (ans + (long long)(w - k) * r) % P;           }     return ans;   }   int main() {     in[0] = 1;     for (int i = 1; i <= N - 1; ++i) in[i] = inv(i);     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= n; ++i) {       scanf( %d , w + i);       if (a[i])         s1 += w[i];       else         s0 += w[i];     }     for (int i = 1; i <= n; ++i) printf( %d n , solve(a[i], w[i]));   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int num = 0;     char c = getchar();     if (c ==  - ) return -read();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   inline long long READ() {     long long num = 0;     char c = getchar();     if (c ==  - ) return -READ();     while (c >=  0  && c <=  9 ) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num;   }   struct prob {     long long ss, sl, ts, tl;     long double ps, psl, ptl;     void input() {       cin >> ss >> sl >> ts >> tl >> ps;       ps = 1 - ps;       psl = sl * ps;       ptl = tl * ps;     }   };   int n, t;   prob pr[1007];   inline bool cmp(const prob& a, const prob& b) {     return a.tl * (1 - a.ps) / a.ps < b.tl * (1 - b.ps) / b.ps;   }   inline bool eq(const long double& a, const long double& b) {     return a - b > -1e-16 && a - b < 1e-16;   }   inline bool sm(const long double& a, const long double& b) {     return a - b < -1e-16;   }   inline bool bg(const long double& a, const long double& b) {     return a - b > 1e-16;   }   long double dps[1007][1607], dpt[1007][1607];   int main() {     scanf( %d%d , &n, &t);     for (int i = 1; i <= n; i++) pr[i].input();     sort(pr + 1, pr + n + 1, cmp);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= t; j++) dps[i][j] = -((long long)0x7f7f7f7f7f7f7f7f);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= t; j++) dpt[i][j] = ((long long)0x7f7f7f7f7f7f7f7f);     long double ansa = -((long long)0x7f7f7f7f7f7f7f7f),                 ansb = ((long long)0x7f7f7f7f7f7f7f7f);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= t; j++) {         if (sm(dps[i][j], dps[i][j - 1]) ||             (eq(dps[i][j], dps[i][j - 1]) && bg(dpt[i][j], dpt[i][j - 1]))) {           dps[i][j] = dps[i][j - 1];           dpt[i][j] = dpt[i][j - 1];         }         if (j >= pr[i].ts + pr[i].tl) {           long double wls =               dps[i - 1][j - pr[i].ts - pr[i].tl] + pr[i].ss + pr[i].psl;           long double wlt =               (1 - pr[i].ps) * (dpt[i - 1][j - pr[i].ts - pr[i].tl] + pr[i].ts) +               pr[i].ps * j;           if (sm(dps[i][j], wls) || (eq(dps[i][j], wls) && bg(dpt[i][j], wlt))) {             dps[i][j] = wls;             dpt[i][j] = wlt;           }         }         if (j >= pr[i].ts) {           long double wls = dps[i - 1][j - pr[i].ts] + pr[i].ss;           long double wlt = dpt[i - 1][j - pr[i].ts] + pr[i].ts;           if (sm(dps[i][j], wls) || (eq(dps[i][j], wls) && bg(dpt[i][j], wlt))) {             dps[i][j] = wls;             dpt[i][j] = wlt;           }         }         if (sm(dps[i][j], dps[i - 1][j]) ||             (eq(dps[i][j], dps[i - 1][j]) && bg(dpt[i][j], dpt[i - 1][j]))) {           dps[i][j] = dps[i - 1][j];           dpt[i][j] = dpt[i - 1][j];         }         if (sm(ansa, dps[i][j]) || (eq(ansa, dps[i][j]) && bg(ansb, dpt[i][j]))) {           ansa = dps[i][j];           ansb = dpt[i][j];         }       }     return printf( %.15Lf %.15Lf n , ansa, ansb), 0;   }


#include <bits/stdc++.h>   using namespace std;   long long num[505];   int n;   long long minval = 0x3f3f3f3f3f3f3f3fll;   long long check(int x) {     long long ans = 0;     for (int i = 1; i <= n; i++) {       if (num[i] % x == 0) {         ans += num[i] / x;       } else {         if (num[i] % x + num[i] / x >= x - 1) {           ans += num[i] / x + 1;         } else {           return 0;         }       }     }     return ans;   }   void solve(int x) {     long long t = check(x);     if (t) {       printf( %I64d n , t);       exit(0);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &num[i]);       minval = min(minval, num[i]);     }     long long t = (long long)sqrt(minval);     for (long long i = 1; i <= t; i++) {       solve(minval / i + 1);       solve(minval / i);       solve(minval / i - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double tick() {     static clock_t oldt, newt = clock();     double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;     oldt = newt;     return diff;   }   inline long long int read() {     long long int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long int fastExpo(long long int a, long long int n) {     long long int res = 1;     while (n) {       if (n % 2) res = res * a;       n /= 2;       a = a * a;     }     return res;   }   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   vector<int> v[200010];   int col[200010];   vector<int> l, r;   void dfs(int n, int c) {     col[n] = c;     for (int j : v[n]) {       if (col[j] == -1) dfs(j, 1 - c);     }   }   int main() {     int t = read();     while (t--) {       int n = read(), m = read();       while (m--) {         int a, b;         cin >> a >> b;         v[a].push_back(b);         v[b].push_back(a);       }       for (int i = 1; i <= n; i++) col[i] = -1;       dfs(1, 0);       long long int c1 = 0, c2 = 0;       for (int i = 1; i <= n; i++) {         if (col[i])           c1++;         else           c2++;       }       if (c1 <= n / 2) {         cout << c1 << endl;         for (int i = 1; i <= n; i++)           if (col[i]) cout << i <<    ;       } else {         cout << c2 << endl;         for (int i = 1; i <= n; i++)           if (!col[i]) cout << i <<    ;       }       cout << endl;       for (int i = 1; i <= n; i++) v[i].clear(), col[i] = -1;     }     cerr <<  execution time is:   << tick() <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a[100100];   int main() {     int i, n;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);     int sign = 1;     for (i = 0; i < n; i++) {       if (a[i] >= sign) {         a[i] = sign;         sign++;       }     }     printf( %d n , sign);     return 0;   }


#include<bits/stdc++.h>   typedef int LL;   typedef double dl;   #define opt operator   #define pb push_back   #define pii std::pair<LL,LL>   const LL maxn=2e4+9,mod=998244353,inf=0x3f3f3f3f;   LL Read(){    LL 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<<3ll)+(x<<1ll)+c- 0 ; c=getchar();    }return x*f;   }   void Chkmin(LL &x,LL y){    if(y<x) x=y;   }   void Chkmax(LL &x,LL y){    if(y>x) x=y;   }   LL add(LL x,LL y){    return x+=y,x>=mod?x-mod:x;   }   LL dec(LL x,LL y){    return x-=y,x<0?x+mod:x;   }   LL mul(LL x,LL y){    return 1ll*x*y%mod;   }   LL Pow(LL base,LL b){    LL ret(1); while(b){     if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;    }return ret;   }   const LL Ul=15,Ku=30;   namespace Rmq{    LL lg[maxn];    pii mx[maxn][16];    void Init(LL *A,LL N){     for(LL i=1;i<=N;++i){      mx[i][0]=pii(A[i],i);     }     for(LL i=1;i<=15;++i){      for(LL j=1;j+(1<<i)-1<=N;++j){       mx[j][i]=std::max(mx[j][i-1],mx[j+(1<<i-1)][i-1]);      }     }     for(LL i=1;i<=N;++i) lg[i]=lg[i>>1]+1;    }    LL Query(LL l,LL r){     LL len(lg[r-l+1]-1);     return std::max(mx[l][len],mx[r-(1<<len)+1][len]).second;    }   }   LL n,q;   LL a[maxn],f[16][maxn][31];   void Init(){    n=Read(); q=Read();    for(LL i=1;i<=n;++i){     a[i]=Read();    }    for(LL i=1;i<=n+1;++i){     a[i]+=i;    }   // for(LL i=1;i<=n;++i) printf( %d  ,a[i]-i); puts(  );    Rmq::Init(a,n+1);   // puts( #1 );    for(LL j=0;j<=Ul;++j){     for(LL k=0;k<=Ku;++k) f[j][n+1][k]=n+1;    }   // puts( #2 );    for(LL i=n;i>=1;--i){   //  printf( (%d) n ,i);     for(LL k=0;k<=Ku;++k){      f[0][i][k]=std::min(a[i]+k,n+1);     }     for(LL j=1;j<=Ul;++j){      for(LL k=0;k<=Ku;++k){       LL mx(0);       for(LL k1=k;k1>=0 && mx<n;--k1){        Chkmax(mx,f[j-1][Rmq::Query(i,f[j-1][i][k1])][k-k1]);       }       f[j][i][k]=mx;      }     }    }   }   void Solve(LL l,LL r,LL K){    static LL g[31];    if(l==r){     puts( 0 );     return;    }    Chkmin(K,r-l-1);    for(LL i=0;i<=Ku;++i){     g[i]=std::min(n+1,a[l]+i);    }    LL ret(1);    for(LL i=0;i<=K;++i) if(g[i]>=r){     puts( 1 );     return;    }    for(LL i=Ul;i>=0;--i){     LL flag(0);     static LL h[31];     for(LL k=K;k>=0;--k){      LL mx(0);      for(LL k1=0;k1<=k && mx<r;++k1){       Chkmax(mx,f[i][Rmq::Query(l,g[k1])][k-k1]);      }      h[k]=mx;      if(mx>=r){       flag=1; break;      }     }     if(!flag){      for(LL k=0;k<=Ku;++k) g[k]=h[k];      ret+=(1<<i);     }    }    printf( %d n ,ret+1);   // exit(0);   }   void Solve(){    while(q--){     LL l(Read()),r(Read()),K(Read());     Solve(l,r,K);    }   }   int main(){    Init();    Solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[1001];   long long b[2001];   int main() {     long long n, k, p;     cin >> n >> k >> p;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= k; i++) cin >> b[i];     sort(a + 1, a + n + 1);     sort(b + 1, b + k + 1);     long long ans = (long long)2e15 + 1;     for (int i = 1; i <= k - n + 1; i++) {       long long maks = 0;       for (int j = 1; j <= n; j++) {         maks = max(abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p), maks);       }       ans = min(maks, ans);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s1, s2, t1, t2;     char ch1, ch2;     cin >> s1 >> ch1 >> s2;     cin >> t1 >> ch2 >> t2;     int a = s1 - t1;     int b = s2 - t2;     if (b < 0) {       b += 60;       a--;     }     if (a < 0) {       a += 24;     }     cout << right << setw(2) << setfill( 0 ) << a <<  : ;     cout << right << setw(2) << setfill( 0 ) << b << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 5;   vector<int> g[N];   bool used[N];   int n, m;   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d , &u, &v);       u--, v--;       g[u].push_back(v);     }     for (int i = 0; i < n; i++) {       if (!used[i]) {         for (auto x : g[i]) {           if (x > i) used[x] = true;         }       }     }     for (int i = n - 1; i >= 0; i--) {       if (!used[i]) {         for (auto x : g[i]) {           used[x] = true;         }       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (!used[i]) ans++;     }     printf( %d n , ans);     for (int i = 0; i < n; i++) {       if (!used[i]) printf( %d  , i + 1);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long int n, s, sum = 0, z, count = 0;     scanf( %ld%ld , &n, &s);     z = s;     do {       if (s >= n) {         sum = sum + (s / n) * n;         count = count + (s / n);         s = s - (s / n) * n;       } else         n = n - 1;     } while (s != 0 && n != 0);     printf( %ld , count);     return 0;   }


#include <bits/stdc++.h>   const double EPS = 0.00000001;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int32_t t;     std::cin >> t;     for (int32_t cs = 1; cs <= t; cs++) {       int32_t n, l;       std::cin >> n >> l;       std::vector<int32_t> a(n);       for (auto &x : a) {         std::cin >> x;       }       int32_t indL = 0, indR = n - 1, speed1 = 1, speed2 = 1;       double pos1 = 0, pos2 = l;       double currT = 0.0, ans;       while (1) {         if (indL > indR) {           ans = currT + (pos2 - pos1) / (speed1 + speed2);           break;         }         double t1 = ((double)a[indL] - pos1) / speed1;         double t2 = ((double)pos2 - a[indR]) / speed2;         if (indL == indR) {           if (fabs(t1 - t2) < EPS) {             ans = currT + t1;             break;           }         }         if (t1 < t2) {           indL++;           currT += t1;           speed1++;           pos1 = a[indL - 1];           pos2 -= t1 * speed2;         } else {           indR--;           currT += t2;           speed2++;           pos1 += t2 * speed1;           pos2 = a[indR + 1];         }       }       std::cout << std::fixed << std::setprecision(8);       std::cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {}   const long long maxn = 1050;   long long n, a, b;   long long ans[maxn][maxn];   void no() {     cout <<  NO  <<   n ;     exit(0);   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> b;     if (min(a, b) > 1) no();     if ((n == 2 or n == 3) and a == 1 and b == 1) no();     long long c = 1, d = 0;     if (b != 1) {       swap(a, b);       swap(c, d);     }     for (long long i = 1; i <= n; i++) {       ans[i][i] = 0;       for (long long j = 1; j <= n; j++) {         if (i != j) {           ans[i][j] = ans[j][i] = d;         }       }     }     for (long long i = a; i + 1 <= n; i++) {       ans[i][i + 1] = ans[i + 1][i] = c;     }     cout <<  YES  <<   n ;     for (long long i = 1; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         cout << ans[i][j];       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     int a, b, c;     int sum_a, sum_b, sum_c;     sum_a = 0;     sum_b = 0;     sum_c = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a >> b >> c;       sum_a = sum_a + a;       sum_b = sum_b + b;       sum_c = sum_c + c;     }     if (sum_a == 0 && sum_b == 0 && sum_c == 0) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   const double eps = 1e-6;   const long long _mod = 1000000007LL;   const int save[10][4] = {{0}, {0}, {6, 2, 4, 8}, {1, 3, 9, 7}, {6, 4},                            {0}, {0}, {1, 7, 9, 3}, {6, 8, 4, 2}, {1, 9}};   int todigit(char c) { return (isdigit(c)) ? (c - 48) : c; }   int toint(string s) {     int r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long tolong(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double todouble(string s) {     double r = 0.0;     istringstream sin(s);     sin >> r;     return r;   }   bool bit_check(int k, int p) { return (bool)(k & (1 << p)); }   int bit_set(int k, int p) { return k = (k | (1 << p)); }   template <class T>   string toString(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   template <class T>   T Abs(T x) {     return x > 0 ? x : -x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   template <class T>   inline T max_(T a, T b) {     return a > b ? a : b;   }   template <class T>   inline T min_(T a, T b) {     return a < b ? a : b;   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   int di(string num, int b);   int dig(int num);   int main() {     int a, b;     cin >> a >> b;     int mn = max(dig(a), dig(b));     mn++;     int mx = 0;     for (int i = mn; i < 17; ++i) {       mx = max(mx, di(toString(a + b), i));     }     printf( %d n , mx);     return 0;   }   int di(string num, int b) {     int n = 0;     for (int i = 0; i < num.size(); ++i) {       n = (n * b) + (num[i] -  0 );     }     int cnt = 0;     while (n) {       n = n / b;       ++cnt;     }     return cnt;   }   int dig(int num) {     int mn = 0;     while (num) {       mn = max(mn, num % 10);       num = num / 10;     }     return mn;   }


#include <bits/stdc++.h>   using namespace std;   int n, mem[505][505];   string s;   int dp(int i, int j) {     if (i > j) return 0;     int &ans = mem[i][j];     if (ans != -1) return ans;     ans = dp(i + 1, j) + 1;     for (int k = i + 1; k <= j; k++)       if (s[i] == s[k]) ans = min(ans, dp(i + 1, k - 1) + dp(k, j));     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     memset(mem, -1, sizeof(mem));     cin >> n >> s;     cout << dp(0, n - 1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n][2];     for (int i = 0; i < n; i++) {       cin >> a[i][0] >> a[i][1];     }     int sum1 = 0;     int sum2 = 0;     for (int i = 0; i < n; i++) {       if (abs(sum1 + a[i][0] - sum2) <= 500) {         sum1 += a[i][0];         a[i][0] = -1;       } else {         sum2 += a[i][1];       }     }     if (abs(sum1 - sum2) > 500) {       cout <<  -1 ;     } else {       for (int i = 0; i < n; i++) {         if (a[i][0] == -1) {           cout <<  A ;         } else {           cout <<  G ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, j;     cin >> t;     for (j = 0; j <= t - 1; j++) {       int a, b, c, n;       cin >> a >> b >> n;       n = n % 3;       c = a ^ b;       if (n == 0) {         cout << a << endl;       } else if (n == 1) {         cout << b << endl;       } else {         cout << c << endl;       }     }   }


#include <bits/stdc++.h>   char _;   using namespace std;   int N, C, D;   pair<int, int> A[400000];   long long Z, ZO, ZOZ, O, OZ, OZO;   inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     if ((b.second < 0) ^ (a.second < 0))       return 1LL * a.first * b.second > 1LL * b.first * a.second;     return 1LL * a.first * b.second < 1LL * b.first * a.second;   }   inline bool eq(const pair<int, int>& a, const pair<int, int>& b) {     return 1LL * a.first * b.second == 1LL * b.first * a.second;   }   int main() {     do {       while ((N = getchar()) <  0 )         ;       for (N -=  0 ;  0  <= (_ = getchar()); N = (N << 3) + (N << 1) + _ -  0 )         ;     } while (0);     do {       while ((C = getchar()) <  0 )         ;       for (C -=  0 ;  0  <= (_ = getchar()); C = (C << 3) + (C << 1) + _ -  0 )         ;     } while (0);     do {       while ((D = getchar()) <  0 )         ;       for (D -=  0 ;  0  <= (_ = getchar()); D = (D << 3) + (D << 1) + _ -  0 )         ;     } while (0);     for (int i = 0; i < N; i++) {       do {         while ((A[i].first = getchar()) <  0 )           ;         for (A[i].first -=  0 ;  0  <= (_ = getchar());              A[i].first = (A[i].first << 3) + (A[i].first << 1) + _ -  0 )           ;       } while (0);       do {         while ((A[i].second = getchar()) <  0 )           ;         for (A[i].second -=  0 ;  0  <= (_ = getchar());              A[i].second = (A[i].second << 3) + (A[i].second << 1) + _ -  0 )           ;       } while (0);       A[i].first -= C, A[i].second -= D;     }     sort(A, A + N, cmp);     for (int i = 0, j; i < N; i = j) {       long long NZ = Z, NZO = ZO, NZOZ = ZOZ, NO = O, NOZ = OZ, NOZO = OZO;       for (j = i; j < N && eq(A[i], A[j]); j++) {         if (A[j].second < 0) {           NOZO += OZ;           NZO += Z;           NO++;         } else {           NZOZ += ZO;           NOZ += O;           NZ++;         }       }       Z = NZ, ZO = NZO, ZOZ = NZOZ, O = NO, OZ = NOZ, OZO = NOZO;     }     int L = 0, R = 0, D = 0;     for (int i = 0; i < N; i++)       if (A[i].second == 0) {         if (A[i].first < 0)           L++;         else           R++;       }     for (int i = 0; i < N; i++)       if (A[i].second < 0) D++;     printf( %lld n , OZO + ZOZ - 1LL * L * R * D);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3F3F3F3F;   const int NEGINF = 0xC0C0C0C0;   const double EPS = 1e-8;   int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   string s;   bool test(long long inx) {     int pos = 0;     int m = 0;     int im = 0;     for (auto &x : s) {       if (x ==  R )         pos++;       else         pos--;       if (inx >= 0 && pos == inx) pos--;       if (pos < m) {         m = pos;         im = &x - &(s[0]);       }     }     return im == s.size() - 1;   }   int main() {     cin >> s;     if (s.back() ==  R )       for (auto &x : s) x =  R  +  L  - x;     if (test(-1)) {       cout <<  1 n ;       return 0;     } else if (!test(1)) {       cout <<  0 n ;       return 0;     }     long long m = 1, M = 0x7fffffffffffffffll;     long long ans = 1;     while (M >= m) {       long long med = m + (M - m) / 2;       if (test(med)) {         ans = med;         m = med + 1;       } else         M = med - 1;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[500005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int kk = 1;     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       if (a[i] >= a[kk] * 2) {         ++kk;       }     }     --kk;     kk = min(n / 2, kk);     printf( %d n , n - kk);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int now[30];   char s[maxn];   int num[maxn];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= 30; j++) {         if (s[i] >= now[j]) {           num[i] = j;           now[j] = s[i];           ans = max(ans, j);           break;         }       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) {       printf( %d  , num[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch;     for (ch = getchar(); ch <  0  || ch >  9 ; ch = getchar())       ;     int x = ch -  0 ;     for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar())       x = x * 10 + ch -  0 ;     return x;   }   const int N = 3e5 + 5;   int n, m, q, p[N], u[N], v[N];   struct Graph {     int t[N << 1], nxt[N << 1], lst[N], l;     void add(int x, int y) {       t[++l] = y;       nxt[l] = lst[x];       lst[x] = l;     }     int n, dfn[N], low[N], sta[N], col[N], top, tot, id;     void init(int N) {       n = N;       l = 1;       tot = id = 0;       for (int i = 1; i <= n; i++) col[i] = low[i] = dfn[i] = lst[i] = 0;     }     void tarjan(int x, int y) {       dfn[x] = low[x] = ++tot;       sta[++top] = x;       for (int i = lst[x]; i; i = nxt[i]) {         if (i == y) continue;         if (!dfn[t[i]]) {           tarjan(t[i], i ^ 1);           low[x] = min(low[x], low[t[i]]);         } else           low[x] = min(low[x], dfn[t[i]]);       }       if (dfn[x] == low[x])         for (sta[top + 1] = 0, id++; sta[top + 1] != x; top--) col[sta[top]] = id;     }   } g1, g2;   struct Tree {     int t[N << 1], nxt[N << 1], lst[N], l;     void add(int x, int y) {       t[++l] = y;       nxt[l] = lst[x];       lst[x] = l;     }     int dfn[N], ed[N], dep[N], fa[N][19], tot;     void dfs(int x, int y) {       dfn[x] = ++tot;       fa[x][0] = y;       dep[x] = dep[y] + 1;       for (int i = lst[x]; i; i = nxt[i])         if (t[i] != y) dfs(t[i], x);       ed[x] = tot;     }     void init(int n) {       for (int i = 1; i <= n; i++)         if (!dfn[i]) dfs(i, 0);       for (int j = 1; j <= 18; j++)         for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];     }     int lca(int x, int y) {       if (dep[x] < dep[y]) swap(x, y);       for (int j = 18; j >= 0; j--)         if (dep[fa[x][j]] > dep[y]) x = fa[x][j];       x = dep[x] == dep[y] ? x : fa[x][0];       for (int j = 18; j >= 0; j--)         if (fa[x][j] != fa[y][j]) x = fa[x][j], y = fa[y][j];       return x == y ? x : fa[x][0];     }   } t;   bool cmp(int x, int y) { return t.dfn[x] < t.dfn[y]; }   int sta[N], pr[N], id[N], sz, top;   vector<int> pt;   void build() {     sort(pt.begin(), pt.end(), cmp);     sz = pt.size();     for (int i = 1; i <= sz - 1; i++) {       int x = t.lca(pt[i], pt[i - 1]);       if (x) pt.push_back(x);     }     sort(pt.begin(), pt.end(), cmp);     sz = unique(pt.begin(), pt.end()) - pt.begin();     while (pt.size() > sz) pt.pop_back();     for (int i = 0; i <= sz - 1; i++) pr[pt[i]] = 0;     top = 0;     for (int i = 0; i < sz; i++) {       for (; top && t.ed[sta[top]] < t.dfn[pt[i]]; top--)         ;       if (top) pr[pt[i]] = sta[top];       sta[++top] = pt[i];     }     g2.init(sz);     for (int i = 0; i <= sz - 1; i++) id[pt[i]] = i + 1;     for (int i = 0; i <= sz - 1; i++) {       int x = id[pr[pt[i]]], y = i + 1;       if (x) g2.add(x, y), g2.add(y, x);     }   }   int main() {     n = read();     m = read();     q = read();     g1.init(n);     for (int i = 1; i <= m; i++) {       u[i] = read();       v[i] = read();       g1.add(u[i], v[i]);       g1.add(v[i], u[i]);     }     for (int i = 1; i <= n; i++)       if (!g1.dfn[i]) g1.tarjan(i, 0);     for (int i = 1; i <= m; i++) {       int x = g1.col[u[i]], y = g1.col[v[i]];       if (x != y) t.add(x, y), t.add(y, x);     }     t.init(g1.id);     int cnt = 0;     for (int ty = 1; ty <= q; ty++) {       int nn = read(), mm = read();       pt.clear();       for (int i = 1; i <= nn; i++) {         p[i] = g1.col[(read() + cnt + n - 1) % n + 1];         pt.push_back(p[i]);       }       for (int i = 1; i <= mm; i++) {         u[i] = g1.col[(read() + cnt + n - 1) % n + 1];         v[i] = g1.col[(read() + cnt + n - 1) % n + 1];         pt.push_back(u[i]);         pt.push_back(v[i]);       }       build();       for (int i = 1; i <= mm; i++) {         int x = id[u[i]], y = id[v[i]];         if (x != y) g2.add(x, y), g2.add(y, x);       }       for (int i = 1; i <= sz; i++)         if (!g2.dfn[i]) g2.tarjan(i, 0);       bool ok = 1;       for (int i = 2; i <= nn; i++)         if (g2.col[id[p[i]]] != g2.col[id[p[1]]]) {           ok = 0;           break;         }       if (ok) {         puts( YES );         (cnt += ty) %= n;       } else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200025;   int n, m, i, j, t, k, s, mod, a[maxn], fat[maxn];   bool flg, vis[maxn << 1];   inline int Pow(int x, int y, int mo) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % mo;       x = 1ll * x * x % mo;       y >>= 1;     }     return ret;   }   int father(int x) { return x == fat[x] ? x : fat[x] = father(fat[x]); }   void solve(int delt) {     for (i = 1; i <= n; ++i) fat[i] = i;     for (i = 1; i <= n; ++i) {       k = (a[i] - delt + mod) % mod;       t = lower_bound(a + 1, a + n + 1, k) - a;       if (a[t] == k) fat[father(t)] = father(i);     }     t = 0;     for (i = 1; i <= n; ++i) {       if (fat[i] == i)         t++;       else         fat[i] = i;     }     delt = delt * 1ll * Pow(t, mod - 2, mod) % mod;     for (i = 1; i <= n; ++i) {       k = (a[i] - delt + mod) % mod;       t = lower_bound(a + 1, a + n + 1, k) - a;       if (a[t] == k) fat[father(t)] = father(i);     }     for (i = 2; i <= n; ++i)       if (father(i) ^ father(1)) break;     if (i > n) {       for (i = 1; i <= n; ++i) {         k = (a[i] - delt + mod) % mod;         t = lower_bound(a + 1, a + n + 1, k) - a;         if (a[t] != k) break;       }       if (i > n) {         if (flg)           printf( %d %d n , a[1], delt);         else           t = (1ll * n * delt + a[1]) % mod, printf( %d %d n , t, delt);       } else {         if (flg)           printf( %d %d n , a[i], delt);         else           t = (1ll * n * delt + a[i]) % mod, printf( %d %d n , t, delt);       }       exit(0);     }   }   int main() {     scanf( %d%d , &mod, &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     a[n + 1] = mod + 114514;     if (n == 1 || n == mod) {       printf( %d %d n , a[1], 1);       return 0;     }     if (n == 2) {       printf( %d %d n , a[1], (a[2] - a[1] + mod) % mod);       return 0;     }     sort(a + 1, a + n + 1);     flg = 1;     if (2 * n > mod) {       flg = 0;       for (i = 1; i <= n; ++i) vis[a[i]] = 1;       n = 0;       for (i = 0; i < mod; ++i)         if (!vis[i]) a[++n] = i;       a[n + 1] = mod + 114514;       if (n == 1) {         printf( %d %d n , (a[1] + 1) % mod, 1);         return 0;       }     }     solve(a[2] - a[1]);     solve((a[1] - a[2] + mod) % mod);     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mainstr[111111];   char substr1[111];   char substr2[111];   int main() {     while (scanf( %s %s %s , mainstr, substr1, substr2) != EOF) {       bool flag1 = false, flag2 = false;       int len = strlen(mainstr);       int len1 = strlen(substr1);       int len2 = strlen(substr2);       char *pos = search(mainstr, mainstr + len, substr1, substr1 + len1);       if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2,                                          substr2 + len2) != mainstr + len)         flag1 = true;       reverse(mainstr, mainstr + len);       pos = search(mainstr, mainstr + len, substr1, substr1 + len1);       if (pos != mainstr + len && search(pos + len1, mainstr + len, substr2,                                          substr2 + len2) != mainstr + len)         flag2 = true;       if (flag1 && flag2)         printf( both n );       else if (flag1)         printf( forward n );       else if (flag2)         printf( backward n );       else         printf( fantasy n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double pi = acos(-1);   long long n;   string str;   int main() {     cin >> n >> str;     sort(str.begin(), str.end());     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 10, LG = 20;   int n, h[N], st[N], en[N], par[N][LG], seg[N << 2], lazy[N << 2], TM, ver[N],       ans[N];   vector<int> adj[N];   struct Query {     int l, r, id;     Query(int x = 0, int y = 0, int z = 0) { l = x, r = y, id = z; }   };   vector<Query> query[N];   void dfs(int v) {     st[v] = TM++;     ver[st[v]] = h[v];     for (int i = 1; i < LG; i++) par[v][i] = par[par[v][i - 1]][i - 1];     for (auto u : adj[v])       if (u != par[v][0]) {         par[u][0] = v;         h[u] = h[v] + 1;         dfs(u);       }     en[v] = TM;   }   int k_par(int v, int k) {     for (int i = 0; i < LG; i++)       if (k >> i & 1) v = par[v][i];     return v;   }   int lca(int v, int u) {     if (h[v] < h[u]) swap(v, u);     v = k_par(v, h[v] - h[u]);     if (v == u) return v;     for (int i = LG - 1; i >= 0; i--)       if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];     return par[v][0];   }   int d(int v, int u) { return h[v] + h[u] - 2 * h[lca(v, u)]; }   void build(int l = 0, int r = n, int id = 1) {     if (l + 1 == r) {       seg[id] = ver[l];       return;     }     int mid = l + r >> 1;     build(l, mid, id << 1), build(mid, r, id << 1 | 1);     seg[id] = max(seg[id << 1], seg[id << 1 | 1]);   }   void add(int id, int x) {     seg[id] += x;     lazy[id] += x;   }   void shift(int id) {     add(id << 1, lazy[id]);     add(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   int get(int s, int e, int l = 0, int r = n, int id = 1) {     if (s <= l && e >= r) return seg[id];     if (s >= r || e <= l) return 0;     shift(id);     int mid = l + r >> 1;     return max(get(s, e, l, mid, id << 1), get(s, e, mid, r, id << 1 | 1));   }   void upd(int s, int e, int x, int l = 0, int r = n, int id = 1) {     if (s <= l && e >= r) {       add(id, x);       return;     }     if (s >= r || e <= l) return;     shift(id);     int mid = l + r >> 1;     upd(s, e, x, l, mid, id << 1), upd(s, e, x, mid, r, id << 1 | 1);     seg[id] = max(seg[id << 1], seg[id << 1 | 1]);   }   void dfs_ans(int v) {     for (auto q : query[v]) ans[q.id] = max(ans[q.id], get(q.l, q.r));     for (auto u : adj[v])       if (u != par[v][0]) {         upd(st[u], en[u], -1);         upd(0, st[u], +1);         upd(en[u], n, +1);         dfs_ans(u);         upd(st[u], en[u], +1);         upd(0, st[u], -1);         upd(en[u], n, -1);       }   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1, v, u; i < n; i++) {       cin >> v >> u;       --v, --u;       adj[v].push_back(u);       adj[u].push_back(v);     }     dfs(0);     build();     int Q;     cin >> Q;     for (int i = 0, v, u; i < Q; i++) {       cin >> v >> u;       --v, --u;       if (h[v] < h[u]) swap(v, u);       int dis = d(v, u);       int w = k_par(v, (dis - 1) / 2);       query[v].push_back(Query(st[w], en[w], i));       query[u].push_back(Query(0, st[w], i));       query[u].push_back(Query(en[w], n, i));     }     dfs_ans(0);     for (int i = 0; i < Q; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; ++i) {         cin >> a[i];       }       int ans = 0;       function<void(int, int)> dfs = [&](int p, int s) {         if (p == n) {           if (!s) {             ++ans;           }           return;         }         dfs(p + 1, s - a[p]);         dfs(p + 1, s);         dfs(p + 1, s + a[p]);       };       dfs(0, 0);       cout << (ans >= 2 ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void print(vector<int> v) {     for (int i = 0; i < v.size(); i++) {       if (v[i] != 0) {         cout << v[i];       }     }     cout << endl;   }   void solve(vector<int>& v, int even, int odd) {     if (v.size() == 1) {       cout << -1 << endl;       return;     } else if (v.size() == 2) {       if (odd != 2) {         cout << -1 << endl;         return;       } else {         print(v);         return;       }     } else if (odd == 0) {       cout << -1 << endl;       return;     } else {       while (v[v.size() - 1] % 2 == 0) {         v.pop_back();         even--;       }       if (odd == 1) {         cout << -1 << endl;         return;       } else if (odd % 2 == 0) {         print(v);         return;       } else {         for (int i = 0; i < v.size(); i++) {           if (v[i] % 2 == 1) {             v.erase(v.begin() + i);             print(v);             return;           }         }       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       int e = 0, o = 0;       int n;       cin >> n;       string s;       cin >> s;       vector<int> v(n);       for (int i = 0; i < s.size(); i++) {         v[i] = s[i] - 48;         if (v[i] % 2 == 0)           e++;         else           o++;       }       solve(v, e, o);     }   }


#include <bits/stdc++.h>   using std::max;   using std::min;   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x3f3f3f3f3f3f3f3f;   std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   inline _Tp abs(const _Tp &a) {     return a >= 0 ? a : -a;   }   template <typename _Tp>   inline void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   inline void chmin(_Tp &a, const _Tp &b) {     (b < a) && (a = b);   }   template <typename _Tp>   inline void read(_Tp &x) {     char ch(getchar());     bool f(false);     while (!isdigit(ch)) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     f && (x = -x);   }   template <typename _Tp, typename... Args>   inline void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   inline int read_str(char *s) {     char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     char *tar = s;     *tar++ = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *tar++ = ch, ch = getchar();     return *tar = 0, tar - s;   }   const int max_len = 1 << 18;   const int N = max_len + 9;   const int mod = 998244353;   int _inv_[N];   template <typename _Tp1, typename _Tp2>   inline void add(_Tp1 &a, _Tp2 b) {     (a += b) >= mod && (a -= mod);   }   template <typename _Tp1, typename _Tp2>   inline void sub(_Tp1 &a, _Tp2 b) {     (a -= b) < 0 && (a += mod);   }   template <typename _Tp>   inline _Tp _sub(_Tp a, const _Tp &b) {     (a += mod - b) >= mod && (a -= mod);     return a;   }   long long ksm(long long a, long long b = mod - 2) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod, b >>= 1;     }     return res;   }   void print(const std::vector<int> &a) {     for (auto it : a) printf( %d  , it);     printf(  n );   }   std::vector<int> operator<<(const std::vector<int> &a, unsigned int b) {     std::vector<int> o(a.size() + b);     for (unsigned int i = 0; i < b; ++i) o[i] = 0;     for (unsigned int i = 0; i < a.size(); ++i) o[i + b] = a[i];     return o;   }   inline std::vector<int> operator<<=(std::vector<int> &a, unsigned int b) {     return a = a << b;   }   inline std::vector<int> operator>>(const std::vector<int> &a, unsigned int b) {     return b >= a.size() ? std::vector<int>()                          : std::vector<int>{a.begin() + b, a.end()};   }   inline std::vector<int> operator>>=(std::vector<int> &a, unsigned int b) {     return a = b >= a.size() ? std::vector<int>()                              : std::vector<int>{a.begin() + b, a.end()};   }   std::vector<int> operator+=(std::vector<int> &a, const std::vector<int> &b) {     if (((int)b.size()) > ((int)a.size())) a.resize(((int)b.size()));     for (unsigned int i = 0; i < b.size(); ++i) add(a[i], b[i]);     return a;   }   inline std::vector<int> operator+(const std::vector<int> &a,                                     const std::vector<int> &b) {     std::vector<int> tmp(a);     tmp += b;     return tmp;   }   std::vector<int> operator-=(std::vector<int> &a, const std::vector<int> &b) {     if (((int)b.size()) > ((int)a.size())) a.resize(((int)b.size()));     for (unsigned int i = 0; i < b.size(); ++i) sub(a[i], b[i]);     return a;   }   inline std::vector<int> operator-(const std::vector<int> &a,                                     const std::vector<int> &b) {     std::vector<int> tmp(a);     tmp -= b;     return tmp;   }   int Omgs[N], r[N];   const long long G = ksm(3, (mod - 1) / max_len);   int calc(int len) {     int limit = 1;     while (limit < len) limit <<= 1;     for (int i = 0; i < limit; ++i)       r[i] = (r[i >> 1] >> 1) | ((i & 1) ? (limit >> 1) : 0);     return limit;   }   void setup() {     _inv_[0] = _inv_[1] = 1;     for (int i = 2; i < N; ++i)       _inv_[i] = 1ll * _inv_[mod % i] * (mod - mod / i) % mod;     Omgs[max_len >> 1] = 1;     for (int i = (max_len >> 1) + 1; i < max_len; ++i)       Omgs[i] = 1LL * Omgs[i - 1] * G % mod;     for (int i = (max_len >> 1) - 1; i >= 0; --i) Omgs[i] = Omgs[i << 1];   }   void dft(std::vector<int> &a, int limit) {     static int A[N];     for (int i = 0; i < limit; ++i) A[r[i]] = a[i];     for (int len = 2, hf = 1; len <= limit; len <<= 1, hf <<= 1)       for (int pos = 0; pos < limit; pos += len) {         int *w(Omgs + hf), *p(A + pos), *q(A + pos + hf);         for (int i = 0; i < hf; ++i, ++p, ++q) {           int tmp = 1LL * (*w++) * (*q) % mod;           *q = _sub(*p, tmp), add(*p, tmp);         }       }     for (int i = 0; i < limit; ++i) a[i] = A[i] % mod;   }   void idft(std::vector<int> &a, int limit) {     std::reverse(&a[1], &a[limit]);     dft(a, limit);     unsigned long long inv = mod - (mod - 1) / limit;     for (int i = 0; i < limit; ++i) a[i] = inv * a[i] % mod;   }   std::vector<int> operator*(std::vector<int> a, std::vector<int> b) {     if (a.size() <= 40u || b.size() <= 40u) {       std::vector<int> c(((int)a.size()) + ((int)b.size()) - 1);       for (unsigned int i = 0; i < a.size(); ++i)         for (unsigned int j = 0; j < b.size(); ++j)           add(c[i + j], 1ull * a[i] * b[j] % mod);       return c;     }     int tmp = ((int)a.size()) + ((int)b.size()), limit = calc(tmp);     a.resize(limit), b.resize(limit), dft(a, limit), dft(b, limit);     for (int i = 0; i < limit; ++i) a[i] = 1ull * a[i] * b[i] % mod;     return idft(a, limit), a.resize(tmp - 1), a;   }   std::vector<int> sqr(std::vector<int> a) {     if (a.size() <= 40u) {       std::vector<int> c(((int)a.size()) + ((int)a.size()) - 1);       for (unsigned int i = 0; i < a.size(); ++i)         for (unsigned int j = 0; j < a.size(); ++j)           add(c[i + j], 1ull * a[i] * a[j] % mod);       return c;     }     int tmp = ((int)a.size()) << 1, limit = calc(tmp);     a.resize(limit), dft(a, limit);     for (int i = 0; i < limit; ++i) a[i] = 1ull * a[i] * a[i] % mod;     return idft(a, limit), a.resize(tmp - 1), a;   }   inline std::vector<int> operator*=(std::vector<int> &a,                                      const std::vector<int> &b) {     return a = a * b;   }   template <typename _Tp>   inline std::vector<int> operator*=(std::vector<int> &a, const _Tp &b) {     for (auto &&it : a) it = 1ll * it * b % mod;     return a;   }   template <typename _Tp>   inline std::vector<int> operator*(std::vector<int> a, const _Tp &b) {     return a *= b;   }   template <typename _Tp>   inline std::vector<int> operator*(const _Tp &b, std::vector<int> a) {     return a *= b;   }   template <typename _Tp>   inline std::vector<int> operator/=(std::vector<int> &a, const _Tp &b) {     long long inv = ksm(b);     for (auto &&it : a) it = 1ll * it * inv % mod;     return a;   }   template <typename _Tp>   inline std::vector<int> operator/(std::vector<int> a, const _Tp &b) {     return a /= b;   }   template <typename _Tp>   inline std::vector<int> operator/(const _Tp &b, std::vector<int> a) {     return a /= b;   }   std::vector<int> _inv(const std::vector<int> &F) {     int len = ((int)F.size());     if (len == 1) return {(int)ksm(F[0])};     std::vector<int> H(_inv({F.begin(), F.begin() + (len >> 1)})), tmp(F * H),         ans(H);     tmp = std::vector<int>{tmp.begin() + (len >> 1), tmp.end()} * H;     ans.resize(len);     for (int i = 0; i < len >> 1; ++i)       tmp[i] && (ans[(len >> 1) + i] = mod - tmp[i]);     return ans;   }   std::vector<int> Inv(std::vector<int> F) {     int tmp = ((int)F.size()), L = 1;     for (; L < tmp; L <<= 1)       ;     F.resize(L);     std::vector<int> ans(_inv(F));     return ans.resize(tmp), ans;   }   std::pair<std::vector<int>, std::vector<int> > divide(       const std::vector<int> &f, const std::vector<int> &g) {     int n = ((int)f.size()), m = ((int)g.size());     std::vector<int> F(f), G(g);     std::reverse(F.begin(), F.end()), F.resize(n - m + 1);     std::reverse(G.begin(), G.end()), G.resize(n - m + 1);     std::vector<int> Q(F * Inv(G));     Q.resize(n - m + 1), std::reverse(Q.begin(), Q.end());     std::vector<int> R(f - Q * g);     return R.resize(m - 1), std::make_pair(Q, R);   }   inline std::vector<int> Mod(const std::vector<int> &f,                               const std::vector<int> &g) {     return divide(f, g).second;   }   std::vector<int> _sqrt(const std::vector<int> &F) {     int len = ((int)F.size());     if (len == 1) return {1};     std::vector<int> H(_sqrt({F.begin(), F.begin() + (len >> 1)}));     H.resize(len);     return (H + F * _inv(H)) / 2;   }   std::vector<int> Sqrt(std::vector<int> F) {     int tmp = ((int)F.size()), L = 1;     for (; L < tmp; L <<= 1)       ;     F.resize(L);     std::vector<int> ans(_sqrt(F));     return ans.resize(tmp), ans;   }   std::vector<int> deri(std::vector<int> a) {     for (int i = 0; i + 1 < ((int)a.size()); ++i)       a[i] = 1ll * (i + 1) * a[i + 1] % mod;     return a.pop_back(), a;   }   std::vector<int> inte(std::vector<int> a) {     a.resize(((int)a.size()) + 1);     for (int i = ((int)a.size()) - 1; i >= 1; --i)       a[i] = 1ll * a[i - 1] * _inv_[i] % mod;     return a[0] = 0, a;   }   std::vector<int> Ln(std::vector<int> F) {     std::vector<int> ans(inte(deri(F) * Inv(F)));     return ans.resize(((int)F.size())), ans;   }   std::vector<int> _exp(const std::vector<int> &F) {     int len = ((int)F.size());     if (len == 1) return {1};     std::vector<int> H(_exp({F.begin(), F.begin() + (len >> 1)}));     H.resize(len);     std::vector<int> ans(F - Ln(H));     add(ans[0], 1);     H.resize(len >> 1);     return ans *= H, ans.resize(len), ans;   }   std::vector<int> Exp(std::vector<int> F) {     int tmp = ((int)F.size()), L = 1;     for (; L < tmp; L <<= 1)       ;     F.resize(L);     std::vector<int> ans(_exp(F));     return ans.resize(tmp), ans;   }   std::vector<int> ksm(std::vector<int> a, int b) {     a = Ln(a);     for (auto &&it : a) it = 1ll * it * b % mod;     return Exp(a);   }   long long fac[N], inv[N], ifac[N];   int main() {     setup();     fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;     for (int i = 2; i < N; ++i)       fac[i] = fac[i - 1] * i % mod,       inv[i] = inv[mod % i] * (mod - mod / i) % mod,       ifac[i] = ifac[i - 1] * inv[i] % mod;     int n;     read(n);     std::vector<int> H(n + 5);     for (int i = 0; i < n + 5; ++i) H[i] = i & 1 ? mod - inv[i + 1] : inv[i + 1];     H = Inv(H);     std::vector<int> tp(Inv((std::vector<int>{1} - H) >> 1)), tmp(ksm(H, n + 1)),         B(tmp * tp);     B.resize(n + 5);     std::vector<int> A(deri(H) * B);     A.resize(n + 5), A *= tp, A.resize(n + 5);     std::vector<int> C(n + 5);     for (int i = 0; i <= n; ++i)       C[i] = 1LL * inv[n + 1] *              ((A[i + 1] + 1LL * B[i + 1] * (n - i + 1)) % mod) % mod;     std::vector<int> D(n + 5);     for (int i = 2; i < n + 5; ++i) D[i - 2] = mod - ifac[i];     D = Inv(D) >> 1;     std::vector<int> F(D - C);     sub(F[0], 1), F.resize(n + 1);     for (int i = 0; i < ((int)F.size()); ++i) F[i] = fac[i] * F[i] % mod;     std::vector<int> G(n + 5);     for (int i = 0; i <= n; ++i) G[n - i] = i & 1 ? mod - ifac[i] : ifac[i];     F *= G;     for (int i = 0; i < n; ++i)       printf( %lld%c , 1LL * fac[n] * ifac[i] % mod * F[i + n] % mod,                 n [i == n]);     return 0;   }


#include <bits/stdc++.h>   const long long N = 200200;   const long long Q = 100100;   const long long mod = 998244353;   const long long block = 500;   using namespace std;   string s;   int cnt;   bool t;   void solve() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) {         t = 1;       } else if (t) {         cnt++;       }     }     if (cnt >= 6) {       cout <<  yes             <<   n ;     } else {       cout <<  no             <<   n ;     }   }   bool mtest = false;   int main() {     ios_base::sync_with_stdio(0);     int TE = 1;     if (mtest) cin >> TE;     while (TE--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int N;   int a[MAXN];   vector<int> lol;   int main(int argc, char *argv[]) {     scanf( %d , &N);     int p = 1;     while (p < MAXN) {       lol.push_back(p);       p <<= 1;     }     for (int i = 0, _i = N; i < _i; ++i) {       scanf( %d , a + i);     }     long long ans = 0;     for (int i = 0, _i = N - 1; i < _i; ++i) {       ans += a[i];       cout << ans <<   n ;       a[i + *(--upper_bound(lol.begin(), lol.end(), N - i - 1))] += a[i];       a[i] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void display(vector<int> &a) {     for (int z : a) cout << z <<    ;     cout << endl;   }   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   const int mod = 998244353;   const long long INF64 = 3e18;   void smxl(long long &a, long long b) {     if (a < b) a = b;   }   void smnl(long long &a, long long b) {     if (a > b) a = b;   }   void adsl(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   void misl(long long &a, long long b) {     a -= b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   void smx(long long &a, long long b) {     if (a < b) a = b;   }   void smn(long long &a, long long b) {     if (a > b) a = b;   }   void ads(long long &a, long long b) {     a += b;     if (a >= mod) a -= mod;   }   void mis(long long &a, long long b) {     a -= b;     if (a >= mod) a -= mod;     if (a < 0) a += mod;   }   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long egcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = egcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long mbinp(long long a, long long b) {     a %= mod;     if (b == 0) return 1;     long long ans = mbinp(a, b / 2);     long long tmp = (ans * ans) % mod;     if (b % 2) return ((tmp * a) % mod);     return ((tmp) % mod);   }   long long binp(long long a, long long b) {     if (b == 0) return 1;     long long ans = binp(a, b / 2);     long long tmp = (ans * ans);     if (b % 2) return ((tmp * a));     return ((tmp));   }   long long C(int n, int m) {     long long ret = 1;     for (int i = 1; i <= m; i++) {       ret *= (n - i + 1);       ret /= i;     }     return ret;   }   long long overbinp(long long a, int b) {     long long res = 1;     while (b) {       if (b & 1) {         if (res < INF64 / a)           res *= a;         else           return INF64;       }       if (b > 1) {         if (a < INF64 / a)           a *= a;         else           return INF64;       }       b >>= 1;     }     return res;   }   class DSU {     vector<int> par;     vector<int> siize;       public:     DSU(int n) {       par.resize(n);       siize.resize(n);       for (int i = 0; i < n; i++) {         par[i] = i;         siize[i] = 1;       }     }       public:     int get(int x) { return (x == par[x] ? x : par[x] = get(par[x])); }       public:     void merge(int a, int b) {       int x = get(a);       int y = get(b);       if (x == y) return;       if (siize[x] < siize[y]) swap(x, y);       par[y] = x;       siize[x] += siize[y];     }   };   class BinaryLift {     vector<vector<int> > binlift;     int n;       public:     BinaryLift(vector<int> rnk, vector<int> par) {       n = (int)par.size();       binlift.resize(n);       for (int i = 0; i < n; i++) binlift[i].resize(20);       for (int i = 0; i < n; i++) binlift[i][0] = par[i];       for (int j = 1; j < 20; j++)         for (int i = 0; i < n; i++) {           if ((1 << j) < rnk[i])             binlift[i][j] = binlift[binlift[i][j - 1]][j - 1];           else             binlift[i][j] = -1;         }     }       public:     int get_kth_ancestor(int x, int k) {       int pt = x;       for (int i = 19; i >= 0; i--) {         if (pt == -1) exit(0);         if (k & (1 << i)) pt = binlift[pt][i];       }       return pt;     }       public:     int get_th_ancestor(int x, int k) {       int pt = x;       for (int i = 19; i >= 0; i--) {         if (k & (1 << i)) pt = binlift[pt][i];       }       return pt;     }   };   class SparseTable2D {     vector<vector<vector<vector<int> > > > sparse;     vector<vector<int> > inp;     int m, n;       private:     int lg2(int x) {       int out = 0;       while ((1 << out) <= x) out++;       return out - 1;     }       public:     int rmin(int x1, int y1, int x2, int y2) {       int lenx = x2 - x1 + 1;       int lx = lg2(lenx) + 1;       int leny = y2 - y1 + 1;       int ly = lg2(leny) + 1;       return min(           min(sparse[lx][x1][ly][y1], sparse[lx][x1][ly][y2 + 1 - (1 << ly)]),           min(sparse[lx][x2 + 1 - (1 << lx)][ly][y1],               sparse[lx][x2 + 1 - (1 << lx)][ly][y2 + 1 - (1 << ly)]));     }       public:     SparseTable2D(vector<vector<int> > input, string param) {       n = input.size();       m = input[0].size();       inp = input;       if (param ==  min ) prepromin();     }       private:     void prepromin() {       int lln, lm;       lln = lg2(n) + 1;       lm = lg2(m) + 1;       sparse.resize(lln);       for (int i = 0; i < lln; i++) sparse[i].resize(n);       for (int i = 0; i < lln; i++)         for (int j = 0; j < n; j++) sparse[i][j].resize(lm);       for (int i = 0; i < lln; i++)         for (int j = 0; j < n; j++)           for (int k = 0; k < lm; k++) sparse[i][j][k].resize(m);       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) sparse[0][i][0][j] = inp[i][j];         for (int j = 1; j < lm; j++)           for (int k = 0; k + (1 << j) - 1 < m; k++)             sparse[0][i][j][k] = min(sparse[0][i][j - 1][k],                                      sparse[0][i][j - 1][k + (1 << (j - 1))]);       }       for (int i = 1; i < lln; i++)         for (int j = 0; j + (1 << i) - 1 < n; j++)           for (int k = 0; k < lm; k++)             for (int h = 0; h < m; h++)               sparse[i][j][k][h] = min(sparse[i - 1][j][k][h],                                        sparse[i - 1][j + (1 << (i - 1))][k][h]);     }   };   class SparseTable {     vector<vector<long long> > sparse;     int n;     vector<int> input;       private:     int lg2(int x) {       int out = 0;       while ((1 << out) <= x) out++;       return out - 1;     }       public:     int rmaxpos(int left, int right) {       int len = right - left + 1;       int lg = lg2(len);       return (input[sparse[left][lg]] > input[sparse[left + len - (1 << lg)][lg]]                   ? sparse[left][lg]                   : sparse[left + len - (1 << lg)][lg]);     }       public:     int rmaxval(int left, int right) {       int len = right - left + 1;       int lg = lg2(len);       return (input[sparse[left][lg]] > input[sparse[left + len - (1 << lg)][lg]]                   ? input[sparse[left][lg]]                   : input[sparse[left + len - (1 << lg)][lg]]);     }       public:     int rminpos(int left, int right) {       int len = right - left + 1;       int lg = lg2(len);       return (input[sparse[left][lg]] < input[sparse[left + len - (1 << lg)][lg]]                   ? sparse[left][lg]                   : sparse[left + len - (1 << lg)][lg]);     }       public:     int rminval(int left, int right) {       int len = right - left + 1;       int lg = lg2(len);       return (input[sparse[left][lg]] < input[sparse[left + len - (1 << lg)][lg]]                   ? input[sparse[left][lg]]                   : input[sparse[left + len - (1 << lg)][lg]]);     }       public:     long long rsum(int left, int right) {       long long ans = 0;       int pos;       while (left <= right) {         for (int i = 19; i >= 0; i--)           if ((1 << i) <= right - left + 1) {             pos = i;             break;           }         ans += sparse[left][pos];         left = left + (1 << pos);       }       return ans;     }       public:     SparseTable(vector<int> inp, string operation) {       input = inp;       n = inp.size();       if (operation ==  min )         prepromin();       else if (operation ==  max )         prepromax();       else if (operation ==  sum )         preprosum();     }       private:     void prepromin() {       sparse.resize(n);       int x = lg2(n) + 1;       for (int i = 0; i < n; i++) sparse[i].resize(x);       for (int i = 0; i < n; i++) sparse[i][0] = i;       for (int j = 1; j < x; j++)         for (int i = 0; i + (1 << (j)) - 1 < n; i++)           sparse[i][j] =               (input[sparse[i][j - 1]] < input[sparse[i + (1 << (j - 1))][j - 1]]                    ? sparse[i][j - 1]                    : sparse[i + (1 << (j - 1))][j - 1]);     }     void prepromax() {       sparse.resize(n);       int x = lg2(n) + 1;       for (int i = 0; i < n; i++) sparse[i].resize(x);       for (int i = 0; i < n; i++) sparse[i][0] = i;       for (int j = 1; j < x; j++)         for (int i = 0; i + (1 << (j)) - 1 < n; i++)           sparse[i][j] =               (input[sparse[i][j - 1]] > input[sparse[i + (1 << (j - 1))][j - 1]]                    ? sparse[i][j - 1]                    : sparse[i + (1 << (j - 1))][j - 1]);     }     void preprosum() {       sparse.resize(n);       int x = lg2(n) + 1;       for (int i = 0; i < n; i++) sparse[i].resize(x);       for (int i = 0; i < n; i++) sparse[i][0] = input[i];       for (int j = 1; j < x; j++)         for (int i = 0; i + (1 << (j)) - 1 < n; i++)           sparse[i][j] = sparse[i][j - 1] + sparse[i + (1 << (j - 1))][j - 1];     }   };   class Vector {    public:     pair<long long, long long> x;       public:     Vector(pair<long long, long long> a, pair<long long, long long> b) {       x.first = b.first - a.first;       x.second = b.second - a.second;     }       public:     long double getMagnitude() {       return sqrtl(x.first * x.first + x.second * x.second);     }   };   class Line {    public:     pair<long long, long long> x, y;       public:     Line(pair<long long, long long> a, pair<long long, long long> b) {       x = a;       y = b;     }       private:     long double dotProduct(Vector a, Vector b) {       return a.x.first * b.x.first + a.x.second * b.x.second;     }       private:     long double crossProduct(Vector a, Vector b) {       return a.x.first * b.x.second - a.x.second * b.x.first;     }       private:     long double magnitude(Vector a) { return a.getMagnitude(); }       public:     long double distanceToA(pair<long long, long long> c) {       return dotProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y));     }       public:     long double orthogonalDistance(pair<long long, long long> c) {       return crossProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y));     }       public:     pair<long double, long double> intersection(Line l) {       pair<long double, long double> ans;       ans.first = (long double)((x.first * y.second - x.second * y.first) *                                     (l.x.first - l.y.first) -                                 (x.first - y.first) * (l.x.first * l.y.second -                                                        l.x.second * l.y.first)) /                   ((x.first - y.first) * (l.x.second - l.y.second) -                    (x.second - y.second) * (l.x.first - l.y.first));       ans.second =           (long double)((x.first * y.second - x.second * y.first) *                             (l.x.second - l.y.second) -                         (x.second - y.second) *                             (l.x.first * l.y.second - l.x.second * l.y.first)) /           ((x.first - y.first) * (l.x.second - l.y.second) -            (x.second - y.second) * (l.x.first - l.y.first));       return ans;     }   };   class PruferCode {     vector<int> code;     vector<pair<int, int> > edges;       public:     PruferCode(vector<int> cc) {       code = cc;       findEdges();     }       private:     void findEdges() {       map<int, int> mp;       set<int> has;       set<int> wait;       for (int z : code) {         mp[z]++;         has.insert(z);       }       for (int i = 0; i < code.size() + 2; i++)         if (!has.count(i)) wait.insert(i);       for (int i = 0; i < code.size(); i++) {         int now = *wait.begin();         edges.push_back(make_pair(now, code[i]));         mp[now]++;         mp[code[i]]--;         if (mp[code[i]] == 0) {           has.erase(code[i]);           wait.insert(code[i]);         }         wait.erase(now);       }       assert(wait.size() == 2);       edges.push_back(make_pair(*wait.begin(), *wait.rbegin()));     }       public:     vector<pair<int, int> > getEdges() { return edges; }   };   class Segment {     pair<long long, long long> x, y;       public:     Segment(pair<long long, long long> a, pair<long long, long long> b) {       x = a;       y = b;     }       private:     long double dotProduct(Vector a, Vector b) {       return a.x.first * b.x.first + a.x.second * b.x.second;     }       private:     long double crossProduct(Vector a, Vector b) {       return a.x.first * b.x.second - a.x.second * b.x.first;     }       private:     long double magnitude(Vector a) { return a.getMagnitude(); }       public:     long double distanceToA(pair<long long, long long> c) {       return dotProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y));     }       public:     long double distanceToSegment(pair<long long, long long> c) {       if (distanceToA(c) >= 0 && distanceToA(c) <= magnitude(Vector(x, y)))         return crossProduct(Vector(x, y), Vector(x, c)) / magnitude(Vector(x, y));       else         return min(magnitude(Vector(x, c)), magnitude(Vector(y, c)));     }   };   class HopcroftKarp {     vector<int> matched;     vector<vector<pair<int, int> > > adj;     int left;     int right;       public:     HopcroftKarp(vector<vector<pair<int, int> > > inp, int l, int r) {       adj = inp;       left = l;       matched.resize(l);       for (int i = 0; i < l; i++) matched[i] = -1;       right = r;     }       public:     vector<int> match() {       bool cont = true;       set<int> lfree, rfree;       for (int i = 0; i < left; i++) lfree.insert(i);       for (int i = left; i < left + right; i++) rfree.insert(i);       vector<bool> yet(left, 0);       for (int i = 0; i < left; i++)         for (int j = 0; j < adj[i].size(); j++)           if (adj[i][j].second == 1 && rfree.count(adj[i][j].first) && !yet[i]) {             yet[i] = true;             matched[i] = adj[i][j].first;             adj[i][j].second = 2;             for (int x = 0; x < adj[adj[i][j].first].size(); x++)               if (adj[adj[i][j].first][x].first == i)                 adj[adj[i][j].first][x].second = 2;             rfree.erase(adj[i][j].first);             lfree.erase(i);           }       while (cont) {         vector<int> par(left + right, -1);         queue<pair<int, int> > kyou;         for (int z : lfree) kyou.push(make_pair(z, 0));         int update = -1;         vector<int> vis(left + right, 0);         while (kyou.size()) {           pair<int, int> frt = kyou.front();           kyou.pop();           if (rfree.count(frt.first)) {             update = frt.first;             break;           }           if (frt.second == 0) {             for (pair<int, int> z : adj[frt.first]) {               if (z.second == 1 && !vis[z.first]) {                 par[z.first] = frt.first;                 vis[z.first] = 1;                 kyou.push(make_pair(z.first, 1));               }             }           } else {             for (pair<int, int> z : adj[frt.first]) {               if (z.second == 2 && !vis[z.first]) {                 par[z.first] = frt.first;                 vis[z.first] = 1;                 kyou.push(make_pair(z.first, 0));               }             }           }         }         int x = update;         int cnt = 0;         while (x != -1 && par[x] != -1) {           for (int i = 0; i < adj[x].size(); i++)             if (adj[x][i].first == par[x]) {               adj[x][i].second = (cnt == 0 ? 2 : 1);               if (cnt == 0) {                 matched[par[x]] = x;                 rfree.erase(x);                 lfree.erase(par[x]);               }             }           for (int i = 0; i < adj[par[x]].size(); i++)             if (adj[par[x]][i].first == x)               adj[par[x]][i].second = (cnt == 0 ? 2 : 1);           cnt++;           cnt %= 2;           x = par[x];         }         if (update == -1) cont = false;       }       return matched;     }   };   class Triangle {     pair<long long, long long> x, y, z;       public:     Triangle(pair<long long, long long> a, pair<long long, long long> b,              pair<long long, long long> c) {       x = a;       y = b;       z = c;     }       private:     long double crossProduct(Vector a, Vector b) {       return a.x.first * b.x.second - a.x.second * b.x.first;     }       public:     long double perimeter() {       long double s1, s2, s3;       s1 = Vector(x, y).getMagnitude();       s2 = Vector(y, z).getMagnitude();       s3 = Vector(x, z).getMagnitude();       return s1 + s2 + s3;     }       public:     long double area() { return abs(crossProduct(Vector(x, y), Vector(x, z))); }   };   class SuffixArray {     vector<int> order;     vector<int> lcp;     string str;       public:     SuffixArray(string in) {       str = in;       str +=  $ ;       order.resize(str.length());       lcp.resize(str.length());       compute();     }     void compute() {       vector<pair<char, int> > a;       vector<int> equi(order.size());       vector<int> bij(order.size());       for (int i = 0; i < str.length(); i++) a.push_back(make_pair(str[i], i));       sort(a.begin(), a.end());       for (int i = 0; i < str.length(); i++) order[i] = a[i].second;       equi[order[0]] = 0;       int r = 0;       for (int i = 1; i < str.length(); i++) {         if (a[i].first == a[i - 1].first)           equi[order[i]] = r;         else           equi[order[i]] = ++r;       }       int k = 0;       while ((1 << k) < str.length()) {         vector<pair<pair<int, int>, int> > a(str.length());         for (int i = 0; i < str.length(); i++)           a[i] = make_pair(               make_pair(equi[i], equi[(i + (1 << k)) % (str.length())]), i);         sort(a.begin(), a.end());         for (int i = 0; i < str.length(); i++) {           order[i] = a[i].second;           bij[order[i]] = i;         }         int r = 0;         equi[order[0]] = 0;         for (int i = 1; i < str.length(); i++) {           if (a[i].first == a[i - 1].first)             equi[order[i]] = r;           else             equi[order[i]] = ++r;         }         k++;       }       k = 0;       for (int i = 0; i < str.length() - 1; i++) {         int p = bij[i];         int j = order[p - 1];         while (i + k < str.length() && j + k < str.length() &&                str[i + k] == str[j + k])           k++;         lcp[p] = k;         k = max(k - 1, 0);       }     }       public:     int count(string ptr) {       int low = 0;       int hi = str.length() - 1;       int res1, res2;       res1 = 0;       res2 = 1e9;       while (low <= hi) {         int mid = (low + hi) / 2;         bool gr = false;         int i = 0;         for (i; i < min(ptr.length(), str.length() - order[mid]); i++) {           if (ptr[i] != str[order[mid] + i]) {             if (ptr[i] > str[order[mid] + i]) gr = true;             break;           }         }         if (i == ptr.length()) {           res2 = min(res2, mid);           hi = mid - 1;         } else if (!gr)           hi = mid - 1;         else           low = mid + 1;       }       low = 0;       hi = str.length() - 1;       while (low <= hi) {         int mid = (low + hi) / 2;         bool gr = false;         int i = 0;         for (i; i < min(ptr.length(), str.length() - order[mid] + 1); i++) {           if (ptr[i] != str[order[mid] + i]) {             if (ptr[i] > str[order[mid] + i]) gr = true;             break;           }         }         if (i == ptr.length()) {           res1 = max(res1, mid);           low = mid + 1;         } else if (!gr)           hi = mid - 1;         else           low = mid + 1;       }       if (res2 == 1e9) return 0;       return (res1 - res2 + 1);     }       public:     vector<int> get() { return order; }       public:     vector<int> getLcp() { return lcp; }       public:     long long diffSubstrings() {       long long out = 0;       for (int i = 1; i < str.length(); i++)         out += str.length() - order[i] - lcp[i] - 1;       return out;     }   };   string longestCommonSubstring(string a, string b) {     int len = 0;     string res = a +  %  + b;     SuffixArray sf = SuffixArray(res);     vector<int> order = sf.get();     vector<int> lcp = sf.getLcp();     vector<int> col(order.size());     for (int i = 0; i < order.size(); i++) {       if (order[i] < a.length())         col[order[i]] = 1;       else if (order[i] > a.length())         col[order[i]] = 2;     }     int pos = -1;     for (int i = 1; i < order.size(); i++)       if (col[order[i]] + col[order[i - 1]] == 3) {         if (lcp[i] > len) {           len = max(len, lcp[i]);           pos = (col[order[i]] == 1 ? order[i] : order[i - 1]);         }       }     return a.substr(pos, len);   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> all(n);     vector<int> bij(n + 1);     set<int> st;     for (int i = 0; i < n; i++) {       cin >> all[i];       bij[all[i]] = i;       st.insert(i);     }     set<int> b;     vector<int> bb(k);     for (int i = 0; i < k; i++) {       int x;       cin >> x;       bb[i] = x;       b.insert(x);     }     long long ans = 1;     for (int i = 0; i < k; i++) {       int pos = bij[bb[i]];       auto t = st.find(pos);       auto m = t;       m++;       if (t == st.begin()) {         auto r = t;         r++;         if (b.count(all[*r])) {           cout << 0 <<   n ;           return;         } else {           st.erase(*r);         }       } else if (m == st.end()) {         auto r = t;         r--;         if (b.count(all[*r])) {           cout << 0 <<   n ;           return;         } else           st.erase(*r);       } else {         auto r = t;         auto q = t;         r++;         q--;         if (!b.count(all[*r]) && !b.count(all[*q])) {           ans *= 2;           ans %= mod;           st.erase(*r);         } else if (!b.count(all[*r]))           st.erase(*r);         else if (!b.count(all[*q]))           st.erase(*q);         else {           cout << 0 <<   n ;           return;         }       }       b.erase(bb[i]);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   long long cap[200005];   int n, m;   inline long long tri(int n) { return n * (n + 1LL) / 2; }   inline long long arithsum(int a, int d, int n) {     long long ret = a * (long long)n;     ret += tri(n - 1) * d;     return ret;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %lld , &cap[i]);     }     long long ret = 0;     for (int rep = 1; (rep)*n <= m; rep++) {       long long total = 0;       bool bad = false;       long long currVal = min(arithsum(m, -n, rep), cap[n - 1]);       for (int i = 0; i < n; i++) {         currVal = min(currVal, cap[i] + m - rep * (i + 1));       }       for (int i = n - 1; !bad && i >= 0; i--) {         total += currVal;         if (i > 0) {           long long drop = currVal - cap[i - 1];           if (drop > m - rep) bad = true;           currVal = min(currVal - rep, cap[i - 1]);         }       }       long long lowFirst = arithsum(1, n, rep);       if (!bad && currVal >= lowFirst) {         ret = max(ret, total);       }     }     printf( %lld n , ret);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, s, x;     cin >> t >> s >> x;     int tmp = x - t;     if ((tmp % s == 0 || tmp % s == 1) && tmp >= 0 && tmp != 1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   struct edge {     int v, next;   };   int ans, ans2, f[1005][1 << 12];   int Pow(int a, int b) {     int rec = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) rec = 1ll * rec * a % mod;     return rec;   }   struct nade {     int head[1005], edgenum, d[1005][1005], num[1005], sta[1005], n;     edge e[1005 << 1];     void add(int u, int v) {       e[++edgenum] = edge{v, head[u]};       head[u] = edgenum;     }     void dfs(int u, int fa) {       num[u] = sta[u] = 0;       for (int i = head[u], v; i; i = e[i].next)         if ((v = e[i].v) ^ fa) {           dfs(d[u][num[u]++] = v, u);           sta[u] |= 1 << v - 1;         }     }   } s, t;   int dfs(int u, int i, int sta) {     if (!i) return !sta;     int &rec = f[s.d[u][i - 1]][sta];     if (rec != -1) return rec;     rec = dfs(u, i - 1, sta);     for (int v = s.d[u][i - 1], k = 0; k < t.n; k++)       if (sta >> k & 1)         rec = (rec + 1ll * dfs(u, i - 1, sta ^ (1 << k)) *                          dfs(v, s.num[v], t.sta[k + 1])) %               mod;     return rec;   }   int main() {     scanf( %d , &s.n);     for (int i = 1, u, v; i < s.n; i++) {       scanf( %d%d , &u, &v);       s.add(u, v);       s.add(v, u);     }     scanf( %d , &t.n);     for (int i = 1, u, v; i < t.n; i++) {       scanf( %d%d , &u, &v);       t.add(u, v);       t.add(v, u);     }     s.dfs(1, 0);     memset(f, -1, sizeof f);     for (int r = 1; r <= t.n; r++) {       t.dfs(r, 0);       for (int i = 1; i <= s.n; i++)         ans = (ans + dfs(i, s.num[i], t.sta[r])) % mod;       memset(f, -1, sizeof f);     }     s = t;     s.dfs(1, 0);     for (int r = 1; r <= t.n; r++) {       t.dfs(r, 0);       ans2 = (ans2 + dfs(1, s.num[1], t.sta[r])) % mod;       memset(f, -1, sizeof f);     }     ans = 1ll * ans * Pow(ans2, mod - 2) % mod;     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using pii = pair<int, int>;   const int mod = 998244353;   const int inf = 0x3f3f3f3f;   const int N = 2e5 + 10;   int n, m, a[N];   LL sum[N], fac[N], rev[N];   LL pow_mod(LL x, int p) {     LL s = 1;     while (p) {       if (p & 1) s = s * x % mod;       x = x * x % mod;       p >>= 1;     }     return s;   }   LL C(int n, int m) { return fac[n] * rev[m] % mod * rev[n - m] % mod; }   LL solve(int A, int d) {     int p = lower_bound(a, a + n, d) - a;     int q = n - p;     if (q < A) return 0;     LL ret1, ret2;     if (q > A) {       ret1 = C(n, q) * C(q - 1, A) % mod * (q - A) % mod *              ((sum[n] - sum[p] + mod) % mod) % mod * fac[p] % mod * fac[A] % mod *              fac[q - 1 - A] % mod;     } else {       ret1 = 0;     }     if (p) {       ret2 = C(n, q + 1) * C(q, A) % mod * (q + 1 - A) % mod * sum[p] % mod *              fac[p - 1] % mod * fac[A] % mod * fac[q - A] % mod;     } else {       ret2 = 0;     }     LL ret = (ret1 + ret2) % mod;     return ret * rev[n] % mod;   }   int main() {     int x, y;     scanf( %d %d , &n, &m);     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     sort(a, a + n);     fac[0] = 1;     for (int i = (1); i < (n + 1); ++i) {       fac[i] = fac[i - 1] * i % mod;     }     rev[n] = pow_mod(fac[n], mod - 2);     for (int i = (n); i > (0); --i) rev[i - 1] = rev[i] * i % mod;     sum[0] = 0;     for (int i = (0); i < (n); ++i) {       sum[i + 1] = (sum[i] + a[i]) % mod;     }     while (m--) {       scanf( %d %d , &x, &y);       printf( %lld n , solve(x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int input;     vector<int> ret;     cin >> input;     for (int i = 1; i < input; i += 2) {       ret.push_back(i + 1);       ret.push_back(i);     }     if (ret.empty() || ret.size() != input) ret = {-1};     for (auto &d : ret) {       cout << d <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   double ans[1024 * 1024], l, r, x[20], y[20], a[20], cosA[20], sinA[20], maxi;   int main() {     scanf( %d %lf %lf , &n, &l, &r);     maxi = l;     for (int i = 0; i < n; i++) {       scanf( %lf %lf %lf , &x[i], &y[i], &a[i]);       cosA[i] = cos(a[i] * 3.14159265359 / 180);       sinA[i] = sin(a[i] * 3.14159265359 / 180);     }     int maxiMask = 1 << n;     for (int i = 0; i < maxiMask; i++) ans[i] = l;     for (int i = 0; i < maxiMask; i++) {       double curAns = ans[i];       for (int j = 0; j < n; j++) {         int newPotPos = 1 << j;         if (!(newPotPos & i)) {           double vx = curAns - x[j];           double vy = -y[j];           double nvx = vx * cosA[j] - vy * sinA[j];           double nvy = vx * sinA[j] + vy * cosA[j];           double pAns = x[j] - y[j] * nvx / nvy;           int newPos = newPotPos ^ i;           if (nvy >= 0.0) {             ans[newPos] = r;             maxi = r;           } else {             ans[newPos] = max(ans[newPos], pAns);             maxi = max(maxi, ans[newPos]);           }         }       }     }     maxi = min(maxi, r);     printf( %.11lf , maxi - l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, count = 0, count1 = 0, ans = 0, i, ma;     cin >> n;     long long int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     ma = a[0];     for (i = 0; i < n; i++) {       if (a[i] > ma) {         ma = a[i];       }     }     for (i = 0; i < n; i++) {       count = ma - a[i];       ans = ans + count;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool ok(int a, int b) {     int c = 0;     for (int i = 0; i < 4; i++) {       if ((a % 10) != (b % 10)) c++;       if (c > 1) return false;       a /= 10;       b /= 10;     }     return true;   }   int getlow(int a, int m) {     for (int i = m; i <= 2011; i++)       if (ok(a, i)) return i;     return -1;   }   int main() {     int n;     scanf( %d , &n);     int p = 1000;     vector<int> v;     for (int i = 0; i < n; i++) {       int t;       scanf( %d , &t);       t = getlow(t, p);       p = t;       if (t == -1) {         printf( No solution n );         return 0;       }       v.push_back(t);     }     for (int i = 0; i < n; i++) printf( %d n , v[i]);   }


#include <bits/stdc++.h>   using namespace std;   inline void read(register int *n) {     register char c;     *n = 0;     do {       c = getchar();     } while (c <  0  || c >  9 );     do {       *n = c -  0  + *n * 10;       c = getchar();     } while (c >=  0  && c <=  9 );   }   long long C[2048][2048], fac[1000001], dfac[1000001], D[2048][2048];   long long pmod(long long x, long long y) {     if (y == 0) return 1;     if (y % 2) return pmod(x, y - 1) * x % 1000000007;     long long r = pmod(x, y / 2);     return r * r % 1000000007;   }   long long calc(long long n, long long k, long long c = 0) {     long long res = 0;     for (register int i = (0); i < (int)(k + 1); ++i) {       long long tmp = C[k][i] * pmod(i + c, n);       tmp %= 1000000007;       if (i % 2)         res -= tmp;       else         res += tmp;       res %= 1000000007;     }     return res;   }   inline long long binom(long long n, long long r) {     if (r < 0 || r > n) return 0;     long long res = 1;     res = res * fac[n] % 1000000007;     res = res * dfac[r] % 1000000007;     res = res * dfac[n - r] % 1000000007;     return res;   }   int main() {     for (register int i = (0); i < (int)(1000001); ++i)       fac[i] = (i ? fac[i - 1] * i : 1) % 1000000007,       dfac[i] = pmod(fac[i], 1000000007 - 2);     for (register int i = (0); i < (int)(2048); ++i)       for (register int j = (0); j < (int)(i + 1); ++j)         C[i][j] = (j == 0 || j == i) ? 1 : (C[i - 1][j - 1] + C[i - 1][j]);     for (register int i = (0); i < (int)(2048); ++i)       for (register int j = (0); j < (int)(2048); ++j)         if (i == 0)           D[i][j] = j == 0;         else if (j <= 1)           D[i][j] = j;         else           D[i][j] = (j * D[i - 1][j] + D[i - 1][j - 1]) % 1000000007;     int n, m, k;     cin >> n >> m >> k;     if (m == 1) {       cout << pmod(k, n) << endl;       return 0;     }     long long res = 0;     for (register int x = (1); x < (int)(min(k, n) + 1); ++x)       for (int y = 0; y <= x; y++)         if (x * 2 - y <= k) {           long long tmp = binom(k, x * 2 - y);           tmp = tmp * binom(x * 2 - y, x - y) % 1000000007;           tmp = tmp * binom(x, x - y) % 1000000007;           tmp = tmp * D[n][x] % 1000000007;           tmp = tmp * D[n][x] % 1000000007;           tmp = tmp * fac[x] % 1000000007;           tmp = tmp * fac[x] % 1000000007;           tmp = tmp * pmod(y, n * (m - 2));           res = (res + tmp) % 1000000007;         }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long int n, x, ans = 0, i;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       ans += (i + 1) * x;     }     ans -= (((n - 1) * (n)) / 2);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c;   int main() {     scanf( %d %d %d n , &a, &b, &c);     if (a == b && c == 0)       printf( YES n );     else if ((a != b && c == 0) || (a > b && c > 0) || (a < b && c < 0))       printf( NO n );     else {       if ((b - a) % c == 0)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_L = 3000;   int T[MAX_L][MAX_L];   int last[MAX_L], z[MAX_L];   ;   char s[MAX_L], p[MAX_L];   int main() {     int Ls, Lp, is, ip, k, i, j, r;     scanf( %s%s , &s, &p);     Ls = strlen(s);     Lp = strlen(p);     for (i = 0; s[i]; i++) {       is = i;       ip = 0;       while (s[is] && p[ip]) {         while (s[is] && p[ip] && s[is] != p[ip]) is++;         if (s[is] == p[ip]) {           is++;           ip++;         }       }       if (!p[ip]) {         last[i] = is - 1;         z[i] = is - i - Lp;       } else         last[i] = -1;     }     if (last[0] != -1) T[last[0]][z[0]] = 1;     for (i = 0; i < Ls - 1; i++)       for (k = 0; k <= i + 1; k++) {         j = i + 1;         T[j][k] = max(T[j][k], T[i][k]);         T[j][k + 1] = max(T[j][k + 1], T[i][k]);         if (last[j] != -1) {           r = last[j];           T[r][k + z[j]] = max(T[r][k + z[j]], T[i][k] + 1);         }       }     i = Ls - 1;     for (j = 0; j <= Ls; j++) printf( %d  , T[i][j]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int v0, v1, v2, vm, a0, a1, a2;     bool err = true;     scanf( %d%d%d%d , &v2, &v1, &v0, &vm);     for (int i = v0; i <= v0 * 2; i++) {       for (int j = v1; j <= v1 * 2; j++) {         for (int k = v2; k <= v2 * 2; k++) {           if (vm <= i && vm <= j && vm <= k && i < j && j < k && vm * 2 >= i &&               vm * 2 < j) {             a0 = k;             a1 = j;             a2 = i;             err = false;             break;           }         }       }     }     if (err) {       printf( -1 n );     } else {       printf( %d n%d n%d n , a0, a1, a2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int main() {     int n;     cin >> n;     string s;     cin >> s;     queue<int> D, R;     for (int i = 0; i < n; i++) {       if (s[i] ==  D ) D.push(i);       if (s[i] ==  R ) R.push(i);     }     while (D.size() && R.size()) {       if (D.front() < R.front()) {         R.pop();         D.push(D.front() + n);         D.pop();       } else {         D.pop();         R.push(R.front() + n);         R.pop();       }     }     cout << (D.size() ?  D  :  R ) << endl;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-19;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const int MAXN = 300005;   using namespace std;   int n, m;   int ans[MAXN];   vector<int> g[MAXN];   bool used[MAXN];   void dfs(int v) {     int kol = 0;     for (int j = 0; j < (int)g[v].size(); j++)       if (ans[v] == ans[g[v][j]]) kol++;     if (kol > 1) {       ans[v] ^= 1;       for (int j = 0; j < (int)g[v].size(); j++) {         dfs(g[v][j]);       }     }   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int ta, tb;       scanf( %d %d , &ta, &tb);       ta--;       tb--;       g[ta].push_back(tb);       g[tb].push_back(ta);     }     memset(ans, 0, sizeof ans);     for (int i = 0; i < n; i++) dfs(i);     for (int i = 0; i < n; i++) printf( %d , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T, class U>   ostream& operator<<(ostream& o, const pair<T, U>& p) {     o <<  (  << p.first <<  ,  << p.second <<  ) ;     return o;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  [ ;     for (T t : v) {       o << t <<  , ;     }     o <<  ] ;     return o;   }   const int MAX_V = 300003;   const int MAX_LOG_V = 19;   vector<int> G[MAX_V];   int root = 0;   int parent[MAX_LOG_V][MAX_V];   int depth[MAX_V];   void lca_dfs(int v, int p, int d) {     parent[0][v] = p;     depth[v] = d;     for (int i = 0; i < (int)(G[v].size()); ++i) {       if (G[v][i] != p) {         lca_dfs(G[v][i], v, d + 1);       }     }   }   void lca_init(int V) {     lca_dfs(root, -1, 0);     for (int k = 0; k + 1 < MAX_LOG_V; ++k) {       for (int v = 0; v < V; ++v) {         if (parent[k][v] < 0)           parent[k + 1][v] = -1;         else           parent[k + 1][v] = parent[k][parent[k][v]];       }     }   }   int lca(int u, int v) {     if (depth[u] > depth[v]) swap(u, v);     for (int k = 0; k < MAX_LOG_V; ++k) {       if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];     }     if (u == v) return u;     for (int k = MAX_LOG_V - 1; k >= 0; --k) {       if (parent[k][u] != parent[k][v]) {         u = parent[k][u];         v = parent[k][v];       }     }     return parent[0][u];   }   const int N = MAX_V;   const ll mod = 998244353;   int n, k;   int a[N];   int L[N];   bool invalid = false;   ll dp[N][2] = {};   int dfs(int x, int par) {     map<int, int> m;     for (int e : G[x])       if (e != par) {         int res = dfs(e, x);         if (res != 0) m[e] = res;       }     if (m.empty()) {       int idx = (a[x] != 0);       dp[x][idx] = 1;       if (L[a[x]] == x) return -1;       return a[x];     }     unordered_set<int> s;     vector<int> ch;     for (const auto& p : m) {       ch.push_back(p.first);       if (p.second != -1) s.insert(p.second);     }     if (s.size() > 1) {       invalid = true;       return 0;     }     if (a[x] == 0 && s.size() == 0) {       dp[x][0] = 1;       for (int v : ch) (dp[x][0] *= (dp[v][0] + dp[v][1])) %= mod;       int C = ch.size();       vector<ll> pre(C), suf(C);       for (int i = 0; i < (int)(C); ++i)         pre[i] = suf[i] = (dp[ch[i]][0] + dp[ch[i]][1]) % mod;       for (int i = 0; i < (int)(C - 1); ++i) (pre[i + 1] *= pre[i]) %= mod;       for (int i = C - 1; i > 0; --i) (suf[i - 1] *= suf[i]) %= mod;       dp[x][1] = 0;       for (int i = 0; i < (int)(C); ++i) {         ll mul = 1;         if (i != 0) (mul *= pre[i - 1]) %= mod;         if (i != C - 1) (mul *= suf[i + 1]) %= mod;         ll add = (mul * dp[ch[i]][1]) % mod;         (dp[x][1] += add) %= mod;       }       return -1;     } else {       int col = a[x];       if (!s.empty()) {         assert(s.size() == 1);         int h = *s.begin();         if (col != 0 && col != h) {           invalid = true;           return 0;         }         col = h;       }       dp[x][1] = 1;       for (int v : ch) {         if (m[v] == -1)           (dp[x][1] *= (dp[v][0] + dp[v][1])) %= mod;         else           (dp[x][1] *= dp[v][1]) %= mod;       }       return (x == L[col]) ? -1 : col;     }   }   int main() {     scanf(  %d %d , &n, &k);     vector<vector<int>> col(k + 1);     for (int i = 0; i < (int)(n); ++i) {       scanf(  %d , &a[i]);       col[a[i]].push_back(i);     }     for (int i = 0; i < (int)(n - 1); ++i) {       int u, v;       scanf(  %d %d , &u, &v);       --u;       --v;       G[u].push_back(v);       G[v].push_back(u);     }     lca_init(n);     for (int i = 1; i <= k; ++i) {       int x = col[i][0];       for (int j : col[i]) x = lca(x, j);       if (a[x] != 0 && a[x] != i) invalid = true;       a[x] = i;       L[i] = x;     }     dfs(0, -1);     printf( %lld n , invalid ? 0 : dp[0][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1510, INF = 1e9 + 9;   int n, s, m, k, last[N], a[N], dp[N][N];   bool check(int x) {     memset(dp, 0, sizeof dp);     for (int i = 0; i < n; i++) {       int val = 0;       for (int j = last[i]; j <= i; j++) val += a[j] <= x;       for (int j = 1; j <= m; j++)         dp[i + 1][j] = max(dp[i][j], dp[last[i]][j - 1] + val);     }     return k <= dp[n][m];   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> s >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     fill(last, last + n, n + 1);     while (s--) {       int l, r;       cin >> l >> r;       for (int i = --l; i < r; i++) last[i] = min(last[i], l);     }     int l = 0, r = INF;     while (r - l > 1) {       int mid = l + r >> 1;       check(mid) ? r = mid : l = mid;     }     cout << (r == INF ? -1 : r) << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     pair<int, int> A;     int x, y;     Node() {}     Node(pair<int, int> A, int x, int y) {       this->A = A;       this->x = x;       this->y = y;     }   };   char s[1001][1001];   int sp[10], cur, ans[10];   Node heap[1000001];   void swap(Node& a, Node& b) {     Node t = a;     a = b;     b = t;   }   bool cmp(Node a, Node b) {     int val_a = a.A.first / sp[a.A.second];     int val_b = b.A.first / sp[b.A.second];     if (val_a != val_b)       return val_a < val_b;     else if (a.A.second != b.A.second)       return a.A.second < b.A.second;     else       return a.A.first < b.A.first;   }   void push(Node x) {     int now = cur++;     heap[now] = x;     while (now > 1) {       int par = now / 2;       if (cmp(heap[now], heap[par]))         swap(heap[now], heap[par]);       else         break;       now = par;     }     return;   }   Node pop() {     Node ret = heap[1];     heap[1] = heap[--cur];     int now = 1;     while (now * 2 < cur) {       int l = now * 2, r = now * 2 + 1, t;       if (r == cur) r = l;       if (cmp(heap[l], heap[r]))         t = l;       else         t = r;       if (cmp(heap[t], heap[now]))         swap(heap[t], heap[now]);       else         break;       now = t;     }     return ret;   }   int dx[4] = {1, 0, 0, -1};   int dy[4] = {0, 1, -1, 0};   int main() {     int n, m, p;     cur = 1;     scanf( %d %d %d , &n, &m, &p);     for (int i = 1; i <= p; i++) scanf( %d , &sp[i]);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (s[i][j] >=  0  && s[i][j] <=  9 ) {           push(Node(pair<int, int>(0, s[i][j] -  0 ), i, j));         }       }     while (cur > 1) {       Node now = pop();       pair<int, int> A = now.A;       int x = now.x, y = now.y;       int cnt = A.first, who = A.second;       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (nx < 0 || ny < 0 || nx >= n || ny >= m || s[nx][ny] !=  . ) continue;         s[nx][ny] =  0  + who;         push(Node(pair<int, int>(cnt + 1, who), nx, ny));       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (s[i][j] >=  0  && s[i][j] <=  9 ) {           ans[s[i][j] -  0 ]++;         }       }     for (int i = 1; i <= p; i++) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int len(int n) {     if (n < 10) return 0;     return 1 + len(n / 10);   }   int main() {     int n, l;     long long sum = 0, z = 1;     cin >> n;     l = len(n);     for (int x = 0; x < l; x++) z *= 10;     while (n > 0) {       sum += (n - z + 1) * (l + 1);       n = z - 1;       z /= 10;       l--;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, mod = 1000000007;   int n, m, T, q, f[6];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       for (int j = 1; j <= 4; j++) {         if ((j & 1) == (x & 1)) f[j]++;       }       for (int j = 2; j <= 4; j++) f[j] = max(f[j], f[j - 1]);     }     printf( %d n , f[4]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200005];   long double b[200005];   int n;   long double dp1[200005], dp2[200005];   long double check(long double val) {     int i;     for (i = 0; i < n; i++) b[i + 1] = a[i] - val;     dp1[1] = b[1];     long double ans = b[1];     for (i = 2; i <= n; i++) {       dp1[i] = max(dp1[i - 1], (long double)0) + b[i];       ans = max(ans, dp1[i]);     }     for (i = 0; i <= n + 1; i++) b[i + 1] = -b[i + 1];     ans = max(ans, b[1]);     dp2[1] = b[1];     for (i = 2; i <= n; i++) {       dp2[i] = max(dp2[i - 1], (long double)0) + b[i];       ans = max(ans, dp2[i]);     }     return ans;   }   int main() {     scanf( %d , &n);     int i;     for (i = 0; i < n; i++) scanf( %d , &a[i]);     long double lo, hi;     lo = -(1e4);     hi = 1e4;     long double eps = 1e-12;     while (lo < hi - eps) {       long double mid1, mid2;       mid1 = (2 * lo + hi) / 3;       mid2 = (lo + hi * 2) / 3;       long double sol1, sol2;       sol1 = check(mid1);       sol2 = check(mid2);       if (sol1 < sol2 - eps) {         hi = mid2;       } else {         lo = mid1;       }     }     cout << fixed << setprecision(9) << check(lo) << endl;   }