#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << endl
#define hh cout << endl
#define INF 1e18
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

template <typename C,
          typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
          typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto &x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}

ll mod_pow(ll a, ll b)
{
    if (b < 0)
        return 0;
    a %= mod;
    if (b == 0)
        return 1;
    if (b == 1)
        return a % mod;
    if (b == 2)
        return ((a % mod) * (a % mod)) % mod;
    return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod;
}

bool isPrime(int n)
{
    if (n == 1)
        return false;
    if (n == 2)
        return true;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}

int32_t main()
{
    fast int tc = 1;
    // cin>>tc;
    while (tc--)
    {
        int n, m;
        cin >> n;
        cin >> m;

        int a = 0;

        int nl = 0, ol = 0;
        nl = ol + m;

        int pre[n + 1] = {0};
        map<int, int> mp;

        vector<int> v;

        fo(i, 1, n)
        {
            int a, b;
            cin >> a >> b;
            v.push_back(a);
            mp[a] += b;
        }
        sort(all(v));

        // for (auto it = next(mp.begin()); it != mp.end();it++){

        //     // if(it!=mp.begin())

        //     it->second += prev(it)->second;
        // }

        for (int i = 0; i < n; i++)
        {

            if (nl < v[i])
            {
                break;
            }
            else
            {
                nl += mp[v[i]];
                mp[v[i]] = 0;
            }
        }

        cout << nl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c))
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cerr << #a << ": " << (a) << endl;
#define dbgs(s) cerr << #s << endl;
#define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl;
#define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; }
template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;}
template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;}
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }
inline constexpr int offset[] = {1,0,-1,0,1};

int main() {
    fastio;
    ll ans{};
    ll N,K;
    cin >> N >> K;
    vector<array<ll,2>> a(N);
    rep(i,N) rep(j,2) cin >> a[i][j];
    sort(all(a));
    ll p{};
    rep(i,N) {
        ll c = a[i][0]-p;
        if (c > K) break;
        K -= c;
        K += a[i][1];
        p = a[i][0];
    }
    ans = p + K;
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--)  //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forll(a,start,end) for(long long a=start;a<end;a++)
#define forull(a,start,end) for(unsigned long long a=start;a<end;a++)
#define fi first
#define se second
typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vii;
typedef vector<pll>   vll;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
const double PI = acos(-1);

void solve(){
    /* code */
    int n,m;  cin>>n>>m;
    vi A(n); fori(i,0,n) cin>>A[i];
    vi B(m); fori(i,0,m) cin>>B[i];
    int a=0,b=0;
    while(a<n || b<m){
        if(a==n){
            cout<<B[b]<<' ';
            b++;
        }
        else if(b==m){
            cout<<A[a]<<' ';
            a++;
        }
        else{
            if(A[a]<B[b]){
                cout<<A[a]<<' ';
                a++;
            }
            else if(A[a]>B[b]){
                cout<<B[b]<<' ';
                b++;
            }
            else{
                a++;b++;
            }
        }
    }
}

int main()
{
    DONTSYNC;
    // TEST
    solve();
    return 0;
}

#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a / gcd(a, b) * b;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template <class T>
void CVEC(const T &v) {
	int c = v.size() - 1;
	for (int i = 0; i < c; i++) cout << v[i] << ' ';
	if (c > -1) cout << v[c];
	cout << '\n';
}

#pragma endregion header

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }

  template< typename C >
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while(a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if(check(nxt)) a = 2 * a + type;
      else M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template< typename C >
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if(a <= 0) {
      if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) {
        Monoid nxt = f(L, seg[a]);
        if(check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template< typename C >
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if(b >= sz) {
      if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for(b += sz; a < b; a >>= 1, b >>= 1) {
      if(b & 1) {
        Monoid nxt = f(seg[--b], R);
        if(check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

signed main(){
	int n, q;
	cin >> n >> q;
	SegmentTree<int> seg(n, [](int a, int b){return a^b;}, 0);
	for(int i = 1; i <= n; i++){
		int a;
		cin >> a;
		seg.update(i, a);
	}
	vector<int> t(q), x(q), y(q);
	rep(i,q){
		cin >> t[i] >> x[i] >> y[i];
	}
	rep(i,q){
		if(t[i] == 1){
			int tmp = seg[x[i]];
			seg.update(x[i], tmp^y[i]);
		}
		if(t[i] == 2){
			//cout << "!" <<endl;
			cout << seg.query(x[i],y[i]+1) << endl;
		}
	}
}


//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll, ll>>>;
Graph G;
vll dist;
vector<bool> seen;
vll T;
vector<bool> C;
vector<bool> CHA;
//ll mod = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    vll AE(N), AO(N);
    vector<pair<ll, ll>> A(2 * N);
    vector<pair<ll, ll>> PE(N), PO(N);
    vector<char> AN(2 * N);
    rep(i, N) {
        cin >> AE[i] >> AO[i];
        A[2 * i] = make_pair(AE[i], i * 2);
        A[2 * i + 1] = make_pair(AO[i], i * 2 + 1);

    }
    sort(all(A));
    reverse(all(A));
    set<ll> BE, BO, ME, MO;
    vector<bool> B(2 * N, false);
    vector<bool> U(2 * N, false);

    rep(i, N) {
        if (A[i].second % 2 == 0) {
            BE.insert(A[i].second);
            B[A[i].second] = true;
        }
        else {
            BO.insert(A[i].second);
            B[A[i].second] = true;
        }
    }
    rep(i, N) {
        if (A[i+N].second % 2 == 0) {
            ME.insert(A[i+N].second);
        }
        else {
            MO.insert(A[i+N].second);
        }
    }
    ll i = 0;
    rep(i, 2*N) {
        if (U[i])continue;

        if (B[i]) {
            if (i % 2 == 0) {

            }
        }
    }
    while (i < 2 * N) {
        if (!U[i]) {
            if (B[i]) {
                if (i % 2 == 0) {
                    auto k = MO.begin();
                    ll n = *k;
                    MO.erase(n);
                    BE.erase(i);
                    AN[min(n, i)] = '(';
                    AN[max(n, i)] = ')';
                    U[n] = true;
                    U[i] = true;
                }
                if (i % 2 != 0) {
                    auto k = ME.begin();
                    ll n = *k;
                    ME.erase(n);
                    BO.erase(i);
                    AN[min(n, i)] = '(';
                    AN[max(n, i)] = ')';
                    U[n] = true;
                    U[i] = true;
                }
            }
            else {
                if (i % 2 == 0) {
                    auto k = BO.begin();
                    ll n = *k;
                    BO.erase(n);
                    ME.erase(i);
                    AN[min(n, i)] = '(';
                    AN[max(n, i)] = ')';
                    U[n] = true;
                    U[i] = true;
                }
                if (i % 2 != 0) {
                    auto k = BE.begin();
                    ll n = *k;
                    BE.erase(n);
                    MO.erase(i);
                    AN[min(n, i)] = '(';
                    AN[max(n, i)] = ')';
                    U[n] = true;
                    U[i] = true;
                }
            }

        }
        i++;
    }

    rep(i, 2 * N) {
        cout << AN[i];
    }
    cout << endl;
}

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

#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
#ifdef DEBUG
template<class T> int size(T &&x) {
	return int(x.size());
}
template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) {
	out << '{';
	for(auto it = x.begin(); it != x.end(); ++it)
		out << *it << (it == prev(x.end()) ? "" : ", ");
	return out << '}';
}
void dump() {}
template<class T, class... Args> void dump(T &&x, Args... args) {
	cerr << x << ";  ";
	dump(args...);
}
#endif
#ifdef DEBUG
  struct Nl{~Nl(){cerr << '\n';}};
# define debug(x...) cerr << (strcmp(#x, "") ? #x ":  " : ""), dump(x), Nl(), cerr << ""
#else
# define debug(...) 0 && cerr
#endif
mt19937_64 rng(0);
int random(int l, int r) {
	return uniform_int_distribution<int>(l, r)(rng);
}

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
const LL INF = 1e18;
const int maxn = 300100;
const int mod = 998244353;

void solve() {
	int n;
	cin >> n;
	vector <PII> s;
	vi pos(n+n+1, 0);
	vector <char> result(n+n+1, ')');

	FOR(i, 1, n+n) {
		int a;
		cin >> a;
		s.pb({a, i});
	}
	sort(all(s));
	FOR(i, 0, n+n-1) {
		pos[s[i].e2] = i + 1;
	}

	debug(pos);
	vector <PII> stos;

	FOR(i, 1, n+n) {
		int typ = ((pos[i] <= n) ? 0 : 1);
		if (stos.empty() || stos.back().e2 == typ) {
			stos.pb({i, typ});
		}
		else {
			result[stos.back().e1] = '(';
			result[i] = ')';
			stos.pop_back();
		}
	}

	FOR(i, 1, n+n) cout << result[i];
	cout << "\n";
}

int main() {
	boost;
	int tests;
	tests = 1;
	//cin >> tests;
	while (tests--) {
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N;
	int A[200010];
	int X[200010];
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		X[A[i]] = i;
	}
	vector<int> op;
	for(int i = 1; i <= N; i++){
		if(A[i] == i) continue;
		int a = X[i];
		for(int j = a-1; j >= i; j--){
			X[A[j]] = j+1; X[A[j+1]] = j;
			swap(A[j], A[j+1]);
			op.push_back(j);
		}
		for(int j = i; j < a; j++){
			if(A[j] != j){
				cout << -1 << "\n"; return 0;
			}
		}
	}
	if((int) op.size() != N-1) cout << -1 << endl;
	else{
		for(auto i : op) cout << i << "\n";
	}
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define lli long long int
#define double long double
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define siz(x) x.size()
#define prs(x,y) x.find(y)!=x.end()
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define forn(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}
inline int level(int n){int ans=0;while(n%2==0){n/=2;ans++;}return ans;}
#define gog(T,x) cout<<"Case #"<<T<<": "<<x<<"\n";
#define pii pair<int,int>
vector<pii> fw,bc;
vector<int> xs;
vector<int> vis;
vector<map<int,int> > mp;
queue<int> qu;
vector<int> ans;
void solve()
{
	while(!qu.empty())
	{
		int y=qu.front();
		ans.push_back(y+1);
		qu.pop();
		xs[fw[y].first]++;
		xs[bc[y].first]++;
		int ff=fw[y].first;
		int bb=bc[y].first;
		int ffs=mp[ff][xs[ff]];
		int bbs=mp[bb][xs[bb]];
		if(!vis[ffs] && xs[fw[ffs].first]==fw[ffs].second && xs[bc[ffs].first]==bc[ffs].second)
		{
			vis[ffs]=true;
			qu.push(ffs);
		}
		if(!vis[bbs] && xs[fw[bbs].first]==fw[bbs].second && xs[bc[bbs].first]==bc[bbs].second)
		{
			vis[bbs]=true;
			qu.push(bbs);
		}

	}
}
int main()
{
	fast_io //REMOVE FOR interactive problems
	lli n;
	cin>>n;
	fw=vector<pii>(n+1,{-1,-1});
	bc=vector<pii>(n+1,{-1,-1});
	xs=vector<int>(n+1,0);
	vis=vector<int>(n+1,0);
	mp=vector<map<int,int> >(n+1);
	forn(i,n)
	{
		int x;
		cin>>x;
		x--;
		int cnt=0;
		if(x>i)
		{
			for(int j=i;j<x;j++)
			{
				if(fw[j]!=make_pair(-1,-1))
				{
					cout<<-1;
					return 0;
				}
				fw[j]={x,cnt};
				mp[x][cnt]=j;
				cnt++;
			}
		}
		else if(x==i)
		{
			cout<<-1;
			return 0;
		}
		else
		{
			for(int j=i-1;j>=x;j--)
			{
				if(bc[j]!=make_pair(-1,-1))
				{
					cout<<-1;
					return 0;
				}
				bc[j]={x,cnt};
				mp[x][cnt]=j;
				cnt++;
			}
		}

	}
	forn(i,n-1)
	{
		if(bc[i]==make_pair(-1,-1) || fw[i]==make_pair(-1,-1))
		{
			cout<<-1;
			return 0;
		}
		else if(bc[i].second==0 && fw[i].second==0)
		{
			vis[i]=true;
			qu.push(i);
		}
	}
	solve();
	if((lli)ans.size()!=n-1)
	{cout<<-1;return 0;}
	for(auto x: ans)
		cout<<x<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    const int mod=1e9+7;
    int n,ans=0;
    cin>>n;
    vector<long long>sum(n+1);
    vector<vector<int> >lst(n+1,vector<int>(n+1)),dp(n+1,vector<int>(n+1));
    for(int i=1;i<=n;i++) {
        long long v;
        cin>>v;
        sum[i]=sum[i-1]+v;
    }
    lst[1][0]=dp[0][0]=1;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++)
            dp[i][j]=lst[j][sum[i]%j];
        for(int j=2;j<=n;j++)
            lst[j][sum[i]%j]=(lst[j][sum[i]%j]+dp[i][j-1])%mod;
    }
    for(int i=1;i<=n;i++) ans=(ans+dp[n][i])%mod;
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;

template<typename T>
void scan(T& n){
  cin>>n;
}

void scan(){}

template<typename T,class... Args>
void scan(T& n,Args&... args){
  scan(n);
  scan(args...);
}

template<typename T>
void scanall(T start,T end){
  for(;start!=end;++start){
    scan(*start);
  }
}

template<typename T>
void print(T n){
  cout<<n;
}

void print(){}

template<typename T,class... Args>
void print(T n,Args... args){
  print(n);
  print(args...);
}

template<typename T>
void println(T n){
  print(n);
  cout<<endl;
}

template<typename T,class... Args>
void println(T n,Args... args){
  print(n,' ');
  println(args...);
}

template<typename T>
void printall(T start,T end){
  if(start!=end){
    print(*start);
    for(++start;start!=end;++start){
      print(' ',*start);
    }
  }
  cout<<endl;
}

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

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

template<typename T,typename U>
T power(T a,U n){
  T res=1;
  while(n){
    res*=(n&1)?a:1;
    a*=a;
    n>>=1;
  }
  return res;
}

template<typename T>
struct combination{
  vector<T> fact;
  combination(const int Max=3000000):fact(Max+1,1){
    for(int i=2;i<=Max;++i){
      fact[i]=fact[i-1]*i;
    }
  }
  template<typename U>
  T nCk(U n,U k){
    if(n<k||n<0||k<0){
      return 0;
    }
    return fact[n]/fact[k]/fact[n-k];
  }
};

void solve();

int main(){
  cout<<fixed<<setprecision(15);
  bool is_multicase=false;
  int T=1;
  if(is_multicase){
    scan(T);
  }
  for(int i=0;i<T;++i){
    solve();
  }
  return 0;
}

template<u64 mod>
struct modint{
  u64 val;
  constexpr modint(const i64 x=0) noexcept:val((x%i64(mod)+i64(mod))%i64(mod)){}
  constexpr u64 &value() noexcept{
    return val;
  }
  constexpr modint operator+(const modint rhs) const noexcept{
    return modint(*this)+=rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept{
    return modint(*this)-=rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept{
    return modint(*this)*=rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept{
    return modint(*this)/=rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept{
    val+=rhs.val;
    val-=((val>=mod)?mod:0);
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept{
    val+=((val<rhs.val)?mod:0);
    val-=rhs.val;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept{
    val=val*rhs.val%mod;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept{
    u64 exp=mod-2;
    while(exp){
      if(exp&1){
        (*this)*=rhs;
      }
      rhs*=rhs;
      exp>>=1;
    }
    return *this;
  }
  friend constexpr ostream &operator<<(ostream &os,const modint &x) noexcept{
    return os<<(x.val);
  }
  friend constexpr istream &operator>>(istream &is,modint &x) noexcept{
    u64 t;
    is>>t;
    x=t;
    return is;
  }
};

void solve(){
  typedef modint<1000000007> mint;
  int N;
  scan(N);
  vector<i64> A(N);
  scanall(A.begin(),A.end());
  vector<i64> csum(N+1);
  for(int i=1;i<=N;++i){
    csum[i]=csum[i-1]+A[i-1];
  }
  vector<vector<mint>> dp(N+1,vector<mint> (N+1));
  dp[0][0]=1;
  for(int i=1;i<=N;++i){
    vector<i64> rem(N+1);
    for(int j=0;j<=N;++j){
      rem[j]=csum[j]%i;
    }
    vector<vector<int>> vec(i);
    for(int j=0;j<=N;++j){
      vec[rem[j]].emplace_back(j);
    }
    for(int j=0;j<i;++j){
      for(size_t k=1;k<vec[j].size();++k){
        dp[i][vec[j][k]]=dp[i-1][vec[j][k-1]]+dp[i][vec[j][k-1]];
      }
    }
  }
  mint ans=0;
  for(int i=1;i<=N;++i){
    ans+=dp[i][N];
  }
  println(ans);
}


/**
 *	author: Hritik Raj
 *	created: 06-06-2021 17:33:26
**/
#include <bits/stdc++.h>

using namespace std;
#define int long long

void solve(){
    int n;
    cin>>n;
    int ans = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>> x;
        ans += max(0LL, x-10);
    }
    cout<<ans<<"\n";
}

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

    int t;
    // cin>>t;
    t = 1;
    int _=1;
    while(t--){
        // cout<<"Case #"<<_++<<": ";
        solve();
    }
    return 0;
}


#include<cstdio>
const int mod(1e9+7);
long long f(int x)
{
	long long res=1;
	for(int i=1;i<=x;i++)
		res=(res*i)%mod;
	return res;
}
long long pow(long long x,int p)
{
	long long res=1;
	while(p)
	{
		if(p%2) res=(res*x)%mod;
		p/=2;
		x=(x*x)%mod;
	}
	return res;
}
long long c(int n,int m)
{
	return ((f(n)*pow(f(m),mod-2))%mod*pow(f(n-m),mod-2))%mod;
}
int main()
{
	long long n,m,k;
	scanf("%lld%lld%lld",&n,&m,&k);
	if(n-m>k) printf("0\n");
	else if(n<=k) printf("%lld\n",c(n+m,m));
	else if(n>k) printf("%lld\n",((c(n+m,m)-c(n+m,n-k-1))%mod+mod)%mod);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef vector<pll> vll;
typedef vector<vl> vvl;

#define fori(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define trav(x, a) for (auto &x : a)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define sz(a) (int)(a).size()
#define fi first
#define se second

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

const ll mod = 1e9 + 7;
const ll INF = 1e18;

ll modinv(ll a, ll m)
{
    assert(m > 0);
    if (m == 1)
        return 0;
    a %= m;
    if (a < 0)
        a += m;
    assert(a != 0);
    if (a == 1)
        return 1;
    return m - modinv(m, a) * m / a;
}

template <int MOD_>
struct modnum
{
private:
    int v;

public:
    static const int MOD = MOD_;

    modnum() : v(0) {}
    modnum(ll v_) : v(int(v_ % MOD))
    {
        if (v < 0)
            v += MOD;
    }
    explicit operator int() const { return v; }
    friend bool operator==(const modnum &a, const modnum &b) { return a.v == b.v; }
    friend bool operator!=(const modnum &a, const modnum &b) { return a.v != b.v; }

    modnum operator~() const
    {
        modnum res;
        res.v = modinv(v, MOD);
        return res;
    }

    modnum &operator+=(const modnum &o)
    {
        v += o.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    modnum &operator-=(const modnum &o)
    {
        v -= o.v;
        if (v < 0)
            v += MOD;
        return *this;
    }
    modnum &operator*=(const modnum &o)
    {
        v = int(ll(v) * ll(o.v) % MOD);
        return *this;
    }
    modnum &operator/=(const modnum &o)
    {
        return *this *= (~o);
    }

    friend modnum operator+(const modnum &a, const modnum &b) { return modnum(a) += b; }
    friend modnum operator-(const modnum &a, const modnum &b) { return modnum(a) -= b; }
    friend modnum operator*(const modnum &a, const modnum &b) { return modnum(a) *= b; }
    friend modnum operator/(const modnum &a, const modnum &b) { return modnum(a) /= b; }
};

using num = modnum<mod>;

vector<num> fact;
vector<num> ifact;

void init()
{
    fact = {1};
    for (int i = 1; i < 2000005; i++)
        fact.push_back(i * fact[i - 1]);
    for (num x : fact)
        ifact.push_back(1 / x);
}

num ncr(int n, int k)
{
    if (k < 0 || k > n)
        return 0;
    return fact[n] * ifact[k] * ifact[n - k];
}

num powmod(num x, int a)
{
    if (a == 0)
        return 1;
    if (a & 1)
        return x * powmod(x, a - 1);
    return powmod(x * x, a / 2);
}

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

    init();

    int n, m, k;
    cin >> n >> m >> k;
    // x1 + x2 + .. + x_{m+1} = n
    // x1 <= k
    // x1 + x2 <= k + 1
    // x1 + x2 + x3 <= k + 2

    // vector<num> dp(n + 1);
    // dp[0] = 1;

    // fori(i, m + 1)
    // {
    //     num sum = 0;
    //     for (int j = 0; j <= min(k + i, n); j++)
    //     {
    //         sum += dp[j];
    //         dp[j] = sum;
    //     }
    // }

    // // w_i - b_i = k+1
    // // w_i + b_i = i

    // // (0,k) -> (w,b+k)

    // cout << int(dp[n]) << endl;

    if (n > m + k)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << int(ncr(n + m, n) - ncr(n + m, n - (k + 1))) << endl;
    }
    // cout << int(ncr(2 * n, n) / (n + 1)) << endl;

    return 0;
}


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pqi priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define printdecimal(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define mod (int)(1e9+7)
#define inf LLONG_MAX
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}

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

	int n;
	string s;
	cin>>n>>s;
	stack<char> st;
	for(char x:s)
	{
		if(st.size()<2)	st.push(x);
		else
		{
			char a,b;
			b=st.top();
			st.pop();
			a=st.top();
			st.pop();
			if(x=='x'&&a=='f'&&b=='o') continue;
			else
			{
				st.push(a);
				st.push(b);
				st.push(x);
			}
		}
	}
	cout<<st.size();
	return 0;
}

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

template <typename T, typename TT>
void print(T c, TT a,int n){

	vector<int> r;
	for(int i=0;i<n;i++)
		r.push_back(a[i][0] - c[0]);

	int mi = *min_element(r.begin(), r.end());

	if(mi<0){
		for(auto &x:r)	x+=abs(mi);
		for(auto &x:c)	x-=abs(mi);
	}

	mi = *min_element(c.begin(), c.end());

	if(mi<0){
		cout<<"No\n";
		return;
	}

	cout<<"Yes\n";
	for(auto x:r)	cout<<x<<" ";
	cout<<"\n";
	for(auto x:c)	cout<<x<<" ";
	cout<<"\n";
}

void solve(){
	int n;cin>>n;

	vector<vector<int>>a(n, vector<int>(n));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>a[i][j];

	for(int i=0;i<n;i++){
		vector<int> c = a[i];
		int fail = 0;

		for(int j=0;j<n && !fail;j++){
			if(j==i)	continue;

			vector<int>temp(n);
			for(int k=0;k<n;k++){
				temp[k] = a[j][k] - c[k];
			}
			sort(temp.begin(), temp.end());
			if(temp[0] != temp.back()){
				fail = 1;
				break;
			}
		}

		if(!fail){
			print(c, a, n);
			return;
		}
	}
	cout<<"No\n";
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
   	solve();
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int p=1e9+7;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
ll n,k;
cin>>n>>k;
while(k--){
if(n%200==0) n/=200;
else n=n*1000+200;
}
cout<<n;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi(a,b) for(int i=(a);i<(b);i++)
#define fj(a,b) for(int j=(a);j<(b);j++)
#define pb(n) push_back(n)
string ts(int a){
	string q="";
	while(a!=0){
		q+=a%10+48;
		a/=10;
	}
	return q;
}
int main(){
	string s;
	ll n,k;
	cin>>s>>k;
	istringstream iss(s);
	iss>>n;
	fi(0,k){
		if(n%200==0){
			n/=200;
			s=to_string(n);
		}
		else{
			s+="200";
			istringstream iss(s);
			iss>>n;
		}
		//cout<<n<<' '<<s<<endl;
	}
	cout<<n;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    a=(a*a)+(b*b);
    c=a-(c*c);
    if(c<0)
    cout<<"Yes"<<endl;
    else
         cout<<"No"<<endl;
}

/*
      Ashraful Islam Paran
      24-April-2021
      18:03:40
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define show(x, y) cout << x << "         " << y << "\n"
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

#define dbg(args...)            \
    do                          \
    {                           \
        cerr << #args << " : "; \
        faltu(args);            \
    } while (0)
clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu()
{
    cerr << endl;
}
template <typename T>
void faltu(T a[], int n)
{
    for (int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
const int mod = 1e9 + 7;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

inline void normal(int &a)
{
    if (a >= mod)
        a %= mod;
    (a < 0) && (a += mod);
}
inline int modMul(int a, int b)
{
    normal(a), normal(b);
    return (a * b) % mod;
}
inline int modAdd(int a, int b)
{
    normal(a), normal(b);
    return (a + b) % mod;
}
inline int modSub(int a, int b)
{
    normal(a), normal(b);
    a -= b;
    normal(a);
    return a;
}
inline int modPow(int b, int p)
{
    int r = 1;
    while (p)
    {
        if (p & 1)
            r = modMul(r, b);
        b = modMul(b, b);
        p >>= 1;
    }
    return r;
}
inline int modInverse(int a) { return modPow(a, mod - 2); }
inline int modDiv(int a, int b) { return modMul(a, modInverse(b)); }

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b)
{
    //return (a.second < b.second);
    if (a.first == b.first)
    {
        return (a.second > b.second);
    }
    else
    {
        return (a.ff < b.ff);
    }
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int a,b,c;
    cin>>a>>b>>c;
    if((a*a+b*b)<c*c)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    cerr << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define  m_p make_pair
#define x first
#define y second
using namespace std;
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
using P=pair<int,int>;
const int inf=0x3f3f3f3f;
const LL LLinf=0x3f3f3f3f3f3f3f3f;

int main()
{
    IOS;
    #ifdef _DEBUG
    freopen("D:/CODE/algorithm_contest/out.txt","w",stdout);
    freopen("D:/CODE/algorithm_contest/in.txt","r",stdin);
    #endif

    LL B,C;
    while(cin>>B>>C)
    {
        LL ans=0;
        if(B>0)
        {
            ans=C;
            if(C==1) ans++;
            ans+=min(C-2+1,2*B-1);
        }
        else if(B<0)
        {
            ans=C+1;
            ans+=max(min(-2*B-1,C-3+1),0ll);
        }
        else if(B==0)
        {
            ans=C;
        }
        cout<<ans<<endl;
    }
    return 0;
}

// Code for B - Many 110
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define MOD 1000000007
#define mod(x) ( (x) % MOD + MOD ) % MOD

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T, typename U> void view(const std::map<T, U>& m){ for(const auto& e : m){ std::cout << e.first << "=>" << e.second << " "; } std::cout << std::endl; }

int main() {
  int N;
  cin >> N;
  string T;
  cin >> T;

  if (T == "0") {
    cout << 10000000000 << endl;
    return 0;
  }

  if (T == "1") {
    cout << 20000000000 << endl;
    return 0;
  }

  if (T == "11") {
    cout << 10000000000 << endl;
    return 0;
  }

  // if (T == "110") {
  //   cout << 10000000000 << endl;
  //   return 0;
  // }

  // if (T == "011") {
  //   cout << 9999999999 << endl;
  //   return 0;
  // }

  // if (T == "101") {
  //   cout << 9999999999 << endl;
  //   return 0;
  // }

  string base = "110";
  bool any = false;
  ll start;
  REP(j, 3) {
    bool isOk = true;
    REP(i, N) {
      if (T[i] != base[(i + j) % 3]) {
        isOk = false;
        break;
      }
    }
    if (isOk) {
      any = true;
      start = j;
      break;
    }
  }

  if (!any) {
    cout << 0 << endl;
    return 0;
  }

  if (start == 1) {
    start = 2;
  } else if (start == 2) {
    start = 1;
  }

  ll m = ( N - start ) / 3;
  ll end = ( N - start ) % 3;

  // cout << 10000000000 - (( start + end ) / 3) - (m - 1);
  cout << 10000000000 - (start > 0 ? 1 : 0) - (m - 1) - (end > 0 ? 1 : 0);
  return 0;
}


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

int main(){

    int H,W;
    cin >> H >> W;

    vector<string> S(H);
    for(int i=0; i<H; i++){
        cin >> S.at(i);
    }

    int count = 0;

    //横
    for(int i=0; i<H; i++){
        for(int j=0; j<W-1; j++){
            if(S.at(i).at(j)=='.' && S.at(i).at(j+1)=='.'){
                count++;
            }
        }
    }

    // 縦
    for(int j=0; j<W; j++){
        for(int i=0; i<H-1; i++){
            if(S.at(i).at(j)=='.' && S.at(i+1).at(j)=='.'){
                count++;
            }
        }
    }

    cout << count << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
   int h,w;cin>>h>>w;
   vector<string> v;
   string last(w+1,'#');
   rep(i,h){
      string s;cin>>s;
      v.push_back(s);
      v[i].push_back('#');
   }
   int ans=0;
   v.push_back(last);
   rep(i,h){
      rep(j,w){
         if(v[i][j]=='.'){
            ans+=(v[i][j+1]=='.');
            ans+=(v[i+1][j]=='.');
         }
      }
   }
   cout<<ans<<endl;
}


#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e16;
const long double PI=3.14159265358979323;
const long long int pl=1100;
const long double eps =0.0000001;

long long int N,sum=0,A[200200],B[200200],M=0,id;

int main()
{
    cout << fixed << setprecision(18);
    //入力
    cin>>N;
    for (long long int i = 0; i < (1<<N); i++)
    {
        cin>>A[i];
        if(M<A[i]){M=max(M,A[i]);id=i;}
    }
    if(id<(1<<(N-1))){
        id=0;
        M=0;
        for (long long int i = (1<<(N-1)); i < (1<<N); i++)
        {
            if(M<A[i]){M=max(M,A[i]);id=i;}
        }
        cout<<id+1<<endl;

    }else{
        id=0;
        M=0;
        for (long long int i = 0; i < (1<<(N-1)); i++)
        {
            if(M<A[i]){M=max(M,A[i]);id=i;}
        }
        cout<<id+1<<endl;
    }

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define siz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define fil(x, y) fill(af(x), y)
#define pb push_back
#define lb lower_bound
#define ub upper_bounn
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;

void solve(){
	int n;
	cin >> n;
	vector<pii> a(1<<n);
	for (int i = 0; i < ( 1 << n); i++) cin >> a[i].first, a[i].second = i + 1;
	for (int i = n; i > 1; i--){
		vector<pii> b;
		for (int j = 0; j < (1 << i); j += 2){
			b.pb(max(a[j], a[j + 1]));
		}
		swap(a, b);
	}
	if (a[0].first > a[1].first) cout << a[1].second << '\n';
	else cout << a[0].second << '\n';

}
/*
 * do i rlly need to check everything????
 */

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


#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecint(A, n) vector<long long int> A(n);
#define vecint2(A, n, m) vector<vector<long long>> A(n, vector<long long>(m));
#define vecchar(A, n) vector<char> A(n);
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define vecstr(A, n) vector<string> A(n);
#define keta(s) cout << fixed << setprecision(s);
#define test cout<<"OK"<<endl; //test;
const double pi=3.14159265358979323846;
using namespace std;
long long MOD=1000000007; // %MOD
int main() {
  int N,W;
  cin>>N>>W;
  vecint(A,200005);
  rep(i,N){
    int S,T,P;
    cin>>S>>T>>P;
    A[S]+=P;
    A[T]-=P;
  }
  vecint(B,200005);
  B[0]=A[0];
  rep(i,200004){
    B[i+1]=B[i]+A[i+1];
  }
  sort(B);
  reverse(B);
  if(B[0]>W) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

#include<bits/stdc++.h>

#define ll long long

using namespace std;

int read()
{
	int a=0,f=1,c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		a=a*10+c-'0';
		c=getchar();
	}
	return a*f;
}

const int K=1e5+10;

int k;
int n,m;
ll a[K],L[K],R[K];

bool check(ll d)
{
	ll sl=0,sr=0;
	for(int i=1;i<=k;++i)
	{
		L[i]=(max(a[i]*m-d,(ll)0)+n-1)/n;sl+=L[i];
		R[i]=(a[i]*m+d)/n;sr+=R[i];
	}

	if(sl<=m && m<=sr)
	{
		ll ext=m-sl;
		for(int i=1;i<=k;++i)
		{
			ll t=min(ext,(ll)R[i]-L[i]);
			L[i]+=t;ext-=t;
		}
		return 1;
	}
	else return 0;
}

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

	k=read();
	n=read();m=read();
	for(int i=1;i<=k;++i)a[i]=read();

	ll l=0,r=1e18;
	while(l<r)
	{
		ll mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid+1;
	}

	check(l);
	for(int i=1;i<=k;++i)printf("%lld ",L[i]);
	puts("");

	return 0;
}


#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, m, t;
  cin >> n >> m >> t;
  int lt = 0;
  int battery = n;
  bool ok = true;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    battery -= a - lt;
    if (battery <= 0) {
      ok = false;
    }
    battery += b - a;
    if (n < battery) {
      battery = n;
    }
    lt = b;
  }
  battery -= t - lt;
  if (battery <= 0) {
    ok = false;
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

 #include <iostream>
    using namespace std;
    long long s[1006], e[1006];
    int main() {
    	long long n, m, t;
    	cin >> n >> m >> t;
    	for (int i=0; i<m; i++) {
    		cin >> s[i] >> e[i];
    	}
    	long long count;
        count=n;
    	count-=s[0];
    	for (int i=0; i<m; i++) {
     		if (count<=0) {
    			cout << "No" << endl;
    			return 0;
    		}
    		count+=e[i]-s[i];
    		if (count>n) {
    			count=n;
    		}
    		if (i==m-1) {
    			continue;
    		}
    		count-=(s[i+1]-e[i]);
    	}
    	count-=t-e[m-1];
    	if (count<=0) {
    		cout << "No" << endl;
    	}
    	else {
    		cout << "Yes" << endl;
    	}
return 0;
    }


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

const ll MODULO = 998244353LL;
ll mod_pow(ll x, ll n, ll modval) {
    if (x == 0) {
        return 0;
    }
    if (n == 0) {
        return 1;
    }
    ll res = mod_pow(x * x % modval, n / 2, modval);
    if (n & 1) {
        res = res * x % modval;
    }
    return res;
}
ll mpow(ll x, ll n) {
    return mod_pow(x, n, MODULO);
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0;
    if (n == 1 && m == 1) {
        print(k);
        return 0;
    } else if (n == 1) {
        for (ll x = 1; x <= k; x++) {
            ll mx = mpow(k - x + 1, m) - mpow(k - x, m);
            if(mx<0)mx+=MODULO;
            ans = (ans + mx) % MODULO;
        }
        print(ans);
    } else if (m == 1) {
        for (ll x = 1; x <= k; x++) {
            ll nx = mpow(x, n) - mpow(x - 1, n);
            if (nx < 0) nx += MODULO;
            ans = (ans + nx) % MODULO;
        }
        print(ans);
    } else {
        for (ll x = 1; x <= k; x++) {
            ll nx = mpow(x, n) - mpow(x - 1, n);
            if (nx < 0) nx += MODULO;
            ll mx = mpow(k - x + 1, m);
            ans = (ans + nx * mx) % MODULO;
        }
        print(ans);
    }
}

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

ll power(ll x, ll y){
    x%=MOD;
    ll ret=1;
    while(y){
        if(y&1) ret=ret*x%MOD;
        x=x*x%MOD;
        y>>=1;
    }
    return ret;
}

ll divid(ll x, ll y){
    x%=MOD;
    return x*power(y,MOD-2)%MOD;
}

VVI prd(VVI& a, VVI& b){
    int n=a.size(), m=b[0].size();
    VVI ret(n,VI(m));
    REP(i,n)REP(j,m){
        ll sum=0;
        REP(k,a[0].size()){
            sum=(sum+a[i][k]*b[k][j]%MOD)%MOD;
        }
        ret[i][j]=sum;
    }
    return ret;
}

VVI matrix_power(VVI x, ll y){
    int n=x.size();
    VVI ret(n,VI(n,0));
    REP(i,n) ret[i][i]=1;
    while(y){
        if(y&1) ret=prd(ret,x);
        x=prd(x,x);
        y>>=1;
    }
    return ret;
}

int main(){
    int n, m, k; cin >> n >> m >> k;
    VVI a(1,VI(n)); REP(i,n) cin >> a[0][i];
    VVI mx(n,VI(n,0));
    REP(i,n) mx[i][i]=m;
    ll p=divid(1,2);
    int x, y;
    REP(i,m){
        cin >> x >> y;
        x--, y--;
        mx[x][x]=(mx[x][x]+MOD-p)%MOD;
        mx[y][y]=(mx[y][y]+MOD-p)%MOD;
        mx[x][y]=(mx[x][y]+p)%MOD;
        mx[y][x]=(mx[y][x]+p)%MOD;
    }
    p=divid(1,m);
    REP(i,n)REP(j,n){
        mx[i][j]=mx[i][j]*p%MOD;
    }
    mx=matrix_power(mx,k);
    VVI ans=prd(a,mx);
    REP(i,n) cout << ans[0][i] << endl;
    return 0;
}


#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int GetDigit(ll num){
    return std::to_string(num).length();
}
bool check(int i){
  int N=i+1;
  if(N==2 || N==4 || N==8 || N==16 || N==32 || N==64 || N==128 || N==256 || N==512 || N==1024 || N==2048 || N==4096 || N==8192 || N==16384 || N==32768 || N==65536) return true;
  else return false;
}
int main(){
  int N;
  cin>>N;
  vector<int> V(100010);
  V[0]=1;
  for(int i=1;i<100010;i++){
    V[i]=V[i-1];
    if(check(i)) V[i]++;
  }

  for(int i=0;i<N;i++) cout<<V[i]<<" ";
return 0;}

/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll>
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 998244353;
map<ll, vl>g;
vl a, b;
ll vis[200010], s1[200010], s2[200010];
void dfs(int node, int par)
{
	vis[node] = 1;
	s1[par-1] += a[node-1];
	s2[par-1] += b[node-1];
	FR(i, g[node])
	{
		if(!vis[i])
			dfs(i, par);
	}
}
void solve()
{
	IN(n)IN(m);
	FOR(i, 0, n)
	{
		IN(in);
		a.push_back(in);
	}
	FOR(i, 0, n)
	{
		IN(in);
		b.push_back(in);
	}
	FOR(i, 0, m)
	{
		IN(in1)IN(in2);
		g[in1].pb(in2);
		g[in2].pb(in1);
	}
	FOR(i, 1, n + 1)
	{
		if(!vis[i])
			dfs(i, i);
	}
	FOR(i, 0, n)
		if (s1[i] != s2[i])
		{
			cout << "No";
			return;
		}
	cout << "Yes";
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find {
    vector<int> par, siz;
    union_find(int n) {
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (siz[x] < siz[y]) {
            par[x] = y;
            siz[y] += siz[x];
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
        }
    }

    long long size(int x){
        return siz[find(x)];
    }

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

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

    ll n, k; cin >> n >> k;
    ll a[n][n]; zep(i, 0, n)zep(j, 0, n)cin >> a[i][j];

    union_find ufi(n), ufj(n);

    zep(x, 0, n){
        zep(y, x + 1, n){
            bool ok = true;
            zep(j, 0, n)if(a[x][j] + a[y][j] > k)ok = false;
            if(ok)ufj.unite(x, y);
        }
    }

    zep(x, 0, n){
        zep(y, x + 1, n){
            bool ok = true;
            zep(i, 0, n)if(a[i][x] + a[i][y] > k)ok = false;
            if(ok)ufi.unite(x, y);
        }
    }

    ll ans = 1;
    zep(i, 0, n){
        if(ufj.find(i) == i){
            rep(p, 1, ufj.size(i)){
                ans *= p;
                ans %= MOD;
            }
        }
    }

    zep(j, 0, n){
        if(ufi.find(j) == j){
            rep(p, 1, ufi.size(j)){
                ans *= p;
                ans %= MOD;
            }
        }
    }

    print(ans)
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <random>

const int32_t MOD = 998244353;

int32_t dfs(int32_t x, std::vector< bool > &vis, const std::vector< std::vector< bool > > &adj) {
    vis[x] = true;
    int32_t comp = 1;

    int32_t n = adj.size();
    for(int32_t i = 0; i < n; i++) {
        if(adj[x][i] && !vis[i]) {
            comp += dfs(i, vis, adj);
        }
    }

    return comp;
}

int32_t fact(int32_t x) {
    int32_t ans = 1;
    for(int32_t i = 2; i <= x; i++) {
        ans = (int64_t) ans * i % MOD;
    }
    return ans;
}

int32_t count(const std::vector< std::vector< bool > > &adj) {
    int32_t n = adj.size(), ans = 1;

    std::vector< bool > vis(n, false);
    for(int32_t i = 0; i < n; i++) {
        if(!vis[i]) {
            ans = (int64_t) ans * fact(dfs(i, vis, adj)) % MOD;
        }
    }

    return ans;
}

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

    int32_t n, k;
    std::cin >> n >> k;

    std::vector< std::vector< int32_t > > v(n, std::vector< int32_t >(n));
    for(int32_t i = 0; i < n; i++) {
        for(int32_t j = 0; j < n; j++) {
            std::cin >> v[i][j];
        }
    }

    std::vector< std::vector< bool > > rows(n, std::vector< bool >(n, false));
    for(int32_t i1 = 0; i1 < n; i1++) {
        for(int32_t i2 = i1 + 1; i2 < n; i2++) {
            int32_t cnt = 0;
            for(int32_t j = 0; j < n; j++) {
                if(v[i1][j] + v[i2][j] <= k) {
                    cnt++;
                }
            }
            if(cnt == n) {
                rows[i1][i2] = true;
                rows[i2][i1] = true;
            }
        }
    }

    std::vector< std::vector< bool > > cols(n, std::vector< bool >(n, false));
    for(int32_t i1 = 0; i1 < n; i1++) {
        for(int32_t i2 = i1 + 1; i2 < n; i2++) {
            int32_t cnt = 0;
            for(int32_t j = 0; j < n; j++) {
                if(v[j][i1] + v[j][i2] <= k) {
                    cnt++;
                }
            }
            if(cnt == n) {
                cols[i1][i2] = true;
                cols[i2][i1] = true;
            }
        }
    }

    std::cout << (int64_t) count(rows) * count(cols) % MOD << '\n';
}


#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn=100,maxm=499950;

int n,K,MOD,f[maxn+5][maxm+5],F[maxn+5];

int main(){
	scanf("%d%d%d",&n,&K,&MOD);f[0][0]=1;
	for (int i=1,sum=i*K;i<=n;i++,sum+=i*K){
		for (int j=0;j<i;j++) F[j]=0;
		for (int j=0;j<=sum;j++){
			F[j%i]=(F[j%i]+f[i-1][j])%MOD;
			if (j>=i*(K+1)) F[j%i]=(F[j%i]+MOD-f[i-1][j-i*(K+1)])%MOD;
			f[i][j]=F[j%i];
		}
	}
	for (int x=1;x<=n;x++){
		int ans=MOD-1;
		for (int j=0;j<=maxm;j++) ans=(ans+(LL)f[x-1][j]*f[n-x][j]%MOD*(K+1)%MOD)%MOD;
		printf("%d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

struct info{
    ll num;
    ll cost;
};

bool operator< (const info &info1, const info &info2){
    return info1.cost<info2.cost;
}
bool operator> (const info &info1, const info &info2){
    return info1.cost>info2.cost;
}

int main(){
    ll X, Y;
    cin >> X >> Y;

    if(X>=Y){
        cout << X-Y << endl;
        return 0;
    }

    priority_queue<info, vector<info>, greater<info>> pque;
    pque.push({Y,0});
    map<ll,int> dict;

    while(!pque.empty()){
        info now=pque.top();
        //cout << now.num << ' ' << now.cost << endl;
        pque.pop();

        if(dict.count(now.num))continue;
        else{
            dict[now.num]=now.cost;
        }

        if(now.num==X){
            cout << now.cost << endl;
            return 0;
        }else if(now.num%2==0){
            pque.push({X,now.cost+abs(X-now.num)});
            pque.push({now.num/2,now.cost+1});
        }else{
            pque.push({now.num+1,now.cost+1});
            pque.push({now.num-1,now.cost+1});
        }
    }
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N, K;

ll cou0[4000005];
ll cou1[4000005];

ll sumi;

//綺麗さがiのときに何通りあるか
ll kire[4000005];

void pre() {
	//合計がそれぞれいくつあるか
	for(ll i = 2; i <= 2*N; i++) {
		if(i <= 1) continue;
		if(i <= N + 1) {
			cou1[i] = i-1;
			cou0[i] = i-1;
		} else {
			cou1[i] = 2*N+1-i;
			cou0[i] = 2*N+1-i;
		}
	}
	rep(i, 3*N+1) cou1[i+1] += cou1[i];

}

//3つの合計がnum以下になる君合わせ
ll get_cou(ll num) {
	ll ret = 0;
	for(ll i = 1; i <= N; i++) {
		ll maxi = num - i;
      if(maxi < 0) continue;
		ret += cou1[maxi];
	}

	return ret;
}

//合計が決まってるとき、kireの値で何通りあり得るか
void pre2() {
	for(ll ki = 1; ki <= N; ki++) {
		ll others = sumi - ki;
		if(others <= 1 || others > 2*N) continue;
		kire[ki] += cou0[others];
	}

	rep(i, N+5) {
		//cout << "kire[" << i << " ] = " << kire[i] << endl;
		kire[i+1] += kire[i];
	}
}

int main(){
	cin >> N >> K;

	pre();

	ll ok = 0;
	ll ng = 3*N;
	while(ok + 1 < ng) {
		ll mid = (ok + ng)/2;
		if(get_cou(mid) >= K) {
			ng = mid;
		} else {
			ok = mid;
		}
	}
	//cout << ok << endl;

	//三つの合計はsumi
	sumi = ok + 1;

	//3つの合計がsumiになるときにkireisaで何番目になるかの二部たん
	pre2();
	ll K2 = K - get_cou(ok);
	//cout << "p0 ok = " << ok << " get_cout - " << get_cou(ok) << endl;

	//綺麗さについて二部たん

	ok = 0;
	ng = N+1;
	while(ok + 1 < ng) {
		ll mid = (ok + ng)/2;
		if(kire[mid] >= K2) {
			ng = mid;
		} else {
			ok = mid;
		}
	}
	//cout << "K2 = " << K2 << " kire[" << ok << "] = " << kire[ok] << endl;

	ll kirev = ok + 1;
	//cout << "sumi = " << sumi << endl;
	//cout << "kirev = " << kirev << endl;

	ll K3 = K2 - kire[ok];

	//cout << "K3 = " << K3 << endl;

	//3つのわ, kirei, oisi, ninki
	vector<tuple<ll, ll, ll, ll> >ans;

	for(ll oi = 1; oi <= N; oi++) {
		ll nin = sumi - kirev - oi;
		if(nin <= 0 || nin > N) continue;
		ans.push_back({sumi, kirev, oi, nin});
	}
	sort(ans.begin(), ans.end());
	//cout << "K3 = " << K3 << " ans " << ans.size() << endl;

	ll _, k, o, n;
	tie(_, k, o, n) = ans[K3-1];
	cout << k << " " << o << " " << n << endl;

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define INF 1000000000
#define all(x) (x.begin(), x.end())
#define IOS ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef vector<int> vi;

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

vi adj[112345];
int ans = 0;
int visited[112345];

void dfs(int v) {
	visited[v] = 1;
	ans++;
	for (auto x : adj[v]) {
		if (visited[x] == 1) continue;
		dfs(x);
	}
}

void solve() {
	int n,m;cin>>n>>m;
	int a,b;
	for (int i = 0; i < m; i++) {
		cin>>a>>b;
		adj[a].pb(b);
	}
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			visited[i] = 0;
		}
		dfs(k);
	}

	cout << ans << '\n';

}

int main()
{
	//testcases();
	IOS;
    solve();
	return 0;

}

#include <bits/stdc++.h>

std::vector<std::string> split(const std::string& source, const char delim);

struct Node{
    explicit Node(const int nodeId)
    :node_id(nodeId){
    };

    int addNode(const std::shared_ptr<Node>& nodeSptr){
        child_node_sptr_list.emplace_back(nodeSptr);
        return 0;
    };

    int node_id;
    std::vector<std::weak_ptr<Node>> child_node_sptr_list;
};

int main(){
    std::string buffer;
    std::getline(std::cin, buffer);
    auto splitInput = split(buffer, ' ');
    const int NUM_CITY = std::stoi(splitInput[0]);
    const int NUM_ROOT = std::stoi(splitInput[1]);

    std::map<int, std::shared_ptr<Node>> nodeSptrList;
    for(int num = 0; num < NUM_CITY; ++num){
        nodeSptrList.emplace(num + 1, std::make_shared<Node>(num + 1));
        nodeSptrList[num + 1]->addNode(nodeSptrList[num + 1]);
    }

    for(int num = 0; num < NUM_ROOT; ++num){
        std::getline(std::cin, buffer);
        auto splitRootInfo = split(buffer, ' ');
        const int startNodeId = std::stoi(splitRootInfo[0]);
        const int endNodeId = std::stoi(splitRootInfo[1]);
        nodeSptrList[startNodeId]->addNode(nodeSptrList[endNodeId]);
    }

    std::map<std::pair<int, int>, int> uniqueRootList;
    for(const auto& startNodeSptrPair : nodeSptrList){
        std::queue<std::shared_ptr<Node>> nodeSptrQueue;
        nodeSptrQueue.emplace(startNodeSptrPair.second);

        while(!nodeSptrQueue.empty()){
            std::shared_ptr<Node> nodeSptr{nodeSptrQueue.front()};
            nodeSptrQueue.pop();

            for(auto it = nodeSptr->child_node_sptr_list.begin(); it != nodeSptr->child_node_sptr_list.end(); ++it){
                if(std::shared_ptr<Node> childNodeSptr = it->lock()){
                    const auto scanningRoot = std::make_pair(startNodeSptrPair.first, childNodeSptr->node_id);
                    if(uniqueRootList.find(scanningRoot) == uniqueRootList.end()){
                        nodeSptrQueue.emplace(childNodeSptr);
                        uniqueRootList.emplace(scanningRoot, 1);
                    }
                }
            }
        }
    }
    std::cout << uniqueRootList.size() << std::endl;

    return 0;
}

std::vector<std::string> split(const std::string& source, const char delim){
    std::vector<std::string> splitData;
    std::stringstream sstream(source);
    std::string itemBuffer;

    while(std::getline(sstream, itemBuffer, delim)){
        splitData.emplace_back(itemBuffer);
    }

    return splitData;
}


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

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define f first
#define s second
#define ub  upper_bound
#define lb  lower_bound
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << "[" << name << " : " << arg1 << "]" << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr << "[";
cerr.write(names, comma - names) << " : " << arg1<<"] | ";__f(comma+1, args...);
}

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;

int main(){
  fastio;

  int n;
  cin >> n;

  vll a(n), b(n);
  vi id(n);

  ll va = 0, vb = 0;
  for(int i=0;i<n;i++)
    cin >> a[i] >> b[i], id[i] = i, va += a[i];

  sort(all(id),[&](auto i, auto j){
    return (2*a[i]+b[i] > 2*a[j]+b[j]) or ((2*a[i]+b[i] == 2*a[j]+b[j]) and a[i] > a[j]);
  });

  int ans = 0;
  for(int x:id){
    if(vb > va) break;
    ans++;
    vb += (a[x]+b[x]);
    va -= a[x];
  }

  cout << ans << endl;

  return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<iomanip>
#include<iterator>
#include<sstream>
using namespace std;
int main()
{
    long long n,a,b,ta,ao,i,k,l;
    vector<pair<long long,long long> >v;
    cin>>n;
    ta=ao=0;
    while(n--)
    {
        cin>>a>>b;
        v.push_back(make_pair(((2*a)+b),a));
        ao+=a;
    }
    sort(v.begin(),v.end(),greater<pair<long long,long long> >());
    k=l=0;
    for(i=0;i<v.size();i++)
    {
        k+=(v[i].first-v[i].second);
        l+=v[i].second;
        if(k>(ao-l))
        {
            cout<<i+1<<endl;
            break;
        }
    }
    return 0;
}


#pragma GCC optimize("Ofast")

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<set<ll>> vset;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef deque<ll> dql;
typedef deque<int> dqi;
typedef unsigned long long ull;
typedef tuple<int,int,int> State;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}

#define vmax(type)   std::numeric_limits<type>::max()
#define vmin(type)   std::numeric_limits<type>::min()
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))
#define endl '\n'

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

int db = 0;
const ll mod = 1e9 + 7;
const ll N = 55;
const ll inf = 1e9;
#define er if(db) error
int n;
ll x;
ll a[N], pres[N], dp[N][2];

ll rec(int i, int t){
	if(i == n-1)
		return 1;
	if(dp[i][t] != -1)
		return dp[i][t];
	ll pro = a[i+1] / a[i];
	ll cur = pres[i] + t;
	if(cur == pro)
		return dp[i][t] = rec(i+1, t);

	ll ans = rec(i+1, 0);
	if(cur)
		ans += rec(i+1, 1);
	return dp[i][t] = ans;
}

void solve()
{
	cin>>n>>x;
	rep(i, n)
		cin>>a[i];
	memset(dp, -1, sizeof(dp));
	repr(i, n){
		pres[i] = x / a[i];
		x %= a[i];
	}
	cout<<rec(0, 0)<<endl;
}

// #define _DEBUG
// #define testCases
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

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

	int tc = 1;
#ifdef testCases
	cin>>tc;
#endif
	for(int t = 1; t <= tc; t++)
	{
#ifdef _DEBUG
	db = 1;
	int tt = clock();
#endif
		// cout<<"Case #"<<t<<": ";
		solve();

#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << endl;
		tt = clock();
#endif
	}
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(all(v));
#define RSORT(v) sort(rall(v));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main() {
  // cout << fixed << setprecision(5);
  int N, M, T;
  cin >> N >> M >> T;
  vector<int> A(M), B(M);
  rep(i, M) cin >> A[i] >> B[i];

  int battery = N;
  int last_time = 0;
  rep(i, M) {
    battery += last_time - A[i];
    if (battery <= 0) {
      cout << "No" << endl;
      return 0;
    }
    battery += B[i] - A[i];
    battery = min(battery, N);
    last_time = B[i];
  }
  battery += last_time - T;
  if (battery > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main() {
  string S, small, large ;
  cin >> S ;
  small="abcdefghijklmnopqrstuvwxyz" ;
  large="ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  int size_S=S.size(), size_small=small.size(), size_large=large.size() ;

  for(int i=0;i<size_S;i++){
    if(i%2==0){ //奇数
      for(int j=0;j<size_small;j++){
        if(S.at(i)==small.at(j)) break ;
        if(j==size_small-1){
          cout << "No" << endl ;
          return 0 ;
        }
      }
    }
    if(i%2==1){  //偶数
      for(int k=0;k<size_large;k++){
        if(S.at(i)==large.at(k)) break ;
        if(k==size_large-1){
          cout << "No" << endl ;
          return 0 ;
        }
      }
    }
  }

  cout << "Yes" << endl ;

  return 0 ;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

bool solve(string s) {
  for (int i = 0; i < s.size(); i += 2) {
    if (!islower(s[i])) return false;
  }
  for (int i = 1; i < s.size(); i += 2) {
    if (!isupper(s[i])) return false;
  }
  return true;
}

int main2() {
  string s; cin >> s;
  bool ans = solve(s);
  cout << (ans ? "Yes": "No") << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

int main()
{
    size_t N;
    long long K, M;
    cin >> N >> K >> M;

    vector<vector<long long>> dp(N + 1, vector<long long>(N / 2 * (N / 2 + 1) / 2 * K + (N + 5), 0));
    dp[0][0] = 1;
    for (size_t i = 1; i <= N; i++)
    {
        vector<long long> sum(i, 0);
        for (size_t j = 0; j < dp[i].size(); j++)
        {
            sum[j % i] += dp[i - 1][j];
            sum[j % i] %= M;
            if (j >= (K + 1) * i)
            {
                sum[j % i] -= dp[i - 1][j - (K + 1) * i];
                if (sum[j % i] < 0)
                {
                    sum[j % i] += M;
                }
                sum[j % i] %= M;
            }
            dp[i][j] = sum[j % i];
        }
    }

    for (size_t i = 1; i <= N; i++)
    {
        long long ans = 0;
        for (size_t j = 1; j < dp[i].size(); j++)
        {
            ans += dp[i - 1][j] * dp[N - i][j];
            ans %= M;
        }
        ans *= (K + 1);
        ans %= M;
        ans += K;
        ans %= M;
        cout << ans << endl;
    }
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>
//#include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif

int n, k, m;

constexpr int HighestDim = 505000;

long long int A[HighestDim + 1], B[HighestDim + 1];

void mult(long long int* a, int v){
    for(int i = HighestDim, j = i - v; j >= 0; --i, --j){
        a[i] -= a[j]; if(a[i] < 0) a[i] += m;
    }
}

void div(long long int* a, int v){
    for(int i = v, j = 0; i <= HighestDim; ++i, ++j){
        a[i] += a[j]; if(a[i] >= m) a[i] -= m;
    }
}

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);
    A[0] = 1; B[0] = 1;
    std::cin >> n >> k >> m;

    for(int i = 1; i <= n - 1; ++i) mult(A, i * (k + 1));
    for(int i = 1; i <= n - 1; ++i) div(A, i);

    std::vector<long long int> res(n + 1);
    res[1] = k; res[n] = k;

    for(int i = 2, j = n - 1; i <= j; ++i, --j){
        mult(A, n - i + 1); div(A, (k + 1) * (n - i + 1) );
        mult(B, (k + 1) * (i - 1)); div(B, i - 1);
        for(int d = 0; d <= HighestDim; ++d) res[i] += static_cast<long long int>(A[d]) * B[d] % m;
        res[i] %= m; res[i] *= (k + 1); res[i] %= m;
        --res[i]; if(res[i] < 0) res[i] += m;
        res[j] = res[i];
    }
    for(int i = 1; i <= n; ++i) std::cout << res[i] << '\n';

    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
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;
}
struct edge {
  ll to, cost;
};

// 半分全列挙のお勉強
int main() {
  int N; cin >> N;
  ll T; cin >> T;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  int n = min(N, 20);
  int m = N - n;
  vector<ll> v1, v2;
  v1.push_back(0); v2.push_back(0);
  int k1 = 1 << n; int k2 = 1 << m;
  for(int i = 1; i < k1; ++i) {
    ll t = 0;
    for(int j = 0; j < n; ++j) {
      if(((1 << j) & i) != 0) {
        t += A[j]; // 前からn個だけ走査して条件を満たした項目だけ足し込む
      }
    }

    if(t <= T) v1.push_back(t);
  }

  for(int i = 1; i < k2; ++i) {
    ll t = 0;
    for(int j = n; j < N; ++j) {
      if(((1 << (j - n)) & i) != 0) {
        t += A[j]; // 前からn個だけ走査して条件を満たした項目だけ足し込む
      }
    }

    if(t <= T) v2.push_back(t);
  }

  sort(all(v1)); sort(all(v2));
  ll ans = 0;
  for(ll i : v1) {
    int l = -1;
    int r = v2.size();
    while(r - l > 1) {
      int mid = l + (r - l) / 2;
      if(i + v2[mid] <= T) l = mid;
      else r = mid;
    }
    ll res = i + v2[l];
    ans = max(ans, res);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

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

    vector<long long> A;
    A.push_back(0);
    for (int i = 1; i <= N; i++) {
        long long a;
        cin >> a;
        A.push_back(a);
    }

    vector<long long> max_move, move;
    max_move.resize(N + 1);
    move.resize(N + 1);

    for (int i = 0; i < N; i++) {
        move[i + 1] = move[i] + A[i + 1];
        max_move[i + 1] = max(move[i + 1], max_move[i]);
    }

    long long x = 0;
    long long x_max = 0;
    for (int i = 1; i <= N; i++) {
        x_max = max(x_max, x + max_move[i]);
        x += move[i];
    }

    cout << x_max << endl;
    return 0;
}


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

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

	int n;
	cin >> n;
	int c = 0;
	map<int,int> m;
	for(int i = 2; i*i <= n; i++)
	{
		int x = i*i;
		if(m[i] == 1)
			continue;
		while(x <= n)
		{
			m[x] = 1;
			c++;
			x *= i;
		}
	}
	cout << (n - c) << endl;
	return 0;
}

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

#define lli long long int
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
////////////////////////////////////////////////////////    By: Umang Srivastava

// lli extgcd(lli a, lli b, lli *x , lli *y)
// {
//   if(a==0)
//   {
//     *x=0;
//     *y=1;
//     return b;
//   }
//   lli x1 , y1;
//   lli gcd = extgcd(b%a , a , &x1 , &y1);
//   *x= y1 - (b/a) * x1;
//   *y=x1;
//   return gcd;
// }

// lli modinv(lli a, lli m)
// {
//   lli x,y;
//   lli g = extgcd(a,m,&x,&y);
//   if(g!=1)
//     return -1;
//   return (x%m+m)%m;
// }

// lli moddiv(lli a, lli b, lli m)
// {
//   a=a%m;
//   lli inv = modinv(b,m);
//   if(inv!=-1)
//     return ((a*inv + m)%m);
//   else
//     return -1;
// }

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

// lli gcd(lli a, lli b)
// {
//     // if(b<a)
//     // {
//     //     lli t=a;
//     //     a=b;
//     //     b=t;
//     // }
//     if(a==0)
//         return b;
//     return gcd(b%a,a);
// }

// lli fac[1000005];
// void calcfac(lli m)
// {
//  fac[0]=1;
//  for(lli i=1;i<=1000001;i++)
//  {
//    fac[i]=(fac[i-1]*i)%m;
//  }
// }

// lli ncr(lli n,lli r,lli m)
// {
//   if(r==0 || r==n)
//     return 1;
//   return (((fac[n]*binpow(fac[r],m-2,m))%m)*(binpow(fac[n-r],m-2,m)))%m;
// }

/////////////////////////////////////////////////////////

// lli fillst(lli ar[], lli ss, lli se, lli *st, lli si)
// {
// 	if(ss==se)
// 	{
// 		st[si]=ar[ss];
// 		return ar[ss];

// 	}

// 	lli mid = ss + (se-ss)/2;
// 	st[si] = min(fillst(ar,ss,mid,st,2*si+1) , fillst(ar,mid+1,se,st,2*si+2));
// 	return st[si];
// }

// lli RMQ(lli *st, lli ss, lli se, lli qs, lli qe, lli index)
// {
// 	if(qs<=ss && qe>=se)
// 		return st[index];

// 	if(se<qs || ss>qe)
// 		return 10000000000;

// 	lli mid = ss+ (se-ss)/2;

// 	return min(RMQ(st,ss,mid,qs,qe,2*index+1), RMQ(st,mid+1,se,qs,qe,2*index+2));
// }

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  lli n,m,i,j,k,tc,t,a,b,c,d,x,y,q;
  t=1;
  a=b=0;
  c=d=0;
  // cin>>t;
  while(t--)
  {
  	cin>>n;
  	lli ar[n];
  	for(i=0;i<n;i++)
  	{
  		cin>>ar[i];
  	}
  	lli s=0;
  	lli v=0;
  	for(i=0;i<n;i++)
  	{
  		a=ar[i];
  		for(j=i;j<n;j++)
  		{
  			if(ar[j]<a)
  				a=ar[j];
  			v=max(v,a*(j-i+1));
  		}
  	}

  	cout<<v<<endl;

  }
}


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

#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18

#define display(v) for(int i =0;i<(int)v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
#define read(a) for(int i = 0;i<(int)a.size();++i)cin>>a[i]
#define show(x) cout << #x << " is " << x << "\n";
#define show_arr(a) cout << #a << "\n"; display(a) ; cout << "\n";
inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }
const int nax = 300*1000 + 10;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n ; cin>>n;
    int sum = 0;
    vector<pair<int,int>> a(n);
    vi b(n);
    for(int i =0 ;i<n;++i){
        cin>>a[i].ff>>a[i].ss;
        sum += a[i].ff;
        b[i] = 2*a[i].ff + a[i].ss ;
    }
    sort(all(b));
    reverse(all(b));
    int ans = 0;
    int tak = 0 , aoki = sum;
    for(int i = 0;i<n;++i){
        if(tak > aoki)break;
        tak += b[i];
        ++ans;
    }
    cout << ans;

    return 0;
}

// Химаншу
// check overflow
// special case n == 1
// 🍪🍪🍪

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    mint ans = 1;
    int s = 0;
    rep(i,n) s += a[i];
    rep(i,n+s) ans *= (m+n-i);
    rep(i,n+s) ans /= (i+1);
    cout << ans << endl;
}


#include<iostream>
#include<cassert>
using namespace std;
typedef long long ll;

template <int N>
struct modInt {
    long long val;
    modInt(ll v){
        this->val = v%N;
    }
    int toInt(){
        return this->val;
    }
    void operator=(const ll other){
    this->val = other%N;
}

};
template<int N> modInt<N> operator+(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator+(const modInt<N> &,const ll);
template<int N> modInt<N> operator*(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator*(const modInt<N> &,const ll);
template<int N> modInt<N> operator/(const modInt<N> &,const modInt<N> &);
template<int N> modInt<N> operator/(const modInt<N> &,const ll);
template<int N> modInt<N> binpow(const modInt<N> &,const int);
template<int N> modInt<N> inverse(const modInt<N> &);
template<int N> modInt<N> pw(const modInt<N> &,const int);

template<int N> modInt<N> operator+(const modInt<N> &a,const modInt<N> &b){
    return modInt<N>(a.val + b.val);
}

template<int N> modInt<N> operator+(const modInt<N> &a, const ll b){
    modInt<N> c(b);
    return a+c;
}
template<int N> modInt<N> operator*(const modInt<N> &a,const modInt<N> &b){
    modInt<N> res(a.val*b.val);
    return res;
}
template<int N> modInt<N> operator*(const modInt<N> &a, const ll b){
    modInt<N> c(b);
    return a*c;
}
template<int N> modInt<N> operator/(const modInt<N> &a,const modInt<N> &b){
    modInt<N> c = inverse<N>(b);
    return a*c;
}
template<int N> modInt<N> operator/(const modInt<N> &a, const ll b){
    modInt<N> c(b);
    return a/c;
}

template<int N> modInt<N> inverse(const modInt<N> &a){
    return binpow(a,N-2);
}
template<int N> modInt<N> pw(const modInt<N> &a,int exp){
    if(exp<0){
        modInt<N> inverse = inverse(a);
        return binpow<N>(a,-exp);
    }
    return binpow<N>(a,exp);
}

template<int N> modInt<N> binpow(const modInt<N> &a,int b){
    if(b==0){
        return modInt<N>(1);
    }
    modInt<N> v = binpow<N>(a,b/2);
    modInt<N> res = v*v;
    if(b%2==1){
        return a*res;
    }
    return res;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;

    vector<modInt<mod>> row(n+1,1);
    for(int i=1;i<=n;i++){
        row[i] = (row[i-1]*(n-i+1))/i;
    }
    vector<modInt<mod>> dp(m+1,0);
    dp[0] = 1;
    for(int j=2;j<=m;j+=2){
        for(int i=0;i<=min(j,n);i+=2){
            dp[j]=dp[j]+(dp[(j-i)/2]*row[i]);
        }

    }
    cout<<dp[m].toInt()<<endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
// #define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
// const int inf = 1e18;
const int N   = 5e3 + 5;
const int mod = 998244353;
int maxi[12];
int n, m;
int ans = 0;
ll f[N], invf[N];

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

ll modInv(ll n) {
	return mpow(n, mod - 2);
}

ll C(ll n, ll r) {
	if (r == 0) return 1;
	assert(n >= r);
	return (f[n] * invf[r] % mod * invf[n - r] % mod) % mod;
}

void fact() {
	f[0] = 1;
	invf[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
		invf[i] = modInv(f[i]);
	}
}
namespace modop {
ll madd(ll a, ll b) {
	return (a + b) % mod;
}
ll msub(ll a, ll b) {
	return (((a - b) % mod) + mod) % mod;
}
ll mmul(ll a, ll b) {
	return ((a % mod) * (b % mod)) % mod;
}
ll minv(ll base) {
	return mpow(base, mod - 2);
}
ll mdiv(ll a, ll b) {
	return mmul(a, minv(b));
}
}

using namespace modop;
int dp[12][5005];
int go(int bit, int sum) {
	if (bit == 12) {
		if (sum == 0) {
			return 1;
		}
		else {
			return 0;
		}

	}
	if (dp[bit][sum] != -1) {
		return dp[bit][sum];
	}
	int ans = 0;
	int p = (1LL << bit);
	for (int i = 0; i <= maxi[bit]; i += 2) {
		int zx = i * p;
		if (zx <= sum) {
			int coeff = C(n, i);
			ans = madd(ans, mmul(coeff, go(bit + 1, sum - zx)));
		}
		else {
			break;
		}
	}

	return dp[bit][sum] = ans;

}
void testCase() {
	cin >> n >> m;
	fact();

	for (int i = 0; i <= 11; i++) {
		int max_take = min(n, m / (1 << i));
		maxi[i] = max_take;
	}
	memset(dp, -1, sizeof dp);
	cout << go(0, m) << endl;

}

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


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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> p(n);
    vector<ll> q(n);
    rep(i,n){
        cin >> a[i];
        if(i==0){
            p[i] = a[i];
            q[i] = p[i];
        }else{
            p[i] = p[i-1] + a[i];
            q[i] = max(q[i-1],p[i]);
        }

    }
    ll x = 0;
    ll ans=0;
    rep(i,n){
        ans = max(x+q[i], ans);
        x = x + p[i];
    }
    cout << ans << endl;

    return 0;
}

#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
ll A[200001];
ll rui[200001]={};
ll ruimax[200001]={};
ll ruirui[200001]={};
int main(){
	int N;
	scan(N);
	rep(i,N) scan(A[i]);
	rep(i,N) rui[i+1]=rui[i]+A[i];
	rep(i,N) ruirui[i+1]=ruirui[i]+rui[i+1];
	rep(i,N) ruimax[i+1]=max(ruimax[i],rui[i+1]);
	ll ruiruimax=-INFl;
	int ruiruimaxindex=0;
	rep1(i,N){
		if(ruiruimax<ruirui[i]){
			ruiruimax=ruirui[i];
			ruiruimaxindex=i;
		}
	}
	if(N==1){
		prin(max(0LL,A[0]));
		return 0;
	}
	if(ruiruimaxindex<=1){
		prin(max({0LL,A[0],A[0]+A[0],A[0]+A[0]+A[1]}));
		return 0;
	}
	ll ans=ruirui[ruiruimaxindex-2];
	ll now=ans;
	rep(i,ruiruimaxindex-1){
		now+=A[i];
		chmax(ans,now);
	}
	rep(i,ruiruimaxindex){
		now+=A[i];
		chmax(ans,now);
	}
	if(ruiruimaxindex<N){
		rep(i,ruiruimaxindex+1){
			now+=A[i];
			chmax(ans,now);
		}
	}
	prin(ans);
	return 0;
}


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

////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
//#define mod 9999991
long mod=9999991;
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getline(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int,int> a,pair<int,int> b){
    double x=(double )a.first/a.second;
    double y=(double )b.first/b.second;
    return x<y;}
long Pow(long x, long y) {
    if(y == 0)return 1;
    long res=Pow(x,y/2)%mod;
    res=(res*res)%mod;
    if(y&1)res=(res*x)%mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a,b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long t,n,m,f=0,ans,a,b;
long tmp;

int main() {
///<editor-fold desc="ios">
    IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in=1,o;
    cin>>n>>m;
    vector<vector<int>> idx(n+1,{0});
    for(int i = 1; i <=n ; ++i){
        cin>>tmp;
        idx[tmp].push_back(i);
    }
    for(int i = 0; i <=n ; ++i){
        idx[i].push_back(n+1);
    }
    for(int i = 0; i <= n; ++i){
        for(int j = 1; j <idx[i].size() ; ++j){
            if(idx[i][j]-idx[i][j-1]-1>=m){
                cout<<i<<endl;
                return 0;
            }
        }
    }

}

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct UnionFind {
    vector<int> par;
	vector<int> cnt;

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

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

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

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[ry] = rx;
		cnt[rx] += cnt[ry];
    }

	int count(int x) {
		return cnt[root(x)];
	}
};

void solve() {
    ll n, q;
    cin >> n >> q;
    vll c(n);
    rep(i, n) cin >> c[i];
    rep(i, n) --c[i];
    UnionFind uf(n);
    vector<map<ll, ll>> vmp(n);
    rep(i, n) vmp[i][c[i]]++;
    rep(__i, q) {
        ll t, a, b;
        cin >> t >> a >> b;
        --a, --b;
        if(t == 1) {
            if(uf.issame(a, b)) continue;
            if(uf.count(a) < uf.count(b)) swap(a, b);
//            if(vmp[a].size() < vmp[b].size()) swap(a, b);
            ll rt_old = uf.root(b);
            uf.merge(a, b);
            ll rt_new = uf.root(a);
            for(auto i = vmp[rt_old].begin(); i != vmp[rt_old].end(); ++i) {
                vmp[rt_new][i->first] += i->second;
            }
            vmp[rt_old].clear();
        }
        else {
            ll rt = uf.root(a);
            cout << vmp[rt][b] << endl;
        }
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}