#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint l[105], r[105];
llint a[205], b[205], f[205];
bool dp[205][205];

int check(llint L, llint R)
{
	llint id = a[L];
	if(id == 0){
		if(a[R] == 0) return 1;
		else{
			if(b[R] == 1 && f[R] == 1) return 0;
			else return 1e6;
		}
	}
	else{
		if(r[id] != -1 && r[id] != R) return 1e6;
		return 0;
	}
}

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

	cin >> n;
	llint m = 0;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		if(l[i] != -1) a[l[i]] = i, b[l[i]] = 0;
		if(r[i] != -1) a[r[i]] = i, b[r[i]] = 1;
		if(l[i] == -1 && r[i] != -1) f[r[i]] = 1;
		if(l[i] == -1 && r[i] == -1) m++;
	}

	dp[0][0] = true;
	for(int i = 0; i < 2*n; i++){
		if(b[i+1] == 1) continue;
		for(int j = 0; j <= m; j++){
			if(!dp[i][j]) continue;
			for(int k = i+2; k <= 2*n; k++){
				//cout << i+1 << " " << k << endl;

				if(check(i+1, k) > 1000) continue;
				//cout << i+1 << " " << k << endl;
				//if(id && r[id] != -1 && r[id] != j) continue;
				//if(id == 0 && a[j] != 0 && f[j] == 0) continue;
				int cnt = 0;
				cnt += check(i+1, k);
				for(int l = i+2; l < k; l++){
					cnt += check(l, l+(k-(i+1)));
					//cout << cnt << endl;
				}
				//cout << i+1 << " " << k << " " << cnt << endl;
				if(j+cnt <= m && (k-1)+(k-(i+1)) <= 2*n) dp[(k-1)+(k-(i+1))][j+cnt] = true;
			}
		}
	}

	/*for(int i = 0; i <= 2*n; i++){
		for(int j = 0; j <= m; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/

	if(dp[2*n][m]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> tp(sz), com(sz, -1);

    bool ng = false;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (tp[A[i]]) ng = true;
            tp[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (tp[B[i]]) ng = true;
            tp[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            com[A[i]] = B[i];
            com[B[i]] = A[i];
        }
    }
    if (ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;

            rep(k, w) {
                int p = i + k, q = i + k + w;
                if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
                    ok = false;
                }
                if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
                    ok = false;
                }
                if (tp[p] != 0 && tp[q] != 0) {
                    if (tp[p] < 0 || tp[p] + tp[q] != 0) {
                        ok = false;
                    }
                }
                if (tp[p] < 0 || tp[q] > 0) {
                    ok = false;
                } else {
                    if (tp[p] != 0) {
                        int v = tp[p] - 1;
                    }
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define EFOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)
#define INF 1000000000
ll nums = 10000000000;

int main() {
    int n; cin >> n;
    string s,t; cin >> s;
    REP(i,s.size()){
        t.push_back(s[i]);
        if(t.size() <= 2) continue;
        if(t.substr(t.size()-3,t.size()) == "fox"){
            t = t.substr(0,t.size()-3);
        }
    }
    cout << t.size() << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1000000007;
int mpow(int b, int e);

int main(){
    IOS
    int n, m; cin>>n>>m;
    vector<int> g(1<<n, 0), complete(1<<n, -1);
    for(int i=0; i<m; i++){
    	int a, b; cin>>a>>b; a--; b--;
    	g[1<<a] = g[1<<a] | (1<<b);
    	g[1<<b] = g[1<<b] | (1<<a);
    }

    for(int i=1; i<(1<<n); i++){
    	for(int j=0, t=i; t; t>>=1, j++){
    		if(i & (1<<j)){
    			int x = i^(1<<j), y = g[1<<j];
    			if((y & x) != x){
    				complete[i]=0;
    				break;
    			}
    		}
    	}
    	if(complete[i]==-1)
    		complete[i]=1;
    }
    vector<int> dp(1<<n, INT_MAX);
    // dp[0]=1;
    for(int i=1; i<(1<<n); i++){
    	if(complete[i]==1)
    		dp[i]=1;
    	else{
    		for(int j=i-1; j; j = (j-1)&i)
    			dp[i] = min(dp[i], dp[j]+dp[i^j]);
    	}
    }
    // for(auto i: g) cout<<i<<" "; cout<<endl;
    // for(auto i: complete) cout<<i<<" ";
    // cout<<endl;
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}

//modular exponentiation
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}


#include<bits/stdc++.h>
#define re register
#define in inline
#define ll int
using namespace std;
char rbuf[10000002];
int pt;
in char gc(){
    return getchar();
}
in int read(){
    re int t=0;
    re char v=gc();
    while(v<'0')v=gc();
    while(v>='0'){
        t=(t<<3)+(t<<1)+(v^48);
        v=gc();
    }
    return t;
}
struct edge{
    int to,next,w;
}e[3002*3002*2];
int n,m,cnt,k,l[15],r[15],head[3002*3002],a,b,c,pl[32],w[15];
struct node{
    int pos;
    ll dis;
    bool operator <(const node x)const{
        return dis>x.dis;
    }
}h[3002*3002];
priority_queue <node> q;
inline ll M(re ll x,re ll y){
    return (x<y)?(x):(y);
}
inline void dis(re int s){for(re int i=1;i<=n*m+26;++i)h[i].pos=i,h[i].dis=0x7fffffff;
    h[s].dis=0;
    q.push(h[s]);
    while(!q.empty()){
        while((h[q.top().pos].dis<q.top().dis)){q.pop();if(q.empty())break;
        }
        if(q.empty())break;
        node tmp=q.top();
        q.pop();
        for(re int i=head[tmp.pos];i;i=e[i].next){
            if((tmp.dis+e[i].w)<h[e[i].to].dis){
                h[e[i].to].dis=tmp.dis+e[i].w;
                q.push(h[e[i].to]);
            }
        }

    }
}
inline void add(re int x,re int y,re int z){
    e[++cnt].to=y;
    e[cnt].w=z;
    e[cnt].next=head[x];
    head[x]=cnt;
}
char s[3002][3002];
signed main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
    n=read();
    re int ss,tt;
    m=read();
   for(re int i=1;i<=n;++i)scanf("%s",s[i]+1);
   for(re int i=1;i<=n;++i){
   	for(re int j=1;j<=m;++j){
   		if(s[i][j]!='#'&&s[i+1][j]!='#'&&i!=n){
   			add((i-1)*m+j,i*m+j,1);
   			add(i*m+j,(i-1)*m+j,1);
		   }
	   if(s[i][j]!='#'&&s[i][j+1]!='#'&&j!=m){
   			add((i-1)*m+j,(i-1)*m+j+1,1);
   			add((i-1)*m+j+1,(i-1)*m+j,1);
		   }
	   if(s[i][j]>='a'&&s[i][j]<='z'){
	   	add((i-1)*m+j,n*m+s[i][j]-'a'+1,1);
	   	add(n*m+s[i][j]-'a'+1,(i-1)*m+j,0);
	   }
	   if(s[i][j]=='S')ss=(i-1)*m+j;
	   if(s[i][j]=='G')tt=(i-1)*m+j;
	   }
	   }
   dis(ss);
   if(h[tt].dis<=1e9)
 printf("%d ",h[tt].dis);
 else puts("-1");
}

#include"bits/stdc++.h"
using namespace std;
const int N=2100;
char a[N][N];
vector<pair<int,int>> c[26];
int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};
int d[N][N];
int n,m;
const int inf=1e9;
bool vis[26];
bool ok(int x,int y){
	return (x<=n and y<=m and x>=1 and y>=1);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)d[i][j]=inf;
	for(int i=1;i<=n;i++){
		scanf("%s", a[i]+1);
	}
	int sx=-1,sy=-1,gx=-1,gy=-1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]<='z' and a[i][j]>='a')c[a[i][j]-'a'].push_back({i,j});
			if(a[i][j]=='S'){sx=i;sy=j;}
			if(a[i][j]=='G'){gx=i;gy=j;}
		}
	}

	deque<pair<int,int>> q;
	q.push_back({sx,sy});
	d[sx][sy]=0;

	while(!q.empty()){

		auto p=q.front();
		q.pop_front();
		int cur=d[p.first][p.second];
		int curc=a[p.first][p.second];
		if(curc<='z' and curc>='a' and !vis[curc-'a']){

				for(auto pp:c[curc-'a']){
					if(d[pp.first][pp.second]>1+cur){

						q.push_front({pp.first,pp.second});
						d[pp.first][pp.second]=1+cur;
					}
				}
				vis[curc-'a']=1;
			}

		for(int k=0;k<4;k++){
			int nx=p.first+dx[k];
			int ny=p.second+dy[k];
			if(!ok(nx,ny))continue;
			if(a[nx][ny]=='#')continue;

			if(d[nx][ny]>1+cur)
			{
				d[nx][ny]=1+cur;
				q.push_back({nx,ny});
			}
		}

	}

	if(d[gx][gy]==inf)puts("-1");
	else cout<<d[gx][gy]<<"\n";

}


     // Rakib (CSE'19)

    #include<bits/stdc++.h>

    #define               ll               long long
    #define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define               pb               push_back
    #define               ull              unsigned long long
    #define               read(i,n,a)      for(i=0;i<n;++i) cin>>a[i]
    #define               show(i,a)        for(auto i:a) cout<<i<<" "; cout<<endl
    #define               dpoint(n)        cout<<showpoint<<fixed<<setprecision(n)
    #define               MOD              998244353

    using namespace std;

    int gcd(int x,int y){
            if(!y) return x;
            return gcd(y,x%y);
    }

    ll proceed(){

        ll r,c;
        cin >> r >> c;
        char ch[r][c];

        ll i,j;

        for(i=0;i<r;++i){
            for(j=0;j<c;++j) cin >> ch[i][j];
        }

        ll cnt=0,ans=0;
        for(i=0;i<r;++i){
            for(j=0;j<c;++j){
                if(ch[i][j]=='.') ++cnt;
                else{
                    ans+=max(cnt-1,(ll)0);
                    cnt=0;
                }
            }
            ans+=max(cnt-1,(ll)0);
            cnt=0;

        }

        //cout << ans << endl;

        cnt=0;
        for(i=0;i<c;++i){
            for(j=0;j<r;++j){
                if(ch[j][i]=='.') ++cnt;
                else{
                    ans+=max(cnt-1,(ll)0);
                    cnt=0;
                }
            }
            ans+=max(cnt-1,(ll)0);
            cnt=0;
        }

        cout << ans << endl;

        return 0;

     }
        //** Main **//

    int main(){

                //boost_;
                int t=1,i=0;
                 //cin >> t;
                while(t--){

                    proceed();

                }

                return 0;
    }

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <stdio.h>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//DP処理用
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
sort(変数名.begin(), 変数名.end());*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h,w; cin>>h>>w;
vector<vector<char>> data(h,vector<char>(w));
REP(i,h) REP(j,w) cin>>data[i][j];
ll ans = 0;
REP(i,h-1){
  REP(j,w){
    if(data[i][j]=='.'&&data[i+1][j]=='.') ans++;
  }
}
REP(i,h){
  REP(j,w-1){
    if(data[i][j]=='.'&&data[i][j+1]=='.') ans++;
  }
}
cout<<ans;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
signed main()
{
	int n,m;
	cin>>n>>m;m*=100;
	int tot=0;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		tot+=a*b;
		if (tot>m) re cout<<i+1,0;
	}
	cout<<-1;
	re 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}
int main(){

	ll N,M;
	scanf("%lld %lld",&N,&M);

	ll tmp = mod_pow(10,N,M*M);

	printf("%lld\n",(tmp/M)%M);

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int n;
  cin >> n;
  double e[n+2];
  e[0] = 1;
  double ans = 0;
  LOOP1(i,n-1){
    //n面の中から n-i を選ぶ回数の期待値
    double p = (double)(n-i)/n;
    e[i] = 1/(p);
    ans += e[i];
    //cerr << e[i] << endl;
  }
  printf("%.12f\n", ans);
}


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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a,b,c) for(int a = b; a >= c; --a)
#define pb push_back
#define int long long
#define SZ(a) (int)(a.size())
#define mtp make_tuple

const int MOD = 998244353;
const int oo = 1e9;
const int mod = 1e9 + 7;
const int N = 2e5 + 100;
const int M = 7776;
typedef pair<double, double> ii;
typedef pair<char, pair<int, int> > iii;

int n;
int pr[N], a[N], color[N];
unordered_map<int, int> ump[N];

int find(int u) { return (u == pr[u]) ? u : (pr[u] = find(pr[u])); }

signed main()
{
	// freopen("test.inp", "r", stdin);
	ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    FOR(i, 1, n) {
        cin >> a[i];
        color[a[i]] = i;
        ump[i][a[i]] = 1;
        pr[i] = i;
    }
    FOR(i, 1, n) {
        int u = find(i);
        int v = find(color[a[i]]);
        if(u != v) {
            if(ump[u].size() > ump[v].size())
                swap(u, v);
            for(auto &it: ump[u]) {
                ump[v][it.fi] = 1;
            }
            ump[u].clear();
            pr[u] = v;
        }
    }
    FOR(i, 1, n / 2) {
        int u = find(i);
        int v = find(n - i + 1);
        if(u != v) {
            if(ump[u].size() > ump[v].size())
                swap(u, v);
            for(auto &it: ump[u]) {
                ump[v][it.fi] = 1;
            }
            ump[u].clear();
            pr[u] = v;
        }
    }

    int res = 0;
    FOR(i, 1, n) if(find(i) == i) {
        res += (ump[i].size() - 1);
    }
    cout << res;
}

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

int N;
string s;

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

	cin >> N >> s;
	string t;
	for(int i = 0; i < N; i++)
	{
		t += s[i];
		while(t.size() > 2 && t[t.size() - 1] == 'x' && t[t.size() - 2] == 'o' && t[t.size() - 3] == 'f')
		{
			t.pop_back();
			t.pop_back();
			t.pop_back();
		}
	}
	cout << t.size();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
using pi = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vector<int> >;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()

//const int inf = 9e18;
const int NUM=1000030;
const int N = 10000000;
vector<int> lp, sieve;
vector<int> pr;
void primefactor();
int binpow(int a, int b);
int binpow(int a, int b, int mod);
int gcd(int a, int b);
int lcm (int a, int b);
bool comp(int a, int b);
int inversemod(int a, int mod);
void calc_sieve();

int mod1=1e9+7;

void test()
{
    int n;
    cin>>n;
    vi arr(n+1);
    for(int i=1;i<=n;i++) cin>>arr[i];
    vvi modtaken(n+1, vi(n+1));
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=arr[i];
        for(int j=1;j<=n;j++) modtaken[j][i]=sum%j;
    }
    // for(int i=1;i<=n;i++)
    // {
    //     for(int j=1;j<=n;j++) cerr<<modtaken[i][j]<<" ";
    //     cerr<<endl;
    // }
    // cerr<<endl;
    vvi leftelement(n+1, vi(n+1, -1));
    for(int i=1;i<=n;i++)
    {
        map<int, int> ele;
        ele.clear();
        for(int j=1;j<=n;j++)
        {
            if(ele.count(modtaken[i][j])) leftelement[i][j]=ele[modtaken[i][j]];
            ele[modtaken[i][j]]=j;
        }
    }
    vvi dp(n+1, vi(n+1, 0));
    for(int j=1;j<=n;j++) dp[1][j]=1;
    for(int i=2;i<=n;i++)
    {
        for(int j=2;j<=n;j++)
        {
            if(leftelement[i][j]==-1) continue;
            dp[i][j]+=dp[i-1][leftelement[i][j]];
            dp[i][j]%=mod1;
            dp[i][j]+=dp[i][leftelement[i][j]];
            dp[i][j]%=mod1;
        }
    }
    // for(int i=1;i<=n;i++)
    // {
    //     for(int j=1;j<=n;j++) cerr<<dp[i][j]<<" ";
    //     cerr<<endl;
    // }
    // cerr<<endl;

    // for(int i=1;i<=n;i++)
    // {
    //     for(int j=1;j<=n;j++) cerr<<leftelement[i][j]<<" ";
    //     cerr<<endl;
    // }
    // cerr<<endl;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=dp[i][n];
        ans%=mod1;
    }
    cout<<ans<<endl;
}

signed main()
{
//    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--) test();
    return 0;
}

//    1. Take care of the corner cases, write one or two tests that seem to be the cases.
//    2. Check the bounds on the intput and decide the algorithm.
//    3. Make the test cases for the bounds, try to include 0, 1, 2 cases in the new test cases, and if possible, scale the cases.
//    4. Check for overflow and the array bounds carefully, always take care of the decreasing loop.

void calc_sieve() //credits: Anish_Sofat
{
    sieve.resize(NUM+1,0);
    for (int x = 2; x <= NUM; x++)
        {
            if (sieve[x]) continue;
            for (int u = x; u <= NUM; u += x)
            {
                    sieve[u] = x ;
            }
        }
}

void primefactor()
{
    lp.resize(N+1,0);
    for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}

int binpow(int a, int b)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int binpow(int a, int b, int mod)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}

int gcd(int a, int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}

int lcm (int a, int b)
{
    return ((a / gcd(a, b)) * b);
}

bool comp(int a, int b)
{
    return a>b;
}

int inversemod(int a, int mod)
{
    return binpow(a,mod-2, mod);
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)
const int N = 5e3 + 5;
const int P = 1e9 + 7;
int n, ans, a[N], sum[N], f[N][N], g[N][N];

signed main () {
	cin >> n;
	rep(i, 1, n) cin >> a[i], sum[i] = sum[i - 1] + a[i];
	f[0][0] = g[0][0] = 1;
	rep(i, 1, n) {
		rep(j, 1, i) f[i][j] = g[sum[i] % j][j - 1];
		rep(j, 1, i) g[sum[i] % (j + 1)][j] = (g[sum[i] % (j + 1)][j] + f[i][j]) % P;
	}
	rep(i, 1, n) ans = (ans + f[n][i]) % P;
	cout << ans;
	return 0;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const ll mod = 998244353;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int H, W, K;
vector<vector<char>> area(5001, vector<char>(5001, 'n'));

ll dp[5001][5001] = {};

//a^n mod
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod が素数
//a^(-1) mod
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    cin >> H >> W >> K;
    int i_h, i_w;
    char i_a;
    REP(i, K) {
        cin >> i_h >> i_w >> i_a;
        area[i_h-1][i_w-1] = i_a;
    }

    dp[0][0] = 1;
    REP(i, H*W-K) dp[0][0] = (dp[0][0] * 3) % mod;

    ll inv3 = modinv(3, mod);
    REP(i, H) {
        REP(j, W) {
            dp[i][j] %= mod;
            if (area[i][j] == 'X') {
                dp[i+1][j] += dp[i][j];
                dp[i][j+1] += dp[i][j];
            } else if (area[i][j] == 'R') {
                dp[i][j+1] += dp[i][j];
            } else if (area[i][j] == 'D') {
                dp[i+1][j] += dp[i][j];
            } else {
                dp[i+1][j] += (2 * dp[i][j]) * inv3;
                dp[i][j+1] += (2 * dp[i][j]) * inv3;
            }
        }
    }
    //REP(i, H) {
    //    REP(j, W) {
    //        cout << setw(10) << dp[i][j];
    //    }
    //    cout << endl;
    //}
    cout << dp[H-1][W-1] << endl;
}

#include <bits/stdc++.h>
#include <variant>

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

pair<i32,bool> solve(const vector<vi32>& g, i32 i) {
  bool flip = true;
  vector<pair<i32,bool>> children;
  for (auto&& to : g[i]) {
    auto [sc, fl] = solve(g, to);
    if (fl) flip = !flip;
    children.emplace_back(-sc, fl);
  }
  dump<<i<<endl;
  sort(all(children), [](auto&& lhs, auto&& rhs) {
      auto [ls, lf] = lhs;
      auto [rs, rf] = rhs;
      if (ls >= 0 && rs < 0) return true;
      else if (ls < 0 && rs >= 0) return false;
      if (ls >= 0) {
        if (lf == rf) {
          return ls > rs;
        } else {
          return rf;
        }
      } else {
        if (lf == rf) {
          return ls > rs;
        } else {
          return lf;
        }
      }
  });
  i32 score = 1;
  bool current = false;
  for (auto&& [sc, fl] : children) {
    dump<<sc<<" "<<fl<<endl;
    if (current) {
      score += sc;
    } else {
      score -= sc;
    }
    if (fl) current = !current;
  }
  return make_pair(score, flip);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n;
  cin>>n;
  vector<vi32> g(n);
  rep2(i,1,n) {
    i32 p;
    cin>>p;
    --p;
    g[p].push_back(i);
  }
  auto [score, flip] = solve(g, 0);
  auto ans = (n + score) / 2;
  cout<<ans<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
void prints(set<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
void printms(multiset<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
void printv(vector<ll> s) {for(ll u: s) cout<<u<<" "; cout<<"\n";}
const ll mod=1e9+7;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n,m;
    cin>>n>>m;
    vector<ll> a(n), b(m);
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<m;i++)
        cin>>b[i];
    vector<ll> ans;
    for(ll i=0;i<n;i++){
        ll val=a[i];
        bool ok=true;
        for(ll u: b){
            if(u==val){
                ok=false;
                break;
            }
        }
        if(ok) ans.pb(val);
    }
    for(ll i=0;i<m;i++){
        ll val=b[i];
        bool ok=true;
        for(ll u: a){
            if(u==val){
                ok=false;
                break;
            }
        }
        if(ok) ans.pb(val);
    }
    sort(ans.begin(),ans.end());
    for(ll u: ans)
        cout<<u<<" ";

    cerr<<"\n\nTIME: "<<(long double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

// Author: Muhesh Kumar

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

using ll  = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define nl '\n'
#define fr first
#define sc second
#define pb push_back
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sz(x) (int) (x).size()
#define trav(a, b) for(auto &a: b)
#define rep(i, a, b) for(int i = a; i < b; i++)

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m; cin >> n >> m;
    vector<int> a(n), b(m);
    unordered_map<int, int> occ1, occ2;
    trav(i, a) {
        cin >> i;
        occ1[i]++;
    }
    trav(i, b) {
        cin >> i;
        occ2[i]++;
    }

    vector<int> res;
    trav(i, a) {
        if (!occ2.count(i)) res.pb(i);
    }
    trav(i, b) {
        if (!occ1.count(i)) res.pb(i);
    }

    sort(all(res));
    trav(i, res) cout << i << " ";

    return 0;
}


#include<bits/stdc++.h>
#define forb(i,a,b) for(ll i=a;i<b;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define sortb(a) sort(a.begin(),a.end())
#define sortr(a) sort(a.begin(),a.end(),greater<ll> ())
#define inf LLONG_MAX
typedef long long int ll;
typedef long double ld;
using namespace std;

void solve(){
	ll n,a,x;
	cin>>n>>a;
	x=n;
	ll ct=0;
	while(x>0){
		ct+=(x%10);
		x/=10;
	}
	if(ct<=a){
		cout<<0<<endl;
	}
	else{
		ll i=0,ans=0;
		bool y=true;
		while(ct>a and y){
			if((ct-(n%10))>a){
				ans+=((10-(n%10))*pow(10,i));
				ct-=(n%10);
				n/=10;
				i++;
			}
			else{
				y=false;
			}
		}
		cout<<ans<<endl;
	}
}

int main(){
	ll a,b;
	string s;
	cin>>a>>b>>s;
	forb(i,0,a){
		if(s[i]=='o'){
			b++;
		}
		if(s[i]=='x' and b){
			b--;
		}
	}
	cout<<b<<endl;

}

#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(30)
#define TORAD(x) (x*acos(-1)/180.0)
#define TODEG(x) (x*180/acos(-1))
#define elif else if

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

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

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

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

// MAIN PROGRAM -------------

int main(){
	ll n,p;
	cin>>n>>p;
	--p;
	ll ans=modpow(p-1,n-1,MOD);
	cout<<(ans*p)%MOD;
}

/*

*/


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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;
}

int main(){
    int n;
    cin >> n;
    int m = (1<<n);
    vector<string> res;
    rep(bits,1<<n){
        if(bits==0)continue;
        vector<bool> flag(m);
        rep(i,m){
            int c = 0;
            rep(j,n){
                if((bits>>j)&1){
                    if((i>>j)&1)c++;
                }
            }
            if(c%2==1)flag[i] = 1;
        }
        string s;
        rep(i,m){
            if(flag[i]){
                s.push_back('A');
            }else{
                s.push_back('B');
            }
        }
        res.push_back(s);
    }
    cout << res.size() << "\n";
    for(auto x:res){
        cout << x << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()

#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"

//#define inf 1<<30

// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel
// istringstream ss(str) while(ss >> n)

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;

const ll inf = 2e18+100;
const ll mod = 1e9+7;

int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};

// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};

// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

void solve()
{
    ll x;
    cin >> x;

    if(x <= 10) cout << 0 << endl;
    else {
        ll ans = 0;
        ll val = 9, pwr = 1;

        for(ll i = 99; ; ){

            ans += (val*pwr);
            pwr *= 10;
            //cout << i << endl;
            if(i == x) {
                //cout << "as\n";
                cout << ans << endl;
                return;
            }
            if(i > x) {
                string now = to_string(x);
                ll mn_pwr = 1;
                //cout << ans << endl;
                int siz = now.size();

                if(siz%2) {
                    string a, b;
                    b = now.substr(0, (siz/2)+1);
                    for(int l=(siz/2)+1; l >= 1; l--) {
                        if(l == 1) a += "1";
                        else a += "0";
                    }
                    reverse(all(a));
                    ll tmp1 = stoll(b);
                    ll tmp2 = stoll(a);
                    //cout << tmp1 << " " << tmp2 << endl;
                    //cout << ans << endl;
                    ans -= (tmp1-tmp2);
                    //cout << ans << endl;
                    //return;
                }
                for(int j = (siz/2)-(!(siz%2)); j >= 0; j--) {
                    ll dig = now[j]-'0';
                    dig = 9 - dig;
                    ans -= (dig*mn_pwr);
                    mn_pwr *= 10;
                    //cout << ans << endl;
                }
                int ck = 0;
                /*
                for(int l = 0, r = siz-1;! l < r; l++, r--) {
                    if(now[l] != now[r]) {
                        ck = 1;
                        break;
                    }
                }*/
                if(siz%2 or now.substr(0, siz/2) > now.substr(siz/2)) ans--;
                cout << ans << endl;
                return;
            }

            i *= 100;
            i += 99;
        }
    }
}

int main()
{
    fast_io;

    int tt = 1;

    //cin >> tt;

    while(tt--) {
        solve();
    }

    return 0;
}


#ifdef LOCAL
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#endif

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

#define ll long long
#define vll vector<ll>
#define pii pair<ll,ll>
#define un_mp unordered_map<char,ll>
#define endl "\n"
#define pb push_back
#define all(a) a.begin(),a.end()

void solve(){
    ll a,b,n,tt,d,m,k;
    cin>>n;
    a=n;
    n/=100;
    cout<<(n+1)*100-a<<endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,n,tt,d,m,k,x,y;
    tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}

//always use
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long ll;
#define MOD 998244353

//2 147 483 647 (2^31-1) int max
//9 223 372 036 854 775 807 (2^63-1) ll max

//codeforces and USACO
void fast_io(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);}

//USACO
void file_io(string taskname){
  string fin = taskname + ".in";
  string fout = taskname + ".out";
  const char* FIN = fin.c_str();
  const char* FOUT = fout.c_str();
  freopen(FIN, "r", stdin);
  freopen(FOUT, "w", stdout);
  fast_io();}

//Printing pairs and vectors
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

//main code
int main(){
  fast_io();
  ll n;
  cin >> n;
  ll l=1,r=n+1; //l is <= answer, r > answer
  while(l+1<r){
    ll m=(l+r)/2;
    if (m > 1414213569LL || m*m>(2*(n+1)-m)){
      r=m;
    }
    else{
      l=m;
    }
  }
  //cout << l << "\n";
  cout << n-l+1;
}


#include <iostream>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;

int in(){
  double x;
  cin >> x;
  x*=10000;
  return round(x);
}

bool ok(ll dx,ll dy,ll z){
  return dx*dx+dy*dy <= z*z;
}

ll f(ll x,ll y,ll z,ll lim){
  int l=0,r=1;
  ll res = 0;
  for(int i=1e9+50000;i>=lim;i-=10000){
    while(ok(x-l*10000,i-y,z))--l;
    while(ok(r*10000-x,i-y,z))r++;
    res += r-l-1;
  }
  return res;
}

int main(){
  ll x=in(),y=in(),z=in();
  x%=10000;
  y%=10000;
  ll ans = f(x,y,z,10000);
  ans += f(x,-y,z,0);
  cout << ans << endl;
  return 0;

}

#include <cstdio>
#define DIV 10000LL
using namespace std;

typedef long long LL;

LL x, y, R;

inline LL read()
{
	// Returns: input * 10000.
	LL res = 0LL;
	int num = 0;
	bool flag = false, negative = false;
	for(char c=getchar(); c != ' ' && c != '\n'; c=getchar())
	{
		if(c == '-') negative = true;
		else if(c == '.') flag = true;
		else
		{
			res *= 10LL;
			res += c - '0';
			if(flag) num ++;
		}
	}
	for(int i=num; i<4; i++)
		res *= 10LL;
	return negative? -res: res;
}

inline LL in_circle(const LL& dx, const LL& dy)
{
	return dx * dx + dy * dy <= R * R;
}

inline LL findtop(LL i)
{
	i *= DIV;
	LL l = y, r = y + R;
	while(l < r)
	{
		LL mid = l + r + 1LL >> 1LL; // l<0?
		if(in_circle(i - x, mid - y))
			l = mid;
		else r = mid - 1LL;
	}
	return l;
}

inline LL ceildiv(const LL& a)
{
	// Returns: ceil(a / DIV).
	if(a < 0LL) return a / DIV;
	if(a % DIV == 0LL) return a / DIV;
	return a / DIV + 1LL;
}

inline LL floordiv(const LL& a)
{
	// Returns: floor(a / DIV).
	if(a >= 0LL) return a / DIV;
	if(a % DIV == 0LL) return a / DIV;
	return a / DIV - 1LL;
}

int main()
{
	x = read(), y = read(), R = read();
	LL ans = 0LL, left = ceildiv(x - R), right = floordiv(x + R);
	for(LL i=left; i<=right; i++)
	{
		LL top = findtop(i);
		LL bottom = (y << 1LL) - top;
		ans += floordiv(top) - ceildiv(bottom) + 1LL;
	}
	printf("%lld\n", ans);
	return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
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 (b<a) { a=b; return 1; } return 0; }

class UnionFind{
public:
    vector<ll> parent; //parent[i]はiの親
    vector<ll> siz; //素集合のサイズを表す配列(1で初期化)
    map<ll,vector<ll>> group; //集合ごとに管理する(key:集合の代表元、value:集合の要素の配列)
    ll n; //要素数

    //コンストラクタ
    UnionFind(ll n_):n(n_),parent(n_),siz(n_,1){
        //全ての要素の根が自身であるとして初期化
        for(ll i=0;i<n;i++){parent[i]=i;}
    }

    //データxの属する木の根を取得(経路圧縮も行う)
    ll root(ll x){
        if(parent[x]==x) return x;
        return parent[x]=root(parent[x]);//代入式の値は代入した変数の値なので、経路圧縮できる
    }

    //xとyの木を併合
    void unite(ll x,ll y){
        ll rx=root(x);//xの根
        ll ry=root(y);//yの根
        if(rx==ry) return;//同じ木にある時
        //小さい集合を大きい集合へと併合(ry→rxへ併合)
        if(siz[rx]<siz[ry]) swap(rx,ry);
        siz[rx]+=siz[ry];
        parent[ry]=rx;//xとyが同じ木にない時はyの根ryをxの根rxにつける
    }

    //xとyが属する木が同じかを判定
    bool same(ll x,ll y){
        ll rx=root(x);
        ll ry=root(y);
        return rx==ry;
    }

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

    //素集合をそれぞれグループ化
    void grouping(){
        //経路圧縮を先に行う
        rep(i,n)root(i);
        //mapで管理する(デフォルト構築を利用)
        rep(i,n)group[parent[i]].push_back(i);
    }

    //素集合系を削除して初期化
    void clear(){
        rep(i,n){parent[i]=i;}
        siz=vector<ll>(n,1);
        group.clear();
    }
};
int main() {
    ll N; cin>>N;
    vector<ll> A(N), B(N);
    rep(i, N){
        cin>>A[i];
        B[i] = A[i];
    }

    reverse(B.begin(), B.end());

    ll res = 0;
    UnionFind uf(2e5+1);
    rep(i, N){
        if(!uf.same(A[i], B[i])){
            res++;
            uf.unite(A[i], B[i]);
        }
    }
    cout << res << endl;
}

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

struct UnionFind {
  vector<int> par, size;

  UnionFind(int n) : par(n), size(n) {
    for(int i = 0; i < n; i++) {
      par[i] = i;
      size[i] = 1;
    }
  }

  int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return false;

    if(size[rx] > size[ry]) {
      par[ry] = rx;
      size[rx] += size[ry];
    } else {
      par[rx] = ry;
      size[ry] += size[rx];
    }
    return true;
  }

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

  int tree_size(int x) {
    return size[root(x)];
  }
};

void milkshake() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n);
  for(auto &x : a) {
    cin >> x;
    m = max(m, x);
    x--;
  }

  UnionFind tree(m);
  for(int i = 0; i < n/2; i++) {
    tree.unite(a[i], a[n - 1 - i]);
  }

  int ans = 0;
  for(int i = 0; i < m; i++) {
    if(tree.par[i] == i)
      ans += tree.tree_size(i) - 1;
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  while(tt--) milkshake();
  return 0;
}


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

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else
    #define D(a) 8
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;

    int v, t, s, d; cin >> v >> t >> s >> d;
    cout << (v*t > d || d > v*s ? "Yes" : "No") << endl;

	return 0;
}

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define PRINT(a) printf("%.15Lf\n",a);
#define YESNO(a) cout << (a ? "YES" : "NO") << endl
#define YesNo(a) cout << (a ? "Yes" : "No") << endl
#define yesno(a) cout << (a ? "yes" : "no") << endl
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

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

	int A, B, C; cin >> A >> B >> C;
	cout <<21- (A + B + C )<< endl;

	return 0;
}


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

int main() {
    string s; cin >> s;
    int tmp = 8;
    map<char,int> sub;
    for(int i = 0; i < (int) s.size(); i++) sub[s.at(i)]++;
    vector<string> oct(0);
    int count = 1;

    bool result = false;
    if(s.size() == 1) {
        if(s == "8") result = true;
    } else if((int) s.size() == 2) {
        count = 2;
        while(tmp * count < 100) {
            oct.push_back(to_string(tmp * count));
            count++;
        }
        for(int i = 0; i < (int) oct.size(); i++) {
            bool isOk = true;
            map<char,int> tar = sub;
            for(int j = 0; j < (int) oct.at(i).size(); j++) {
                bool ari = false;
                if(tar[oct.at(i).at(j)] > 0) {
                    ari = true;
                    tar[oct.at(i).at(j)]--;
                }
                if(ari) continue;
                else {
                    isOk = false;
                    break;
                }
            }
            if(isOk) {
                result = true;
                break;
            }
        }

    } else {
        count = 13;
        while(tmp * count < 1000) {
            oct.push_back(to_string(tmp * count));
            count++;
        }
        for(int i = 0; i < (int) oct.size(); i++) {
            bool isOk = true;
            map<char,int> tar = sub;
            for(int j = 0; j < (int) oct.at(i).size(); j++) {
                bool ari = false;
                if(tar[oct.at(i).at(j)] > 0) {
                    ari = true;
                    tar[oct.at(i).at(j)]--;
                }
                if(ari) continue;
                else {
                    isOk = false;
                    break;
                }
            }
            if(isOk) {
                result = true;
                break;
            }
        }
    }
    if(result) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

//Shinchan Loves Coding :))
#include<bits/stdc++.h>

using namespace std;

#define night_rider ios::sync_with_stdio(false);cin.tie(NULL);
#define double long double
#define int long long int
#define en "\n"
#define fi first
#define se second
#define PB push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define rep(i,x,y) for(int i=x ; i<y ; i++)
#define erep(i,x,y) for(int i=x ; i<=y ; i++)
#define erepr(i,x,y) for(int i=x ; i>=y ; i--)
#define repr(i,x,y) for(int i=x ; i>y ; i--)

typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> pii;

//--------------------------------------------------------------------------------------------------------------------------------------------------------------

const int no=3e6+5,modulo=1e9+7,inf=1e18,N=2e3+1;
const double PI = 3.1415926535897932384;
int ar[no] ,br[no],cr[no];//,dr[no],er[no];
//int used[no];
//int color[no];
//pii adj[no];
//vi adj[no] ;
//LOWER_BOUND(n) - FIRST ELEMENT GREATER THAN EQUAL TO n
//UPPER_BOUND(n) - FIRST ELEMENT GREATER THAN n

//--------------------------------------------------------------------------------------------------------------------------------------------------------------

map<char,int> fir,sec;

int make(string s) {
    string ans="";
    for(auto &ii : s) {
        ans+=(char)(sec[ii]+'0');
    }
    int x=0,k=ans.size();
    reverse(all(ans));
    rep(i,0,k) {
        x+=pow(10,i)*(ans[i]-'0');
    }
    return x;
}

void solve () {
    int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0,w=0,k=0;
    vector<string> v(3);
    rep(i,0,3) {
        cin>>v[i];
        rep(j,0,v[i].size()) {
            if(!j) fir[v[i][j]]++;
            sec[v[i][j]]++;
        }
    }
    if(sec.size()>=11) {
        cout<<"UNSOLVABLE";
        return ;
    }
    rep(i,0,10) {
        ar[i]=i;
    }
    do {
        a=0;
        for(auto ii : sec) {
            sec[ii.fi]=ar[a];
            a++;
        }
        bool ok=0;
        for(auto ii : fir) {
            if(sec[ii.fi]==0) {ok=1;}
        }
        if(!ok) {
            x=make(v[0]);
            y=make(v[1]);
            z=make(v[2]);
            // cout<<x<<" "<<y<<" "<<z<<en;
            if(x+y==z) {
                cout<<x<<"\n"<<y<<"\n"<<z<<en;
                return ;
            }
        }

    } while(next_permutation(ar,ar+10));
    cout<<"UNSOLVABLE";
}

inline void runn() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}

signed main() {
    night_rider
    runn();
    int t=1;
    cout<<fixed<<setprecision(15);
  //  cin>>t;
    rep(i,1,t+1) {
       // cout << "Case #" << i << ": ";
        solve();
    }
}


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

void prime_factor(int n, vector<bool> &p)
{
    for (int i = 2; i * i <= n; i++)
    {
        while(n % i == 0)
        {
            p[i] = true;
            n /= i;
        }
    }
    if(n != 1)p[n] = true;
    return;
}

int GCD(long long x, long long y) {
    if(x < y) swap(x, y); //この式はなくても良い。

    while (y > 0) {
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    int prime_num[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    long long ans = INFINITY;

    for (int i = 0; i < (1 << 15); i++)
    {
        bitset<15> s(i);
        long long Y = 1;
        for (int j = 0; j < 15; j++)
        {
            if(s[j] == 1)Y *= (prime_num[j]);
        }

        bool bf = false;
        for (int i = 0; i < n; i++)
        {
            if(GCD(Y, x[i]) == 1)
            {
                bf = true;
                break;
            }
        }
        if(!bf)
        {
            ans = min(ans, Y);
        }
    }
    cout << ans << endl;
}

#define MOD_TYPE 1

#pragma region Macros

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

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  set<ll> st;
  rep(i, n) st.insert(a[i]);
  while (st.size() >= 2)
  {
    ll Max = *st.rbegin();
    ll Min = *st.begin();
    st.erase(Max);
    ll k = CEIL(Max, Min) - 1;
    st.insert(Max - k * Min);
  }
  cout << *st.begin() << "\n";
}

int main()
{
  solve();
}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        ll             uint64_t
#define        ll1              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((ll)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N] ;

ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}
bool chk(ll ii,ll jj,ll nn,ll mm){if(ii<0||jj<0||ii>=nn||jj>=mm) return false;else return true;}

int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18, cs;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

        cin>>n;
        ll a1[n],b1[n];
        for(i=0;i<n;i++)
        {
            cin>>a1[i];
        }
        for(i=0;i<n;i++)
        {
               cin>>b1[i];
        }
        ll ans=a1[0]*b1[0];
        ma=a1[0];
        cout<<a1[0]*b1[0]<<endl;
        for(i=1;i<n;i++)
        {
               ma=max(ma,a1[i]);
               ans=max(ans,ma*b1[i]);
               cout<<ans<<endl;
        }

    //code
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

signed main(){
    string s;cin>>s;
    bool f=true;
    for(int i=0;i<(int)s.size();i+=2)if(!('a'<=s[i] and s[i]<='z')) f=false;
    for(int i=1;i<(int)s.size();i+=2)if(('a'<=s[i] and s[i]<='z')) f=false;
    cout<<(f?"Yes":"No")<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	long long x, y, a, b;
	cin >> x >> y >> a >> b;
	long long ans = 0;
	long long tmp = x;
	while (1) {
		if (tmp >= (y / a))break;
        if (tmp * a >= (long long) 2e18)break;
		if (tmp * (a - 1) > b)break;
		ans++;
		tmp *= a;
	}
	ans += (y - tmp -1) / b;
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
#define pf(dans) printf("%.12lf", dans)
#define pfn(dans) pf(dans); cout << endl;
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9 + 10;
const ll LINF = (ll)1e18 + 10;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define reprev(i, n) for (i = n - 1; i >= 0; i--)

template <typename T>
T my_abs(T x){
    return (x >= 0)? x : -x;
}

template <typename T>
void chmax(T &a, T b){
    a = max(a, b);
}

template <typename T>
void chmin(T &a, T b){
    a = min(a, b);
}

ll gcd(ll a, ll b){
    if (a > b) return gcd(b, a);
    if (a == 0) return b;
    return gcd(b % a, a);
}

bool incld_bit(ll bit, int i){
    return ((bit>>i) & 1) == 1;
}

// --------------------------------------------------------------------------------

int main(void){
    int i, j;
    int a, b, c;

    cin >> a >> b >> c;

    cout << a + b + c - min({a, b, c}) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

struct Solver {
  void solve() {
    int n;
    scanf("%d",&n);
    vi a(n), b(n);
    cin>>a>>b;
    int x = 0;
    rep(i,n) x += a[i]*b[i];
    if (x == 0) yn;
  }
};

int main() {
  int ts = 1;
  // scanf("%d",&ts);
  rrep(ti,ts) {
    Solver solver;
    solver.solve();
  }
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n;
    std::cin >> n;

    int a[n] ;
    int b[n] ;

    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] * b[i];
    }

    string msg = ans == 0 ? "Yes" : "No";
    std::cout << msg << std::endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#define rep(i,n) for (int i=0;i<n;i++)

#define DENOM 1000000007

using namespace std;
using ll = long long;

char win_rps(char a, char b) {
  if (a==b) {
    return a ;
  }
  if ((a=='R' && b=='S') || (a=='S' && b=='R')) {
    return 'R' ;
  } else if ((a=='S' && b=='P') || (a=='P' && b=='S')) {
    return 'S' ;
  } else {
    return 'P' ;
  }
}

int main(){
  int n, k ;
  string prev_s, s;
  size_t s_length;
  cin >> n >> k ;
  cin >> prev_s;
  for (int i = 0 ; i< k ; ++i) {
    prev_s += prev_s ;
    s_length = prev_s.size() ;
    if (s_length == 1) {
      cout << prev_s[0] << endl ;
      return 0 ;
    }
    s = "" ;
    for (int j = 0 ; j < s_length ; j+=2) {
      s += win_rps(prev_s[j], prev_s[j+1]) ;
    }
    prev_s = s ;
    cerr << i << ": " << prev_s << endl ;
  }
  cout << prev_s[0] << endl ;
  return 0 ;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

short A[501][501], B[501][501];
int D[1 << 18];

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

	int H, W;
	cin >> H >> W;
	rep(i, H) rep(j, W - 1) cin >> A[i][j];
	rep(i, H - 1) rep(j, W) cin >> B[i][j];
	rep(i, H) rep(j, W - 1) A[i][j] <<= 1;
	rep(i, H - 1) rep(j, W) B[i][j] <<= 1;

	priority_queue<ll, vector<ll>, greater<ll>> q;
	D[0] = -2e9 + 1;
	q.push((ll)D[0] << 32);
	int owa = (H - 1) << 9 | W - 1;

	while (q.size()) {
		auto tmp = q.top();
		q.pop();
		int d0 = tmp >> 32;
		int hwp = tmp & (1 << 20) - 1;
		if (D[hwp] != d0) continue;

		int h = hwp >> 9;
		int w = hwp & 511;
		int p = (d0 & 1) << 1 | 1;
		d0 |= 1;

		if (hwp == owa) break;

		if (w > 0) if (D[hwp - 1] > d0 + A[h][w - 1]) {
			D[hwp - 1] = d0 + A[h][w - 1];
			q.push((ll)(d0 + A[h][w - 1]) << 32 | hwp - 1);
		}
		if (w < W - 1) if (D[hwp + 1] > d0 + A[h][w]) {
			D[hwp + 1] = d0 + A[h][w];
			q.push((ll)(d0 + A[h][w]) << 32 | hwp + 1);
		}
		if (h > 0) if (D[hwp - 512] > d0 + p) {
			D[hwp - 512] = d0 + p;
			q.push((ll)(d0 + p) << 32 | hwp - 512);
		}
		if (h < H - 1) if (D[hwp + 512] > d0 + B[h][w]) {
			D[hwp + 512] = d0 + B[h][w];
			q.push((ll)(d0 + B[h][w]) << 32 | hwp + 512);
		}
	}

	co(D[owa] - D[0] >> 1);

	Would you please return 0;
}


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

int n, m, q, a, b, v[55], w[55], cnt, dp[55][55];

pair <int, int> p[55];

int main(){
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i++) cin >> a >> b, p[i] = make_pair(a, b);
    sort(p + 1, p + 1 + n);
    for(int i = 1; i <= m; i++) cin >> v[i];
    while(q--){
        cin >> a >> b, cnt = 0;
        for(int i = 1; i <= m; i++) if(i > b || i < a) w[++cnt] = v[i];
        sort(w + 1, w + 1 + cnt);
        for(int i = 1; i <= cnt; i++)
            for(int j = 1; j <= n; j++){
                if(p[j].first > w[i]){
                    dp[i][j] = dp[i][j - 1];
                    continue;
                }
                dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - 1] + p[j].second);
            }
        cout << dp[cnt][n] << endl;
        memset(dp, 0, sizeof(dp));
    }
    return 0;
}

/**
*    author:  tomo0608
*    created: 20.02.2021 21:39:59
**/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

// Primality test
class Prime {
    public:
    const int N;
    vector<int> min_prime;
    vector<int> primes;
    Prime(int size): N(size), min_prime(N+1){
        rep(i,N+1)min_prime[i] = i;
        min_prime[0] = -1;
        min_prime[1] = -1;
        for(int i = 2;i<=N;i++){
            if(min_prime[i]!=i)continue;
            primes.push_back(i);
            int tmp = 2*i;
            while(tmp <= N){
                if(min_prime[tmp]==tmp)min_prime[tmp] = i;
                tmp += i;
            }
        }
    }
    bool check(int x){ return min_prime[x] == x;}
};

void solve(){
    ll n,x;cin >> n >> x;
    V<ll> a(n);cin >> a;
    ll ans = x - *max_element(all(a));
    rep2(S,1, n+1){
        VV<ll> dp(S+1, V<ll>(S, -1));
        dp[0][0] = 0;
        rep(i,n){
            VV<ll> new_dp(S+1, V<ll>(S,-1));
            rep(j,S+1)rep(k,S){
                if(dp[j][k] != -1){
                    if(j < S)chmax(new_dp[j+1][(k + a[i])%S], dp[j][k] + a[i]);
                    chmax(new_dp[j][k], dp[j][k]);
                }
            }
            dp = new_dp;
        }
        if(dp[S][x%S] != -1){
            chmin(ans, (x - dp[S][x%S])/S);
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << setprecision(20);
    int codeforces = 1;
    //cin >> codeforces;
    while(codeforces--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int K;
LL dp[4][200001];

int main(){
  cin>>K;
  rep(t,4) rep(i,K+1) dp[t][i]=0;
  dp[0][1]=1;
  rep(t,3) for(int i=1; i<=K; i++)
    for(int j=i; j<=K; j+=i) dp[t+1][j]+=dp[t][i];
  LL ans=0;
  rep(i,K+1) ans+=dp[3][i];
  cout<<ans<<endl;
  return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
set<int>s;
signed main(){
	cin>>n;
	for(int i=2;i*i<=n;i++){
		if(s.count(i))continue;
		int t=i*i;
		while(t<=n)s.insert(t),t*=i;
	}
	cout<<n-s.size();
	return 0;
}


//Hare Krishna
//author: Dipjoy Basak
//dip_10

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

#define endl "\n"
#define ll long long
#define int ll
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define rrep(i, r, l) for (int i = r; i >= l; i--)
#define readarray(a, n) rep(i, 0, n - 1) cin >> a[i];
#define all(v) v.begin(), v.end()
#ifndef ONLINE_JUDGE
#define debug(x)       \
    cerr << #x << " "; \
    _print(x);         \
    cerr << endl;
#else
#define debug(x) ;
#endif
#define INF INT_MAX

//*----------------------------------------DEBUG functions--------------------------*

void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ld t) { cerr << t; }
void _print(double t) { cerr << t; }

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
    cerr << "{";
    _print(p.ff);
    cerr << ",";
    _print(p.ss);
    cerr << "}";
}
template <class T>
void _print(vector<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(set<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T>
void _print(multiset<T> v)
{
    cerr << "[ ";
    for (T i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
    cerr << "[ ";
    for (auto i : v)
    {
        _print(i);
        cerr << " ";
    }
    cerr << "]";
}

//-----------------------------------------------------------------------------------------------------------------------------

const int mod = 1000000007;
const int maxn = 100005;
int x, y, z, n, k;
int r, c;
string ans;
bool vis[40][40];

void google(int t)
{
    cout << "Case #" << t << ": ";
}

const int mod2 = 998244353;

void solve()
{
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    string s[h];
    rep(i, 0, h - 1)
    {
        cin >> s[i];
    }

    int ans = 0;
    rep(i, y, w)
    {
        if (s[x - 1][i - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rrep(i, y - 1, 1)
    {
        if (s[x - 1][i - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rep(i, x + 1, h)
    {
        if (s[i - 1][y - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    rrep(i, x - 1, 1)
    {
        if (s[i - 1][y - 1] == '.')
        {
            ans++;
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(15) << fixed;
    int t;
    t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // google(i);
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

template< int mod = 1000000007 >
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

// const int mod = 1000000007;
const int mod = 998244353;
using mint = ModInt< mod >;
const int MAX = 5100005;

mint fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
    }
    finv[MAX-1] = fac[MAX-1].inverse();
    for(int i=MAX-2;i>=1;i--){
        finv[i] = finv[i+1]*(i+1);
        inv[i+1] = fac[i]*finv[i+1];
    }
}

// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k]);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)cin>>s[i];
    mint ans = 1;
    bool pos = 1;
    int ret = 0;
    for(int sum=0;sum<h+w-1;sum++){
        int r = 0, b = 0;
        int cnt = 0;
        for(int i=0;i<h;i++){
            int j = sum - i;
            if(j<0 )break;
            if(j>=w)continue;
            ret++;
            if(s[i][j] == 'R')r++;
            else if(s[i][j] == 'B')b++;
            else cnt++;
        }
        if(r && b)ans = 0;
        if(r || b)ans *= 1;
        else ans *= 2;
    }
    cout << ans << endl;
    cerr<<ret<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
pair<long long,long long> sum[400040] = {};
vector< pair<long long, long long>> z;
set<long long> st;
int main() {
    int n;
    long long c;
    cin >> n >> c;
    for (int i = 0; i < n; i++) {
        long long a, b, c;
        cin >> a >> b >> c;
        z.emplace_back(make_pair(a, c));
        z.emplace_back(make_pair(b + 1, -c));
        st.insert(a);
        st.insert(b + 1);
    }
    sort(z.begin(), z.end());
    sum[0] = make_pair(z[0].first, z[0].second);
    long long now = z[0].first, now1 = 0;
    for (int i = 1; i < z.size(); i++) {
        if (now == z[i].first) {
            sum[now1].second += z[i].second;
        }
        else {
            now1++;
            sum[now1] = make_pair(z[i].first, z[i].second);
            sum[now1].second += sum[now1 - 1].second;
            now = z[i].first;
        }
    }
    cout << endl;
    long long ans = 0;
    for (int i = 1; i < st.size(); i++) {
        long long v = min(sum[i - 1].second, c);
        ans += v * (sum[i].first - sum[i - 1].first);
    }
    cout << ans << endl;
}

// abc199_d
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Graph {

    int n;
    vector<vector<int>> edges;

    vector<int> con_graph;
    vector<int> vals;

    vector<vector<int>> con_graph_list;
    ll tmp_ans = 0;

    Graph(int n_) : n(n_), edges(n_), con_graph(n_, -1), vals(n_, -1) {}

    void add_edge(int u, int v) {
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }

    void dfs0(int u, int p, int k){

        con_graph[u] = k;

        for (auto v: edges[u]){
            if (v == p) continue;
            if (con_graph[v] != -1) continue;
            dfs0(v, u, k);
        }
    }

    void dfs(int idx, int k){

        if (idx == con_graph_list[k].size()){
            tmp_ans++;
        } else {

            int u = con_graph_list[k][idx];

            vector<bool> tmp(3);
            for (auto v: edges[u]){
                if (vals[v] == -1) continue;
                tmp[vals[v]] = true;
            }

            REP(i, 3){
                if (tmp[i]) continue;
                vals[u] = i;
                dfs(idx+1, k);
                vals[u] = -1;
            }
        }
    }

    void func(){

        int k = 0;
        REP(i, n){
            if (con_graph[i] != -1) continue;
            dfs0(i, -1, k++);
        }

//        print(k);
        con_graph_list.resize(k);
        REP(u, n){
            con_graph_list[con_graph[u]].emplace_back(u);
        }

//        print(con_graph_list);

        ll ans = 1;

        REP(i, k){
            tmp_ans = 0;
            if (con_graph_list[i].size() == 1){
                ans *= 3;
            } else {
                vals[con_graph_list[i][0]] = 0;
                dfs(1, i);
                ans *= 3 * tmp_ans;
            }
        }

        print(ans);
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    Graph g(N);
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
    }

    g.func();

    return 0;
}


#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int n ;
PII a[N] ;
stack<int> st ;
char s[N] ;
int b[N] ;
int work()
{
  cin >> n ;
  for(int i = 1; i <= 2 * n ;i ++ ) cin >> a[i].x , a[i].y = i ;
  sort(a + 1 , a + 2 * n + 1) ;
  for(int i = 1; i <= 2 * n ;i ++ )
  		 b[a[i].y] = i <= n ;
  for(int i = 1; i <= 2 * n ;i ++ ) {
  	if(st.empty() || b[st.top()] == b[i]) st.push(i) , s[i] = '(' , cout << "(";
  	else st.pop() , cout << ")" ;
  }
  return 0 ;
}
int main()
{
  //   freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ;
  //   freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*

*/

#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define erep2(i, x) for (register int& i = cur[x]; i; i = e[i].next)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define fi first
#define se second
#define ui unsigned int
#define ld long double
#define pb push_back
#define pc putchar
#define lowbit(x) (x & -x)
#define maxr 2000020
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
using namespace std;

namespace Fast_Read{
    char buffer[maxr], *p1, *p2;
    template<class T> void read_signed(T& x){
        char ch = gc(); x = 0; bool f = 1;
        while (!isdigit(ch) && ch != '-') ch = gc();
        if (ch == '-') f = 0, ch = gc();
        while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();
        x = (f) ? x : -x;
    }
    template<class T, class... Args> void read_signed(T& x, Args&... args){
        read_signed(x), read_signed(args...);
    }
    template<class T> void read_unsigned(T& x){
        char ch = gc(); x = 0;
        while (!isdigit(ch)) ch = gc();
        while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = gc();
    }
    template<class T, class... Args> void read_unsigned(T& x, Args&... args){
        read_unsigned(x), read_unsigned(args...);
    }
    #define isletter(ch) ('a' <= ch && ch <= 'z')
    int read_string(char* s){
        char ch = gc(); int l = 0;
        while (!isletter(ch)) ch = gc();
        while (isletter(ch)) s[l++] = ch, ch = gc();
        s[l] = '\0'; return l;
    }
}using namespace Fast_Read;

int _num[20];
template <class T> void write(T x, char sep = '\n'){
	if (!x) {putchar('0'), putchar(sep); return;}
	if (x < 0) putchar('-'), x = -x;
	int c = 0;
	while (x) _num[++c] = x % 10, x /= 10;
	while (c) putchar('0' + _num[c--]);
	putchar(sep);
}

#define read read_signed
#define reads read_string
#define writes puts

#define maxn 200020
#define maxm
#define maxs
#define maxb
#define inf
#define eps
#define M
#define ll long long int

int n, a[maxn];
int main(){
    read(n); rep(i, 1, n) read(a[i]);
    sort(a + 1, a + 1 + n);
    double res = 0, x = a[(n + 1) >> 1] / 2.0;
    rep(i, 1, n) res += a[i]; res /= n;
    res += x;
    double tmp = 0;
    rep(i, 1, n) {
        tmp += min(1.0 * a[i], 2.0 * x);
    }
    tmp /= n;
    res -= tmp;
    printf("%.10f", res);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
// constexpr int INF = 1070000000;
// constexpr long long LINF = 4611686015206162431;
constexpr int MOD = 1000000007;
// constexpr long double PI = 3.1415926535897932;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

using vec = vector<ll>;
using mat = vector<vector<ll>>;

mat matmul(mat &A, mat &B) {
    mat C(A.size(), vec(B[0].size()));
    rep (i, A.size()) {
        rep (k, A[0].size()) {
            rep (j, B[0].size()) {
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
            }
        }
    }
    return C;
}

mat matpow(mat A, ll n) {
    mat B(A.size(), vec(A.size()));
    rep (i, A.size()) B[i][i] = 1;
    while (n > 0) {
        if (n & 1) B = matmul(B, A);
        A = matmul(A, A);
        n >>= 1;
    }
    return B;
}

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

    int N, M, K;
    cin >> N >> M >> K;
    mat A(1, vec(N));
    rep (i, N) cin >> A[0][i];
    vvc<int> graph(N);
    rep (i, M) {
        int X, Y;
        cin >> X >> Y;
        X--; Y--;
        graph[X].push_back(Y);
        graph[Y].push_back(X);
    }

    ll invm = modinv(M, MOD), inv2 = modinv(2, MOD);

    mat B(N, vec(N));

    rep (j, N) {
        for (int i : graph[j]) {
            B[i][j] = invm * inv2 % MOD;
        }
        B[j][j] = ((M - graph[j].size() + inv2 * graph[j].size()) % MOD) * invm % MOD;
    }

    B = matpow(B, K);
    A = matmul(A, B);
    rep (i, N) {
        cout << A[0][i] << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
const int N=102;
const int mod=1e9+7;
int n,m,K,v[N],deg[N];
void add(int &x,int y)
{
	(x+=y)>=mod&&(x-=mod);
}
int mul(int x,int y)
{
	return 1ll*x*y%mod;
}
struct mat
{
	int a[N][N];
	mat(int x=0)
	{
		memset(a,0,sizeof a);
		for(int i=1;i<=n;++i)
			a[i][i]=x;
	}
	mat operator *(mat &x)const
	{
		mat res;
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				for(int k=1;k<=n;++k)
					add(res.a[j][k],mul(a[j][i],x.a[i][k]));
		return res;
	}
}f[30];
int power(int x,int y=mod-2)
{
	int res=1;
	for(;y;y>>=1,x=mul(x,x))
		if(y&1)res=mul(res,x);
	return res;
}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	int inv=mul(power(2),power(m));
	for(int i=1;i<=n;++i)
		scanf("%d",&v[i]);
	for(int i=1,x,y;i<=m;++i)
	{
		scanf("%d%d",&x,&y);
		++deg[x];++deg[y];
		f[0].a[x][y]=f[0].a[y][x]=inv;
	}
	for(int i=1;i<=n;++i)
	{
		f[0].a[i][i]=mul(m-deg[i],inv<<1);
		add(f[0].a[i][i],mul(deg[i],inv));
	}
	for(int i=1;i<30;++i)
		f[i]=f[i-1]*f[i-1];
	mat res(1);
	for(int i=0;i<30;++i)
		if(K>>i&1)res=res*f[i];
	for(int i=1;i<=n;++i)
	{
		int ans=0;
		for(int j=1;j<=n;++j)
			add(ans,mul(v[j],res.a[j][i]));
		printf("%d\n",ans);
	}
}


#include <stdio.h>
#include <math.h>
int main(void) {
  long long int n;
  long long int m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  long long int x = 0;
  for(long long int i = 1; i < n; i++) {
    x +=i;
  }
  for(long long int l =1; l <n; l++){
    printf("%lld ",l);
  }
  printf("%lld ",1000000000-x);

  long long int y = 0;
  for(long long int j = 1; j < m; j++) {
    y +=j;
  }
  for(long long int q =-1; -1*q < m; q--){
    printf("%lld ",q);
  }
  printf("%lld",-1000000000+y);

  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int N, M, TIME=clock();
vector<pair<int, string>> V;
vi C(8);
int sum = 0;
vector<string> S(20);

int total() {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	vector<string> v(20);
	rep(i, N) v[i] = S[i];
	rep(q, 2) {
		rep(i, N) {
			s = v[i] + v[i];
			for (auto a : t) {
				bool f = false;
				rep(j, N) {
					if (a == s.substr(j, a.size())) {
						f = true;
						break;
					}
				}
				if (f) p += a.size();
				else u.insert(a);
			}
			t.clear();
			swap(t, u);
		}
		rep(i, N) { v[i].clear(); rep(j, N) v[i] += S[j][i]; }
	}
	return p;
}

int delta(int a, int b, int x, int y) {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	rep(q, 2) {
		s = S[a] + S[a];
		for (auto a : t) {
			bool f = false;
			int c = (b+N-a.size()+1)%N;
			rep(j, a.size()) {
				if (a == s.substr(c+j, a.size())) {
					f = true;
					break;
				}
			}
			if (f) p += a.size();
			else u.insert(a);
		}
		t.clear();
		swap(t, u);
		swap(a, x);
	}
	rep(q, 2) {
		s = "";
		rep(i, N) s += S[i][b];
		rep(i, N) s += S[i][b];
		for (auto a : t) {
			bool f = false;
			int c = (b+N-a.size()+1)%N;
			rep(j, a.size()) {
				if (a == s.substr(c+j, a.size())) {
					f = true;
					break;
				}
			}
			if (f) p += a.size();
			else u.insert(a);
		}
		t.clear();
		swap(t, u);
		swap(b, y);
	}
	return p;
}

int delta_1(int a, int b) {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	s = S[a] + S[a];
	for (auto a : t) {
		bool f = false;
		int c = (b+N-a.size()+1)%N;
		rep(j, a.size()) {
			if (a == s.substr(c+j, a.size())) {
				f = true;
				break;
			}
		}
		if (f) p += a.size();
		else u.insert(a);
	}
	t.clear();
	swap(t, u);

	s = "";
	rep(i, N) s += S[i][b];
	rep(i, N) s += S[i][b];
	for (auto a : t) {
		bool f = false;
		int c = (b+N-a.size()+1)%N;
		rep(j, a.size()) {
			if (a == s.substr(c+j, a.size())) {
				f = true;
				break;
			}
		}
		if (f) p += a.size();
		else u.insert(a);
	}
	t.clear();
	swap(t, u);
	return p;
}

int main() {
	cin >> N >> M;
	string s;
	rep(i, M) {
		cin >> s;
		V.pb({s.size(), s});
		rep(j, s.size()) C[s[j]-'A']++;
	}
	rep(i, 8) sum += C[i];
	rep(i, 7) C[i+1] += C[i];
	sort(all(V));

	int a=0, b=0, c=0, x, y, z;
	rep(i, N) {
		rep(j, N) {
			x = rand()%sum;
			rep(k, 8) {
				if (x < C[k]) {
					S[i] += 'A'+k;
					break;
				}
			}
		}
	}
	// show(total())
	int count = 0;
	while (true) {
		count++;
		a = rand()%N;
		b = rand()%N;
		if (count%5 == 0) {
			y = S[a][b]-'A';
			x = y;
			while (x == y) x = rand()%8;
			c = delta_1(a, b);
			S[a][b] = 'A'+x;
			z = delta_1(a, b);
			if (c > z) S[a][b] = 'A'+y;
		} else {
			x = rand()%N;
			y = rand()%N;
			c = delta(a, b, x, y);
			swap(S[a][b], S[x][y]);
			z = delta(a, b, x, y);
			if (c > z) swap(S[a][b], S[x][y]);
		}
		// list(c)list(z) show(total())
		if (clock()-TIME > 2.95 * CLOCKS_PER_SEC) break;
	}
	// show(count)
	rep(i, N) std::cout << S[i] << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e3 + 10;
const ll mod = 1e9 + 7;

ll n, m, a[N];

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

ll get_c(ll n, ll m)
{
	ll res = 1;
	for (ll i = 1; i <= m; i++)
		res = res * (n - i + 1) % mod * ksm(i, mod - 2) % mod;
	return res;
}

int main()
{
	scanf("%lld %lld", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);

	ll sum = 0;
	for (int i = 1; i <= n; i++)
		sum += a[i];

	printf("%lld\n", get_c(m + n, sum + n));

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
  for(auto s:S) os<<s<<" ";  return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair
// inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;}
const int mod = 1e9+7;
inline int add(int a, int b){
  a += b;
  if(a >= mod)
    a -= mod;
  return a;
}
inline int mul(int a,int b){
  return a*1ll*b%mod;
}

int power(int a, int b){
  int res = 1;
  while(b){
    if(b&1)
      res = mul(res , a);
    a = mul(a ,a);
    b >>= 1;
  }
  return res;
}

const int N = 4e6 + 100;

int A[N];

int main(){
  fio; cout<<fixed<<setprecision(25);
  int n , m;
  cin >> n >> m;
  int sm = 0;
  for(int i =1 ;i <= n ; ++i){
    cin >> A[i];
    sm += A[i];
  }
  //cout << sm << endl;
  if(sm > m)
    cout << 0 << endl;
  else{
    m -= sm;
    //we want sum as m
    int num = 1;
    int den = 1;
    for(int i = 0;i < sm+n ; ++i){
      den = mul(den , i+1);
      num = mul(num , m-i+sm+n);
    }
    //cout << num << ' ' << den << endl;
    cout << mul(num, power(den , mod-2)) << endl;
  }

  return 0;
}