#include <bits/stdc++.h>

using namespace std;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;

using Array = vector<ll>;
using Matrix = vector<Array>;

/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/

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

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

template<int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

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

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

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

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

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

using mint = ModInt<MOD>;

void solve() {
    int n, m;
    cin >> n >> m;
    vec<ll> a(n);
    REP(i, n) cin >> a[i];

    int s = 0;
    REP(i, n) {
        s += a[i];
    }

    auto nCr = [](ll n, ll r) -> mint {
        mint ret = 1;
        REP(i, r) ret *= i + 1;
        ret = ret.inverse();
        REP(i, r) ret *= n - i;
        return ret;
    };
    cout << nCr(m + n, s + n) << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    REP(i, t - 1) {
        solve();
    }*/

    solve();

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD 1000000007
#define INF 1000000000
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        ll r,c,m;
        cin>>r>>c>>m;
        vector <pair<ll,ll>> v;
        vector <ll> x(c+1,r+1);
        vector <ll> y(r+1,c+1);
        for(int i=1;i<=m;i++){
            ll x1,y1;
            cin>>x1>>y1;
            x[y1]=min(x[y1],x1);
            y[x1]=min(y[x1],y1);
        }
        ll ans=0ll;
        for(int i=1;i<=x[1]-1;i++)
            ans+=y[i]-1ll;
        for(ll i=1;i<=y[1]-1;i++){
            v.push_back(make_pair(x[i]-1,i));
            ans+=x[i]-1ll;
        }
        sort(v.begin(),v.end());
        ordered_set s;
        ll j=1;
        for(int i=0;i<y[1]-1;i++){
            while(j<=v[i].ff&&j<=x[1]-1){
                ll val=1e6;
                val*=y[j]-1ll;
                val+=j;
                s.insert(val);
                j++;
            }
            v[i].ss*=(ll)1e6;
            ll val=j-1-s.order_of_key(v[i].ss);
            ans-=val;
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i=0; i<N; i++) cin >> A[i];

    vector<vector<long long> > mintable(N, vector<long long>(N, 100001));

    for (int left=0; left<N; left++) {
        for (int right=left; right<N; right++) {
            if (right == left) {
                mintable[left][right] = A[left];
                continue;
            }
            mintable[left][right] = min(mintable[left][right-1], A[right]);
        }
    }

    long long best = 0;
    for (int left=0; left<N; left++) {
        for (int right=left; right<N; right++) {
            best = max(best, mintable[left][right] * (1+right-left));
        }
    }
    cout << best << endl;
    return 0;
}

#include <bits/stdc++.h>

#define psk push_back
#define ppk pop_back
#define mkp make_pair

using namespace std;

typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int u32;
typedef unsigned short u16;

typedef pair<int,int> PII;
typedef pair<LL,int> PLI;
typedef pair<int,LL> PIL;
typedef pair<LL,LL> PLL;
typedef map<int,int> MII;
typedef map<LL,int> MLI;
typedef map<int,LL> MIL;
typedef map<LL,LL> MLL;
typedef vector<int> VI;
typedef vector<PII > VII;
typedef vector<LL> VL;
typedef queue<int> QI;
typedef queue<PII > QII;

const short MSK15=0x7fff;
const u16 MSK16=0xffff;
const int MSK31=0x7fffffff;
const u32 MSK32=0xffffffff;
const LL MSK63=0x7fffffffffffffff;
const uLL MSK64=0xffffffffffffffff;
const int Inf=(1<<30)-1;
const int mInf1=0x3f3f3f3f;
const int mInf2=0x7f7f7f7f;
const LL lInf=(1LL<<62)-1;
const LL lmInf1=0x3f3f3f3f3f3f3f3fLL;
const LL lmInf2=0x7f7f7f7f7f7f7f7fLL;
const double dInf=1e15;
const double eps=1e-8;

u16 rnd16(){	return (u16)(rand())&MSK16;    }
u32 rnd32(){    return (((u16)(rand())&MSK16)<<16)|(rand()&MSK16);    }
uLL rnd64(){    return (((uLL)(rand())&MSK16)<<48)|(((LL)(rand())&MSK16)<<32)|(((u16)(rand())&MSK16)<<16)|(rand()&MSK16);    }
short rnd15(){    return rand()&MSK15;    }
int rnd31(){	return ((rand()&MSK15)<<16)|(rand()&MSK16);    }
LL rnd63(){    return (((LL)(rand())&MSK15)<<48)|(((LL)(rand())&MSK16)<<32)|((u32)(rand()&MSK16<<16))|(rand()&MSK16);    }
int rnd(){    return rnd31();    }
LL lrnd(){    return rnd63();    }

int a[10010];
int n;

LL check(int v)
{
	int maxn=0,cur=0;
	for(int i=1; i<=n+1; i++)
	{
		if(a[i]>=v) cur++;
		else maxn=max(maxn,cur), cur=0;
	}
//	cout<<v<<" "<<maxn<<endl;
	return 1LL*v*maxn;
}

int main()
{
    ios::sync_with_stdio(false);

	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];

	LL maxn=0;
	for(int i=1; i<=n; i++) maxn=max(maxn,check(a[i]));

	cout<<maxn<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='.'){
            break;
        }else{
            cout<<s[i];
        }
    }
    cout<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  string x;
  cin >> x;
  int a = x.size();
  rep(i, a){
    if(x.at(i) == '.'){
      x.erase(i);
      break;
    }
  }
  cout << x << endl;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>
#define ld long double
#define ull unsigned long long

using namespace std;

const int nax = 4e5 + 11;
int a[nax];
int n;

bool cmp(int x, int y){
    return a[x] < a[y];
}

int score[nax];
int pref[nax];

int OFFSET = 2e5 + 2;

vector<int> ziomki[nax];

char ans[nax];

void reku(int lo, int hi){
    if(lo > hi) return;
    if(score[lo] != score[hi]){
        ans[lo] = '(';
        ans[hi] = ')';
        reku(lo + 1, hi - 1);
        return;
    }
    int cur = pref[lo - 1];
    int idx = pref[lo - 1] + OFFSET;
    auto it = upper_bound(ziomki[idx].begin(), ziomki[idx].end(), lo - 1);
    int nxt = (*it);
    reku(lo, nxt);
    reku(nxt + 1, hi);
}

void solve(){
    cin >> n;
    n *= 2;
    for(int i=1;i<=n;i++) cin >> a[i];
    vector<int> id;
    for(int i=1;i<=n;i++) id.pb(i);
    sort(id.begin(), id.end(), cmp);
    //for(int x : id) cout<<x<<endl;
    for(int i=1;i<=n/2;i++) score[id[i - 1]] = 1;
    for(int i=n/2+1;i<=n;i++) score[id[i - 1]] = -1;
    for(int i=1;i<=n;i++){
        pref[i] = pref[i - 1] + score[i];
        ziomki[pref[i] + OFFSET].pb(i);
    }
    reku(1, n);
    for(int i=1;i<=n;i++) cout<<ans[i];

}

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

    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e5+5;
int a[M],b[M],f[M];
ll pref(int l, int r)
{
	unordered_map<int, vector<int>> vec;
	for(int i=l;i<=r;i++)
	{
		vec[a[i]-i].pb(i);
	}
	ll res = 0;
	for(int i=r;i>=l;i--)
	{
		ll z;
		if(sz(vec[b[i]-i]))
		{
			int id = vec[b[i]-i].back();
			res += (ll)(i-id);
			z = i-id;
		}
		else
		{
			cout<<"-1\n";
			exit(0);
		}
		vec[a[i]-i].pop_back();
		if(i != r and b[i]-i == b[i+1] - (i+1))
			res-=z;
	}
	return res;
}
ll suff(int l, int r)
{
	unordered_map<int, vector<int>> vec;
	for(int i=r;i>=l;i--)
	{
		vec[a[i]-i].pb(i);
	}
	ll res = 0;
	for(int i=l;i<=r;i++)
	{
		ll z;
		if(sz(vec[b[i]-i]))
		{
			int id = vec[b[i]-i].back();
			res += (ll)(id-i);
			z = id - i;
		}
		else
		{
			cout<<"-1\n";
			exit(0);
		}
		vec[a[i]-i].pop_back();
		if(i != l and b[i]-i == b[i-1] - (i-1))
			res-=z;
	}
	return res;
}
ll solve(int l, int r)
{
	for(int j=l+1;j<=r;j++)
	{
		if(f[j] != -1)
		{
			return pref(l,j-1)+suff(j, r);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n, L;
	cin>>n>>L;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	a[0] = 0;
	a[n+1] = L+1;
	b[n+1] = L+1;
	for(int i=0;i<=n+1;i++)
	{
		if(a[i] > b[i])
			f[i] = -1;
		if(a[i] < b[i])
			f[i] = 1;
	}
	for(int i=1;i<=n+1;i++)
	{
		if(f[i-1] == 1 and f[i] == -1)
		{
			// cout<<i<<endl;
			cout<<"-1\n";
			return 0;
		}
	}
	int l = 0;
	ll ans = 0;
	for(int i=1;i<=n+1;i++)
	{
		if(f[i] == 0)
		{
			ans += solve(l, i);
			l = i;
		}
	}
	cout<<ans<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
int MOD = 1000000007;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << 7 * 3 - (a + b + c) << endl;
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int  main()
{
    vector<int>vc(3);
    cin>>vc[0];
    cin>>vc[1];
    cin>>vc[2];
    sort(vc.begin(),vc.end());
    if(vc[2]-vc[1]==vc[1]-vc[0])
    {
    	cout<<"Yes";
	}
	else
	cout<<"No";
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e'){
            count++;
        }
    }
    cout << count << endl;

}

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
/********************************************************************/
#define M1 1000000007
#define M2 998244353
const double pi = 3.14159265;

#define ll long long
#define lld long double

#define pb push_back
#define mp make_pair
#define vi vector<ll>

#define endl '\n'

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl

#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define collect(v, n)            \
    for (ll i = 0; i < n; i++) { \
        cin >> v[i];             \
    }

#define prv(v)                         \
    for (auto x : v) cout << x << " "; \
    cout << endl;
#define prmap(v) \
    for (auto x : v) cout << x.first << " " << x.second << endl;
#define prpair(x) cout << x.first << " " << x.second << endl;

/*
__builtin_popcount(n)      // the number of ones in the int
__builtin_popcountll(n)  // the number of ones in the ll

__builtin_parity(n)  // the parity (even or odd) of the number of ones

__builtin_clz(n)  // the number of zeros at the beginning of the number

__builtin_clzll(n)  // the number of zeros at the beginning of the ll
__builtin_ctz(n)  // the number of zeros at the end of the number
*/

// template <typename T>
// #define o_set(T)                                   \
        //     tree<T, null_type, less_equal<T>, rb_tree_tag, \
        //          tree_order_statistics_node_update>
// member functions :
// 1. order_of_key(k) : number of elements strictly lesser than k
// 2. find_by_order(k) : k-th element in the set
// MULTISET ==> less_equal
// SET ==> less

ll powM(ll x, ll y, ll m) {
    ll ans = 1, r = 1;
    x %= m;
    while (r > 0 && r <= y) {
        if (r & y) {
            ans *= x;
            ans %= m;
        }
        r <<= 1;
        x *= x;
        x %= m;
    }
    return ans;
}

int add(int a, int b) {
    a += b;
    if (a >= M2) a -= M2;
    return a;
}

int mul(int a, int b) { return a * 1ll * b % M2; }

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

map<long long, long long> factorize(long long n) {
    map<long long, long long> ans;
    for (long long i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ans[i]++;
            n /= i;
        }
    }
    if (n > 1) {
        ans[n]++;
        n = 1;
    }
    return ans;
}

ll countBits(ll n) {
    ll count = 0;
    while (n) {
        count++;
        n >>= 1;
    }
    return count;
}

ll isP(ll n) {
    if (n == 0 || n == 1) return 0;
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) return 0;
    }
    return 1;
}

ll min(ll a, ll b) {
    if (a < b) return a;
    return b;
}

ll gcd(ll x, ll y) {
    if (x == 0) return y;
    return gcd((ll)y % x, (ll)x);
}

ll modI(ll a, ll m) {
    ll m0 = m, y = 0, x = 1;
    if (m == 1) return 0;
    while (a > 1) {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0) x += m0;
    return x;
}

/* **********END OF TEMPLATE*********** */

void solve() {
    string s;
    cin >> s;
    ll ans = 0;
    ll n = s.size();
    for (ll i = 0; i + 3 < n; i++) {
        ans += (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' &&
                s[i + 3] == 'e');
    }
    cout<<ans<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(12);
    ll tt = 1;
    // cin >> tt;

    for (ll tc = 1; tc <= tt; tc++) {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define oss ostringstream
#define db double
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define lb lower_bound
#define ub upper_bound
#define vin(a,n) vi a(n); rep(k,0,n) {cin>>a[k];}
#define vout(a) rep(k,0,a.size()) {cout<<a[k]<<" ";} cout<<"\n";
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353
#define inf LLONG_MAX

const ll N=1e9+7;

ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a; b/=2;a=a*a;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}

signed main(){
    IOS
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll l;
    cin>>l;
    rep(i,0,l){
        ll n;
        cin>>n;
        if(n&1) cout<<"Odd\n";
      	else{
            if((n/2)&1)cout<<"Same\n";
            else cout<<"Even\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ll test_case=1;   //cin>>test_case;

    while(test_case--)
    {
        // cout << "Case #" << i << ": ";
        ll x;
        cin>>x;
        if(x%100==0)
        {
            cout<<100<<"\n";
            continue;
        }
        ll yy=x/100;
        yy++;
        cout<<100*yy-x<<"\n";

        //Case_Ends_Here :)
    }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque>
#include <string>

using namespace std;

struct Request {
	int s;
	int t;
	int p;
};

struct Point {
	int time;
	long long cost;
	int upOrDown;	//1--up, -1--down

    bool operator < (const Point &a) const {
        return this->time>a.time;//最小值优先
    }
};

int n;
int w;
Request r[200010];

int main()
{
	std::priority_queue<Point> q;

	scanf("%d%d", &n, &w);
	for (int i = 0 ; i < n ; i++) {
		scanf("%d%d%d", &(r[i].s), &(r[i].t), &(r[i].p));

		Point ptA;
		ptA.time = r[i].s;
		ptA.cost = r[i].p;
		ptA.upOrDown = 1;

		q.push(ptA);

		ptA.time = r[i].t;
		ptA.cost = r[i].p;
		ptA.upOrDown = -1;
		q.push(ptA);
	}

	long long curCost = 0;
	while (q.empty() == false) {
		Point curP = q.top();
		q.pop();
		int curTime = curP.time;

		if (curP.upOrDown == 1) {
			curCost = curCost + curP.cost;
		} else {
			curCost = curCost - curP.cost;
		}

		if (q.empty())
			break;

		curP = q.top();
		while (curP.time == curTime) {
			if (curP.upOrDown == 1) {
				curCost = curCost + curP.cost;
			} else {
				curCost = curCost - curP.cost;
			}
			q.pop();
			if (q.empty())
				break;
			curP = q.top();
		}

		if (curCost > w) {
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

struct Row
{
  long start;
  long end;
  long p;

  bool operator<(const Row& rhs) const
  {
    return end < rhs.end;
  }
};

std::string solve(long n, long w, std::vector<Row>& rows)
{
  std::sort(rows.begin(), rows.end(),
      [](const Row& lhs, const Row& rhs) { return lhs.start < rhs.start; });

  long sum = 0;
  std::multiset<Row> olds;
  for (auto& r : rows) {
    sum += r.p;
    for (auto it = olds.begin(); it != olds.end(); ++it) {
      if (it->end <= r.start) {
        sum -= it->p;
      } else {
        olds.erase(olds.begin(), it);
        break;
      }
    }
    if (sum > w) return "No";
    olds.insert(r);
  }
  return "Yes";
}

int main()
{
  long n, w;
  std::cin >> n >> w;

  std::vector<Row> rows(n);
  for (auto& r : rows) {
    std::cin >> r.start >> r.end >> r.p;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, w, rows) << std::endl;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
	template<class T>
	inline void read(T &x) {
		x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		if(fu)x=-x;
	}
	inline int read() {
		int x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		return fu?-x:x;
	}
	char _n_u_m_[40];
	template<class T>
	inline void write(T x ) {
		if(x==0){
			putchar('0');
			return;
		}
		T tmp = x > 0 ? x : -x ;
		if( x < 0 ) putchar('-') ;
		register int cnt = 0 ;
		while( tmp > 0 ) {
			_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
			tmp /= 10 ;
		}
		while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
	}
	template<class T>
	inline void write(T x ,char ch) {
		write(x);
		putchar(ch);
	}
}
using namespace fastIO;
ll n,m,k;
const long long mod=998244353;
inline long long pw(long long x,long long p)
{
    long long res=1;
    for(;p;p>>=1,x=x*x%mod)
        if(p&1)res=res*x%mod;
    return res;
}
inline long long getm(long long top,long long bot) {
	return (top*pw(bot,mod-2))%mod;
}
ll ans;
int main() {
	read(n);read(m);read(k);
	if(n>1&&m>1){
		F(i,1,k){
		ans+=(pw(i,n)-pw(i-1,n)+mod)*pw(k-i+1,m);
		ans%=mod;
	}write(ans);
	}
	else{
		if(n<m)swap(n,m);
		write(pw(k,n));
	}
	return 0;
}

#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int n = scan();
  auto s = scan<string>();
  vector<int> x(n + 1);
  generate(ALL(x), scan<>);

  vector<int> buf(n + 1);
  auto check = [&](int k) -> bool {
    for (int z : Rep(k)) {
      for (int i : Rep(n + 1)) buf[i] = x[i] / k + (z < x[i] % k);
      for (int i : Rep(n)) {
        if (s[i] == '<' and not(buf[i] < buf[i + 1])) return false;
        if (s[i] == '>' and not(buf[i] > buf[i + 1])) return false;
      }
    }
    return true;
  };

  int ok = 1, ng = 10001;
  while (ng - ok > 1) {
    int mid = (ok + ng) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  cout << ok << '\n';
  for (int z : Rep(ok))
    for (int i : Rep(n + 1))
      cout << x[i] / ok + (z < x[i] % ok) << " \n"[i == n];
}


/*/
   Author: Chaitanya_1999
   "Everything in this world is magic, except to the magician"
/*/
#include<bits/stdc++.h>
using namespace std;

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
// for all eight directions
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
// for all 4 directions
//int dx[4]={-1,1,0,0};
//int dy[4]={0,0,-1,1};
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
  vector<string> v; stringstream ss(s); string x;
  while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
  stringstream s; s << "[";
  for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
  if(n>0)
  s << arr[n - 1] ;
  s<< "]";
  return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
  cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
  __trace_out_var(a);
  cerr << "; ";
  __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
signed main(){
  IOS;
  int T=1;
  // cin >> T;
  vector<int>tw;
  tw.pb(1);
  while(tw.back()<1e18L){
    tw.pb(tw.back()*2ll);
  }
  while(T--){
    int n;
    cin >> n ;
    int ans = INF;
    int k = 0;
    for(auto i : tw){
      int rem = n%i;
      int q = n/i;
      ans=min(ans,rem+q+k);
      k++;
    }
    assert(ans!=INF);
    cout << ans;

  }
  return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF  = 1e9;
constexpr llong  LINF = 1e18;
constexpr double EPS  = 1e-12;
constexpr int    MOD  = 1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a)cerr<<(cnt++?' ':'>')<<elem;cerr<<endl;}

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

int main(){//I refer to other commentaries.
	int n;
	cin>>n;

	llong low=-LINF, high=LINF, add=0;
	REP(i,n){
		llong a;
		int t;
		cin>>a>>t;

		if(t==1){
			low+=a;
			high+=a;
			add+=a;
		}else if(t==2){
			chmax(low,a);
			chmax(high,a);
		}else{
			chmin(low,a);
			chmin(high,a);
		}
	}

	int q;
	cin>>q;
	while(q--){
		llong x;
		cin>>x;

		cout<<min(high,max(low,x+add))<<endl;
	}
}


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

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

    ll n,k;
    cin>>n>>k;
    ll cnt[n]={};
    for(int i=0;i<n;i++){
        ll a;
        cin>>a;
        cnt[a]++;
    }
    ll ans = 0;
    ll now = min(k,cnt[0]);
    ans += now;
    for(int i=1;i<n;i++){
        ans += min(now,cnt[i]);
        chmin(now,cnt[i]);
    }
    cout << ans << endl;

}

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

#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

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

//-------------------------- Libraries --------------------------//

//---------------------------- Solve ----------------------------//

void solve() {
    int N, K; cin >> N >> K;
    vector<int> cnt(N+1);
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        cnt[a]++;
    }
    long long ans = 0, tmp = K;
    for (int i = 0; i <= N; i++) {
        if (cnt[i] >= tmp) continue;
        ans += (long long)(tmp - cnt[i]) * i;
        tmp = cnt[i];
    }
    cout << ans << '\n';
}

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

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

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

inline int read () {
	int ret = 0, t = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	if (c == '-') t = -1, c = getchar();
	while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
	return ret * t;
}

const int MAXN = 200200;
int n, fa[MAXN][22]; vector <int> E[MAXN];
int dep[MAXN], wson[MAXN];
void dfs (int x, int f) {
	dep[x] = dep[f] + 1; fa[x][0] = f;
	for (auto i: E[x]) if (i != f) dfs(i, x);
}

int dis (int u, int v) {
	int ret = dep[u] + dep[v], i;
	if (dep[u] < dep[v]) swap(u, v);
	for (i = 20; i >= 0; i--) if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
	if (u == v) return ret - 2 * dep[u];
	for (i = 20; i >= 0; i--) if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
	u = fa[u][0]; return ret - 2 * dep[u];
}

int las = 0, ans[MAXN];
void calc (int x, int f) {
	ans[x] = ans[las] + dis(las, x); las = x;
	for (auto i: E[x]) if (i != f && i != wson[x]) calc(i, x);
	if (wson[x]) calc(wson[x], x);
}

int main () {
	n = read(); int i, j;
	for (i = 1; i < n; i++) {
		int u = read(), v = read();
		E[u].push_back(v), E[v].push_back(u);
	}
	dfs(1, 0);
	for (i = 1, j = 0; i <= n; i++) if (dep[j] < dep[i]) j = i;
	int rt = j; dfs(j, 0);
	for (i = 1, j = 0; i <= n; i++) if (dep[j] < dep[i]) j = i;
	for (i = j; i; i = fa[i][0]) wson[fa[i][0]] = i;
	for (i = 1; i <= 20; i++) for (j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
	calc(rt, 0);
	for (i = 1; i <= n; i++) printf("%d ", ans[i]);
	return 0;
}

// in case of multiple test cases and N=1e5 don't intialize arrays as global except for graph vector-array
// always check whether or not you are doing mod of a negative number
// always use 1LL instead of 1
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

// using long doubles saves you from corner cases but is very time consuming
#define double        long double
#define int           long long
#define pb            push_back
#define pii           pair<int,int>
#define vi            vector<int>
#define vii           vector<pii>
#define mi            map<int,int>
#define mii           map<pii,int>
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
// just comment the line below in case of interactive problems
#define endl          "\n"
#define repp(i,a,b)   for(int i=a;i<b;i++)
#define rep(i,a,b)    for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)       cout << #x << "=" << x << endl
#define deb2(x, y)    cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)   cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v)    for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI            3.1415926535897932384626
#define F         first
#define S         second
#define mod       1000000007
#define clr(x,y)    memset(x, y, sizeof(x))
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inp(arr, n)    repp(i, 0, n) cin >> arr[i]
#define outp(arr, n)    repp(i, 0, n) cout << arr[i] << " "

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x

void solve()
{
  int n;  cin >> n;
  int ans = 0;
  vector<pair<int, int> > points;

  while (n--) {
      int x, y;
      cin >> x >> y;
      points.pb({x, y});
  }

  int flag = 0;
  repp(i, 0, sz(points)){
      repp(j, 0, sz(points)){
          repp(k, 0, sz(points)){
              if(i != j and j != k and i != k){
                  int a = points[i].F * (points[j].S - points[k].S) +  points[j].F * (points[k].S - points[i].S) + points[k].F * (points[i].S - points[j].S);
                  if(a == 0){
                      flag = 1;
                       break;
                    }
                  }
              }
          }
      }
  cout << (flag ? "Yes" : "No");
}

int32_t main()
{
  IOS;
  int T = 1;
// cin >> T;
  //sieve();
  // int numOfSetBits = __builtin_popcountll(n);
  //std::cout << std::fixed << std::setprecision(12);
  for (int i = 1; i <= T; i++)
  {
    //cout << "Case #" << i << ": ";
    solve();
  }
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll h,w,a,b;
ll hmax = 16;
ll wmax = 16;
vvll use(hmax+1,vll(wmax+1,0));
ll solve(ll now, ll cnt){
    //cout << now << endl;
    ll ni = now/w;
    ll nj = now%w;
    ll ret = 0;
    if(cnt==a) return 1;
    if(now==h*w) return 0;
    if(use[ni][nj]==1){
        ret += solve(now+1,cnt);
    }else{
        if(nj+1<w&&use[ni][nj+1]==0){
            use[ni][nj]=1;
            use[ni][nj+1]=1;
            ret += solve(now+1,cnt+1);
            use[ni][nj]=0;
            use[ni][nj+1]=0;
        }
        if(ni+1<h){
            use[ni][nj]=1;
            use[ni+1][nj]=1;
            ret += solve(now+1,cnt+1);
            use[ni][nj]=0;
            use[ni+1][nj]=0;
        }
        ret += solve(now+1,cnt);
    }
    return ret;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> h >> w >> a >> b;
    ll ans = solve(0,0);
    cout << ans << endl;
    return 0;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}
const ll oo = (ll)1e18;
bool esPrimo(int x){
	forn(i,2,x)if(x%i == 0)return false;
	return true;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	vi primos;
	forn(i,2,51){
		if(esPrimo(i))primos.pb(i);
	}
	debug(primos);
	int N; cin >> N;
	vi A(N);
	forn(i,0,N)cin >> A[i];
	ll res = oo;
	forn(mask,0,(1<<primos.size())){
		ll act = 1;
		forn(bit,0,(int)primos.size()){
			if(mask&(1<<bit)){
				act *= ll(primos[bit]);
			}
		}
		bool can = true;
		forn(i,0,N){
			if(__gcd(ll(A[i]),act) == 1){
				can = false;
				break;
			}
		}
		if(can){
			res = min(res,act);
		}
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector <string> s(n);
    rep(i, n){
        cin >> s[i];
    }
    ll a = 1, b = 0;
    reverse(s.begin(), s.end());
    rep(i, n){
        if(s[i] == "AND"){
            a += b;
            b *= 2;
        }
        else{
            b += a;
            a *= 2;
        }
    }
    if(s[n - 1] == "AND"){
        cout << a + b << endl;
    }
    else{
        cout << a + b << endl;
    }
}

/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
" when you are not practicing someone else is ,
 and the day u meet them u will lose "
*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 100050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 1000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

#define loop(i,n)  for (lli i = 0; i < n; i++)
#define FOR(i,a,b) for (lli i = a; i < b; i++)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename Head>
void print(Head&& head)
{
    cout<<head<<endl;
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail)
{
    cout<<head<<" ";
    print(tail...);
}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}

int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n;
    cin>>n;
    print(max(0LL,n));
  }
return 0;
}


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
vector<string> c;
int main(){
    int n;cin>>n;
    cout<<((1<<n)-1)<<endl;
    string s="AB";
    c.push_back(s);
    for(int i=2;i<=n;i++){
        vector<string> d;
        for(auto j:c){
            d.push_back(j+j);
            string p="";
            for(int k=0;k<j.length();k++){
                if(j[k]=='A') p+='B';
                else p+='A';
            }
            d.push_back(j+p);
        }
        string t="";
        for(int k=1;k<=(1<<(i-1));k++){
            t+='A';
        }
        for(int k=1;k<=(1<<(i-1));k++){
            t+='B';
        }
        d.push_back(t);
        c=d;
    }
    for(auto i:c){
        cout<<i<<endl;
    }
}

//#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 __gnu_pbds;
#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod= 998244353;
long double pi = acosl(-1);
const ll infl = 8e18+5;
const int inf = 1e9+2;
const int nmax = 5e3+5;
//const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

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

    int n;
    cin>>n;
    vector<string>ans;
    for(int i=1; i<(1<<n); i++){
        string s;
        for(int j=1; j<=(1<<n); j++){
            if( __builtin_popcount(i&j)&1 ) s+='A';
            else s+='B';
        }
        ans.push_back(s);
    }

    cout<<ans.size()<<"\n";
    for(auto z : ans) cout<<z<<"\n";
}
/*
*/


#include <bits/stdc++.h>
#define ll  long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i,a,b) for(i=a;i<b;i++)
#define rfor(i,a,b) for(i=b-1;i>=a;i++)     // reverse loop
#define yes "YES"
#define no "NO"
#define sorta(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())          // reverse sort
#define all(a) a.begin(),a.end()
using namespace std;
//const unsigned int mod = 1000000007;
vector<ll>prime(10000001,1);
vector<ll>sdf(1000001,1);
long long inf=1000000000000000007;

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

    ll n,x,i;
    cin>>n>>x;
    x=x*100;
    vector<ll >a(n),p(n);
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>p[i];
    }
    long double  ans=0;int f=0;
    for(i=0;i<n;i++)
    {
        ans+=(a[i]*p[i]);
        //cout<<ans<<endl;
        if(ans>x)
            {f=1;break;}
    }

            if(f==1)
                cout<<(i+1)<<endl;
            else
                cout<<-1<<endl;

}

/*
 * Author: Moon_light
 * Solution:
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define lowbit(x) ((x)&(-x))
#define sz(x) ((int)x.size())
#define fr(x) freopen(x,'r',stdin)
#define fw(x) freopen(x,'w',stdout)
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) begin(a),end(a)
#define bitcnt(x) (__builtin_popcountll(x))
#define rep(i,a,b) for(int i = (a);i<=(b); ++i)
#define per(i,a,b) for(int i = (a);i>=(b); --i)
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VB;
typedef double db;

//global variable
const int N = 1;
const int mod = 1e9+7;
int t;

//functions
LL qmi(LL a,LL k,LL mod){
    LL res = 1;
    while(k){
        if(k&1) res = res*a%mod;
        k >>= 1;
        a = a*a%mod;
    }
    return res%mod;
}
int gcd(int a,int b) {
    return b==0? a:gcd(b,a%b);
}

//code from here! Come on! Have a pleasant experience~
int main()
{
    IO;
    int a,b;
    cin>>a>>b;
    int c = a+b;
    int ans = 4;
    if(c >= 15 && b >= 8){
        ans = 1;
    }else if(c >= 10 && b >= 3){
        ans = 2;
    }else if(c >= 3){
        ans = 3;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int x, y; cin >> x >> y;
  cout << (abs(x-y) < 3 ? "Yes" : "No");
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<vi> vii;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define loop(n) for(int i=0; i<n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define file_read freopen("input.txt", "r", stdin); \
				  freopen("output.txt", "w", stdout);
#define tc int t; cin>>t; while(t--)
#define endl "\n"
#define usainbolt cin.tie(0) -> sync_with_stdio(0)

int main(void){
	usainbolt;
	//file_read

	int x, y;
	cin>>x>>y;

	int ans = abs(x-y);

	if(ans < 3){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

}


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

int main(){
    ll a, b, k; cin >> a >> b >> k;
    ll comb[61][61];
    comb[0][0]=1;
    for(int i=1;i<=60;i++){
        REP(j,i+1){
            if(j==0)
                comb[i][j]=comb[i-1][j];
            else
                comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
        }
    }
    string ans="";
    int n=a+b;
    REP(i,n){
        if(a==0||b==0){
            if(a==0)
                ans+='b';
            else
                ans+='a';
        }
        else{
            ll c=comb[a+b-1][a-1];
            if(k-c<=0){
                ans+='a';
                a--;
            }
            else{
                k-=c;
                ans+='b';
                b--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi acos(-1)
#define int long long
#define fastttt std::ios::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL);
#define endl "\n"
long long pow2(long long a,long long b,long long m){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%m;}
                a=(a*a)%m;
                b>>=1;
        }
    return ans;
}
long long pow2(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a);}
                a=(a*a);
                b>>=1;
        }
    return ans;
}
int ncr(int n, int r)
{
    long long p = 1, k = 1;
    if (n - r < r)
        r = n - r;
    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;
            long long m = __gcd(p, k);
            p /= m;
            k /= m;

            n--;
            r--;
        }
    }
    else
        p = 1;
    return p;
}
string call(int a,int b,int k,int i,int cur){
    if(i == 0)return "";
    if(a == 0){
        string ret(i,'b');
        return ret;
    }
    if(b == 0){
        string ret(i,'a');
        return ret;
    }
    int up = ncr(a+b-1,b);
    if(up+cur-1 < k){
        return "b"+call(a,b-1,k,i-1,cur+up);
    }
    else{
        if(a)
        return "a"+call(a-1,b,k,i-1,cur);
        else return "b"+call(a,b-1,k,i-1,cur);
    }
}
void solve(){
    int a,b,k;
    cin>>a>>b>>k;
    cout<<call(a,b,k,a+b,1);
}
int32_t main()
{
    fastttt
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

struct point { ll x, y; };

struct matrix {
	ll mat[3][3];

	matrix operator*(matrix rhs) {
		matrix res;
		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) {
				res.mat[i][j] = 0;
				for (int k=0; k<3; k++) {
					res.mat[i][j] += mat[i][k] * rhs.mat[k][j];
				}
			}
		}
		return res;
	}

	point operator*(point p) {
		return {
			mat[0][0]*p.x + mat[0][1]*p.y + mat[0][2],
			mat[1][0]*p.x + mat[1][1]*p.y + mat[1][2],
		};
	}

	void print() {
		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) cout<<mat[i][j]<<' ';
			cout<<endl;
		}
		cout<<endl;
	}
};

matrix rot_cw() { return {0,1,0, -1,0,0, 0,0,1}; }
matrix rot_ccw() { return {0,-1,0, 1,0,0, 0,0,1}; }
matrix ref_x(ll k) { return {-1,0,2*k, 0,1,0, 0,0,1}; }
matrix ref_y(ll k) { return {1,0,0, 0,-1,2*k, 0,0,1}; }

int n, m, q;
point ps[N];
matrix pre[N];

int main() {
	cin>>n;
	for (int i=1; i<=n; i++) cin>>ps[i].x>>ps[i].y;

	cin>>m; pre[0] = {1,0,0, 0,1,0, 0,0,1};
	for (int i=1; i<=m; i++) {
		int t; cin>>t;
		if (t == 1) pre[i] = rot_cw();
		else if (t == 2) pre[i] = rot_ccw();
		else {
			int k; cin>>k;
			if (t == 3) pre[i] = ref_x(k);
			else pre[i] = ref_y(k);
		}
		pre[i] = pre[i] * pre[i-1];
	}

	cin>>q;
	while (q--) {
		int a, b; cin>>a>>b;
		point p = pre[a] * ps[b];
		cout<<p.x<<' '<<p.y<<endl;
	}

}

#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define sz(x)                 (int)(x).size()
#define all(x)                (x).begin(), (x).end()
#define tr(x, it)             for(auto (it) = (x).begin();it != (x).end();it++)
#define fo(i, k, n)           for(int i = (k);i < (n);i++)
#define Fo(i, k, n)           for(int i = (k);i >= (n);i--)
#define el                    "\n"
#define ff                    first
#define ss                    second
#define ll                    long long
#define pb                    push_back
#define mp                    make_pair
#define pii                   pair<int, int>
#define vi                    vector<int>
#define mii                   map<int, int>
//#define pqb                   priority_queue<int>
//#define pqs                   priority_queue<int, vi, greater<int>>
//#define pc(x)                 putchar(x);
//#define setbits(x)            __builtin_popcountll(x)
//#define zrobits(x)            __builtin_ctzll(x)
#define mod                   1000000007
#define inf                   1e18
//#define ps(x, y)              fixed<<setprecision(y)<<x
//#define mk(arr, n, type)      type *arr = new type[n];
//#define w(x)                  int x; cin>>x; while(x--)
#define deb(x)                cout<<#x<< " = "<< x<<"\n";
int a[200], b[200];
int c[20], d[20];
ll ans = 0;
int n, m, k;

void dp(int i, int da[]){
	// deb(i)
	if(i == k){
		// fo(j, 1, n+1) cout<<da[j]<<" ";
		// cout<<el;
		// fo(j, 1, n+1) cout<<db[j]<<" ";
		// cout<<el;
		ll cnt = 0;
		fo(j, 0, m){
			if(da[a[j]] > 0 && da[b[j]] > 0) cnt++;
		}
		ans = max(ans, cnt);
		return;
	}
	da[c[i]]++;
	dp(i+1, da);
	da[c[i]]--;
	da[d[i]]++;
	dp(i+1, da);
	da[d[i]]--;
}

void solve(){
	cin>>n>>m;
	fo(i, 0, m){
		cin>>a[i]>>b[i];
	}
	cin>>k;
	fo(i, 0, k){
		cin>>c[i]>>d[i];
	}
	int da[200], db[200];
	memset(da, 0, sizeof(da));
	memset(db, 0, sizeof(db));
	dp(0, da);
	cout<<ans;
}

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


#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
#include <bits/stdc++.h>
using namespace std;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
// sort(ALL(v), [](auto const& lhs, auto const& rhs) { return lhs > rhs; /* 左の方が大きい...というイメージ。*/ });
// --------------------------------------------------------------------------------------------- //

static const int MAX = 100001;
static const ll MOD = 1000000007;

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, M; cin >> N >> M;
	if(N == 1){
		if(M == 0){
			cout << 1 << " " << 2 << endl;
		}
		return 0;
	}
	if(M < 0 ||  M == N || M == N -1){
		cout << -1 << endl;
		return 0;
	}

	vector<pair<int, int> > ans;
	ll base = 1000001;
	ans.push_back({1, base});
	int k = 1;
	rep(i,  N-1 - M-1){
		ans.push_back({base + k, base + k+ 1});
		k+= 2;
	}
	k = 1;
	rep(i, M + 1){
		ans.push_back({1 + k, 1 + k + 1});
		k += 2;
	}

	sort(ALL(ans));
	rep(i, ans.size()){
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
int i, n, m, k, ans;
int a[1000];

int main() {
    scanf(" %d %d", &n, &m);
    if (m == 0) {
        rep(0,n) printf("%d %d\n", 2+4*i, 4+4*i);
        exit(0);
    }
    if (m < 0 || m >= n-1) {
        printf("-1\n"); exit(0);
    }
    rep(0,n-1) {
        printf("%d %d\n", 2+4*i, 4+4*i);
    }
    printf("%d %d\n", i*4-m*4-3, i*4-1);
}


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef ENVIRONMENT_LINKED_BOOST
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#endif

using namespace std;
using uint  = unsigned int;
using ll    = long long;
using ull   = unsigned long long;
using lpair = std::pair<ll, ll>;
#define REP(i, a, b)    for (ll i = a; i < b; ++i)
#define REPREV(i, a, b) for (ll i = a; i > b; --i)

const int _ = []() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    return 0;
}();

template <typename value_t>
void resize(value_t& v, const value_t& val) { v = val; }
template <typename vec_t, typename value_t, typename... arg_t>
void resize(std::vector<vec_t>& v, const value_t& val, int size, arg_t... arg) {
    v.resize(size);
    for (auto& c : v) resize(c, val, arg...);
}
template <typename A, typename B>
void chmin(A& a, const B& b) { a = min(a, static_cast<A>(b)); };
template <typename A, typename B>
void chmax(A& a, const B& b) { a = max(a, static_cast<A>(b)); };

int main() {
    map<ll, vector<int>> mp;
    ll N, M;
    cin >> N >> M;
    REP(i, 0, M) {
        ll x, y;
        cin >> x >> y;
        mp[x].push_back(y);
    }
    set<ll> cur;
    cur.insert(N);
    for (auto& [x, v] : mp) {
        set<ll> tmp;
        for (ll y : v) {
            if (cur.count(y - 1) || cur.count(y + 1)) tmp.insert(y);
        }
        for (ll y : v) cur.erase(y);
        cur.insert(tmp.begin(), tmp.end());
    }
    cout << cur.size() << endl;
    return 0;
}

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

ll n, m;
int MAX = 400010;
vector<ll> dp(MAX * 2, 0);
vector<vector<int>> G(MAX);
vector<int> seen(MAX, false);

void dfs(int v) {
    seen[v] = true;

    for (auto &nv : G[v]) {
        dp[nv] += dp[v];
        if (nv >= MAX || seen[nv]) continue;

        dfs(nv);
    }
}

int main() {
    cin >> n >> m;
    vector<set<P>> v(2 * m + 2);

    vector<ll> x(m), y(m);

    v[m + 1].insert({0, 0});
    rep(i, m) {
        cin >> x[i] >> y[i];
        if (y[i] - n + m + 1 >= 0 && y[i] - n + m + 1 < 2 * m + 2)
            v[y[i] - n + m + 1].insert({x[i], i + 1});
    }

    rep(i, 2 * m + 2) {
        if (!v[i].empty()) {
            G[(*v[i].rbegin()).second].push_back(MAX + i);
        }
    }
    rep(i, 2 * m + 2) {
        if (v[i].empty()) continue;
        if (i - 1 >= 0 && v[i - 1].size()) {
            auto it1 = v[i - 1].begin();
            ll next = 2 * n;
            auto it2 = v[i].begin();
            while (it2 != v[i].end()) {
                it2++;
                if (it2 != v[i].end())
                    next = (*it2).first;
                else
                    next = 2 * n;
                it2--;
                while (it1 != v[i - 1].end() && (*it1).first <= (*it2).first)
                    it1++;
                while (it1 != v[i - 1].end() && (*it1).first <= next) {
                    G[(*it2).second].push_back((*it1).second);
                    it1++;
                }
                it2++;
            }
        }
        if (i + 1 < 2 * m + 2 && v[i + 1].size()) {
            auto it1 = v[i + 1].begin();
            ll next = 2 * n;
            auto it2 = v[i].begin();
            while (it2 != v[i].end()) {
                it2++;
                if (it2 != v[i].end())
                    next = (*it2).first;
                else
                    next = 2 * n;
                it2--;
                while (it1 != v[i + 1].end() && (*it1).first <= (*it2).first)
                    it1++;
                while (it1 != v[i + 1].end() && (*it1).first <= next) {
                    G[(*it2).second].push_back((*it1).second);
                    it1++;
                }
                it2++;
            }
        }
    }
    dp[0] = 1;
    dfs(0);

    ll ans = 0;
    for (int i = MAX; i < MAX + 2 * m + 2; i++) ans += dp[i];
    cout << ans << endl;
}


#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>s(h);
	rep(i, h) {
		cin >> s[i];
	}
	ll ans(0);

	rep(i, h) {
		bool ok = false;
		rep(j, w) {
			if (ok && s[i][j] == '.')ans++;
			else if (s[i][j] == '.')ok = true;
			else if (s[i][j] == '#')ok = false;
		}
	}
	rep(i, w) {
		bool ok = false;
		rep(j, h) {
			if (ok && s[j][i] == '.')ans++;
			else if (s[j][i] == '.')ok = true;
			else if (s[j][i] == '#')ok = false;
		}
	}
	cout << ans;
	return 0;
}

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

int main(){
  ios::sync_with_stdio(0); cin.tie(0);
  int h, w, count=0; cin >> h >> w;
  vector<string> str;
  for(int i=0;i<h;i++) {
    string s; cin >> s;
    str.push_back(s);
  }
  for(int i=0;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(str[i][j] == '.' && str[i][j] == str[i][j+1]) count++;
    }
  }
  for(int i=1;i<h;i++) {
    for(int j=0;j<w;j++) {
      if(str[i][j] == '.' && str[i][j] == str[i-1][j]) count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

int main()
{
  long long T, N, prev = 0;
  cin >> T >> N;
  vector<long long> nums;
  for (int a = 1; a <= 100; a++)
  {
    int x = (100 + T) * a / 100;
    if (x != prev + 1)
    {
      nums.push_back(x - 1);
    }
    prev = x;
  }
  int l = nums.size();
  N--;
  cout << (nums.at(N % l) + (100 + T) * (N / l)) << endl;
}

#include <bits/stdc++.h>
//#include <atcoder/modint>
//#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c = a % i_7;
    if(c >= 0) return c;
    return c + i_7;
}
long long po(long a, long b){
    if(b == 0) return 1;

    long long z = po(a , b / 2);
    z = mod(z * z);
    if(b % 2 != 0) z = mod(a * z);
    return z;
}

bool prime_(int n){
  if(n == 1){
    return false;
  }else if(n == 2){
    return true;
  }else{
    for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false;
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a < b) std::swap(a,b);
  if(a % b == 0) return b;
  else return gcd_(b, a % b);
}

long long lcm_(long long x, long long y){
  return (x / gcd_(x,y)) * y;
}

using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;
  int a[4];
  REP(i, 4) cin>>a[i];
  int ans = 100;
  REP(i, 4) ans = min(ans, a[i]);
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_HW = 2005;
const ll MOD = 1e9+7;
char c[MAX_HW][MAX_HW];
ll cntu[MAX_HW][MAX_HW],cntd[MAX_HW][MAX_HW],cntl[MAX_HW][MAX_HW],cntr[MAX_HW][MAX_HW];
ll mypow2[MAX_HW*MAX_HW];

void init()
{
	mypow2[0] = 1;
	rep(i,MAX_HW*MAX_HW-1)
	{
		mypow2[i+1] = mypow2[i] * 2 % MOD;
	}
}

int main()
{
	init();
	int H,W;
	cin >> H >> W;
	ll cnt = 0;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> c[i][j];
			if (c[i][j] == '.') cnt++;
		}
	}

	ll temp = 0;
	rep(i,H)
	{
		temp = 0;
		rep(j,W)
		{
			if (c[i][j] == '.') temp++;
			else temp = 0;
			cntl[i][j] = temp;
		}
	}
	temp = 0;
	rep(i,H)
	{
		temp = 0;
		for (int j = W-1; j >= 0; --j)
		{
			if (c[i][j] == '.') temp++;
			else temp = 0;
			cntr[i][j] = temp;
		}
	}
	temp = 0;
	rep(j,W)
	{
		temp = 0;
		rep(i,H)
		{
			if (c[i][j] == '.') temp++;
			else temp = 0;
			cntu[i][j] = temp;
		}
	}
	temp = 0;
	rep(j,W)
	{
		temp = 0;
		for (int i = H-1; i >= 0; --i)
		{
			if (c[i][j] == '.') temp++;
			else temp = 0;
			cntd[i][j] = temp;
		}
	}

	/*
	rep(i,H)
	{
		rep(j,W)
		{
			cout << cntr[i][j] << " ";
		}
		cout << endl;
	}
	*/

	ll ans = 0;
	rep(i,H)
	{
		rep(j,W)
		{
			if (c[i][j] == '.')
			{
				temp = cntr[i][j] + cntl[i][j] + cntd[i][j] + cntu[i][j] - 3;
				ll temp2 = ((mypow2[temp] - 1 + MOD) % MOD) * mypow2[cnt-temp] % MOD;
				ans = (ans + temp2) % MOD;
				//cout << temp << " " << ans << endl;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

#include<iostream>
#define ll long long
//我把题目读成求周长段数的还有救嘛……
using namespace std;
bool s[11][11];
bool pd(ll i,ll j){
	ll he=s[i][j]+s[i][j+1]+s[i+1][j]+s[i+1][j+1];
	if(he==1 or he==3) return 1;
	else return 0;
}
int main(){
	ll h,w,i,j,sl=0;
	char sr;
	cin>>h>>w;
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			cin>>sr;
			if(sr=='.') s[i][j]=0;
			else s[i][j]=1;
		}
	}
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(pd(i,j)) sl++;
		}
	}
	cout<<sl;
    return 0;
}


// Atcoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#define _USE_MATH_DEFINES

#include<math.h>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include <sstream>

using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1LL << 50)
#define MOD (1e9+7)
#define rrep(i,n) for(int i=n-1;i>=0;--i)

//typedef pair < ll, ll> P;

//元がintの分けたものを返す p[0]は1桁目
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
//桁数を返す
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
//元がstringの分けたものを返す d[0]は最高位
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	reverse(s.begin(), s.end());
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}

/*long double　は%Lf*/
//queue古い順,stack新しい
/****Union-Find-Tree***/
int par[int(0x7ffffff)];//Parent
int Rank[int(0x7ffffff)];//Deep_of_the_Tree

//n要素で初期化
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
	}
}
//木の根探し
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (Rank[x] < Rank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

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

int N, M;
vector<int>G[25]; int V[25],id[25]; int c = 0;
int color[25]; bool used[25];
bool dfs(int u,int prec) {

	if (used[u])return true;

	if (c >> id[u] & 1) {
		prec += 2; prec %= 3;
	}
	else {
		prec++; prec %= 3;
	}
	for (int to : G[u]) {
		if (used[to] && color[to] == prec)return false;
	}
	color[u] = prec;
	used[u] = true;
	for(int to : G[u]) {
		if (!dfs(to, prec))return false;
	}
	return true;

}
int32_t main() {
	cin >> N >> M;
	init(N);
	rep(i, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		unite(a, b);
		G[a].push_back(b); G[b].push_back(a);
	}
	rep(i, N) {
		id[i] = V[find(i)];
		V[find(i)]++;
	}
	ll res = 1;
	rep(i, N) {
		if (V[i]==0)continue;
		ll cnt = 0;
		rep(j, (1 << V[i])) {
			c = j;
			rep(k, 3) {
				fill(color, color + 22, -1);
				fill(used, used + 22, false);
				color[i] = k; used[i] = true;
				bool flag = true;
				for (int to : G[i]) {
					if (!dfs(to, k))flag = false;
				}
				cnt += flag;
			}
		}
		cnt /= 2LL;
		res *= cnt;
	}
	cout << res << endl;
}

#include<bits/stdc++.h>
#define MAX 20
#define MOD 1000000007
using namespace std;
vector<int> v[MAX+10];
int c[MAX+10];
bool vis[MAX+10];
bool dfs(int x)
{
	vis[x] = true;
	bool ans = true;
	for(int y:v[x])
	{
		if(c[y]==-1)
			continue;
		if(vis[y])
			ans = ans&&(c[x]!=c[y]);
		else
			c[y] = 1-c[x], ans = ans&&dfs(y);
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	while(m--)
	{
		int x,y;
		cin>>x>>y;
		--x, --y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int lmt = 1<<n;
	long long ans = 0;
	for(int i=0;i<lmt;++i)
	{
		for(int j=0;j<n;++j)
		{
			if(i&(1<<j))
				c[j] = -1;
			else c[j] = 0;
			vis[j] = false;
		}
		long long tmp = 1;
		bool ok = true;
		for(int j=0;ok&&j<n;++j)
		{
			if(!vis[j]&&c[j]!=-1)
				ok = ok&&dfs(j), tmp *= 2;
			else if(c[j]==-1)
				for(int x:v[j])
					if(c[x]==-1)
						ok = false;
		}
		if(ok)
			ans += tmp;
	}
	cout<<ans<<endl;
	return 0;
}


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

struct xy {
	int x;
	int y;
};

const int n = 50;
vector<vector<int>> t(n, vector<int>(n));
vector<vector<int>> p(n, vector<int>(n));
xy s;
clock_t start;
string ans = "";
int maxPoint = 0;

void input () {
  cin >> s.x >> s.y;
	rep(i, n) rep(j, n) cin >> t[i][j];
	rep(i, n) rep(j, n) cin >> p[i][j];
}

bool isTimeLimit(clock_t start) {
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if (time >= 500) return true;
  else return false;
}

int cnt = 0;
void dfs(int mode, xy now, int point, string tmpans, set<int> step) {
  cnt++;
  // タイムリミット
  if (cnt%500 == 0) {
    if (isTimeLimit(start)) {
      cout << ans << endl;
      exit(0);
    }
  }

  switch (mode) {
    case 0: now.x--; break;
    case 2: now.x++; break;
    case 1: now.y--; break;
    case 3: now.y++; break;
  }

  if (!(now.x >= 0 && now.x <= 49 && now.y >= 0 && now.y <= 49)) {
    return ;
  }
  auto it = step.find(t[now.x][now.y]);
  if (it != step.end()) return;
  step.insert(t[now.x][now.y]);
  switch (mode) {
    case 0: tmpans += "U"; break;
    case 2: tmpans += "D"; break;
    case 1: tmpans += "L"; break;
    case 3: tmpans += "R"; break;
  }

  point += p[now.x][now.y];

  if (point > maxPoint) {
    maxPoint = point;
    ans = tmpans;
  }

  rep(i, 4) dfs(i, now, point, tmpans, step);
  return;
}

int main() {
	// 入力
  input();

  start = clock();
  rep(i, n) {
    // 初期化
    xy now;
    now.x = s.x;
    now.y = s.y;
    set<int> step; // 踏んだタイル番号を保持
    step.insert(t[now.x][now.y]);
    string tmpans = "";
    int point = 0;

    // 進む方向探索
    // 0：上、1：下、2：左、3：右
    dfs(i, now, point, tmpans, step);
  }
	return 0;
}

#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <random>

#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;
const int BOARD_SIZE=50;
struct Status{
	vector<bool> tile_passed;
	int ci=0;
	int cj=0;
	int current_point = 0;
	string route = "";
	bool operator<(const Status& cmp) const{
		return current_point>cmp.current_point;
	}
};
int t[BOARD_SIZE][BOARD_SIZE];
int p[BOARD_SIZE][BOARD_SIZE];
vector<Status> generate_next(Status current, int min_ci, int max_ci, int min_cj, int max_cj){
	vector<Status> retval;
	Status temp;
	if(current.ci>min_ci && !current.tile_passed[t[current.ci-1][current.cj]]){
		temp = Status(current);
		temp.ci=current.ci-1;
		temp.current_point+=p[temp.ci][temp.cj];
		temp.tile_passed[t[temp.ci][temp.cj]]=true;
		temp.route+="U";
		retval.push_back(temp);
	}
	if(current.ci<max_ci && !current.tile_passed[t[current.ci+1][current.cj]]){
		temp = Status(current);
		temp.ci=current.ci+1;
		temp.current_point+=p[temp.ci][temp.cj];
		temp.tile_passed[t[temp.ci][temp.cj]]=true;
		temp.route+="D";
		retval.push_back(temp);
	}
	if(current.cj>min_cj && !current.tile_passed[t[current.ci][current.cj-1]]){
		temp = Status(current);
		temp.cj=current.cj-1;
		temp.current_point+=p[temp.ci][temp.cj];
		temp.tile_passed[t[temp.ci][temp.cj]]=true;
		temp.route+="L";

		retval.push_back(temp);
	}
	if(current.cj<max_cj && !current.tile_passed[t[current.ci][current.cj+1]]){
		temp = Status(current);
		temp.cj=current.cj+1;
		temp.current_point+=p[temp.ci][temp.cj];
		temp.tile_passed[t[temp.ci][temp.cj]]=true;
		temp.route+="R";

		retval.push_back(temp);
	}
	return retval;

}

int main(){
	int si,sj;
	cin>>si>>sj;
	int temp;
	for(int i=0;i<BOARD_SIZE;i++){
		for(int j=0;j<BOARD_SIZE;j++){
			cin>>temp;
			t[i][j]=temp;
		}
	}
	for(int i=0;i<BOARD_SIZE;i++){
		for(int j=0;j<BOARD_SIZE;j++){
			cin>>temp;
			p[i][j]=temp;
		}
	}
	vector<Status> *current = new vector<Status>();
	vector<Status> *next = new vector<Status>();
	Status initial;
	for(int i = 0;i<BOARD_SIZE*BOARD_SIZE;i++){
		initial.tile_passed.push_back(false);
	}
	initial.ci=si;
	initial.cj=sj;
	initial.tile_passed[t[si][sj]]=true;
	initial.current_point=p[si][sj];
	next->push_back(initial);
	int best_point = 0;
	string best_route="";
	int best_ci,best_cj;
	for(int cnt=0;cnt<400;cnt++){
		delete current;
		current = next;
		next = new vector<Status>();
		for(auto i = current->begin();i!=current->end();i++){
			//try 4 neighbour
			vector<Status> next_result = generate_next(*i,0,49,0,49);
			std::copy(next_result.begin(),next_result.end(),std::back_inserter(*next));
		}
		sort(next->begin(),next->end());
		if(next->size()>0 && next->at(0).current_point>best_point){
			best_point = next->at(0).current_point;
			best_route = next->at(0).route;
		}
		/*for(auto i1=next->begin();i1!=next->end();i1++){
			if(i1->ci==17){
				best_point = i1->current_point;
				best_route = i1->route;
				best_ci = i1->ci;
				best_cj = i1->cj;
				break;
			}
		}*/
		if(next->size()>1000){
			vector<Status> *shuffled_next = new vector<Status>();
			copy(next->begin(),next->begin()+200,std::back_inserter(*shuffled_next));
			std::random_device seed_gen;
			std::mt19937 engine(seed_gen());

			shuffle(next->begin()+200,next->end(),engine);
			copy(next->begin()+200,next->begin()+1000,std::back_inserter(*shuffled_next));
			delete next;
			next = shuffled_next;
		}
	}
	cout<<best_route<<endl;

}


#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>
#include <numeric>

//#pragma region ACL
//#include <atcoder/fenwicktree>
////#include <atcoder/math>
//#include <atcoder/string>
//#include <atcoder/scc>
//#include <atcoder/segtree>
//#include <atcoder/lazysegtree>
//#pragma endregion

using namespace std;
//using namespace atcoder;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main()
{
	int a, b; cin >> a >> b;
	cout << (a + b) / 2 << " " << (a - b) / 2 << endl;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_set>
#include <chrono>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;

template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
    if (_l < _b) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
    if (_l > _b) {
        _l = _b;
        return true;
    }
    return false;
}

template<typename _T>
void vdeb(const std::vector<_T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        // std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

using namespace std;

bool ju(vector<vector<int>> &da, int n, int k, int d) {
    vector<vector<int>> li(n+1, vector<int>(n+1));
    rip(i,n,0) rip(j,n,0) li[i+1][j+1] = (da[i][j] >= d);
    rip(i,n+1,0) rip(j,n,0) li[i][j+1] += li[i][j];
    rip(i,n+1,0) rip(j,n,0) li[j+1][i] += li[j][i];
    int cnt = 0;
    rip(i,n-k+1,0) rip(j,n-k+1,0) {
        int su = li[i][j] + li[i+k][j+k] - li[i+k][j] - li[i][j+k];
        cnt += (su > k*k/2);
    }
    return cnt == (n-k+1)*(n-k+1);
}

int main() {
    int n, k; cin >> n >> k;
    vector<vector<int>> da(n, vector<int>(n));
    rip(I,n,0) rip(j,n,0) cin >> da[I][j];
    int ng = INT_MAX/2, ok = -1;
    while(abs(ng-ok) > 1){
        int now = (ok + ng)/2;
        if(ju(da, n, k, now)) {
            ok = now;
        }
        else{
            ng = now;
        }
    }
    cout << ok << endl;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define HgS 1000000007
#define ll long long
#define reg register
#define opr operator
#define ret return
#define gc getchar
#define pc putchar
#define cst const
#define db double
#define il inline
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t='\n')
{
	static char ch[40];reg int tp=0;
	if(!x){fputs("0",stdout);if(t)pc(t);return;}
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
il ll umax(ll a,ll b){return a>b?a:b;}
il ll umin(ll a,ll b){return a<b?a:b;}
il ll uabs(ll x){return x>0?x:-x;}
il ll qpow(ll n,ll e=HgS-2,ll p=HgS)
{
	reg ll res=1;
	while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;}
	return res;
}
ll n,a[200005],maxa[200005],sum[200005],ts[200005],b;
int main()
{
	n=rd();for(int i=1;i<=n;++i)a[i]=rd(),maxa[i]=umax(maxa[i-1],a[i]);
	for(int i=1;i<=n;++i)sum[i]=sum[i-1]+a[i],ts[i]=ts[i-1]+sum[i];
	for(int i=1;i<=n;++i)prt(maxa[i]*i+ts[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+1000;
int n;
int a[N];
ll sum[N],ans[N];
int mx[N] ;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		mx[i] = max(mx[i-1],a[i]);
		sum[i]=sum[i-1]+a[i];
		ans[i]=ans[i-1]+sum[i];
	}
	for(int i=1;i<=n;i++){
		printf("%lld\n",ans[i]+1ll*mx[i]*i);
	}
 }


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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 FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

    int n;
    cin >> n;
    VLL A(n), B(n);
    REP(i, n) {
        cin >> A[i] >> B[i];
    }
    ll ans = INF;
    REP(i, n) {
        REP(t, n) {
            if (i == t) {
                chmin(ans, A[i] + B[t]);
            } else {
                chmin(ans, max(A[i], B[t]));
            }
        }
    }
    COUT(ans);
    return 0;
}

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

string complement(string s)
{
	string t="";
	for(int i=0;i<s.length();i++)
	{
		if(s.at(i)=='A')
			t+='B';
		else
			t+='A';
	}
	return t;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int power2[9];
	power2[0]=1;
	for(int i=1;i<9;i++)
		power2[i]=power2[i-1]*2;
	vector<string> ans[9];
	for(int i=1;i<9;i++)
	{
		for(int j=0;j<ans[i-1].size();j++)
		{
			string z=ans[i-1][j];
			string w=complement(z);
			string x=z+z;
			string y=z+w;
			ans[i].push_back(x);
			ans[i].push_back(y);
		}
		string a="";
		for(int j=0;j<power2[i-1];j++)
		{
			a+='A';
		}
		for(int j=0;j<power2[i-1];j++)
		{
			a+='B';
		}
		ans[i].push_back(a);
	}
	int tt=1;
	//cin >> tt;
	while(tt--)
	{
		int n;
		cin >> n;
		cout << ans[n].size() << '\n';
		for(int i=0;i<ans[n].size();i++)
			cout << ans[n][i] << '\n';
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,L,R) for(int i=L;i<R;i++)
using namespace std;
typedef vector<vector<int>> Graph;

//main area
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    A[0] = 105;
    int k = 1;
    rep1(i,10000){
        if(i%3==0 || i%5==0 || i%7==0){
            A[k] = 2*i;
            k++;
            if(k==N) break;
        }
    }
  	// cout << A[N-1] << endl;
    rep(i,N){
        cout << A[i] << (i==N-1?'\n':' ');
    }
}
/*

*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// constexpr int mod = 1e9 + 7;
// constexpr int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int n;

inline void work() {
    cin >> n;
    cout << "6 10 15";
    int p = 16;
    for (int i = 4; i <= n; ++i) {
        while (p % 6 != 0 && p % 10 != 0 && p % 15 != 0) {
            ++p;
        }
        cout << " " << p;
        ++p;
    }
    cout << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}


/**
*    author:
*    created: 15.11.2020 20:57:58
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 1001001001;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
typedef vector<int> vi;
typedef vector<vi> vvi;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

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

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int x;
  cin >> x;
  if(x >= 0) cout << x << endl;
  else cout << 0 << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
    bool f=true;ll x=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    if(f) return x;
    return ~(--x);
}
il int read(char *s){
    int len=0;
    register char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
    return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}ll n;
string c;
const ll mod =1e9+7;
il ll ksm(ll d,ll t){
    ll res=1;
    for(;t;t>>=1,d=d*d%mod)
        if(t&1) res=res*d%mod;
    return res;
}
struct hmap{
    static const int P=2e6+3,M=3e6+10;
    int hed[M],nxt[M],cnt;ll val[M];ll as[M];
    bool count(ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return 1;
            c=nxt[c];
        }return 0;
    }
    ll& operator [](ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return as[c];
            c=nxt[c];
        }
        ++cnt;val[cnt]=x;nxt[cnt]=hed[x%P];hed[x%P]=cnt;
        return as[cnt];
    }
    int size(){return cnt;}
}f;
ll get_f(ll tmp){
    if(f.count(tmp)) return f[tmp]%mod;
    if(tmp&1) return f[tmp]=((get_f(tmp/2+1)*get_f(tmp/2+1)%mod)+(get_f(tmp/2)*get_f(tmp/2)%mod))%mod;
    else return f[tmp]=get_f(tmp/2)*((get_f(tmp/2+1)+get_f(tmp/2-1))%mod)%mod;
}
int main(){
    n=read();
    c="";
    string t;
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    t=getchar(),c=c+t,getchar();
    if(n==2||c=="AAAA"||c=="AAAB"||c=="AABA"||c=="AABB"||c=="ABAB"||c=="ABBB"||c=="BBAB"||c=="BBBB"){
        print(1);
        return 0;
    }
    else if(c=="ABAA"||c=="BABA"||c=="BABB"||c=="BBAA"){
        print(ksm(2,n-3));
        return 0;
    }
    else if(c=="BAAA"||c=="ABBA"||c=="BBBA"||c=="BAAB"){
        f[1]=f[2]=1;
        print(get_f(n-1));
        return 0;
    }
    return 0;
}

/*
1000
B
A
A
A

589888339
*/


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <unordered_map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

vector<int> g[2010];
vector<int> w[2010];
const int MX = 1e9;

int d[2010];

struct node {
    int u;
    int dd;
    node(int _u) {
        u = _u;
        dd = d[u];
    }
};

int visit[2010];

bool operator<(const node& a, const node& b) {
    return a.dd > b.dd;
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        g[a].push_back(b);
        w[a].push_back(c);
    }

    for (int s = 1; s <= n; ++s) {
        //printf("src=%d\n", s);
        priority_queue<node> q;
        for (int i = 1; i <= n; ++i) {
            d[i] = MX;
            visit[i] = 0;
        }
        for (int j = 0; j < g[s].size(); ++j) {
            d[g[s][j]] = min(d[g[s][j]], w[s][j]);
        }
        for (int j = 0; j < g[s].size(); ++j) {
            q.push(node(g[s][j]));
        }
        while (!q.empty() && !visit[s]) {
            node cur = q.top();
            int x = cur.u;
            //printf(" x=%d\n", x);
            q.pop();
            if (visit[x]) continue;
            visit[x] = 1;
            //printf("  visit x=%d d[x]=%d\n", x, d[x]);
            for (int j = 0; j < g[x].size(); ++j) {
                int y = g[x][j];
                if (!visit[y]) {
                    if (d[x] + w[x][j] < d[y]) {
                        d[y] = d[x] + w[x][j];
                        q.push(node(y));
                        //printf("    relax y=%d d[y]=%d\n", y, d[y]);
                    }
                }
            }
        }
        if (visit[s]) {
            printf("%d\n", d[s]);
        } else {
            printf("-1\n");
        }
    }
}

#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>;
using edge = struct { int to; int cost; };
const int INF = 1e9;

int n,m;
vector<int> a,b,c;
vector<vector<edge>> g;

void solve(int s) {
  vector<int> d(n+5, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    REP(i,g[v].size()) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  int ans = INF;
  REP(i,n) {
    if (d[i] == INF) continue;
    for(auto x: g[i]) {
      if (x.to == s) ans = min(ans, d[i] + x.cost);
    }
  }

  cout << (ans == INF ? -1 : ans) << endl;
  return;
}

int main() {
  cin >> n >> m;
  a.resize(m); b.resize(m); c.resize(m);
  g.resize(n);

  REP(i,m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    edge e = { b[i], c[i] };
    g[a[i]].emplace_back(e);
  }

  REP(i,n) solve(i);
  return 0;
}


#include "iostream"

using namespace std;

int main() {
    int a, b, w;
    cin >> a >> b >> w;
    w *= 1000;
    const int INF = 1001001001;
    int l = INF, r = -INF;
    for (int n = 1; n <= w; ++n) {
        if (a*n <= w && w <= b*n) {
            l = min(l, n);
            r = max(r, n);
        }
    }
    if (l == INF) {
        cout << "UNSATISFIABLE" << endl;
    } else {
        cout << l << " " << r << endl;
    }
    return 0;
}

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    double cx = gx - sx;
    double cy = gy / sy;
    double dx = cx * (1 / (1 + cy));
    cout << fixed << std::setprecision(10) << sx + dx << endl;
    return 0;
}