#include<bits/stdc++.h>
#pragma GCC optimize(3)
#define ll long long
#define int long long
using namespace std;

const int maxn=200005;
const int inf=1ll<<60;

int a[maxn];
int b[maxn];
int val[maxn];
int f[105][10005];
int vis[105][10005];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	int ans=inf;
	for(int num=n; num>=1; num--) {
		int left=m%num,sum=0;
		for(int i=1; i<=n; i++) {
			b[i]=a[i]%num;
			val[i]=a[i]/num;
			sum+=b[i];
		}
		memset(f,0,sizeof(f));
		memset(vis,0,sizeof(vis));
//		for(int i=1;i<=num;i++) {
//			for(int j=0;j<=sum;j++) {
//				vis[i][j]=f[i][j]=0;
//			}
//		}
		for(int i=1; i<=n; i++) {
			for(int p=num; p>=2; p--) {
				for(int j=sum; j>=b[i]; j--) {
					if(vis[p-1][j-b[i]]) {
						f[p][j]=max(f[p][j],f[p-1][j-b[i]]+val[i]);
					}
				}
			}
			f[1][b[i]]=max(f[1][b[i]],val[i]);
			for(int p=num; p>=2; p--) {
				for(int j=sum; j>=b[i]; j--) {
					vis[p][j]|=vis[p-1][j-b[i]];
				}
			}
			vis[1][b[i]]=1;
		}
		for(int k=0; k+left<=sum; k+=num) {
			if(vis[num][left+k]) {
				ans=min(ans,(m-left-k)/num-f[num][left+k]);
			}
		}
      	if(1.0*clock()/CLOCKS_PER_SEC>1.82) {
        	cout<<ans;
          	return 0;
        }
	}
	cout<<ans;
}

#include <bits/stdc++.h>

using namespace std;

/*
Fix k.
For this k, we will:
Compute the maximum possible sum of k items that is equal to X modulo k.
We will do this by using a DP approach. We go through the items one by one and decide IN ORDER whether we use them.
Our DP state is (# items used, current sum % k, items gone through) -> value.
For each k, we have 10^6 DP states.
The processing for each state is constant time.
So we have at most 10^8 "things" to do.
*/

void maxeq(long long& a, long long b){
	a = max(a, b);
}

long long DP[102][101][101];
int main(){
	long long n, x;
	cin>>n>>x;
	vector<long long> A(n);
	for (int i = 0; i < n; i++) cin>>A[i];
	long long ans = 2e18;
	// (# items used, current sum % k, items gone through) -> value.
	for (int k = 1; k <= n; k++){
		//long long DP[k+1][k][n+1];
		for (int a = 0; a <= k+1; a++){
			for (int b = 0; b < k; b++){
				for (int c = 0; c <= n; c++){
					DP[a][b][c] = LLONG_MIN / 3;
				}
			}
		}
		DP[0][0][0] = 0;
		for (int c = 0; c < n; c++){ // we decide whether to take item c
			for (int a = 0; a < k+1; a++){
				for (int b = 0; b < k; b++){
					// take
					maxeq(DP[a + 1][(b + A[c]) % k][c + 1], DP[a][b][c] + A[c]);
					// don't take
					maxeq(DP[a][b][c + 1], DP[a][b][c]);
				}
			}
		}
		if (DP[k][x % k][n] > 0) ans = min(ans, (x - DP[k][x % k][n]) / k);
	}
	cout << ans << endl;
}


// time-limit: 2000
// problem-url: https://atcoder.jp/contests/abc202/tasks/abc202_e
#include <bits/stdc++.h>
using namespace std;

#define nl "\n"
#define big int

#ifdef DEBUG
#define ds(statement) cerr << statement << endl
#define dv(var) cerr << (#var) << ": " << var << endl
#else
#define ds(statement)
#define dv(var)
#endif

vector<vector<big>> child;
vector<pair<big, big>> ts;
vector<vector<big>> depth_ent;
big tc = 0;

void dfs(big node, big depth)
{
    ts[node].first = tc++;
    depth_ent[depth].push_back(ts[node].first);

    for (auto c : child[node])
    {
        dfs(c, depth + 1);
    }

    ts[node].second = tc++;
}

void solve()
{
    big n, t, q;
    cin >> n;
    child = vector<vector<big>>(n);
    depth_ent = vector<vector<big>>(n);
    ts = vector<pair<big, big>>(n);
    for (big i = 1; i < n; i++)
    {
        cin >> t;
        child[t - 1].push_back(i);
    }

    dfs(0, 0);

    cin >> q;
    while (q-- > 0)
    {
        big d, u, ans;
        cin >> u >> d;
        u--;

        vector<big> v = depth_ent[d];
        ans = (lower_bound(v.begin(),v.end(),ts[u].second) - lower_bound(v.begin(),v.end(),ts[u].first));

        cout << ans << nl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef DEBUG
    (void)!freopen("/home/sarvjot/error.txt", "w", stderr);
#endif
    solve();
    return 0;
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	vi a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	int s=0;
	rep(i,n)s+=a[i]*b[i];
	if(s)no;
	else yes;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll P=1000000007;

ll pow(ll x,ll n){
    if(n==1)return x;
    ll half=pow(x,n/2),ret=half*half%P;
    if(n%2)ret=ret*x%P;
    return ret;
}

ll inv(ll x){
    return pow(x,P-2);
}

vector<vector<ll>> matmul(const vector<vector<ll>> &a,const vector<vector<ll>> &b){
    int n=a.size(),p=a[0].size(),m=b[0].size();
    vector<vector<ll>> c(n,vector<ll>(m,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            for(int k=0;k<p;k++)
                c[i][j]=(c[i][j]+a[i][k]*b[k][j])%P;
    return c;
}

vector<vector<ll>> matpow(const vector<vector<ll>> &a,int n){
    if(n==1)return a;
    if(n==2)return matmul(a,a);
    if(n==3)return matmul(matmul(a,a),a);
    vector<vector<ll>> half=matpow(a,n/2),ret=matmul(half,half);
    if(n%2)ret=matmul(ret,a);
    return ret;
}

int main() {
    int n,m,k;
    cin>>n>>m>>k;
    ll inv2m=inv(m)*inv(2)%P;
    vector<ll> a(n);
    for(ll &x:a)
        cin>>x;
    if(k==0){
        for(ll x:a)cout<<x<<endl;
        return 0;
    }
    vector<vector<ll>> mat(n,vector<ll>(n,0));
    for(int i=0;i<n;i++)
        mat[i][i]=1;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        mat[u][u]=(mat[u][u]-inv2m+P)%P;
        mat[u][v]=(mat[u][v]+inv2m)%P;
        mat[v][u]=(mat[v][u]+inv2m)%P;
        mat[v][v]=(mat[v][v]-inv2m+P)%P;
    }
    mat=matpow(mat,k);
    for(int i=0;i<n;i++){
        ll ans=0;
        for(int j=0;j<n;j++)
            ans=(ans+mat[i][j]*a[j])%P;
        cout<<ans<<endl;
    }
}

//
//  mod.cpp
//
//
//  Created by Sagar Singh on 17/12/20.
//

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#define bug1( x )                   { cerr << (#x) <<"="<< x << endl; }
#define bug2( x , y )               { cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl; }
#define bug3( x , y , z )           { cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl; }
#define bug4( x , y , z , w)        { cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl; }
#define bug5( x , y , z , w ,p)     { cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl; }
#define bug6( x , y , z , w ,p , q) { cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl; }
#define bugn( x , n )               { cerr<<(#x)<<":";for(int i=0;i<n;i++)cout<<(#x)<<"["<<i<<"]:"<< x[i] << "    "; cout<<endl; }
#define bugnm( x , n , m )          { cerr<<(#x)<<endl;for(int i=0;i<n;i++){ cout<<"Row #"<<i<<":"; for(int j=0;j<m;j++) cout<<x[i][j]<<"     "; cout << endl;} }
typedef unsigned long long ul;
typedef long double ld;
typedef long long ll;
using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;

const int mod = 1e9+7;
int add(int x,int y){
    int z = x + y;
    if( z >= mod ){
        z -= mod;
    }
    return z;
}
int sub(int x,int y){
    int z = x - y;
    if( z < 0 ){
        z += mod;
    }
    return z;
}
int mul(int x,int y){
    ll z = 1ll * x * y;
    if( z >= mod ){
        z %= mod;
    }
    return z;
}
int binpow(int a,ll p){
    int r = 1;
    while( p ){
        if( p & 1 )
            r = mul(r,a);
        a = mul(a,a), p >>= 1;
    }
    return r;
}
int n, m, k;
vvi mul(vvi a, vvi b){
    vvi c(n,vi(n));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            for(int k=0;k<n;++k){
                c[i][j] = add(c[i][j],mul(a[i][k],b[k][j]));
            }
        }
    }
    return c;
}
vvi binpow(vvi a,int p){
    vvi r(n,vi(n));
    for(int i=0;i<n;++i){
        r[i][i] = 1;
    }
    while( p ){
        if( p & 1 )
            r = mul(r,a);
        a = mul(a,a), p >>= 1;
    }
    return r;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m >> k;
    vvi w(n,vi(n));
    vi a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    for(int i=0;i<m;++i){
        int u, v; cin >> u >> v;
        w[u-1][v-1] += 1;
        w[v-1][u-1] += 1;
    }
    for(int i=0;i<n;++i){
        int k = 0;
        for(int j=0;j<n;++j){
            k += w[i][j];
        }
        w[i][i] += 2*m - k;
    }
    w = binpow(w,k);
    for(int j=0;j<n;++j){
        int tmp = 0;
        for(int i=0;i<n;++i){
            tmp = add(tmp,mul(a[i],w[i][j]));
        }
        tmp = mul(tmp,binpow(mul(binpow(2,k),binpow(m,k)),mod-2));
        cout << tmp <<   endl;
    }

}


#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll INF = 1001002003004005006ll;
constexpr int n_max = 2e5+10;

template<class T>
inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; };
template<class T>
inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; };

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

void LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, K; cin >> N >> K;
  rep(i,0,K) {
    if (N%200 == 0) {
      N /= 200;
    } else {
      N = N*1000+200;
    }
  }

  cout << N << endl;

  return 0;
};

#include "bits/stdc++.h"
using namespace std;

int main() {

    long long n, k;

    cin >> n >> k;

    for (int i = 0; i < k; i++) {
        if (n % 200 == 0) {
            n /= 200;
        }
        else {
            n *= 1000;
            n += 200;
        }
    }

    cout << n << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int into;
int main()
  { int h,w,x,y;
   cin>>h>>w>>x>>y;
   x--;y--;
   string s[h];
   for(int i=0;i<h;i++)
    cin>>s[i];
   int ans=0;
   for(int i=x+1;i<h;i++)
   { if(s[i][y]=='#')
      break;
    else ans++; }
   for(int i=x-1;i>=0;i--)
   { if(s[i][y]=='#')
      break;
    else ans++;
   } for(int i=y+1;i<w;i++)
   { if(s[x][i]=='#')
      break;
    else ans++;
   }
   for(int i=y-1;i>=0;i--)
   {  if(s[x][i]=='#')
     break;
    else
      ans++;}
   ans++;
     cout<<ans<<endl;

   }

#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)

int si, sj;
int t[52][52];
int p[52][52];
int c[52][52];
int score;
vector<char> ans;
int cnt;

void dfs(int i, int j, int score2, vector<char> ans2)
{
	if (cnt++ > 150000)
	{
		//cout << score << endl;
		for (char x : ans) cout << x; cout << endl;
		exit(EXIT_SUCCESS);
	}
	score2 += p[i][j];
	if (score < score2)
	{
		score = score2;
		ans = ans2;
	}

	c[i][j] = 1;
	if (t[i][j] == t[i+1][j]) c[i+1][j] = 1;
	else if (t[i][j] == t[i-1][j]) c[i-1][j] = 1;
	else if (t[i][j] == t[i][j+1]) c[i][j+1] = 1;
	else if (t[i][j] == t[i][j-1]) c[i][j-1] = 1;

	if (c[i+1][j] == 0) {ans2.push_back('D'); dfs(i+1, j, score2, ans2); ans2.erase(ans2.end()-1);}
	if (c[i-1][j] == 0) {ans2.push_back('U'); dfs(i-1, j, score2, ans2); ans2.erase(ans2.end()-1);}
	if (c[i][j+1] == 0) {ans2.push_back('R'); dfs(i, j+1, score2, ans2); ans2.erase(ans2.end()-1);}
	if (c[i][j-1] == 0) {ans2.push_back('L'); dfs(i, j-1, score2, ans2); ans2.erase(ans2.end()-1);}

	c[i][j] = 0;
	if (t[i][j] == t[i+1][j]) c[i+1][j] = 0;
	else if (t[i][j] == t[i-1][j]) c[i-1][j] = 0;
	else if (t[i][j] == t[i][j+1]) c[i][j+1] = 0;
	else if (t[i][j] == t[i][j-1]) c[i][j-1] = 0;
}

signed main(void)
{
	rep (i, 52) c[0][i] = c[51][i] = c[i][0] = c[i][51] = 1;
	cin >> si >> sj;
	reps (i, 1, 51) reps (j, 1, 51) cin >> t[i][j];
	reps (i, 1, 51) reps (j, 1, 51) cin >> p[i][j];
	c[si][sj] = 1;
	if (t[si][sj] == t[si+1][sj]) c[si+1][sj] = 1;
	else if (t[si][sj] == t[si-1][sj]) c[si-1][sj] = 1;
	else if (t[si][sj] == t[si][sj+1]) c[si][sj+1] = 1;
	else if (t[si][sj] == t[si][sj-1]) c[si][sj-1] = 1;

	vector<char> tmp;
	dfs(si+1, sj+1, 0, tmp);
	for (char x : ans) cout << x; cout << endl;
}


#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define min(a,b) (a<b?a:b)
#define ll long long
//#define file
using namespace std;

int a[100002],b[100002],n,L,i,j,k,l,sum;
ll ans;

void Exit() {printf("-1\n");exit(0);}

int main()
{
	#ifdef file
	freopen("c.in","r",stdin);
	#endif

	scanf("%d%d",&n,&L);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) scanf("%d",&b[i]);

	a[0]=0,a[n+1]=L+1;
	b[0]=0,b[n+1]=L+1;
	l=0;
	fo(i,0,n)
	if (b[i]+1<b[i+1])
	{
		sum=0;
		while (l<=n && a[l]+1==a[l+1]) ++l;
		k=min(l,i);

		while (l<=n && sum<b[i+1]-b[i]-1)
		sum+=a[l+1]-a[l]-1,++l;

		if (sum>b[i+1]-b[i]-1) Exit();
		ans+=max(l,i+1)-k-1;
	}
	printf("%lld\n",ans);

	fclose(stdin);
	fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, L;
    cin >> N >> L;
    Vl A(N + 2), B(N + 2);
    for (ll i = 1; i <= N; i++) {
        cin >> A[i];
        A[i] -= i;
    }
    for (ll i = 1; i <= N; i++) {
        cin >> B[i];
        B[i] -= i;
    }
    A[N + 1] = B[N + 1] = (L + 1) - (N + 1);

    Vl pos = B;
    pos.erase(unique(pos.begin(), pos.end()), pos.end());

    ll ans = 0;
    for (auto p : pos) {
        int idxl_a = lower_bound(A.begin(), A.end(), p) - A.begin();
        int idxr_a = upper_bound(A.begin(), A.end(), p) - A.begin();
        int idxl_b = lower_bound(B.begin(), B.end(), p) - B.begin();
        int idxr_b = upper_bound(B.begin(), B.end(), p) - B.begin();
        if (idxr_a - idxl_a == 0) {
            prints()(-1);
            return;
        }
        ans += max(idxr_b - idxr_a, 0) + max(idxl_a - idxl_b, 0);
    }

    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loope(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloope(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define vii vector<vector<int>>
#define si set<int>
#define NO cout<<"NO\n";
#define YES cout<<"YES\n";
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
// #include < ext / pb_ds / assoc_container.hpp >
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//         tree_order_statistics_node_update>
//         ordered_set;
ll ceil(ll a, ll b) {
    return (a + b - 1) / b;
}
//graph theory
vector<vi> adj;
vi vis;

int dfs(int cur) {
    int ret = 1;
    vis[cur] = 1;
    // cout << cur << ",";
    for (const auto &v : adj[cur]) {
        if (vis[v])continue;
        ret += dfs(v);
    }
    return ret;
}
const int maxm = 2 * 1e5 + 1;

void solve()
{
    int n; cin >> n;
    vi a(n);
    loop(i, 0, n)cin >> a[i];
    adj = vector<vi>(maxm + 1);
    vis = vi(maxm + 1);

    int ans = 0;
    loop(i, 0, n / 2) {
        if (a[i] == a[n - i - 1])continue;
        adj[a[i]].pb(a[n - i - 1]);
        adj[a[n - i - 1]].pb(a[i]);
    }

    loop(i, 0, n) {
        if (vis[a[i]])continue;
        ans += dfs(a[i]) - 1;
        // cout << "\n";
        // cout << a[i] << " " << ans << "\n";
    }
    cout << ans << "\n";
}
int main()
{
    io;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int test = 1, i = 0;
    // cin >> test;
    while (i++ != test)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const long long MOD = 1000000007;

#define ll long long

vector<bool>vis ( 2e5+10 ,false);

vector<int>adj[200009];

void dfs ( int a){

     if(vis[a]==false)return;

    vis[a]=false;

    for ( int x : adj[a]){
        dfs(x);
    }

}

void solve()
{

    int n;
    cin >> n;

    vector<int> v(n);
    set<int>st;

    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        st.insert(v[i]);
        vis[v[i]]=true;
    }

    int ans =st.size();

    int i=0,j=n-1;

    while ( i< j){

        adj[v[i]].push_back(v[j]);
        adj[v[j]].push_back(v[i]);
        i++;
        j--;

    }

    for ( int i=1 ; i<=200000; i++){
        if(vis[i]==true){
            ans--;

            dfs(i);
        }

    }

    cout << ans;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
// return a*1ll + b*1ll;
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
// return a*b*1ll;
}
// ****************************************************************************
pair<int,int> dp[2][100001];
int n;
int a[100001];
int res;
pair<int,int> rec(int f,int i){

    if(i==n)
    return {0ll,1ll};
    // if(dp[f][i]!={-1ll,-1ll})
    // return dp[f][i];
    auto p = dp[f][i];
    if(p.first!=-1)
    return p;
    // int temp;
    if(i==0){
        int x = rec(0,i+1).first;
        int y = rec(0,i+1).second;
        // return {add(a,mul(a[i]))}
        // return add({x,mul(a[i],y)});
        return {add(x,mul(a[i],y)),y};
    }
    int ans =0;
    if(f==0){
        // now we can put both
        // int temp = rec(0,i+1);
        // int tempp = rec(1,i+1);
        // res=add(res,mul(a[i],temp));
        // res=add(res,-mul(a[i],tempp));
        // // int x = mul(a[i],tempp);
        // // res = (res-x)%M;
        // // res=add(res,-x);
        // // res = mod(mod(res)-x);
        // return dp[f][i]=add(temp,tempp);
        int ans;
        int x1 = rec(0,i+1).first;
        int y1 = rec(0,i+1).second;
        ans = add(x1,mul(a[i],y1));
       int  x2 = rec(1,i+1).first;
        int y2 = rec(1,i+1).second;
        ans=add(ans,x2);
        ans=add(ans,-mul(a[i],y2));
        return dp[f][i]={ans,add(y1,y2)};
    }
    else{
        // now i can only put +here
        // ans=mul(a[i],rec(0,i+1));
        // int temp = rec(0,i+1);
        // res=add(res,mul(a[i],temp));
        // return dp[f][i]=temp;
        int x = rec(0,i+1).first;
        int y = rec(0,i+1).second;
        return dp[f][i]={add(x,mul(a[i],y)),y};
        // return dp[f][i]={add}
    }
    // cout<<ans<<endl;
    return {1,1};

}

void solve(){
    cin>>n;
    fo(i,0,n)
    cin>>a[i];
    // memset(dp,-1,sizeof dp);
    // cout<<rec(0,0);
    fo(i,0,2){
        fo(j,0,n)
        dp[i][j]={-1,-1};
    }
    // cout<<rec(0,0).first;
    auto p = rec(0,0);
    cout<<p.first;
    // cout<<mod(res);
    // cout<<res;
}
signed main()
{
FIO
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
}

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

set<int> s;

void rec(int B, int C){

    if(C < 0) return ;

    s.insert(B);

    rec(-B, C - 1);
    rec(B-1, C - 2);
}

int solve(int B, int C){
    s.clear();

    rec(B, C);

    cout<<"ANS = "<<endl;
    cout<<s.size()<<endl<<endl;

    for(int y : s){
        // cout<<y<<endl;
        cout<<y<<" ";
    }
    cout<<endl;
}

int solve2(int B, int C){

    int a = 0, b = 0, c = 0;
    int D, E, F, G;
    int res = 0;
    int maxi = 0;

    a = (C - 1)/ 2;
    b = max((C - 2)/2, 0ll);
    c =(C + 0)/2;

    if(B == 0) {
        cout<<C<<endl;
        return 0;
    } else if(B < 0) {
        D = -B + a;
        E = -B - a;
        F = B + b;
        G = B - c;
    } else {
        D = B + b;
        E = B - c;
        F = -B + a;
        G = -B - a;
    }

    // cout<<D<<" "<<E<<" "<<F<<" "<<G<<endl;
    // cout<<G<<" "<<F<<" "<<E<<" "<<D<<endl;
    res += F - G + 1;
    res += max(0ll, D - max(E-1, F));

    // cout<<a<<" "<<b<<endl;

    cout<<res<<endl;

    return res;
}

signed main(){
	cout<<fixed<<setprecision(10);

	int B, C;

    cin>>B>>C;

    // solve(B, C);

    solve2(B, C);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

string s = "";
map<char, char> mp;

int main(){
	mp['0'] = '0' ; mp['1'] = '1' ; mp['6'] = '9' ; mp['8'] = '8' ; mp['9'] = '6' ;
	cin >> s;
	for(int i = s.length() - 1 ; i >= 0 ; i --) cout << mp[s[i]];
	return 0;
}

#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fo(i,z,n) for(int i = z;i<n;i++)
#define rfo(i,z,n) for(int i = z;i >= n;i--)

#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vc vector<char>
#define vpi vector<pair<int,int> >
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvpi vector<vector<pair<int,int> > >
#define vvc vector<vector<char> >
#define vvl vector<vector<ll> >
#define pb push_back
#define f first
#define int long long
#define float double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

 void __print(int x) {cerr << x;}
// void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
// void __print(float x) {cerr << x;}
// void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int ceil(int a,int b){
    if(a%b == 0)return a/b;
    else return a/b+1;
}

int pow(int a,int b){
    if(b == 0)return 1;
    int res = pow(a,b/2);
    res = res*res;
    if(b&1)res *= a;
    return res;
}

// ordered_set s;

void solve(){

    string s;
    cin >> s;
    int n = s.length();
    reverse(all(s));
    for(int i = 0;i < n;i++){
        if(s[i] == '6')s[i] = '9';
        else if(s[i] == '9')s[i] = '6';
    }
    cout << s << endl;

    return;

}

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);

     int t = 1;
     // cin >> t;
     while(t--){
        solve();
     }

return 0;

    }


#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

void solve() {
    string s;
    cin >> s;
    int n = s.size();
    string t = "atcoder";
    int ans = inf;
    int off = 0;
    for (int i = 0; i <= min(s.size(), t.size()); i++) {
        if (i > 0) {
            bool flag = false;
            for (int j = i - 1; j < s.size(); j++) {
                if (s[j] == t[i - 1]) {
                    s.erase(s.begin() + j);
                    s.insert(s.begin() + i - 1, t[i - 1]);
                    off += j - (i - 1);
                    flag = true;
                    break;
                }
            }
            if (not flag) break;
        }

        if (i == t.size()) {
            if (s.size() > t.size()) {
                chmin(ans, off);
            }
            break;
        }

        for (int j = i; j < s.size(); j++) {
            if (s[j] > t[i]) {
                chmin(ans, off + j - i);
                break;
            }
        }
    }
    if (ans != inf) {
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
}

signed main() {
    fio();
    int t;
    cin >> t;
    while (t--) solve();
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define ford(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define vll vector<ll>
#define sz(s) (int)(s.size())
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
ll q_p(ll x,ll y){
	ll res=1;
	x%=mod;
	while(y){
		if(y%2){
			res=res*x;
			res%=mod;
		}
		y/=2;
		x=x*x;
		x%=mod;
	}
	re res;
}
int n;
pair<int,string> p[1001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>p[i].se>>p[i].fr;
	}
	sort(p,p+n);
	reverse(p,p+n);
	cout<<p[1].second;
	re 0;
}
/*
检查循环是rep(i,n)还是rep(i,m)!!
long long所要的时间比int长!!
没有long long必要不写long long!!
写公式前先想一想!!
二分前看一看边界对不对，有没有特殊值!!
提交前要测特殊数据（边界上的）!!
*/


#include <bits/stdc++.h>
using namespace std;

//#define int long long

template <int mod = 1000000007>
struct modint{
    int x;
    modint(int y = 0) : x((y % mod + mod) % mod) { }
    friend modint operator^(modint a, long long b) {
        modint r = 1;
        for(; b; b >>= 1, a *= a) if(b & 1) r *= a;
        return r;
    }
    friend modint operator-(modint a) {return modint(0) - a;}
    friend modint operator!(modint a) {return a ^ (mod - 2);}
    modint& operator/=(modint const& b) {return *this *= !b;}
    friend bool operator==(modint a, modint b) {return a.x == b.x;}
    friend bool operator!=(modint a, modint b) {return a.x != b.x;}
    friend modint operator+(modint a, modint const& b) {return a += b;}
    friend modint operator-(modint a, modint const& b) {return a -= b;}
    friend modint operator*(modint a, modint const& b) {return a *= b;}
    friend modint operator/(modint a, modint const& b) {return a /= b;}
    modint& operator*=(modint const& b) {x = 1LL * x * b.x % mod; return *this;}
    friend ostream& operator<<(ostream& os, modint const& a) {return os << a.x;}
    modint& operator+=(modint const& b) {x += b.x; x = (x >= mod) ? x - mod : x;return *this;}
    modint& operator-=(modint const& b) {x = x >= b.x ? x - b.x : x - b.x + mod;return *this;}
};

using mint = modint <>;

mint nCr(int n, int m) {
    if(m > n) return mint(0);
    mint p = 1, q = 1;
    for(int i = n - m + 1; i <= n; i++) p *= i;
    for(int i = 1; i <= m; i++) q *= i;
    return p / q;
}

int32_t main() {

    ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, m, sum = 0; cin >> n >> m;
    vector <int> v(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> v[i];
        sum += v[i];
    }

    if(sum > m) {
        cout << 0 << endl;
        return 0;
    }

    mint a = nCr(m + n, (sum + n));
    cout << a << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll mod = 998244353;

vector<ll> fac(300001); //n!(mod mod)
vector<ll> ifac(300001); //k!^{M-2} (mod mod)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod mod) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int N, K; cin >> N >> K;
    int a[N][N];
    rep(i, N){
        rep(j, N){
            cin >> a[i][j];
        }
    }

    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % mod; // n!(mod mod)
        ifac[i+1] = ifac[i]*mpow(i+1, mod-2) % mod; // k!^{mod-2} (mod mod) ←累乗にmpowを採用
    }

    ll ans = 1;

    UnionFind Ux(N);
    for (int i = 0; i < N-1; i++){
        for (int j = i+1; j < N; j++){
            bool check = true;
            for (int k = 0; k < N; k++){
                if(a[i][k] + a[j][k] > K){
                    check = false;
                    break;
                }
            }
            if(check){
                Ux.merge(i, j);
            }
        }
    }

    unordered_set<int> setx;
    for (int i = 0; i < N; i++){
        int x = Ux.root(i);
        if(!setx.count(x)){
            setx.insert(x);
            int y = Ux.size(x);
            ans *= fac[y];
            ans %= mod;
        }
    }

    UnionFind Uy(N);
    for (int i = 0; i < N-1; i++){
        for (int j = i+1; j < N; j++){
            bool check = true;
            for (int k = 0; k < N; k++){
                if(a[k][i] + a[k][j] > K){
                    check = false;
                    break;
                }
            }
            if(check){
                Uy.merge(i, j);
            }
        }
    }

    unordered_set<int> sety;
    for (int i = 0; i < N; i++){
        int x = Uy.root(i);
        if(!sety.count(x)){
            sety.insert(x);
            int y = Uy.size(x);
            ans *= fac[y];
            ans %= mod;
        }
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  ll x,y; cin >> x >> y;
  if(x >= y) cout << x - y << "\n";
  else {
    map<ll,ll> dp;
    queue<ll> q;
    q.push(y);
    ll res = infll;
    while( !q.empty() ) {
      ll num = q.front(); q.pop();
      if(num <= x) {
	chmin(res, dp[num] + x - num);
	continue;
      }
      chmin(res, dp[num] + num - x);
      if(num % 2 == 0) {
	if(dp[num/2] == 0) {
	  dp[num/2] = dp[num]+1;
	  q.push(num/2);
	}
	else if(chmin(dp[num/2], dp[num]+1)) {
	  q.push(num/2);
	}
      }
      else {
	if(dp[num/2] == 0) {
	  dp[num/2] = dp[num]+2;
	  q.push(num/2);
	}
	else if(chmin(dp[num/2], dp[num]+2)) {
	  q.push(num/2);
	}
	if(dp[num/2+1] == 0) {
	  dp[num/2+1] = dp[num]+2;
	  q.push(num/2+1);
	}
	else if(chmin(dp[num/2+1], dp[num]+2)) {
	  q.push(num/2+1);
	}
      }
    }
    cout << res << "\n";
  }
  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N, M;
int A[1011], B[1011];
int dp[1011][1011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, N) scanf("%d", A+i);
    REP (i, M) scanf("%d", B+i);

    memset(dp, 0x3f, sizeof dp);
    dp[0][0] = M + N;

    REP (i, N+1) REP (j, M+1) {
	if (i < N && j < M) {
	    if (A[i] != B[j]) {
		amin(dp[i+1][j+1], dp[i][j] - 1);
	    } else {
		amin(dp[i+1][j+1], dp[i][j] - 2);
	    }
	}
	amin(dp[i][j+1], dp[i][j]);
	amin(dp[i+1][j], dp[i][j]);
    }

    int ans = dp[N][M];
    printf("%d\n", ans);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

#define FAST cin.tie(nullptr)->sync_with_stdio(false);
#define PRECISE cout << fixed << setprecision(19);
#define ONE int tc = 1;
#define GO for (int i = 0; i < tc; ++i) { solve(); }

void solve() {
    int a, b, c; cin >> a >> b >> c;
    cout << (a * a + b * b < c * c ? "Yes" : "No");
}

int main() {
    FAST PRECISE ONE GO
}

#include <iostream>
#include "bits/stdc++.h"
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    string winner;
    if (c == 0)
    {
        if (b < a)
        {
            winner = "Takahashi";
        }
        else
        {
            winner = "Aoki";
        }
    }
    else
    {
        if (a < b)
        {
            winner = "Aoki";
        }
        else
        {
            winner = "Takahashi";
        }
    }

    cout << winner << endl;
}


#include <iostream>
using namespace std;
using ll = long long;

int main(){
  double A, B;
  cin >> A >> B;
  cout << 100-100*B/A<<endl;
}

#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Travel | diff Travel.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Travel.cpp && ./a.out

/*

 11/15/2020

 21:18-

 */

const int MAX_N=10+1;
LL T[MAX_N][MAX_N],K;
int N;

void solve() {
  int res=0;
  VI P(N); iota(ALL(P),0);
  do {
    if(P[0]!=0) continue;
    LL t=0;
    REP(i,N) {
      int u=P[i],v=i+1<N?P[i+1]:0;
      t+=T[u][v];
    }
    res+=t==K;
  } while(next_permutation(ALL(P)));
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>K;
  REP(i,N)REP(j,N) cin>>T[i][j];
  solve();

  return 0;
}


#include<ctime>
#include<cstdio>
#include<cctype>
using namespace std;
const int N=1e5+10;
int read() {
	char c;
	int x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
int n,x,a[N],b[N];
int main() {
	#ifndef ONLINE_JUDGE
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	for(int i=1;i<=n;++i)
		a[i]=read();
	for(int i=1;i<=n;++i)
		b[i]=read();
	for(int i=1;i<=n;++i)
		x+=a[i]*b[i];
	if(!x)
		puts("Yes");
	else
		puts("No");
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}

// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
int n; cin>>n;
vin  a (n) , b (n);
F (i,0,n,1) cin>>a[i];
F (i,0,n,1) cin>>b[i];
int pr=0;
F (i,0,n,1) {
	pr += (a[i]*b[i]);
}
(pr==0)?cout<<"Yes":cout<<"No";
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/


#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi 3.1415926535897932384626
#define MX 1e5 + 5
#define MOD 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << " , " << #y << " = " << y << endl
#define clr(x) memset(x, 0, sizeof(x))
#define ff first
#define ss second

#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define fr(i, j, k, in) for (int i = j; i < k; i += in)
#define rfr(i, j, k, in) for (int i = j; i >= k; i -= in)
#define freach(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define rfo(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, n) for (int i = 0; i < n; i++)
#define foa(i, a, n) for (int i = a; i < n; i++)
#define endl "\n"
#define sz(a) a.size()
#define digits(n) 1 + floor(log10(n))
#define prec(n) fixed << setprecision(n)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x), greater<int>())
#define sortarr(n, x) sort(n, n + x)

#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

#define miiitr map<int, int>::iterator it;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pair<int, int>> vii;
typedef vector<vector<int>> vvi;
typedef map<int, int> mpii;
typedef set<int> sti;

/****** Template of some basic operations *****/
template <typename T, typename U>
inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
/**********************************************/

/**********output of pair , set , map , vector ********/
template <typename T, typename G>
ostream &operator<<(ostream &out, const pair<T, G> &a)
{
    return out << "(" << a.first << " , " << a.second << ")";
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &a)
{
    out << "[";
    for (const auto &i : a)
        out << i << " , ";
    return out << "]";
}

template <typename T>
ostream &operator<<(ostream &out, const set<T> &a)
{
    out << "{";
    for (const auto &i : a)
        out << i << " , ";
    return out << "}";
}

template <typename T, typename G>
ostream &operator<<(ostream &out, const map<T, G> &a)
{
    out << "<";
    for (const auto &i : a)
        out << i << " , ";
    return out << ">";
}
/**********************************************/
/*************input output of vector***************/
//vi arr = i_vector<int>(n);
//print_stl(arr);
template <typename T>
vector<T> i_vector(int n)
{
    vector<T> v(n);
    T temp;
    for (auto it = v.begin(); it != v.end(); it++)
    {
        cin >> *it;
    }
    return v;
}

template <typename T>
void print_stl(T arr)
{

    for (auto itr = arr.begin(); itr != arr.end(); ++itr)
    {
        cout << *itr << " ";
    }
    cout << endl;
}
/**********************************************/
int n, m, k , x , q , y , t ;
vi a ;

void solve()
{
    cin >> n;
    int count = 0;
    fo(i , n ){
        cin>> m ;
        count^=((i+1)^m) ;
    }
    if(!count){
        cout << "Yes" ;
    }else{
        cout << "No" ;
    }
    // print_stl(a);
}
int32_t main()
{
    fast;
    int t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}

//in dp prefix suffix sum helps..
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include <iterator>
#include <map>
#include<list>
#include <fstream>
#include<unordered_map>
#include<set>
#include<queue>
#define int  long long
#define double long double
#define pb   push_back
#define mp   make_pair
#define pii  pair<int,int>
#define pip pair<int, pair<int, int> >
#define vip vector<pair<int, pii> >
#define vi vector<int>
#define vd vector<double>
#define mii  map<int, int>
#define qu queue<int>
#define set set<int>
#define multiset multiset<int>
#define rep(i, a, b) for(int i=a;i<b;i++)
#define rep1(i, a, b) for(int i=a;i>=b;i--)
#define viv vector<vi>
#define stack stack<int>
#define fi first
#define se second
#define reverse(s) reverse(s.begin(), s.end())
#define sort1(v) sort(v.begin(), v.end())
#define it iterator
#define pq priority_queue<int>
#define pq1 priority_queue <pii, vector<pii>, greater<pii> >
#define mem(x, y) memset(x, (int)y, sizeof(x))
#define ps(x,y) fixed<<setprecision(y)<<x
// author :: Anurag Anand.
using namespace std;
//int z=  1e9+7;
int z= 998244353;
int gcd(int a, int b){
    if(a==0)return b;
    if(b==0)return a;
    return gcd(b, a%b);
}
int power(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)
		{
			res=(res*a)%z;
			b--;
		}
		a=(a*a)%z;
		b=b>>1;
	}
	return res;
}
vi sv;
// vi seg;
// void arrange(int i, int v, int x, int lx, int rx){
// 	if(rx-lx==1){
// 		seg[x] =v;
// 		return;
// 	}
// 	int m= (lx+rx)/2;
// 	if(i<m) arrange(i, v, 2*x+1, lx, m);
// 	else arrange(i, v, 2*x+2, m, rx);
// 	seg[x]=min(seg[2*x+1], seg[2*x+2]);
// }
// int calc(int l, int r, int x, int lx, int rx){
// 	    if(l>=rx||r<=lx) return 1e9;
// 	    if(lx>=l&&rx<=r) return seg[x];
// 	    int mid=(lx+rx)/2;
// 	    int sl= calc(l, r, 2*x+1, lx, mid), sr= calc(l, r, 2*x+2, mid, rx);
// 	    return min(sl, sr);
// }
// vi v[200001];
// int dist[200001], ans[200001]={0}, vis[200001]={0};
// void dijkstra(int root){
// 	int a, d;
// 	dist[root]=0;
// 	set s;
// 	s.insert(mp(0, root));
// 	while(!s.empty()){
// 		a= (*s.begin()).se, d= (*s.begin()).fi;
// 		s.erase(s.begin());
// 		for(int i=0;i<v[a].size();i++){
// 			if(dist[a]+1<dist[v[a][i]]){
// 				s.erase(mp(dist[v[a][i]], v[a][i]));
// 				dist[v[a][i]]=dist[a]+1;
// 				s.insert(mp(dist[v[a][i]], v[a][i]));
// 			}
// 		}
// 	}
// }
vi pp;
int col[100001];
vi v[100001];
int g[100001]={0};
mii m;
void dfs(int u, int p=-1){
	m[col[u]]++;
	rep(i,0,v[u].size()){
		if(v[u][i]==p) continue;
		if(!m[col[v[u][i]]]){
			g[v[u][i]]=1;
		}
		dfs(v[u][i], u);
	}
	m[col[u]]--;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
	pp.assign(1000001, 0);
	for(int i=2;i<1000;i++){
		if(!pp[i]){
			for(int j=i*i;j<=1000000;j+=i){
				pp[j]=1;
			}
		}
	}
	for(int i=2;i<=1000000;i++) if(!pp[i]) sv.pb(i);
	int t;
	t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		rep(i,1,n+1) cin>>col[i];
		int x, y;
		rep(i,1,n){
			cin>>x>>y;
			v[x].pb(y);
			v[y].pb(x);
		}
		g[1]=1;
		dfs(1);
		rep(i,1,n+1) if(g[i]) cout<<i<<"\n";
	}
}


#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pii = pair<int,int>;

template <class T> int sgn(T x) { return (x > 0) - (x < 0); }

template<class T>
struct TPoint {
  typedef TPoint P;
  T x, y;
  static constexpr T eps = static_cast<T>(1e-9);
  explicit TPoint(T x=0, T y=0) : x(x), y(y) {}
  bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
  bool operator==(P p) const {
    // return tie(x,y)==tie(p.x,p.y);
    return abs(x-p.x) <= eps && abs(y-p.y) <= eps;
  }
  P operator+(P p) const { return P(x+p.x, y+p.y); }
  P operator-(P p) const { return P(x-p.x, y-p.y); }
  P operator*(T d) const { return P(x*d, y*d); }
  P operator/(T d) const { return P(x/d, y/d); }
  T dot(P p) const { return x*p.x + y*p.y; }
  T cross(P p) const { return x*p.y - y*p.x; }
  T cross(P a, P b) const { return (a-*this).cross(b-*this); }
  T dist2() const { return x*x + y*y; }
  double dist() const { return sqrt((double)dist2()); }

  // angle to x-axis in interval [-pi, pi]
  double angle() const { return atan2(y, x); }
  P unit() const { return *this/dist(); } // makes dist()=1
  P perp() const { return P(-y, x); } // rotates +90 degrees
  P normal() const { return perp().unit(); }

  // returns point rotated 'a' radians ccw around the origin
  P rotate(double a) const {
    return P(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a)); }
};

using Point = TPoint<double>;

struct DSU {
  struct node {
    int p; // parent
    int s; // size
  };

  vector<node> nodes;
  DSU(int n) {
    nodes.resize(n);
    for (int i =0; i < n; i++) {
      nodes[i].p = i;
      nodes[i].s = 1;
    }
  }

  node& operator[](int index) {
    return nodes[index];
  }

  int size(int v) {
    return nodes[find(v)].s;
  }

  int find(int v) {
    if (nodes[v].p==v)
      return v;
    return nodes[v].p = find(nodes[v].p);
  }

  bool merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (a==b)
      return false;
    if (nodes[a].s < nodes[b].s)
      swap(a,b);
    nodes[b].p = a;
    nodes[a].s += nodes[b].s;
    return true;
  }
};

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<Point> a(n);
  for (int i = 0; i < n; i++) {
    int x,y;
    cin >> x >> y;
    a[i] = Point(x,y);
  }
  const int s = n, t = n+1;
  vector<tuple<double,int,int>> edge;
  for (int i = 0; i < n; i++) {
    edge.emplace_back(a[i].y+100,i,s);
    edge.emplace_back(100-a[i].y,i,t);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      edge.emplace_back((a[i]-a[j]).dist(),i,j);
    }
  }
  sort(edge.begin(),edge.end());
  DSU d(n+2);
  for (auto [l,i,j] : edge) {
    d.merge(i,j);
    if (d.find(s) == d.find(t)) {
      cout << fixed << setprecision(10) << l/2 << endl;
      return 0;
    }
  }
}
// Observations:
// It corresponds to some distance between points
// How to choose which points?
//
// Maybe a binary search? how do i know whether its ok?

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &i : v) os << i << ' ';
    return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

struct union_find {
    vector<int64_t> par;
    vector<int64_t> sz;

    union_find(int64_t _n) {
        par.resize(_n);
        sz.assign(_n, 1);
        for(int64_t i = 0; i < _n; ++i) par[i] = i;
    }

    int64_t root(int64_t x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int64_t x, int64_t y) {
        x = root(x), y = root(y);
        if (x != y) {
            if (sz[x] > sz[y]) swap(x, y);
            par[y] = x;
            sz[x] += sz[y];
        }
    }

    int64_t size(int64_t x) {
        return sz[root(x)];
    }

    bool same(int64_t x, int64_t y) {
        return root(x) == root(y);
    }
};

int main(void) {
    ll n;
    cin >> n;
    Vec x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    ld l = 0, r = LINF;
    while(r - l > EPS) {
        ld m = (l + r) / 2;
        union_find uf(n + 2);
        rep(i, n) {
            REP(j, i + 1, n) {
                if (pow<ld>(x[i] - x[j], 2) + pow<ld>(y[i] - y[j], 2) <= pow(m * 2, 2))
                    uf.unite(i, j);
            }
        }

        rep(i, n) {
            if (100 - y[i] <= m * 2) uf.unite(n, i);
        }

        rep(i, n) {
            if (y[i] + 100 <= m * 2) uf.unite(n + 1, i);
        }

        if (uf.same(n, n + 1)) r = m;
        else
            l = m;
    }
    setp(10);
    co(l);

    return 0;
}


#include <bits/stdc++.h>

//end
int main() {
    long long int g;
    std::cin >> g;
    double rez = std::sqrt((double)2) * std::sqrt((double)(g + 1));
    long long int maz = (long long int)rez + 1;
    for (long long int u = maz; u >= 1; u--) {
        if ((u + 1) * u / 2 <= g + 1) {
            std::cout << g - u + 1 << std::endl;
            break;
        }
    }
}
//end

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m;
signed main(){
    cin>>n;
    int x=sqrt((n+1)<<1);
    if(x*(x+1)>((n+1)<<1)) x--;
    cout<<n-x+1<<endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const ll LLMAX = (1llu<<(sizeof(ll)*8-1)) - 1;
const int IMAX = (1llu<<(sizeof(int)*8-1)) - 1;

const ull Nmax = 2 * 100000 + 100;
ull amax[Nmax];
ull bmax[Nmax];

ull N, a[Nmax], b[Nmax], c[Nmax];

int main(){
  cin >> N;
  for(ull i = 0; i < N; i++){
    cin >> a[i];
    if(i == 0){
      amax[i] = a[i];
    } else {
      amax[i] = max(a[i], amax[i-1]);
    }
  }
  for(ull i = 0; i < N; i++){
    cin >> b[i];
    if(i == 0){
      bmax[i] = b[i];
    } else {
      bmax[i] = max(b[i], bmax[i-1]);
    }
  }
  c[0] = a[0] * b[0];
  for(ull i = 1; i < N; i++){
    c[i] = max(c[i-1], b[i] * amax[i]);
  }
  for(ull i = 0; i < N; i++){
    cout << c[i] << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);i++)
void chmax(ll& a, ll b) {if (b>a) a=b;}

int main() {
  int N;
  cin >> N;
  vector<int> a(N), b(N);
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  ll ans = 0, maxa = 0;
  rep(i,N) {
    chmax(maxa, a[i]);
    chmax(ans, maxa*b[i]);
    cout << ans << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;

#define INF 1000000009
using ll=long long;

struct salesman{
    // 頂点数Nのセールスマン 0スタート
    ll N;
    vector<vector<ll>> g;
    ll MAXN=17;
    vector<vector<ll>> dp;
    ll ans=INF;

    salesman(ll n){
        N=n;
        g.resize(n);
        dp.resize(1<<N);
        for (ll i=0;i<(1<<N);i++){
            dp[i].resize(n);
        }
        for (ll i=0;i<n;i++){
            g[i].resize(n);
            for (ll j=0;j<n;j++){
                g[i][j]=INF;
            }
            g[i][i]=0;
        }
        for (ll r=0;r<(1<<N);r++){
            for (ll i=0;i<N;i++){
                dp[r][i]=INF;
            }
        }
    };

    // 有向グラフ
    void add_edge(ll from,ll to,ll cost){
        g[from][to]=cost;
    };
    //  0に戻ってくる時の最小コスト和
    void run(){
        dp[0][0]=0;
        for (ll r=0;r<(1<<N);r++){
            for (ll l=0;r>>l>0;l++){
                if ((r>>l)&1){
                    for (ll u=0;u<N;u++){
                        if (g[u][l]!=INF) dp[r][l]=min(dp[r][l],dp[r-(1<<l)][u]+g[u][l]);
                    }
                }
            }
        }
        for (ll i=1;i<N;i++){
            if (g[i][0]!=INF && dp[(1<<N)-1][i]!=INF) ans=min(dp[(1<<N)-1][i]+g[i][0],ans);
        }
    };
};

int main(){
    ll N;cin >> N;
    vector<ll> X(N);
    vector<ll>Y(N);
    vector<ll> Z(N);
    salesman solver(N);
    for (int i=0;i<N;i++){
        cin >> X[i] >> Y[i] >> Z[i];
    }
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            ll cost=0;
            if (Z[j]-Z[i]>=0) cost=abs(X[i]-X[j])+abs(Y[i]-Y[j])+Z[j]-Z[i];
            else cost=abs(X[i]-X[j])+abs(Y[i]-Y[j]);
            solver.add_edge(i,j,cost);
        }
    }
    solver.run();
    cout << solver.ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
    int N; cin >> N;
    vector<double> a(N),b(N),c(N),d(N);
    for(int _=0; _<2; _++){
        for(int i=0; i<N; i++) cin >> a[i] >> b[i];
        int x = 0, y = 0;
        for(int i=0; i<N; i++){
            x += a[i];
            y += b[i];
            a[i] *= N;
            b[i] *= N;
        }
        for(int i=0; i<N; i++){
            a[i] -= x;
            b[i] -= y;
        }
        swap(a,c);
        swap(b,d);
    }
    for(int i=0; i<N; i++){
        if(a[i]!=0 || b[i]!=0){
            swap(a[i],a[0]);
            swap(b[i],b[0]);
        }
    }
    string ans = "No";
    const double eps = 1e-6;
    for(int i=0; i<N; i++){
        double angle = atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool flag = true;
        for(int j=0; j<N; j++){
            double A = a[j]*cos(angle)-b[j]*sin(angle);
            double B = a[j]*sin(angle)+b[j]*cos(angle);
            bool flag2 = false;
            for(int k=0; k<N; k++){
                if(std::abs(A-c[k])<=eps && std::abs(B-d[k])<=eps) flag2 = true;
            }
            flag &= flag2;
        }
        if(flag) ans = "Yes";
    }
    cout << ans << endl;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int A[111], B[111];

int cnt[211];

bool dp[211];

int AB[211], BA[211];

void MAIN() {
    scanf("%d", &N);
    REP (i, N) {
	scanf("%d%d", A+i, B+i);
	if (A[i] != -1) A[i]--;
	if (B[i] != -1) B[i]--;
    }

    bool yes = true;
    REP (i, N) {
	if (A[i] == 2*N-1) yes = false;
	if (B[i] == 0) yes = false;
	if (A[i] != -1 && B[i] != -1 && B[i] <= A[i]) yes = false;

	if (A[i] != -1) cnt[A[i]]++;
	if (B[i] != -1) cnt[B[i]]++;
    }

    if (yes) {
	REP (i, 2*N) {
	    if (cnt[i] >= 2) yes = false;
	}
    }

    if (yes) {
	REP (i, N*2) {
	    AB[i] = -2;
	    BA[i] = -2;
	}
	REP (i, N) {
	    if (A[i] != -1) AB[A[i]] = B[i];
	    if (B[i] != -1) BA[B[i]] = A[i];
	}

	dp[0] = true;
	for (int i=0; i<N*2; i+=2) if (dp[i]) {
	    for (int h=1; i+h+h<=N*2; h++) {
		bool ok = true;
		for (int k=i; ok && k<i+h; k++) {
		    if (AB[k] == -1 && BA[k+h] != -2) ok = false;
		    if (BA[k+h] == -1 && AB[k] != -2) ok = false;
		    if (0 <= AB[k] && AB[k] != k+h) ok = false;
		    if (0 <= BA[k]) ok = false;
		    if (0 <= BA[k+h] && BA[k+h] != k) ok = false;
		    if (0 <= AB[k+h]) ok = false;
		}

		if (ok) dp[i+h+h] = true;
	    }
	}

	yes = dp[N*2];
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=1e18;

struct Q{
    int a;
    int b;
    int i;
    bool operator<(const Q &another) const {return a < another.a;};
};

int main(){
    int n; cin >> n;
    VI x(n), y(n);
    REP(i,n) cin >> x[i] >> y[i];
    int m; cin >> m;
    VI op(m), p(m,-1);
    REP(i,m){
        cin >> op[i];
        if(op[i]>=3)
            cin >> p[i];
    }
    int q; cin >> q;
    vector<Q> qu(q);
    REP(i,q){
        cin >> qu[i].a >> qu[i].b;
        qu[i].b--;
        qu[i].i=i;
    }
    sort(ALL(qu));
    qu.push_back({0,0,-1});
    int rad=0;
    bool xr=0, yr=0;
    ll xd=0, yd=0;
    int now=0;
    vector<P> ans(q);
    while(qu[now].a==0){
        ans[qu[now].i]={x[qu[now].b],y[qu[now].b]};
        now++;
    }
    REP(i,m){
        if(op[i]==1){
            rad=(rad+1)%4;
            xd=-xd;
            swap(xd,yd);
            swap(xr,yr);
        }
        else if(op[i]==2){
            rad=(rad+3)%4;
            yd=-yd;
            swap(xd,yd);
            swap(xr,yr);
        }
        else if(op[i]==3){
            xd=-xd+p[i]*2;
            xr=!xr;
        }
        else{
            yd=-yd+p[i]*2;
            yr=!yr;
        }
        while(qu[now].a==i+1){
            int j=qu[now].i;
            ll ansx=x[qu[now].b];
            ll ansy=y[qu[now].b];
            if(rad==0){
                ans[j]={ansx,ansy};
            }
            else if(rad==1){
                ans[j]={ansy,-ansx};
            }
            else if(rad==2){
                ans[j]={-ansx,-ansy};
            }
            else{
                ans[j]={-ansy,ansx};
            }
            ans[j].first=ans[j].first*(xr?-1:1)+xd;
            ans[j].second=ans[j].second*(yr?-1:1)+yd;
            now++;
        }
    }
    REP(i,q){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

VVI g(300000);
VI in(300000,0);
VI ans(300000,0);
VI kk(300000,0);

void dfs(int v){
    for(auto to:g[v]){
        ans[to]+=ans[v];
        if(--in[to]==0){
            dfs(to);
        }
    }
}

int main(){
    int n, m; cin >> n >> m;
    VVI c(n+1,VI(n+1,INF));
    int x, y, z;
    REP(i,m){
        cin >> x >> y >> z;
        for(int j=x;j>=0;j--)
            c[j][y]=min(c[j][y],(ll)z);
        for(int k=y;k>=0;k--)
            c[x][k]=min(c[x][k],(ll)z);
    }
    REP(i,1<<n){
        int popc=0, cnt=0;
        bool no=0;
        REP(j,n){
            if(i>>j&1)
                popc++;
        }
        REP(j,n){
            if(i>>j&1)
                cnt++;
            if(c[popc][j+1]<cnt){
                no=1;
                break;
            }
        }
        if(!no)
            kk[i]=1;
    }
    kk[0]++;
    REP(i,1<<n){
        if(kk[i]==2){
            REP(j,n){
                if(!(i>>j&1)){
                    if(kk[i|(1<<j)]){
                        kk[i|(1<<j)]=2;
                        g[i].push_back(i|(1<<j));
                        in[i|(1<<j)]++;
                    }
                }
            }
        }
    }
    ans[0]=1;
    dfs(0);
    cout << ans[(1<<n)-1] << endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1005,mod=1e9+7;
int n,f[N];
char AA,AB,BA,BB;
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>AA>>AB>>BA>>BB;
	if(n==2)
	{
		cout<<1<<endl;
		return 0;
	}
	if(AB=='A')
	{
		if(AA=='A')
		{
			cout<<1<<endl;
			return 0;
		}
		if(BA=='A')
		{
			f[0]=1,f[1]=2;
			for(int i=2;i<=n;i++)
				f[i]=(f[i-1]+f[i-2])%mod;
			cout<<f[n-3]<<endl;
			return 0;
		}
		cout<<qp(2,n-3)<<endl;
	}
	else
	{
		if(BB=='B')
		{
			cout<<1<<endl;
			return 0;
		}
		if(BA=='B')
		{
			f[0]=1,f[1]=2;
			for(int i=2;i<=n;i++)
				f[i]=(f[i-1]+f[i-2])%mod;
			cout<<f[n-3]<<endl;
			return 0;
		}
		cout<<qp(2,n-3)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll solve(vector<ll> &A1, vector<ll> &A2, ll &T) {
  bitset<20> bs;
  vector<ll> B;
  ll res=0;
  for(ll i=0; i<pow(2,A1.size()); ++i) {
    ll count=0; bs=i;
    for(ll j=0; j<A1.size(); ++j) if(bs.test(j)) count+=A1[j];
    B.push_back(count);
  }
  sort(B.begin(),B.end());
  for(ll i=0; i<pow(2,A2.size()); ++i) {
    ll count=0; bs=i;
    for(ll j=0; j<A2.size(); ++j) if(bs.test(j)) count+=A2[j];
    if(count<=T) {
      count+=*(upper_bound(B.begin(),B.end(),T-count)-1);
      res=max(res,count);
    }
  }
  return res;
}

int main() {
  ll N,T; cin>>N>>T;
  vector<ll> A1, A2;
  for(ll i=0; i<N; ++i) {
    ll A; cin>>A;
    if(i<N/2) A1.push_back(A);
    else A2.push_back(A);
  }
  cout << solve(A1,A2,T) << endl;
}

#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define forn(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ford(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ii pair<int,int>
#define ar array
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
//const int N = 3e5+7 ;
/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

void solve(){
    int n , t ;
    cin >> n >> t ;
    vector<int> a(n) ;
    for(auto& x : a) cin >> x ;
    vector<int> s1{0} , s2{0} ;
    forn(i,n) {
        int m = sz(s1) ;
        forn(j,m) s1.push_back(s1[j]+a[i]) ;
        swap(s1,s2) ;
    }
    sort(all(s1)) ;
    reverse(all(s1)) ;
    int ans = 0 ;
    forn(i,sz(s2)) {
        if(s2[i] > t) continue ;
        ans = max(ans , s2[i]+ *lb(all(s1),t-s2[i],greater<int>())) ;
    }
    cout << ans << endl ;
}

int32_t main(){
    FAST_IO ;
    int t = 1 ;
//    cin >> t ;
    while(t--){
        solve() ;
    }
}


#include<bits/stdc++.h>
using namespace std;

string dfs(int n,string s){
    if(n == 1)return s;
    while(n%3!=1){
        string t;
        for(int i=1;i<n;i++){
            if(s[i]==s[i-1])t+=s[i];
            else {
                int x = 'R'+'W'+'B';
                x -= s[i] + s[i-1];
                t += (char)x;
            }
        }
        swap(t,s);
        n--;
    }
    string t;
    for(int i=0;i<n;i+=3)t+=s[i];
    return dfs((int)t.size(),t);
}

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    cout << dfs(n,s) << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const LL mod = 998244353;

LL f[3010][6010], s[6010];
int n, k;

int main() {
	cin >> n >> k;
	f[0][0] = 1;
	s[0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = i; j >= 1; j--) {
			f[i][j] = s[i * 2 - j * 2];
			s[i * 2 - j] = (s[i * 2 - j] + f[i][j]) % mod;
		}
	cout << f[n][k] << endl;
	return 0;
}


#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define MOD 1000000007
#define INF 9223372036854775800

using namespace std;

//----------------------------(a1,b1) (a2,b2)を通る直線の傾き(key0)と切片(key1)
vector<double> strand(long long int a1,long long int a2,long long int b1,long long int b2){
	vector<double> x;
	double d;
	double s;
	if(a1==a2){
		x.push_back(0);
		x.push_back(0);
		return x;
	}
	else{
		d = (double)(b1-b2)/(double)(a1-a2);
		x.push_back(d);
		s=(double)(b1)-d*(double)(a1);
		x.push_back(s);
		return x;
	}
}
int main(){

ll int N , D, H;
cin >> N >> D >> H;
vector< ll int > d(N);
vector< ll int > h(N);
rep(i,N) cin >> d[i] >> h[i];
vector< vector< double > > f(N);

double ans = 0.0;
rep(i,N){
        f[i] = strand(D,d[i],H,h[i]);
	ans = max( ans, f[i][1] );
}
cout << fixed << setprecision(5) << ans << endl;

	return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ERR(...) fprintf(stderr,__VA_ARGS__);
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
typedef long long ll;
priority_queue<int> Queue;
const int MAXN=200005;
int A[MAXN],B[MAXN],P[MAXN],Q[MAXN];
pair<int,int> S[MAXN];
inline bool ok(int v){return P[v]!=Q[v]&&A[P[v]]>B[v]&&A[v]>B[v]&&A[P[v]]>B[P[v]];}
inline void ac(){
	int n,i,p,q,s=0;
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&A[i]);
	rep(i,1,n)scanf("%d",&P[i]);
	rep(i,1,n)scanf("%d",&Q[i]);
	rep(i,1,n)B[i]=P[Q[i]];
	//rep(i,1,n)printf("%d ",B[i]);printf("\n");
	rep(i,1,n)P[Q[i]]=i;
	//rep(i,1,n)printf("%d ",P[i]);printf("\n");
	rep(i,1,n)if(ok(i))Queue.push(i);
	while(!Queue.empty()){
		i=Queue.top();Queue.pop();
		if(!ok(i))continue;
		p=P[i];q=Q[i];
		swap(B[p],B[i]);
		//printf("%d <- %d <- %d\n",p,i,q);fflush(stdout);
		Q[p]=q;P[q]=p;
		P[i]=Q[i]=i;
		S[++s]=make_pair(p,i);
		if(ok(q))Queue.push(q);
	}
	rep(i,1,n)if(P[i]!=i&&P[i]==Q[i]){
		p=P[i];
		if(A[i]<=B[i]||A[p]<=B[p]){puts("-1");return;}
		P[i]=Q[i]=i;
		P[p]=Q[p]=p;
		S[++s]=make_pair(p,i);
	}
	rep(i,1,n)if(P[i]!=i){puts("-1");return;}
	printf("%d\n",s);
	rep(i,1,s)printf("%d %d\n",S[i].first,S[i].second);
}
int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	ac();
	return 0;
}


#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

const int INF = 1e9+7;

int show_matrix(vector<vector<int>> &dp) {
  loop(0, dp.size(), i) {
    loop(0, dp[i].size(), j) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> Z(N);

  loop(0, N, i) {
    cin >> X[i];
    cin >> Y[i];
    cin >> Z[i];
  }

  vector<vector<ll>> DP(N, vector<ll>(1 << N, INF));
  DP[0][1] = 0;

  for (ll bit=1; bit < (1 << N); bit++) {
    loop(0, N, i) {
      ll next_bit = bit | (1 << i);
      loop(0, N, j) {
        ll cost = abs(X[i] - X[j]) + abs(Y[i] - Y[j]) + max((ll)0, Z[j] - Z[i]);
        DP[j][next_bit] = min(DP[j][next_bit], DP[i][bit] + cost);
      }
    }
  }
  ll complete = (1 << N) - 1;
  print(DP[0][complete]);
}

#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for(ll i = 0; i < n; i++) cin >> a[i];
	sort(a.rbegin(), a.rend());
	vector<ll> pref(n, 0);
	pref[0] = a[0];
	for(ll i = 1; i < n; i++) {
		pref[i] = pref[i-1] + a[i];
	}
	ll ans = 0;
	for(ll i = 0; i < n-1; i++) {
		ans += (n-i-1) * a[i] - (pref[n-1] - pref[i]);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define MOD 1000000007

int main() {
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int ans = 0;
    if (r1 == r2 && c1 == c2) {
        cout << ans << endl;
        return 0;
    }
    int limit = 10;
    for (int dx = -3; dx <= 3; dx++) {
        for (int dy = -3; dy <= 3; dy++) {
            if (abs(dx) + abs(dy) > 3) {
                continue;
            }
            ll nr = r1 + dx;
            ll nc = c1 + dy;
            if (nr + nc == r2 + c2 || nr - nc == r2 - c2 || abs(nr - r2) + abs(nc - c2) <= 3) {
                limit = 2;
            }
        }
    }
    while (true) {
        ans++;
        if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 || abs(r1 - r2) + abs(c1 - c2) <= 3) {
            break;
        }
        if (ans == 1) {
            ll d = r2 - r1;
            r1 += d;
            c1 += d;
            d = (c2 - c1) / 2;
            r1 += d;
            c1 += d;
            continue;
        }
        if (ans == 2) {
            ans++;
            break;
        }
    }
    cout << min(ans, limit) << endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int x,y,a,b;
signed main()
{
	scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
	if(x<a)
		swap(x,a),swap(y,b);
	if(x==a&&y==b)
	{
		puts("0");
		return 0;
	}
	if(x+y==a+b||x-y==a-b||abs(x-a)+abs(y-b)<=3)
	{
		puts("1");
		return 0;
	}
	if((a+b)%2==(x+y)%2||(abs(b+(a-x)-y))<=3||(abs(b-(a-x)-y))<=3)
	{
		puts("2");
		return 0;
	}
	puts("3");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
typedef pair<int, pi> pii;

int x2,y2;

int test(int x1,int y1, int grad1, int grad2) {
	if (x1 - y1 == grad1 or x1+y1 == grad2) {
		return 1;
	} else {
		if (((x1 - y1) - grad1) % 2 == 0) {
			return 2;
		} else if ((grad2 - (x1 + y1)) % 2 == 0) {
			return 2;
		}
	}
	return INT_MAX/2;
}

int32_t main() {
	FAST
	int x1,y1;
	cin >> x1 >> y1 >> x2 >> y2;
	if (x1 == x2 and y1 == y2) {
		cout << 0;
		return 0;
	}

	int grad1 = x2 - y2;
	int grad2 = x2 + y2;

	int ans = test(x1,y1,grad1,grad2);

	for (int x = x2-3; x <= x2+3; x++) {
		for (int y = y2-3; y <= y2 +3;y++) {
			if (abs(x - x2) + abs(y - y2) <= 3) {
				ans = min(ans, test(x1,y1,x - y, x +y) + 1);
			}
		}
	}

	for (int x = x1-3; x <= x1+3; x++) {
		for (int y = y1-3; y <= y1 +3;y++) {
			if (abs(x1 - x) + abs(y1 - y) <= 3) {
				if (x == x2 and y == y2) {
					ans = min(ans, 1ll);
				}

				ans = min(ans, test(x,y,grad1, grad2) + 1);
			}
		}
	}

	cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000000

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int tt=1;
	//cin >> tt;
	while(tt--)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		if(a==c&&b==d)
		{
			cout << 0 << endl;
		}
		else if(a+b==c+d||a-b==c-d||abs(a-c)+abs(b-d)<=3)
		{
			cout << 1 << endl;
		}
		else if(abs((a+b)-(c+d))<=3||abs((a-b)-(c-d))<=3)
		{
			cout << 2 << endl;
		}
		else if((a+b)%2==(c+d)%2)
		{
			cout << 2 << endl;
		}
		else
		{
			cout << 3 << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int a[25];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    int ans = 2e9;
    for(int i=0;i<(1<<n);i++){
        int sum = 0, res = 0;
        for(int j=0;j<n;j++){
            sum |= a[j];
            if(j == n-1 || ((i>>j)&1)){
                res ^= sum;
                sum = 0;
            }
        }
        ans = min(ans, res);
    }
    printf("%d\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
#define BUFF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define DEBUG(var) cout << #var << "=" << var << '\n'
#define WARN puts("warning!")
#define REP(i, a, n) for (int i = a; i <= n; ++i)
#define PER(i, n, a) for (int i = n; i >= a; --i)
#define LL int64_t
template<typename T>void Read(T &x){x=0;char ch=getchar();LL f=1;while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}x*=f;}
template<typename T>int64_t __lcm(T a, T b){return a/__gcd(a,b)*b;}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int64_t Rand(LL a,LL b) {return a + rng() % (b-a+1);}
inline int64_t QuickPow(LL base,LL n,LL Mod = 0){LL ret(1);while(n){if(n&1){ret*=base;if(Mod)ret%=Mod;}base*=base;if(Mod)base%=Mod;n>>=1;}return Mod?ret%Mod:ret;}
inline int64_t Inv(LL x,LL p){return QuickPow(x,p-2,p);}
inline void gettime(){time_t rawtime;struct tm *ptminfo;time(&rawtime);ptminfo = localtime(&rawtime);printf("Current time: %02d-%02d-%02d %02d:%02d:%02d\n",ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday,ptminfo->tm_hour, ptminfo->tm_min, ptminfo->tm_sec);}
const double pi = acos(-1.0);
const LL kInf(LONG_LONG_MAX);
const LL kMod(998244353);
const LL kMax(210);
LL group(1);

inline void Solve()
{
    /*write your code down here*/
    int n;
    cin>>n;
    vector<int>v(n);
    for(auto &it:v)Read(it);
    int res = INT_MAX;
    for(int i = 0;i < (1<<(n-1));i++)
    {
        int XOR = 0,OR = 0;
        for(int j = 0;j <= n;j++)
        {
            if(j < n)OR |= v[j];
            if(j == n ||  ((i>>j) &1))XOR ^= OR,OR = 0;
        }
        res = min(res,XOR);
    }
    cout<<res<<'\n';
}
int main()
{
    //gettime();
    //WARN;
    //Read(group);
    while (group--)
    {
        Solve();
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;

#define int long long

int extgcd(int a, int b, int &x, int &y) {
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    int g = extgcd(b, a % b, x, y);
    int t = x;
    x = y;
    y = t - a / b * y;
    return g;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int T;
    cin >> T;
    while (T--) {
        int n, s, k;

        cin >> n >> s >> k;
        int x, y;
        int g = extgcd(k, n, x, y);

        if (s % g != 0) {
            cout << -1 << endl;
            continue;
        } else if (g == 1) {
            cout << (x * (-s) % n + n) % n << endl;
        } else {
            n /= g;
            s /= g;
            k /= g;
            cout << (x * (-s) % n + n) % n << endl;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;

tuple<long long, long long, long long> extgcd(long long a, long long b) {
    if (b == 0) return {a, 1, 0};
    auto [d, x, y] = extgcd(b, a % b);
    return {d, y, x - a / b * y};
}

// ax ≡ b (mod n) を満たす最小の非負整数 x を返す
// ただし、解が存在しない場合は -1 を返す
long long mod_linear_equation(long long a, long long b, long long n) {
    assert(a > 0 && n > 0);
    auto [d, x, y] = extgcd(a, n);
    n /= d;
    return b % d == 0 ? ((b / d * x) % n + n) % n : -1;
}

void solve() {
    int n, s, k;
    cin >> n >> s >> k;
    long long x = mod_linear_equation(k, -s, n);
    cout << x << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s[n];
	set<string> val;
	for(int i=0;i<n;i++)
	{cin>>s[i];val.insert(s[i]);}
	for(int i=0;i<n;i++)
	{
		//if(s[i][0]!='!')	continue;
		if(val.count('!'+s[i]))
		{
			cout<<s[i];
			exit(0);
		}
	}
	cout<<"satisfiable";
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    irep(i, v) { cout << i->first << " " << i->second << '\n'; }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
string getline() {
    string s;
    fflush(stdin);
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
template <typename Head, typename Value>
auto vectors(const Head& head, const Value& v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail>
auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;  // 998244353;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

int main() {
    map<string, int> m;
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        string t=s;
        int bi=0;
        if(s[0]=='!')bi=1;
        if(t[0]=='!')t=t.substr(1);
        m[t]|=(1<<bi);
    }
    irep(i,m){
        if(i->second==3){
            cout<<i->first<<endl;
            return 0;
        }
    }
    fin("satisfiable");
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a. end())
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<ll>> vvll;
typedef long double ld;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n),t1(n);
    rep(i,n){
        cin >> s[i]>>t[i];
    }
    t1=t;
    Sort(t1);
    Reverse(t1);
    int second=t1[1];
    rep(i,n){
        if (t[i]==second){
            cout<<s[i];
            return 0;
        }
    }

}

/* Up : 1 2 0 5 - 201 */

#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

#include <vector>
#include <iomanip>
#include <time.h>

#define file    freopen("input.txt","r",stdin)
#define ll      long long int
#define space   printf(" ")
#define newline printf("\n")

using namespace std;

ll cs()
{
    ll n;
    scanf("%lld",&n);
    return n;
}
void cp(ll i)
{
    printf("%lld",i);
}

void test_case()
{
    /* start here for test case prob */

    ll n;
    n = cs();
    ll a[n],b[n];
    string s[n];
    getchar();
    for(ll i=0 ; i<n ; i++)
    {
        cin >> s[i];
        cin >> a[i];
        b[i] = a[i];
        getchar();
    }

    sort(b,b+n);
    for(ll i=0 ; i<n ; i++)
    {
        if(b[n-2]==a[i])
        {
            cout << s[i] << endl;
        }
    }

}
void t()
{
    ll tc;
    tc = cs();
    while(tc--)
    {
        test_case();
    }
}

int main()
{
    //file;
    test_case();
    //t();

    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,sum1=0,sum2=0;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		ll k;
		cin>>k;
		sum1+=k;
		sum2+=k*k;
	}
	cout<<sum2*n-sum1*sum1<<'\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long a[401],b[300005];
int main(){
	long long n,c,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		a[b[i]+200]++;
	}
	for(int i=0;i<=399;i++){
		for(int j=i+1;j<=400;j++){
			ans+=a[i]*a[j]*(i-j)*(i-j);
		}
	}
	cout<<ans;
	return 0;
}