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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    vector <int> vs, vt;
    rep(i, n) if (s[i] == '1') vs.pb(i);
    rep(i, n) if (t[i] == '1') vt.pb(i);
    if (vs.size() < vt.size() || (vs.size() - vt.size()) % 2 == 1) {
        printf("-1\n");
        return 0;
    }
    ll ans = 0;
    int j = 0;
    rep(i, vs.size()) {
        if (j < vt.size() && vs[i] >= vt[j]) {
            ans += vs[i] - vt[j];
            ++ j;
        } else {
            if (i + 1 == vs.size()) {
                printf("-1\n");
                return 0;
            }
            ans += vs[i + 1] - vs[i];
            ++ i;
        }
    }
    if (j < vt.size()) {
        printf("-1\n");
        return 0;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int pre = 0;
    queue<int> stk;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            stk.push(i);
        }
    }
    long long ans = 0;
    bool ok = true;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            stk.pop();
            if (t[i] == '0') {
                if (stk.empty()) {
                    ok = false;
                    break;
                }
                ans += stk.front() - i;
                s[stk.front()] = '0';
                stk.pop();
            }
        } else {
            if (t[i] == '1') {
                if (stk.empty()) {
                    ok = false;
                    break;
                }
                ans += stk.front() - i;
                s[stk.front()] = '0';
                stk.pop();
            }
        }
    }
    if (ok) {
        if (stk.size() % 2) {
            ok = false;
        } else {
            while (!stk.empty()) {
                int x = stk.front();
                stk.pop();
                int y = stk.front();
                ans += y - x;
            }
        }
    }
    cout << (ok ? ans : -1) << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define INF 10000000000000000
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.141592653589793238462643383279
#define PYES cout<<"YES"<<endl
#define PNO cout<<"NO"<<endl
#define SB(a) sort(a.begin(),a.end(),greater<int>());
#define SS(a) sort(a.begin(),a.end());
#define vll vector<ll>
#define vpll vector<pll>
vector<bool> prime;
vector<ll> fact,inv,primes,factors;
void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
void factorize(ll a)
{
	factors.clear();
	for(ll i=1;i*i<=a;i++)
	{
		if (i*i==a) factors.pb(i);
		else if (a%i==0)
		{
			factors.pb(i);
			factors.pb(a/i);
		}
	}
	sort(factors.begin(),factors.end());
}
ll power(ll a,ll b)
{
	if(a==1||b==0)	return 1;
	ll c=power(a,b/2);
	ll res=1;
	res=c*c;
	if(res>=mod)	res%=mod;
	if(b%2)	res*=a;
	if(res>=mod)	res%=mod;
	return res;
}
ll modInv(int a)
{
	return power(a,mod-2);
}
void factorial(ll n)
{
	fact.resize(n+1);
	fact[0]=1;
	for(ll i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		if(fact[i]>=mod)	fact[i]%=mod;
	}
}
void InvFactorial(ll n)
{
	inv.resize(n+1);
	inv[0]=1;
	for(ll i=1;i<=n;i++)	inv[i]=modInv(fact[i]);
}
ll ncr(ll n,ll r)
{
	if(n<r||n<0||r<0)	return 0;
	ll b=inv[n-r];
	ll c=inv[r];
	ll a=fact[n]*b;
	if(a>=mod)	a%=mod;
	a*=c;
	if(a>=mod)	a%=mod;
	return a;
}
void remove_duplicates(vector<pair<ll,ll> > &v)
{
	sort(v.begin(),v.end());
	ll _size=unique(v.begin(),v.end())-v.begin();
	v.resize(_size);
}
unsigned ll gcd(unsigned ll u, unsigned ll v)
{
    if(u==0||v==0) return max(u,v);
    unsigned ll shift=__builtin_ctz(u|v);
	u>>=__builtin_ctz(u);
    do{
    	v>>=__builtin_ctz(v);
    	if(u>v)	swap(u,v);
    	v-=u;
    }while(v!=0);
    return u<<shift;
}
void sieve(int n)
{
    prime.assign(n+1,1);
	prime[1]=false;
    for(ll p=2;p*p<=n;p++) if(prime[p])	for(ll i=p*p;i<=n;i+=p)	prime[i]=false;
    for(ll i=2;i<n+1;i++) if(prime[i]) primes.push_back(i);
}
ll size(ll l)
{
	ll p=l;
	ll count=0;
	while(p) p/=10,count++;
	return count;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------
// Always remember: if (condition) if (condition) statement; This doesn't work !!
// Always increase boundaries for global or frequency questions
// pow((int)10,i) doesn't work sometimes. It is better to use multiple of 10 in arrays. Always remember this.
// delete values when defining global if there are multiple testcases
// don't try to be smart and make stupid mistakes
void solve()
{
	ll n;
	cin>>n;
	vll a(n);
	a[0]=10;
	a[1]=15;
	a[2]=6;
	ll p=20,q=45;
	ll b=2;
	for(ll i=3;i<n;i++)
	{
		if (b==2)
		{
			if ((i-1)*6<=10000) a[i]=(i-1)*6;
			else b=1;
		}
		if (b==1)
		{
			if (p<=10000)
			{
				if (p%3) a[i]+=p,p+=10;
				else a[i]+=p+10,p+=20;
			}
			else b=0;
		}
		if (b==0)
		{
			a[i]=q,q+=30;
		}
	}
	for(auto &i: a) cout<<i<<' ';
}
signed main()
{
	fast();
	ll T=1;
	//cin>>T;
	for(ll i=1;i<=T;i++) solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    int n;
    cin>>n;
    string s=to_string(n);
    string t=s;
    reverse(t.begin(),t.end());
    if(s==t)
        cout<<"Yes\n";
    else{
        int count=0;
        for(int i=0;i<t.length();i++){
            if(t[i]=='0')
                count++;
            else
                break;
        }
        for(int i=0;i<count;i++){
            t+='0';
        }
        string p=t;
        reverse(p.begin(),p.end());
        if(p==t)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}
int main()
{
    ios::sync_with_stdio(0);
	cin.tie(0);
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e4; int n;
int a[maxN];

int main()
{
  while (~scanf("%d", &n))
  {
    for (int i = 0; i < n; i++)
      scanf("%d", &a[i]);

    int ans = 0;
    for (int i = 0; i < n; i++)
    {
      int curr = a[i];
      for (int j = i; j < n; j++)
      {
        curr = min(curr, a[j]);
        ans = max(ans, curr * (j - i + 1));
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int main() {
  ll n;
  cin >> n;

  ll n2 = n*2, ans = 0;
  ll sq = sqrt(n2);
  for (ll x = 1; x <= sq; x++) {
    if (n2 % x) continue; // 約数ではない

    ll y = n2/x;
    bool ok = (x+y-1) % 2 == 0 && (x-y+1) % 2 == 0;
    if (ok) ans += x==y ? 1 : 2;
  }

  cout << ans << endl;
  return 0;
}


/*input
5 4 4
3 2
3 4
4 2
5 2

*/

// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++)
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

const ll N = 2e5+5;
vi bit(N,0);
void add(ll idx,ll val)
{
	for(ll i = idx+1;i<N;i+=i&-i) bit[i]+=val;
}

ll prefixSum(ll idx)
{
	ll sum=0;
	for(ll i = idx+1;i>0;i-=i&-i) sum+=bit[i];
	return sum;
}

int solve()
{
	ll h,w,m,ans=0;
	cin>>h>>w>>m;
	vector<ll> row(h,w),col(w,h);
	rep(i,0,m)
	{
		ll x,y;cin>>x>>y;
		x--,y--;
		row[x] = min(row[x],y);
		col[y] = min(col[y],x);
	}

	/*
		0 0 0 0 1 5
		0 0 1 0 0 3
		0 1 0 0 0 2
		0 0 0 0 0 6
		0 0 0 1 0 4
		1 0 0 0 0
		0 1 0 0 0
 	*/
	rep(i,0,col[0]) ans+=row[i];

	vpii b;
	rep(j,0,row[0]) b.pb(mp(col[j],j));
	sort(b.begin(), b.end());

	ll L = 0;
	ll cnt=0;
	rep(i,0,sz(b))
	{
		pii p = b[i];
		while(L<p.F && L<col[0])
		{
			add(row[L],1);
			cnt++;
			L++;
		}

		ans+=col[p.S] - ( cnt - prefixSum(p.S-1));
	}

	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

#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 INF 1000000000
#define LLINF 922337203685775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

int N, M;
int A[200010];
int ans = -LLINF;
vector<VI> G;
int dp[200010];
bool vis[200010];

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

	cin >> N >> M;
	G.resize(N);
	REP(i, N) {
		cin >> A[i];
		dp[i] = LLINF;
	}
	REP(i, M) {
		int v, u; cin >> v >> u;
		v--, u--;
		G[v].push_back(u);
	}
	priority_queue<int, vector<int>, greater<int> > Q;

	REP(now, N) {

		chmax(ans, A[now] - dp[now]);
		chmin(dp[now], A[now]);

		fore(to, G[now]) {
			chmin(dp[to], dp[now]);
		}

	}

	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+1000;
const int MOD=1e9+7;
int n;
int h[N],e[N],ne[N],idx;
ll w[N],d[N];
ll f[2];
void add(int a,int b,ll c)
{
	e[idx]=b;w[idx]=c;ne[idx]=h[a];h[a]=idx++;
}

void dfs(int u,int fa)
{
	for(int i=h[u];~i;i=ne[i])
	{
		int j =e[i];
		if(j==fa) continue;
		d[j]=d[u]^w[i];
		dfs(j,u);

	}
}
int main()
{
	memset(h,-1,sizeof h) ;
	scanf("%d",&n);
	for(int i=1,u,v;i<=n-1;i++)
	{
		ll c;
		scanf("%d %d %lld",&u,&v,&c);
		add(u,v,c);add(v,u,c);
	 }

	 dfs(1,-1);
	 ll ans = 0;
	 for(int i=0;i<60;i++)
	 {

	 	for(int j=1;j<=n;j++)  f[(d[j]>>i)&1]++;
	 	ans =  (ans +(1ll<<i)%MOD*f[0]%MOD* f[1]%MOD) %MOD;
	 	f[0]=f[1]=0ll;
	 }
	 printf("%lld\n",ans);
}

//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647;
use io;
int n,m,a[N],f[N],T;
char an[666][666];
void ck(int k,int x,int y,int b)
{
	if(k==0)
		an[x][y]='A'+b;
	else
	{
		ck(k-1,x,y,b);
		ck(k-1,x+(1<<(k-1)),y,b);
		ck(k-1,x,y+(1<<(k-1)),b);
		ck(k-1,x+(1<<(k-1)),y+(1<<(k-1)),b^1);
	}
}
int main()
{
	int i,j,a1,a2;
	_(n);
	ck(n,0,0,0);
	_pn((1<<n)-1);
	fo(i,(1<<n)-1)
		puts(an[i]);
}


#include<bits/stdc++.h>
using namespace std;
const int mod=3;
const int N=400010;
int f[10][10];
char s[N];
int lucas(int n,int m){
    if(n<mod && m<mod) return f[n][m];
    else return f[n%mod][m%mod]*lucas(n/mod,m/mod);
}
int getx(char s){
    if(s=='R') return 1;
    if(s=='W') return 2;
    else return 0;
}
int main(){
    f[0][0]=f[1][0]=f[2][0]=f[2][2]=f[1][1]=1;
    f[2][1]=2;
    int n;
    scanf("%d",&n);
    scanf("%s",&s);
    n--;
    int ans=0;
    for(int i=0;i<=n;i++) ans+=getx(s[i])*lucas(n,i);
    ans%=mod;
    if(n&1) ans=ans*2%mod;
    if(ans==1) puts("R");
    else if(ans==2) puts("W");
    else puts("B");
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<ll>dp(2,1);
  rep(i,n){
    string s;
    cin>>s;
    vector<ll>p(2); swap(dp,p);
    rep(j,2)rep(x,2){
      int nj = j;
      if( s == "AND")nj &= x;
      else nj |= x;
      dp[nj] += p[j];
    }
  }
  cout<<dp[1]<<endl;
	return 0;
}


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

long long X;
vector<long long> fibo = {0,1};
vector<int> ans = {1};
bitset<100> bs;

int main() {
    scanf("%lld", &X);
    while (fibo[fibo.size()-2] + fibo[fibo.size()-1] <= X) fibo.push_back(fibo[fibo.size()-2] + fibo[fibo.size()-1]);
    int K = fibo.size();
    X -= fibo.back();
    while (X) {
        while (fibo.back() > X) fibo.pop_back();
        bs[fibo.size()] = true;
        X -= fibo.back();
    }
    for (int i = 1; i < K-1; ++i) {
        ans.push_back(3+i%2);
        if (bs[K-i]) ans.push_back(1+i%2);
    }
    printf("%d\n", ans.size());
    if (K % 2 == 0) {
        for (int x: ans) printf("%d\n", x);
    }
    else {
        for (int x: ans) {
            if (x <= 2) printf("%d\n", 3-x);
            else printf("%d\n", 7-x);
        }
    }

    return 0;
}

//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N;

void solve() {
    vector<int> fib(2);
    fib[0] = fib[1] = 1;
    for (int i = 2;; i++) {
        fib.emplace_back(fib[i - 1] + fib[i - 2]);
        if (fib.back() > N)
            break;
    }
    int M = fib.size();

    vp memo;
    memo.emplace_back(0, 0);
    memo.emplace_back(1, 0);
    while (true) {
        auto [x, y] = memo.back();
        if (x + y > N)
            break;
        if (x > y)
            memo.emplace_back(x, x + y);
        else
            memo.emplace_back(x + y, y);
    }
    if (memo.back().first < memo.back().second) {
        for (auto&& [x, y] : memo) {
            swap(x, y);
        }
    }
    /*
    for (auto&& [x, y] : memo) {
        cerr << x << " " << y << endl;
    }
    */
    N -= memo.back().first;
    int inc[2020] = {};
    while (N) {
        int idx = upper_bound(all(fib), N) - fib.begin() - 1;
        inc[idx]++;
        N -= fib[idx];
    }
    vector<int> ans;
    for (int i = 0; i < M - 1; i++) {
        auto [x_now, y_now] = memo[i];
        auto [x_nxt, y_nxt] = memo[i + 1];
        if (x_now != x_nxt) {
            if (i == 0)
                //cout << 1 << endl;
                ans.emplace_back(1);
            else
                //cout << 3 << endl;
                ans.emplace_back(3);
        } else {
            if (i == 0)
                //cout << 2 << endl;
                ans.emplace_back(2);
            else
                //cout << 4 << endl;
                ans.emplace_back(4);
        }
        while (inc[M - 2 - i]) {
            inc[M - i - 2]--;
            //cout << ((M - i - 1) % 2 == 0 ? 2 : 1) << endl;
            ans.emplace_back(((M - i - 1) % 2 == 0 ? 2 : 1));
        }
    }
    cout << ans.size() << endl;
    for (auto&& e : ans) {
        cout << e << endl;
    }
}

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

    cin >> N;

    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define LLI long long int
#define pii pair<ll,ll>
#define F first
#define S second
#define mod 1000000007
using namespace std;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int ans=0; int n; cin>>n; vector<pii> arr(n);
    for(int i=0;i<n;i++){
    	int x,y; cin>>x>>y; arr[i]={x,y};
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(abs(arr[i].F-arr[j].F)>=abs(arr[i].S-arr[j].S)) ans++;
		}
	}
	cout<< ans <<endl;
}

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=2e5+7;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vc<ll> a(2*n);
	ll sum=0;
	for(int i=0;i<2*n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	set<pi> mid;
	ll ans=0;
	for(int l=n-1,r=n;l>=0;l--,r++)
	{
		mid.insert(pi(a[l],l));
		mid.insert(pi(a[r],r));
		ans+=(*mid.begin()).first;
		mid.erase(mid.begin());
	}
	print(sum-ans);
}


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

const int MAX=2000005;
const int MOD=1000000007;

long long 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 % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long 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] % MOD) % MOD;
}

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    if(n>m+k){
        cout<<0<<endl;
        return 0;
    }
    COMinit();
    ll ans=COM(n+m,n)-COM(n+m,m+k+1);
    if(ans<0) ans+=MOD;
    cout<<ans<<endl;
}

#include <iostream>
using namespace std;

int main() {
    int A, B, W;
    cin >> A >> B >> W;
    W *= 1000;
    int m = 1000003;
    int M = -1;
    for (int i=1; i<=1000000;i++) {
        if (A * i <= W && B * i >= W) {
            m = min(m, i);
            M = max(M, i);}
    }
    if (m == 1000003 && M == -1) cout << "UNSATISFIABLE" << endl;
    else cout << m << ' ' << M << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;

int n;
ll a[N], b[N], c[N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%lld", &a[i]);
	}
	ll mx = 0, mx2 = 0;
	for (int i = 0; i < n; ++i) {
		mx = max(mx, a[i]);
		scanf("%lld", &b[i]);
		c[i] = max(mx * b[i], mx2);
		mx2 = max(mx2, c[i]);
	}

	for (int i = 0; i < n; ++i) {
		printf("%lld\n", max(c[i], a[i] * b[i]));
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    ll n; cin>>n;
    vi a(n),p(n),x(n);
    rep(i,n) cin>>a[i]>>p[i]>>x[i];
    ll ans=inf;
    rep(i,n){
        if(a[i]<x[i]) chmin(ans,p[i]);
    }
    if(ans==inf) ans=-1;
    out(ans);
}


#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main(){
  string a;
  int i,j,c=0,f=0;
  cin>>a;
  for(i=0;i<a.length();i++){
      if(isupper(a[i])){
          f++;
      }
  }
  if(f==3){
  for(i=0;i<a.length();i++){
      if((i+1)<a.length()){
       if(a[i]!=a[i+1]){
       c++;
       }
      }
  }
  if(c>0){cout<<"Lost"<<endl;}
  else{cout<<"Won"<<endl;}
  }
  else{
      cout<<"Lost"<<endl;
  }
        return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<int> v;
	int i;
	for (i = 0; N > 0; i++) {
		v.push_back(N % 10);
		N /= 10;
	}
	if (accumulate(v.begin(), v.end(), 0) % 3 == 0) {
		cout << 0;
		return 0;
	}
	for (int k = 1; k < i; ++k) {
		for (int j = 0; j + k - 1 < i; ++j) {
			if ((accumulate(v.begin(), v.end(), 0)-accumulate(v.begin() + j, v.begin() + j + k, 0) )% 3 == 0) {
				cout << k;
				return 0;
			}
		}
	}
	cout << -1;
	return 0;
}


//#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

//using mint = modint1000000007;

vector<int> tpl_sort(vector<vector<int>>& r){
	int n= r.size();
	vector<int> rt, cnt(n); rt.reserve(n+2);
	for(auto& xl: r) for(auto x: xl) cnt[x]++;
	queue<int> qu;
	for(int i=0; i<n; i++) if(cnt[i]==0) qu.emplace(i);
	while(!qu.empty()){
		auto cr = qu.front(); qu.pop();
		rt.emplace_back(cr);
		for(auto x: r[cr]) if(--cnt[x] == 0) qu.emplace(x);
	}
	return rt;
}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n ;
	vector<string> s(n);
	rep(i, n) cin >>s[i];

	vector<VI> r(n);
	vector<set<int>> tc(n);
	rep(i, n) rep(j,n) if(s[i][j]=='1') r[i].push_back(j);
	VI ct(n);

	auto rec=[&](auto rec, int c, const int p)->void{
		for(auto x: r[c]) if(!tc[p].count(x)){
			if(x==p) continue;
			tc[p].insert(x);
			rec(rec, x, p);
		}
	};
	rep(i, n) rec(rec, i, i);

	rep(i, n){
		//dbg(i,"::");for(auto x :tc[i]) cerr<<x<<" "; dbg();
		for(auto x :tc[i]) ct[x]++;
	}
	//for(auto x :ct) cerr<<x<<" "; dbg();
	double ans =0;
	rep(i, n) ans += 1.0 / (ct[i]+1);
	printf("%.16f\n", ans);
	return 0;
}

#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    cout << setprecision(16);

    int N;
    cin >> N;
    vector<string> S(N);

    for (auto &s : S)
        cin >> s;

    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                if (S[i][k] == '1' && S[k][j] == '1')
                    S[i][j] = '1';

    double answer = 0;

    for (int i = 0; i < N; i++) {
        int other = 0;

        for (int j = 0; j < N; j++)
            other += i != j && S[j][i] == '1';

        answer += 1.0 / (other + 1);
    }

    cout << answer << '\n';
}


#include <stdio.h>

int count[10];
int main()
{
	long long int a;
	scanf("%lld",&a);
	int sum = 0,digit = 0;
	while(a)
	{
		sum += (a%10);
		digit++;
		count[(a%10)%3]++;
		a/=10;
	}
	if(sum%3==0) printf("0");
	else if(sum%3==1)
	{
		if(digit>=2&&count[1]>=1) printf("1");
		else if(digit>=3&&count[2]>=2) printf("2");
		else printf("-1");
	}
	else
	{
		if(digit>=2&&count[2]>=1) printf("1");
		else if(digit>=3&&count[1]>=2) printf("2");
		else printf("-1");
	}
}

#include <bits/stdc++.h>

using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
typedef pair<int,int> PI;
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXS 100010

int main(){

	ios::sync_with_stdio(0); cin.tie(0);
	LL n;
	cin>>n;

	int sum=0;
	int rem1=0;
	int rem2=0;
	int lg=0;
	while(n){
		lg++;
		int t1=(n%10)%3;
		sum+=t1;
		sum%=3;
		if(t1==1)
			rem1+=1;
		if(t1==2)
			rem2+=2;

		n/=10;
	}

	if(sum==0)
		cout<<0;
	else{
		if(lg>1&&((sum==1&&rem1>=1)||(sum==2&&rem2>=1)))
			cout<<1;
		else if(lg>2&&((sum==2&&rem1>=2)||(sum==1&&rem2>=2)))
			cout<<2;
		else
			cout<<-1;
	}
}


#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void re(int &x){scanf("%d",&x);}
void re(int &x,int &y){scanf("%d %d",&x,&y);}
void re(ll &x){scanf("%lld",&x);}
void re(ll &x,ll &y){scanf("%lld %lld",&x,&y);}
void re(double &x){scanf("%lf",&x);}
void re(double &x,int &y){scanf("%lf %lf",&x,&y);}
using namespace std;
const int N=5e5+5;
const int inf=0x3f3f3f3f;

int a[N];
int sum[N];
map<ll,int> mp;
int main()
{
    int n;cin>>n;
    rep(i,0,n-1) cin>>a[i];
    ll ans=0;
    ll sum=0;
    mp[0]=1;
    rep(i,0,n-1)
    {
        if(i%2==0)
        {
            sum+=a[i];
        }
        else sum-=a[i];
        ans+=mp[sum];
        mp[sum]++;
    }
    cout<<ans<<endl;

    return 0;
}
// 5 2 3 4 1

#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define ll long long
#define rep(i,x,y) for(int i=x; i<y; i++)
int n,m;
vector<vector<int>> a;
bool check(int x){
	int b[n][n];
	//memset(b,0,sizeof b);

	//cout<<x<<'\n';
	rep(i,0,n){
		rep(j,0,n){
			b[i][j]=(a[i][j]<=x);
			if(i>0)b[i][j]+=b[i-1][j];
			if(j>0)b[i][j]+=b[i][j-1];
			if(i>0 && j>0)b[i][j]-=b[i-1][j-1];
			//cout<<b[i][j]<<' ';
		}
		//cout<<'\n';
	}

	//bool ans=0;
	rep(i,m-1,n){
		rep(j,m-1,n){
			int sum=b[i][j];
			if(j-m>=0)sum-=b[i][j-m];
			if(i-m>=0)sum-=b[i-m][j];
			if(i-m>=0 && j-m>=0)sum+=b[i-m][j-m];
			if(sum>=(m*m+1)/2){return true;}
			//cout<<sum<<' ';
		}
		//cout<<'\n';
	}
	return false;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>m;
	a.resize(n,vector<int>(n));
	set<int> s;
	rep(i,0,n){
		rep(j,0,n){cin>>a[i][j];s.insert(a[i][j]);}
	}

	vector<int> v(s.begin(),s.end());

	int ans;

	int l=0,h=v.size()-1;

	// check(0);
	 // rep(i,0,h+1){
		 // cout<<check(i)<<' ';
	 // }
	 // cout<<'\n';

	 while(l<=h){
		 int mid=(l+h)/2;
		 if(check(v[mid])){
		 	ans=v[mid];
			 h=mid-1;
		 }
		else {
			 l=mid+1;
		 }
	 }
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
int M=1000000007;
const int N=200005;

signed main(){
  int t1=1;
  //cin>>t1;
  while(t1--){
    int n;
    cin>>n;

    int a[1005]{0};
    for(int i=0;i<n;i++) {
      int x;
      cin>>x;
      a[x]++;
    }
    for(int i=0;i<n;i++){
      int x;
      cin>>x;
      a[x+1]--;
    }

    for(int i=1;i<1005;i++) a[i]+=a[i-1];

    int cnt=0;
    for(int i=1;i<=1000;i++) if(a[i]==n) cnt++;
    cout<<cnt<<endl;
  }
}

#include<fstream>
#include<iostream>
#include<sstream>
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<tuple>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<set>
#include<array>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using graph = vector<vector<long long>>;
const long long MOD = 1000000007;
const long long INF = 1e18;
using ll = long long;
using P = pair<int,int>;

void chmin(int &x,int y){ x = min(x,y); }

int digit(ll x){
  int count = 1;
  while(x/10>0){
    count ++;
    x /= 10;
  }
  return count;
}

bool prime(ll x){
  if(x==1) return false;
  for(ll i=2;i*i<=x;i++){
    if(x%i==0) return false;
  }
  return true;
}

void decom(ll x,map<ll,int> &hatano){
  for(ll i=2;i*i<=x;i++){
    if(x%i==0&&prime(i)){
      while(x%i==0){
      x /= i;
      hatano[i] ++;
    }
    }
  }
  if(x!=1) hatano[x] ++;
}

ll speedpow(ll x,ll y){
  ll res = 1;
  ll test = x;
  for(int i=0;i<31;i++){
    if(y&(1<<i)) res *= test;
    res = res%MOD;
    test = (test*test)%MOD;
  }
  return res;
}

ll combination(ll x,ll y){
  ll test = 1;
  ll test1 = 1;
  for(ll i=0;i<y;i++){
    test = (test*(x-i))%MOD;
    test1 = (test1*(i+1LL))%MOD;
  }
  return (test * speedpow(test1,MOD-2))%MOD ;
}

int euclid(int x,int y){
  if(y==0) return x;
  return euclid(y,x%y);
}

/*int main(){
  int n;cin >> n;
  ll m;cin >> m;

  ll a[n];
  rep(i,n) cin >> a[i];

}*/

int main(){
    int n;cin >> n;
    int a[n],b[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];

    int ans = 0;

    for(int i=1;i<=1000;i++){
      bool kon = true;
      rep(j,n){
        if(a[j]>i||b[j]<i) kon = false;
      }
      if(kon) ans ++;
    }

    cout << ans << endl;

}


#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define il inline
#define Ld double
#define pc putchar
#define rg register
#define ll long long
#define lll __int128
#define pb push_back
#define mp make_pair
#define It ::iterator
#define W(p) while(p--)
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define def(N, K, b) const K N = b;
#define FOR(i, b, s) for(int i = b; i < s; ++i)
#define rep(i, b, s) for(int i = b; i <= s; ++i)
#define per(i, b, s) for(int i = b; i >= s; --i)
#define FOR_(i, b, s) for(int i = b; i > s; --i)
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

namespace IO {
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc() {
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread() {}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls) {
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do {
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    template<class T>
	inline void QreadArr(T Begin, T End) {
		while(Begin != End) {
			qread(*Begin);
			++Begin;
		}
	}
    inline void flush() {
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x) {
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite() {}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls) {
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    template<class T>
    inline void WriteArr(T Begin, T End) {
    	const char Kg = ' ', Edl = '\n';
    	while(Begin != End) {
    		qwrite(*Begin);
    		++Begin;
    		putc_(Kg);
		}
		putc_(Edl);
	}
    struct Flusher_{ ~Flusher_() { flush(); } } io_flusher;
}

using namespace IO;
using namespace std;

template<class T1, class T2>
T1 Min(const T1 x, const T2 y) { return x > y ? y : x; }
template<class T1, class T2>
T1 Max(const T1 x, const T2 y) { return x > y ? x : y; }

template<class T1, class T2>
void To_max(T1 &x, const T2 y) { x < y ? x = y : x = x; }
template<class T1, class T2>
void To_min(T1 &x, const T2 y) { x > y ? x = y : x = x; }

il ll qpow(ll n, ll base, ll mod = 1e18) {
	ll ret = 1;
	while(n) {
		if(n & 1) ret = ret * base % mod;
		base = base * base % mod;
		n >>= 1;
	}
	return ret % mod;
}

il ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
il ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//header

int flg;

int main() {
	int n, s, d;
	qread(n, s, d);
	rep(i, 1, n) {
		int x, y; qread(x, y);
		if(x < s && y > d) flg = 1;
	}
	flg ? puts("Yes") : puts("No");
 	return 0;
}


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

const int N = 200005;

int n;
int a[N];
int pos[N];
bool used[N];

int solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    pos[--a[i]] = i;
    used[i] = false;
  }

  vector<int> ans;
  for (int i = n - 1; i > 0; --i) {
    while (pos[i] != i) {
      if (used[pos[i]]) return 0 * printf("-1\n");
      int p = pos[i];
      swap(pos[i], pos[a[p + 1]]);
      swap(a[p], a[p + 1]);
      ans.push_back(p);
      used[p] = true;
    }
  }

  if (ans.size() != n - 1) return 0 * printf("-1\n");
  for (int u : ans) printf("%d\n", u + 1);

  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}

#include <iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define forn(i,a,n,b) for(ll i=a;i<n;i+=b)
#define forr(i,a,n,b) for(ll i=a;i>=n;i-=b)
#define MOD 1000000007
#define vll vector<ll>
using namespace std;

int main()
{
    fastio;
    ll t = 1;
    // cin>>t;
    while(t-->0)
    {
        ll n, takahoshi = 0, ans = 0;
        cin>>n;
        vector<pair<ll, pair<ll, ll>>> pairs;
        forn(i,0,n,1)
        {
            ll a, b;
            cin>>a>>b;
            pairs.emplace_back(2*a+b, make_pair(a,b));
            takahoshi -= a;
        }
        sort(pairs.begin(), pairs.end());
        forr(i,n-1,0,1)
        {
            takahoshi += pairs[i].first;
            ans++;
            if (takahoshi > 0)
            {
                break;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int L;
    cin >> L;
    vector<vector<ll>> comb(L + 1, vector<ll>(L + 1));
    for(int i = 0; i <= L; ++i){
        comb[i][0] = comb[i][i] = 1;
    }
    for(int i = 1; i <= L; ++i){
        for(int j = 1; j < i; ++j){
            comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
        }
    }
    cout << comb[L - 1][11] << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 1e13;
const ld PI = asin(1) * 2;
const ld EPS = 1e-6;

unordered_set<int> pos, tmp;
int n, m;
map<int, vi> black;

int main()
{
    FAST_IO;

    cin >> n >> m;
    pos.insert(n);
    REP(m) {
        int x, y;
        cin >> x >> y;
        black[x].pb(y);
    }

    for (auto p : black) {
        vi ins, del;
        for (int j : p.s) {
            bool ok = false;
            if (pos.count(j-1) || pos.count(j+1))
                ok = true;
            if (ok) {
                //pos.insert(j);
                ins.pb(j);
                //cout << "  inserting j=" << j << endl;
            } else {
                //pos.erase(j);
                del.pb(j);
                //cout << "  erasing j=" << j << endl;
            }
        }
        for (int x : ins) pos.insert(x);
        for (int x : del) pos.erase(x);

        /*cout << " after x = " << p.f << ",  pos: ";
        for (int x : pos) cout << x << " ";
        cout << endl;*/
    }

    cout << (int)pos.size() << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <queue>
#include <limits>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <locale>
#include <bitset>
#include <set>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,n) for(int i = n-1; i >= 0; i--)
#define ll long long
#define P pair<int, int>

#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);

unsigned GetDigit(unsigned num) { return log10(num)+1; }

int main()
{
	int n;
	cin >> n;

	vector<string> s(n);
	set<string> stringSet;
	rep(i, n)
	{
		cin >> s[i];
		stringSet.insert(s[i]);
	}

	for (int i = 0; i < n; i++)
	{
		if(stringSet.count("!" + s[i]) > 0)
		{
			cout << s[i] << endl;
			return 0;
		}
	}

	cout << "satisfiable" << endl;
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<ll> A(N), B(N), C(N), D(N), E(N);
    REP(i, 0, N) cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];

    ll l = 0, h = 1e9 + 1, m;
    vector<int> bit(N);
    while (h - l > 1) {
        m = l + (h - l) / 2;
        REP(i, 0, N) {
            bit[i] = 0;
            if (m <= A[i]) bit[i] |= (1 << 4);
            if (m <= B[i]) bit[i] |= (1 << 3);
            if (m <= C[i]) bit[i] |= (1 << 2);
            if (m <= D[i]) bit[i] |= (1 << 1);
            if (m <= E[i]) bit[i] |= (1 << 0);
        }

        // vector<vector<bool>> dp(N + 1, vector<bool>(1 << 5, false));
        // dp[0][0] = true;
        // REP(i, 0, N) {
        //     REP(j, 0, 1 << 5) {
        //         if (!dp[i][j]) continue;
        //         dp[i + 1][j] = true;
        //         dp[i + 1][j | bit[i]] = true;
        //     }
        // }

        vector<vector<vector<bool>>> dp(N + 1, vector<vector<bool>>(1 << 5, vector<bool>(4, false)));
        dp[0][0][0] = true;
        REP(i, 0, N) {
            REP(j, 0, 1 << 5) {
                REP(k, 0, 4) {
                    if (!dp[i][j][k]) continue;
                    dp[i + 1][j][k] = true;
                    if (k < 3) dp[i + 1][j | bit[i]][k + 1] = true;
                }
            }
        }

        if (dp[N][(1 << 5) - 1][3]) l = m;
        else h = m;
    }
    cout << l << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << std::max((a + b), max((b + c), (c + a)));
    return 0;
}

//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(s) (s).begin(),(s).end()
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<a+b+c-min(a,min(b,c))<<endl;
}
/*======================================================================*/
signed main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int t=1;
  //cin>>t;
  while(t--)
  {
  	solve();
  }
  return 0;
}
/*
注意数组越界，vector长度为0的时候循环会RE
注意输入顺序
注意循环时int*int爆ll
注意答案存爆ll
*/


/*NEVER GIVE UP*/
/*First try brute force and check if it is in the range of time complexity*/
/*Then try to solve the problem in mathematical form*/
/*Then try to imagine how the final ans will look like*/
/*Write on paper if still not able to get*/
/*Try to think diff. algorithms and data structures that could solve the problem*/
#include <bits/stdc++.h>
using namespace std;
int main()
{long long n=0,max=0,max1=0,temp=0,temp1=0;
    cin>>n;
    long long a[1<<n];
    for(long long j=0;j<(1<<n);j++)
    cin>>a[j];
    for(long long j=0;j<(1<<n)/2;j++)
    {
        if(a[j]>max)
        {
            max=a[j];
            temp=j;
        }
    }
    for(long long j=(1<<n)/2;j<(1<<n);j++)
    {
        if(a[j]>max1)
        {
            max1=a[j];
            temp1=j;
        }
    }
    if(max<max1)
    cout<<temp+1;
    else
    cout<<temp1+1;

}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int GCD(int x, int y){
    if(x == 0 && y == 0) return 0;
    if(x>y){
        int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

vector<ll> yakusuu_rekkyo(ll n){
    vector<ll> divisors;
    for(ll i = 1; i <= n; i++){
        if(i * i > n)break;
        if(i * i == n){
            divisors.push_back(i);
            break;
        }else if(n % i == 0){
            divisors.push_back(i);
            divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(), divisors.end());
    return divisors;
}

int main() {
    int n; cin >> n;
    int a[n] = {};
    rep(i,n) cin >> a[i];
    sort(a,a+n);

    set<int> se;
    rep(i,n){
        vector<ll> v = yakusuu_rekkyo(a[i]);
        rep(j,v.size()) se.insert(v[j]);
    }

    int ans = 0;
    for(auto x: se){
        if(x > a[0]) continue;
        int now = -1;
        rep(i,n){
            if(a[i] % x == 0){
                if(now == -1){
                    now = a[i];
                }else{
                    now = GCD(now, a[i]);
                }
            }
        }
        if(now == x) ans++;
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <math.h>

int main() {

    long long int n;
    cin >> n;

    vector< long long int > a;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        a.push_back( in );
    }

    long long int ma = 0;
    long long int cnt = 0;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;

        ma = max( ma, a[i] );
        cnt = max( cnt, ma * in );
        cout << cnt << endl;

    }

    return 0;

}

#include<iostream>
#include<array>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
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;}

int n;
ll a[200010],b[200010];

void solve(){
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    ll a_MAX=0,c_MAX=0;
    rep(i,n){
        chmax(a_MAX,a[i]);
        chmax(c_MAX,a_MAX*b[i]);
        cout << c_MAX << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}


#include <bits/stdc++.h>
#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("")
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;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

// Unionfind
struct uf{
  vi d;
  vector<map<int,int> > mp;
  uf() {};
  uf(int mx) : d(mx,-1), mp(mx) {};
  int root(int x){
    if(d[x]<0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x,y);
    // データ構造をマージする一般的なテク：小さい集団から大きい集団にマージすることを繰り返すことによって、各要素でみたときに高々logn回マージされる（１回のマージで必ず集団の数が２倍以上なるため）
    for(auto p: mp[y]){ // このループの仕方めちゃ便利、連想配列もこのループで回せる
      mp[x][p.first] += p.second; // 連想配列もpair型のようにkey,valueを得ることができる
    }
    mp[y] = map<int,int>(); // 初期化方法
    d[x] += d[y]; d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x){ return -d[root(x)];}
  int operator[] (int x) {return root(x);}
  int operator() (int x) {return size(x);}
};

int main() {
  int n,q; cin >> n >> q;
  uf dis(n);
  rep(i,n){
    int c; cin >> c;
    dis.mp[i][c] = 1;
  }
  vi ans;
  rep(_,q){
    int type; cin >> type;
    if(type == 1){
      int a,b; cin >> a >> b; --a,--b;
      dis.unite(a,b);
    }else{
      int x,y; cin >> x >> y;
      --x;
      ans.push_back(dis.mp[dis.root(x)][y]);
    }
  }
  for(int res: ans) printf("%d\n", res);
  return 0;
}

#include <bits/stdc++.h>
#define REP(i, nn) for (int i = 0; i < (int)nn; i++)
#define REPS(i, ss, nn) for (int i = ss; i < (int)nn; i++)
#define REV(i, ss, nn) for (int i = ss; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std
{
    template <class Fun>
    class y_combinator_result
    {
        Fun fun_;

    public:
        template <class T>
        explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}
        template <class... Args>
        decltype(auto) operator()(Args &&...args)
        {
            return fun_(std::ref(*this), std::forward<Args>(args)...);
        }
    };
    template <class Fun>
    decltype(auto) y_combinator(Fun &&fun)
    {
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template <typename T>
bool umax(T &a, T b)
{
    bool ret = a < b;
    if (ret)
        a = b;
    return ret;
}
template <typename T>
bool umin(T &a, T b)
{
    bool ret = a > b;
    if (ret)
        a = b;
    return ret;
}
struct edge
{
    int to;
    ll cost;
    int from;
    edge() { edge(0, 0); }
    edge(int to_, ll cost_) : to(to_), cost(cost_) {}
    edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_) {}
};

template <typename... T>
void read(T &...a)
{
    ((cin >> a), ...);
}

template <typename... T>
void write(T... a)
{
    ((cout << a), ...);
}

template <typename T>
vector<T> read_array(int sz)
{
    vector<T> ret(sz);
    for (auto &x : ret)
        cin >> x;
    return ret;
}

void solve(){
    ll a, b, c, d;
    read(a, b, c, d);
    if(c * d - b <= 0){
        write("-1\n");
        return;
    }
    ll k = a / (c * d - b);
    if( k * (c * d - b) < a) k++;
    write(k, "\n");
}
int main(){
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    int T = 1;
    // cin >> T;
    while (T--)
        solve();
    return 0;
}


#include <bits/stdc++.h>

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int a,b;
    cin>>a>>b;
    int x=(a+b)/2;
    int y=a-x;
    cout<<x<<" "<<y<<endl;
    return 0;
}

//git pull --rebase origin master
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
ll int gcd(ll int a, ll int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int tc=1;
void solve()
    {
        int a,b;
        cin>>a>>b;
        int x=(a+b)/2;
        int y=a-x;
        cout<<x<<" "<<y;
    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    // wi(t)
    {
      solve();
    }

    return 0;
}

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

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


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

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 500010

ll i, i1, j, k, k1, n, m, res, flag[10], a, b;
string s, t;

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

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    cin >> n >> s >> t; s = '#' + s; t = '#' + t;

    for (i = 1; i <= n; i++) {
        if (s[i] == '0') a++;
        if (t[i] == '0') b++;
        if (s[i] == '0' && t[i] == '0' && a == b) res--;
    }

    if (a != b) res = -1;
    else res += a;

    cout << res << nl;

    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define itn int
#define ll long long
#define yes {puts("Yes");}
#define no {puts("No");}
using namespace std;

ll read(){
	ll a=0,b=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return a*b;
}

ll n,ans,m,k;
char s[1000005];
char t[1000005];

int a1[500005],ct1,a2[500005],ct2;

int main(){
	n=read();
	scanf("%s%s",s,t);
	for(int i=0;i<n;i++){
		if(s[i]=='0'){
			a1[++ct1]=i;
		}
		if(t[i]=='0'){
			a2[++ct2]=i;
		}
	}
	if(ct1!=ct2){
		puts("-1");
		return 0;
	}
	int ans=0;
	for(int i=1;i<=ct1;i++){
		if(a1[i]!=a2[i]){
			ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

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

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}

string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

bitset<20> edges[20];
int dp[(1<<20)];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,x,y;
    cin>>n>>m;
    while (m--)
    {
        cin>>x>>y;
        --x;--y;
        edges[x][y]=edges[y][x]=1;
    }
    for (int i=1;i<(1<<n);++i)
    {
        dp[i]=1;
        for (int j=0;j<n;++j)
            if (i&(1<<j))
                for (int k=j+1;k<n;++k)
                    if (i&(1<<k))
                        if (!edges[j][k])
                            dp[i]=1000000;
        for (int j=(i-1)&i;j;j=(j-1)&i)
            dp[i]=min(dp[i],dp[j]+dp[i^j]);
    }
    cout<<dp[(1<<n)-1];
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, c, f; };
    struct Edge { int i, n, d; };
    Graph(int n, int m) : v(n, { -1, -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int a, int b) {
        e[m] = { b, v[a].n, -1 };
        v[a].n = m;
        m++;
    }
    void dfs(int i, int c) {
        if (v[i].f) return; else v[i].f = 1;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge &o = e[j];
            if (v[o.i].c != c) {
                o.d = v[o.i].c < c;
                continue;
            }
            if (e[j ^ 1].d < 0) o.d = 0;
            dfs(o.i, c);
        }
    }
    void solve() {
        for (int i = 0; i < n; i++) {
            cin >> v[i].c;
        }
        for (int i = 0; i < n; i++) {
            dfs(i, v[i].c);
        }
        for (int i = 0; i < m; i += 2) {
            //cout << e[i].d << ' ' << e[i + 1].d << endl;
            if (e[i].d < 0) e[i].d = e[i + 1].d ^ 1;
            cout << (e[i].d ? "->" : "<-") << '\n';
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.solve();

    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

struct Edge{
    ll to, cost;
    Edge(ll t, ll c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;

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

const ll MOD=1e9+7;
const ll nmax=200000+10;

ll N;
Graph G(nmax);

ll calc(ll i){
    ll even=0,odd=0;
    vl res(N,-1),seen(N,0);
    queue<ll> q;
    res[0]=0;
    q.push(0);
    even++;

    while(!q.empty()){
        ll v=q.front();
        q.pop();
        seen[v]=1;

        for(auto e:G[v]){
            if(seen[e.to]) continue;

            bool ec=(e.cost&(1LL<<i));
            q.push(e.to);
            res[e.to]=res[v]^ec;
            if(res[e.to]==1) odd++;
            else even++;
        }
    }

    ll mid1=MODpow(2,i,MOD);
    ll mid2=odd*even%MOD;
    ll mid=mid1*mid2%MOD;
    return mid;
}

int main(void){
    cin>>N;
    REP(i,N-1){
        ll u,v,w; cin>>u>>v>>w;
        u--,v--;
        G[u].push_back(Edge{v,w});
        G[v].push_back(Edge{u,w});
    }

    ll res=0;
    REP(i,60){
        res+=calc(i);
        res%=MOD;
    }
    cout<<res<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const long nPrime = 1000000007;
//const long nPrime = 998244353;
struct Node{
    long iON = 0;
    long iOFF = 1;
};

long DFS(int x, const vector<vector<pair<int,long>>> &vviEdge,
         vector<Node> &vzNode, vector<int> &viCheck){
    viCheck[x] = 1;

    long nReturn = 0;
    for(int i = 0; i < vviEdge[x].size(); i++){
        int y = vviEdge[x][i].first;
        if(viCheck[y] == 1){
            continue;
        }
        nReturn += DFS(y, vviEdge, vzNode, viCheck);
        vzNode[x].iON += (vviEdge[x][i].second == 0) ? vzNode[y].iON
                                                     : vzNode[y].iOFF;
        vzNode[x].iOFF += (vviEdge[x][i].second == 0) ? vzNode[y].iOFF
                                                      : vzNode[y].iON;
        vzNode[x].iON %= nPrime;
        vzNode[x].iOFF %= nPrime;
        nReturn -= vzNode[y].iON * vzNode[y].iOFF;
        nReturn %= nPrime;
    }

    nReturn += vzNode[x].iON * vzNode[x].iOFF;
    nReturn %= nPrime;
    return nReturn;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<pair<int,long>>> vviEdge(n);
    for(int i = 0; i < n-1; i++){
        int a,b;
        long c;
        cin >> a >> b >> c;
        vviEdge[a-1].push_back(make_pair(b-1,c));
        vviEdge[b-1].push_back(make_pair(a-1,c));
    }

    vector<vector<pair<int,long>>> vviEdgeThis = vviEdge;
    long nAns = 0;
    for(long i = 0; i < 60; i++){
        for(long j = 0; j < n; j++){
            for(long k = 0; k < vviEdgeThis[j].size(); k++){
                vviEdgeThis[j][k].second = ((vviEdge[j][k].second & (1L<<i)) != 0) ? 1:0;
            }
        }
        vector<Node> vzNode(n);
        vector<int> viCheck(n,0);
        long iThis = (1L<<i) % nPrime;
        long nSum = DFS(0, vviEdgeThis, vzNode, viCheck);
        nAns += nSum * iThis;
        nAns %= nPrime;
    }

    nAns += nPrime;
    nAns %= nPrime;
    cout << nAns << endl;
    return 0;
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>

#pragma GCC optimize("O3")

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define rep1(i, n) for(ll i = 1, i##_len = (n); i <= i##_len; ++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)
#define foreach(i, itr) for(auto& i : (itr))
#define asort(arr, size) std::sort(arr, arr + size)
#define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; })
#define cauto const auto&
#define bit(n) (1LL << (n))

////////////////////////////////////
// ここから下に任意のコードを書く //
////////////////////////////////////

ull A[100100];
ull B[100100];
ull C[100100];

ull bcj[100100];

int main() {
    ull N;
    cin >> N;
    rep1(i, N) cin >> A[i];
    rep1(i, N) cin >> B[i];
    rep1(i, N) {
        cin >> C[i];
        ++bcj[B[C[i]]];
    }
    ull count = 0;
    rep1(i, N) {
        count += bcj[A[i]];
    }
    cout << count << endl;

    return 0;
}

#include <iostream>
#include <string>
constexpr int MAX = 30;
long long dp[MAX + 1][MAX + 1];
std::string find_kth(int A, int B, long long K) {
    if (A == 0) {
        return std::string(B, 'b');
    }
    if (B == 0) {
        return std::string(A, 'a');
    }
    if (K <= dp[A - 1][B]) {
        return std::string("a") + find_kth(A - 1, B, K);
    }
    else {
        return std::string("b") + find_kth(A, B - 1, K - dp[A - 1][B]);
    }
}
int main() {
    int A, B;
    long long K;
    std::cin >> A >> B >> K;
    dp[0][0] = 1;
    for (int i = 0; i <= A; ++i) {
        for (int j = 0; j <= B; ++j) {
            if (i > 0) {
                dp[i][j] += dp[i - 1][j];
            }
            if (j > 0) {
                dp[i][j] += dp[i][j - 1];
            }
        }
    }
    std::cout << find_kth(A, B, K) << '\n';
    return 0;
}


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int ri(){
    int n;
    scanf("%d",&n);
    return n;
}

int main(){
    int N;
    cin >> N;
    map<string, int> mp;
    string S[N];
    for (int i = 0;i<N;++i){
        cin >> S[i];
        ++mp[S[i]];
    }
    for (int i = 0; i < N; ++i)
    {
        if(S[i][0]=='!'){
            S[i].erase(0, 1);
            if(mp[S[i]]>=1){
                cout << S[i];
                return 0;
            }
        }
    }
    cout << "satisfiable" << endl;
}

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define loop(i,n)for(i=0;i<n;i++)
//#define INF 1000000000

using ll = long long int;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef long double ld;
typedef vector<ll> vi;
typedef tree<int,null_type,less<int>,rb_tree_tag,
        tree_order_statistics_node_update> indexed_set;

bool sortsec(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
    if(a.second==b.second)return a.first>b.first;
    else return (a.second>b.second);
}

#define eb emplace_back
#define mp make_pair
#define pb push_back
#define MAX 100000
#define MOD 1000000
#define endl '\n'

int main()
{
   //freopen("inputfile.txt","r",stdin);
   ll n;cin>>n;
   map <string,ll> ma;
   string r;
   for(ll i=0;i<n;i++)
   {
       string s;cin>>s;
       ma[s]++;
   }
   bool flag = false;
   //for(auto x:ma)cout<<x.first<<endl;
   //cout<<endl;
   for(auto x:ma)
   {
       //cout<<x.first<<endl;
       string h = x.first;
       char c = '!';
       string r = h.substr(1,h.size());
       if(ma[h]>=1 && ma[c+h]>=1)
       {
           flag = true;
           cout<<h<<endl;
           break;
       }
   }
   if(!flag)cout<<"satisfiable"<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
const ll INF = 1001001001;
void chmin(ll& a,ll b){if(a>b)a = b;}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> g(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a] |= 1 << b;
        g[b] |= 1 << a;
    }
    vector<ll> dp(1<<n,INF);
    dp[0] = 1;
    rep(i,n){
        rep(j,1<<n){
            if(dp[j]==1&&(g[i]&j)==j){
                dp[j|1<<i] = 1;
            }
        }
    }
    rep(i,1<<n){
        for(int j = i; --j &= i;){
            chmin(dp[i],dp[i^j]+dp[j]);
        }
    }
    cout << dp.back() << endl;

}

#include <bits/stdc++.h>

using namespace std;

#define cfor(n) for(int i = 0; i < n; ++i)
#define forcn(i,n) for(int i = 0; i < n; ++i)
#define forlcn(i,l,n) for(int i = l; i < n; i++)
#define fordn(i,n) for(int i = n - 1; i >= 0; --i)
#define forldn(i,l,n) for(int i = n - 1 - l; i >= 0; i--)
#define forau(i,v) for(auto &i : v)

typedef long long ll;
typedef unsigned long long ull;

ll mod = 1000000007;

int main(){
  int A,B; cin>>A>>B;
  int ans = 2*A+100;
  cout << ans - B << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int n;
int a[maxn + 10][maxn + 10];
char s[maxn + 10];
double ans;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; ++j)
			a[i][j] = s[j] == '1';
		a[i][i] = 1;
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				a[i][j] |= a[i][k] && a[k][j];
	for (int i = 1; i <= n; ++i) {
		int v = 0;
		for (int j = 1; j <= n; ++j)
			v += a[j][i];
		ans += 1. / v;
	}
	printf("%.10lf", ans);
}

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=2e5;
priority_queue<int> pq;
int tab[N+10][2];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>tab[n-i+1][0];
	for(int i=1;i<=n;i++)
		cin>>tab[i][1];
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(tab[i][0]>tab[i][1])
			swap(tab[i][0],tab[i][1]);
		if(!pq.empty() && (-pq.top())<tab[i][0])
		{
			ans+=pq.top();
			pq.pop();
			ans+=tab[i][0];
			pq.push(-tab[i][0]);
		}
		ans+=tab[i][1];
		pq.push(-tab[i][1]);
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <iomanip> //<<setprecision(12), or <<fixed
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <set>

using namespace std;

using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;

int main()
{
    ll N,M;
    cin>>N>>M;
    vector<string> S(N);
    for(auto& s:S) cin>>s;

    vector<ll> cnt(N,0);
    for(ll i=0; i<N; i++)
    {
        for(auto c:S[i]) if(c=='1') cnt[i]++;
        //cout<<cnt[i]<<endl;
    }

    vector<ll> oddsum(N+1,0), evensum(N+1,0);
    for(ll i=0; i<N; i++)
    {
        oddsum[i+1]=oddsum[i]+cnt[i]%2;
        evensum[i+1]=evensum[i]+(cnt[i]+1)%2;
        //cout<<oddsum[i+1]<<" "<<evensum[i+1]<<endl;
    }

    ll res=0;
    for(ll i=0; i<N; i++)
    {
        if(cnt[i]%2){ res+=evensum[N]-evensum[i]; }
        else{ res+=oddsum[N]-oddsum[i]; }
    }

    cout<<res<<endl;
    // Find a CounterExample.
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007;
ll fexp(ll b, ll e){
    ll res = 1;
    for(;e;e>>=1){
        if(e&1)res = (res*b)%MOD;
        b = (b*b)%MOD;
    }
    return res;
}

// INVERSO MOLTIPLICATIVO

ll inv(ll a){
    return fexp(a,MOD-2);
}
int T = 1;
ll N;
ll a;
int main(){
    cin >> N;
    ll S=N,M;
    cin >> M;
    for(int i = 0; i < N; i++){
        cin >> a;
        S+=a;
    }
    M+=N-1;
    ll r = 1;
    for(int i = 1; i <= S; i++){
        r *= (M-i+2); r%=MOD;
        r *= inv(i); r %= MOD;
    }
    cout << r << "\n";
    return 0;
}


#include <bits/stdc++.h>

#define int int64_t

const int N=1e5+9, N2=2e5+9;

using namespace std;

signed main(){
	int a, b;
	vector<int> vc, vs;

	cin >> a >> b;

	if (a==b){
		for (int i=1; i<=a; i++){
			cout << -i << " " << i << " ";
		}
	}
	else if (a>b){
		int i=1, mn=0, pl=0;
		for (; i<=b; i++){
			vc.push_back(i);
			vc.push_back(-i);
		}
		for (;i<=a; i++){
			vs.push_back(i*1000);
			vc.back()+=-i*1000;
		}

		for (int k:vc){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}
		for (int k:vs){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}

		cerr << '\n' << pl << " " << mn;
	}
	else {
		int i=1, mn=0, pl=0;
		for (; i<=a; i++){
			vc.push_back(-i);
			vc.push_back(i);
		}
		for (;i<=b; i++){
			vs.push_back(-i*1000);
			vc.back()+=i*1000;
		}

		for (int k:vc){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}
		for (int k:vs){
			cout << k << " ";
			if (k<0) mn+=k;
			else pl+=k;
		}

		cerr << '\n' << pl << " " << mn;
	}
}

#include <iostream>
#include <set>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
ll mod=1000000007;
ll power(ll x,ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        ll n,p ;
        cin>>n>>p;
        if(n==1)
        {
            cout<<p-1;
            return 0;
        }
        if(p==2)
        {
            cout<<0;return 0;
        }
        cout<<(power(p-2,n-1,mod)%mod*(p-1)%mod)%mod;

    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep3(i, k, n) for(int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int index_vout=0; index_vout < v.size(); index_vout++) cout<<v[index_vout]<<' '
#define blank cout<<endl
#define newvar(n) ll n; cin >> n
#define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end())
const ll MOD = 1e9 + 7;
const ll INF = MOD*MOD+1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vl> c(n);
    rep(i,n){
        rep(j, n){
            ll x;
            cin >> x;
            c[i].pb(x);
        }
    }
    vector<vl> dif(n, vl(n-1));
    rep(i,n){
        rep(j,n-1){
            dif[i][j] = c[i][j+1] - c[i][j];
        }
    }
    bool chk = true;
    rep(i,n){
        rep(j, n-1){
            if(dif[0][j] != dif[i][j]) chk = false;
        }
    }

    if(!chk){
        cout << "No";
        return 0;
    }
    cout << "Yes" << endl;
    ll m = INF;
    ll m_i;
    ll m_j;
    rep(i,n){
        rep(j,n){
            if(c[i][j] < m){
                m_i = i;
                m_j = j;
                m = c[i][j];
            }
        }
    }

    vl m_dif(n);
    rep(i,n) cout << c[i][m_j] - m << ' ';
    cout << endl;

    vout(c[m_i]);
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

struct Edge{
  long from;
  long to;
  long cost;
};

int main(){
  long n,m;
  cin >> n >> m;
  vl w(n);
  rep(i,n) cin >> w[i];
  vector<pll> data(m);
  long allmin = 1e16;
  rep(i,m){
    cin >> data.at(i).second >> data.at(i).first;
    chmin(allmin, data.at(i).first);
  }
  sort(all(data));
  long tmpmax = 0;
  rep(i,m){
    chmax(data.at(i).second, tmpmax);
    chmax(tmpmax, data.at(i).second);
  }
  sort(all(w));
  rep(i,n){
    if(w[i] > allmin){
      //cout << allmin << endl;
      cout << -1 << endl;
      return 0;
    }
  }
  long ans = 1e17;
  do{
    vl sum(n+1,0);
    rep(i,n){
      sum[i+1] = sum[i] + w.at(i);
    }
    vector<vector<Edge>> Graph(n);
    REP(i,2,n+1){
      for(long j=0;j+i<=n;j++){
        long wsum = sum[j+i]-sum[j];
        long iter = upper_bound(all(data), pll(wsum-1,1e17)) - data.begin();
        long L;
        if(iter == 0) L = 0;
        else L = data.at(iter-1).second;
        Graph.at(j).push_back(Edge{j,j+i-1,L});
      }
    }
    vl dp(n,0);
    rep(i,n-1){
      for(Edge ed : Graph.at(i)){
        long nv = ed.to;
        long L = ed.cost;
        dp.at(nv) = max(dp.at(nv), dp.at(i) + L);
      }
    }
    ans = min(ans, dp.at(n-1));
  }while(next_permutation(all(w)));
  cout << ans << endl;
}

//
// Created by 原田 on 2021/04/13.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const long long LINF =1e18;
const int INF = 1e9;

int main() {
    string s1,s2,s3;

    cin>>s1>>s2>>s3;

    map<char,int>mp;
    vl kurai = {0,1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000};

    for (int i = 0; i < s1.size(); ++i) {
        mp[s1[i]] ++;
    }
    for (int i = 0; i < s2.size(); ++i) {
        mp[s2[i]] ++;
    }
    for (int i = 0; i < s3.size(); ++i) {
        mp[s3[i]] ++;
    }

    if(mp.size() > 10){
        cout<<"UNSOLVABLE"<<endl;
        return 0;
    }

    vector<int> v(10);
    iota(v.begin(), v.end(), 0);       // v に 1, 2, ... N を設定
    do {

        int i = 0;
        for(auto item : mp){
            mp[item.first] = v[i];
            i++;
        }
        bool ok = true;
        ll s1_n = 0;
        for (int j = 1; j <= s1.size(); ++j) {
            s1_n += mp[s1[s1.size() - j]] * kurai[j];
            if(j == s1.size() && mp[s1[s1.size() - j]] == 0){
                ok = false;
            }
        }
        ll s2_n = 0;
        for (int j = 1; j <= s2.size(); ++j) {
            s2_n += mp[s2[s2.size() - j]] * kurai[j];
            if(j == s2.size() && mp[s2[s2.size() - j]] == 0){
                ok = false;
            }
        }
        ll s3_n = 0;
        for (int j = 1; j <= s3.size(); ++j) {
            s3_n += mp[s3[s3.size() - j]] * kurai[j];
            if(j == s3.size() && mp[s3[s3.size() - j]] == 0){
                ok = false;
            }
        }
        if(s1_n + s2_n != s3_n){
            ok = false;
        }
        if(ok){
            cout<<s1_n<<endl;
            cout<<s2_n<<endl;
            cout<<s3_n<<endl;
            return 0;
        }

    } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    cout<<"UNSOLVABLE"<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int m = 2e5+10;
int k =  ceil(log2(m)) + 1;
int sk = (1 << k);
vector<ll> seg(sk);

void update(int s, int e, int at, int l, int r, int p){
	if(l<=s && e<=r) seg[at]+=p;
	else {
		int q = (s+e)>>1;
		if(r<=q) update(s,q,at*2+1,l,r,p);
		else if(l>q) update(q+1,e,at*2+2,l,r,p);
		else {
			update(s,q,at*2+1,l,q,p);
			update(q+1,e,at*2+2,q+1,r,p);
		}
	}
}

ll get(int s, int e, int at, int id) {
	if(s>=e) return seg[at];
	int q = (s + e) >> 1;
	if(id<=q) return seg[at]+get(s,q,at*2+1,id);
	return seg[at]+get(q+1,e,at*2+2,id);
}

void solve() {
    int n, w;
    cin >> n >> w;
    vector<int> a(n), b(n), p(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> p[i];
    for(int i = 0; i < n; i++) {
    	update(0,m-1,0,a[i],b[i]-1,p[i]);
    }
    bool f=true;
    for(int i = 0; i < m; i++) {
    	ll r = get(0,m-1,0,i);
    	if(r>w) {
    		f = false;
    		break;
    	}
    }

    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

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

ll n, w, s, t, p;

int main() {
  cin >> n >> w;
  vector<ll> c(200001, 0);
  rep (i, n) {
    cin >> s >> t >> p;
    c[s] -= p;
    c[t] += p;
  }
  ll d = w;
  string ans = "Yes";
  rep (i, 200001) {
    d += c[i];
    if (d < 0) {
      ans = "No";
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(void)
{
	long long a, b, c;

	std::cin >> a >> b >> c;
	if (a * a < c * c - b * b)
		std::cout << "Yes" << std::endl;
	else
		std::cout << "No" << std::endl;
	return (0);
}

#include <bits/stdc++.h>
#define x first
#define y second
#define endll '\n'
#define pb push_back
#define mem(x,a) memset(x,a,sizeof(x))
using namespace std;
const int N=1e5+10,mod=19650827;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int n,k,m;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int a[1010];
int f[1010][1010][2];
void work(){
    int a=read(),b=read(),c=read();
    if(a*a+b*b<c*c)puts("Yes");
    else puts("No");
}
int main(){
    //int T=read();
    //while(T--)
        work();
    return 0;
}


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
#define SZ(v) ((int)(v).size())
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

template<class T>
inline void relax(T& a,const T& b) { a=((a>b) ? a : b); }
template<class T>
inline void tense(T& a,const T& b) { a=((a<b) ? a : b); }

template<class T>
inline void read(T& x)
{
	x=0;
	register bool sign=false;
	register char c;
	for(c=getchar();c<'0' || c>'9';c=getchar())
		if(c=='-') sign=true;
	for(;c>='0' && c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	if(sign) x=~x+1;
}

const int N=1e5+5;

int n;
set<int> S[N];
int a[N];

int Mex(set<int>& S)
{
	for(int i=1;;i++)
		if(!S.count(i)) return i;
	return -1;
}

int main()
{
//	freopen("1.in","r",stdin);
	int i,j;

	read(n);
	for(i=1;i<=n;i++) {
		a[i]=Mex(S[i]);
		S[i].clear();
		for(j=i+i;j<=n;j+=i)
			S[j].insert(a[i]);
	}
	for(i=1;i<=n;i++)
		printf("%d ",a[i]);
	puts("");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define popcountll(x) __builtin_popcountll(x)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

void Main();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

#define VM 10
void eprint() { cerr << endl; }
template <class First, class... Rest>
void eprint(First f, Rest... r) {
  cerr << f << ' ';
  eprint(r...);
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  size_t output_num = v.size();
  bool is_omitted = false;
#ifdef VM
  if (VM < output_num) {
    output_num = VM;
    is_omitted = true;
  }
#endif
  os << "[";
  for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", ";
  os << v[output_num - 1];
  if (is_omitted) os << ", ...";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S,T>& m) {
  os << "{\n";
  for(auto [k,v]: m){
    os << k << ": " << v << ",\n";
  }
  return os << '}';
}

// n未満の素数のリストを返す
// エラトステレスの篩
vector<int> prime_enum(int n) {
  if(n <= 2) return vector<int>();
  vector<int> res;
  vector<bool> is_prime(n, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for (ll i = 2; i < n; i++) {
    if (!is_prime[i]) continue;
    res.push_back(i);
    for (ll j = 2; i * j < n; j++) {
      is_prime[i * j] = false;
    }
  }
  return res;
}

// 素数リストを用いた実装
// 素数リストはsqrt(n)までの素数を含む必要がある
map<int, int> prime_factor(int n, const vector<int>& primes) {
  map<int, int> res;
  for (int p : primes) {
    if (p * p > n) break;
    while (n % p == 0) {
      res[p]++;
      n /= p;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

int yakusuu(int n, vector<int>& primes){
  auto m = prime_factor(n, primes);
  int ans = 1;
  for(auto [_, c]: m){
    ans += c;
  }
  return ans;
}

using P = pair<int,int>;

void Main(){
  int n; cin >> n;
  auto primes = prime_enum(n);
  for(int i = 1; i <= n; i++){
    cout << yakusuu(i, primes) << ' ';
  }
}


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int m = 1;
    while (n != 0) {
        m *= 2;
        --n;
    }

    int a, b;
    a = 0; b = 0;
    for (int i = 1; i <= m / 2; ++i) {
        int c;
        cin >> c;
        if (b < c) {
            a = i;
            b = c;
        }
    }
    int e, f;
    e = 0; f = 0;
    for (int i = 1; i <= m / 2; ++i) {
        int c;
        cin >> c;
        if (f < c) {
            e = i + m / 2;
            f = c;
        }
    }

    if (b < f) {
        cout << a << endl;
    }
    else {
        cout << e << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template<class T>void chmin(T& a,T b){
    if(a>b){
        a=b;
    }
}
typedef std::pair<int,int> p;

#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  const int INF=1001001001;
  int N;
  cin>>N;
  int k=1<<(N-1);
  vector<int> a(k),b(k);
  rep(i,k)cin>>a[i];
  rep(i,k)cin>>b[i];

  vector<int>::iterator iter_c=max_element(a.begin(),a.end());
  vector<int>::iterator iter_d=max_element(b.begin(),b.end());

  size_t index_c=distance(a.begin(),iter_c);
  size_t index_d=distance(b.begin(),iter_d);

  if(*iter_c<*iter_d)cout<<index_c+1<<endl;
  else cout<<k+index_d+1<<endl;

}