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

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}

inline bool read(int& a){
int s=0,w=1;
    char ch=getchar();
    if(ch==EOF){
        return false;
    }
    while(ch<'0'||ch>'9'){
        if(ch=='-')w=-1;ch=getchar();
    }
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=s*w;
    return true;
}

inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}

inline void writeln(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
    puts("");
}

const int MOD=998244353;

int n,k;
int f[3010][3010];

signed main(){
    read(n),read(k);
    f[1][1]=1;

    for(int i=2;i<=n;i++){
        for(int j=i;j>=1;j--){
            f[i][j]=(f[i-1][j-1]+f[i][j*2])%MOD;
        }
    }

    writeln(f[n][k]%MOD);

    return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REP1(i, n) for(ll i = 1; i <= (n); i++)
#define REPD(i,a,b) for (ll i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef double d;
typedef long double ld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<d> vd;
typedef vector<ld> vld;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int MOD = 1000000007;
const int INF = 1001001001;
// 小数点 << fixed << setprecision(10) <<
// sort降順 sort(ALL(),greater<int>());
// 円周率 M_PI
// 文字判定 isupper islower
// 順列 do {} while(next_permutation(ALL(X)));
// 最大値 LLONG_MAX
// a内でx以上 auto iter = lower_bound(ALL(a), x);
// a内でxより大きい auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;

// 重複した要素を取り除いて返す
vll deleteDuplication(vll &numberlist) {
  sort(ALL(numberlist));
  numberlist.erase(unique(ALL(numberlist)),numberlist.end());
  return numberlist;
}

// 2つの数の最大公約数を求める
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 各桁の数を合計
int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

// 素因数分解してペアのリストを返す
vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}

int main() {
  int h,w;
  cin >> h >> w;
  char s[h+1][w+1];
  vvll dp(h+1,vll(w+1,0)),X(h+1,vll(w+1,0)),Y(h+1,vll(w+1,0)),Z(h+1,vll(w+1,0));
  REP1(i,h) {
    REP1(j,w) {
      cin >> s[i][j];
    }
  }
  dp[1][1]=1;
  REP1(i,h) {
    REP1(j,w) {
      if(i==1&&j==1) continue;
      if(s[i][j]=='#') continue;
      X[i][j]=X[i][j-1]+dp[i][j-1]%MOD;
      Y[i][j]=Y[i-1][j]+dp[i-1][j]%MOD;
      Z[i][j]=Z[i-1][j-1]+dp[i-1][j-1]%MOD;
      dp[i][j]=(X[i][j]+Y[i][j]+Z[i][j])%MOD;
    }
  }
  cout << dp[h][w] << endl;
  return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=2e5+10,P=998244353;
ll n,m,f[20][N],fac[N],inv[N],ans;
ll C(ll n,ll m)
{return fac[n]*inv[m]%P*inv[n-m]%P;}
signed main()
{
	scanf("%lld%lld",&n,&m);
	ll k=0;inv[1]=1;
	for(ll i=2;i<=n;i++)
		inv[i]=P-inv[P%i]*(P/i)%P;
	fac[0]=inv[0]=1;
	for(ll i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%P,inv[i]=inv[i-1]*inv[i]%P;
	while((1<<(k+1))<=m)k++;k=min(k,n-1);
	for(ll i=1;i<=m;i++)f[1][i]=1;
	for(ll i=1;i<=k;i++)
		for(ll j=1;j<=m;j++){
			if(!f[i][j])continue;
			for(ll k=2*j;k<=m;k+=j)
				(f[i+1][k]+=f[i][j])%=P;
		}
	for(ll i=1;i<=k+1;i++)
		for(ll j=1;j<=m;j++)
			(ans+=f[i][j]*C(n-1,i-1)%P)%=P;
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 1e5 + 5;

int a[N], b[N], f[2][N];
int n, len[2];
ll ans;

int main() {
    memset(f, -0x3f, sizeof(f));
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]), ans += a[i];
    for (int i = 1; i <= n; i++) read(b[i]), b[i] -= a[i];
    for (int i = 1; i <= n; i++) f[i & 1][++len[i & 1]] = b[i];
    sort(f[0] + 1, f[0] + len[0] + 1); reverse(f[0] + 1, f[0] + len[0] + 1);
    sort(f[1] + 1, f[1] + len[1] + 1); reverse(f[1] + 1, f[1] + len[1] + 1);
    for (int i = 1; i <= n / 2; i++) {
        if (f[0][i] + f[1][i] < 0) break;
        ans += f[0][i] + f[1][i];
    }
    print(ans, '\n');
    return 0;
}


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

#define ll              long long int
#define ld              long double
#define mod             1000000007
#define pb              push_back
#define ff              first
#define ss              second
#define inf             1e18
#define mid(l, r)       (l+(r-l)/2)
#define loop(i, a, b)   for(int i=(a); i<b; i++)
#define loopr(i, a, b)  for(int i=(a); i>b; i--)

#define sz(a)           int((a).size())
#define all(c)          c.begin(), c.end()
#define allr(c)         c.rbegin(), c.rend()

#define tr(container, it) \
    for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) \
    (container.find(element) != container.end())
#define vpresent(container, element) \
        (find(all(container),element) != container.end())

#define print(dp, n); \
    loop(i, 0, n){cout << dp[i] << " ";}cout << endl;
#define print2(dp, a, n, b, m); \
    loop(i, a, n){loop(j, b, m){cout << dp[i][j] << " ";}cout << endl;}
#define countetbits(i)\
    __builtin_popcount(i)

typedef vector< long long int > vl;
typedef vector< int > vi;
typedef vector< string > vs;

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

typedef pair< ll,ll > pll;
typedef pair< int, int> pii;

ll gcd(ll a, ll b)
{
    while (true)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}
ll lcm(ll a, ll b)
{
    ll temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}

template <class A, class B>
auto findMin(A a, B b) -> decltype(a < b ? a : b)
{
    return (a < b) ? a : b;
}
//Type Inference refers to automatic deduction of the data type of an expression in a programming language.
//Auto lets you declare a variable with particular type whereas decltype lets you extract the type from the variable so decltype is sort of an operator that evaluates the type of passed expression.

void file_i_o(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}
ll z = 1000000;
ll n;

void run_case(){
    string s;
    cin >> s;
    if( s.substr(0, 1) == s.substr(1, 1) && s.substr(1, 1) == s.substr(2, 1)  ){
        cout << "Won" << endl;
    }
    else cout << "Lost" << endl;
}

int main(){
    clock_t begin = clock();
    file_i_o();
    int tests = 1;
    /* int tests; */
    /* cin >> tests; */

    while(tests-- > 0)
        run_case();

    #ifndef ONLINE_JUDGE
    clock_t end = clock();
    cout << "\n\nExecuted In: " << double(end - begin) /CLOCKS_PER_SEC << " seconds" << endl;
    #endif
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b;
inline int read(){
	int q=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
	while(isdigit(ch)){q=(q<<3)+(q<<1)+ch-48;ch=getchar();}
	return f?q:(~(q-1));
}
inline void print(int x){
	if(x<0){putchar('-');x=-x;}
	if(x>9)print(x/10);
	putchar(x%10+48);
}
signed main(){
	a=read();b=read();
	print(a+a+100-b);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, a, b;
    cin >> n >> a >> b;
    int rest = max(n - a, 0);
    cout << rest + b << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;

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

    int n,a,b;
    cin>>n>>a>>b;

    cout<<n-a+b<<endl;

    return 0;
}


#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

int main(){
  int H,W,min=100,answer=0;
  cin>>H>>W;
  vector<int> A(H*W);
  for(int i=0;i<H*W;i++){
   cin>>A[i];
    if(min>A[i])min=A[i];
  }
  for(int i=0;i<H*W;i++){
   answer=answer+(A[i]-min);
  }
  cout<<answer<<endl;
}

/*..........UNPROFESSIONAL..........*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fk(i,start,end) for(ll i=start;i<ll(end);i++)
typedef long long int ll;
string A="YES";
string B="NO";

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

  ll n,m;
     cin>>n>>m;
     ll a[n][m];
     ll mi=101;
     fk(i,0,n)
     {
     	fk(j,0,m)
     	{
     		cin>>a[i][j];
     		mi=min(mi,a[i][j]);
     	}
     }
     ll count=0;
     fk(i,0,n)
     {
     	fk(j,0,m)
     	{
     		count+=(a[i][j]-mi);
     	}
     }
     cout<<count;

  return 0;
}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;

//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef vector<vector<int>> graph;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define MOD 1000000007
#define MAXX 1.1529215e+18
#define _1 first
#define _2 second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

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

template<class t> using vc=vector<t>;

template<class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

template<class T>
T extgcd(T a, T b, T &x, T &y) {
    T d = a;
    if (b == 0) {
      x = 1;
      y = 0;
    } else {
      d = extgcd(b, a%b, y, x);
      y -= (a/b)*x;
    }
    return d;
}

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p._1<<","<<p._2<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}

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

  int N;
  string S, T;
  cin >> N >> S >> T;
  vector<ll> vs;
  vector<ll> vt;
  bool flag = true;
  ll ans = 0;
  rep(i, N) {
    if (S[i] == '1') {
      vs.pb(i);
    }
    if (T[i] == '1') {
      vt.pb(i);
    }
  }
  vt.pb(INF);
  ll s = 0;
  ll t = 0;
  while(s < vs.size()) {
    if (vs[s] < vt[t]) {
      if (s <= vs.size()-2) {
        ans -= vs[s];
        ans += vs[s+1];
        s+=2;
      } else {
        flag = false;
        break;
      }
    }
    else {
      ans += vs[s]-vt[t];
      s++;
      t++;
    }
    // cout << s << ' ' << t << ' ' << ans << endl;
  }
  if (t < vt.size()-1) {
    flag = false;
  }
  if (flag)
    cout << ans << endl;
  else {
    cout << -1 <<endl;
  }
}

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

// #include <atcoder/all>
// using namespace atcoder;

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

std::string S;
std::string T;

void solve(long long N){
    ll ans = 0;
    queue<int> carry_start_index;
    rep(i, N) {
        if (S[i] == '1') {
            if (carry_start_index.size()) {
                ans += i - carry_start_index.front();
                carry_start_index.pop();
                S[i] = '0';
            }
        }
        if (S[i] != T[i]) {
            carry_start_index.push(i);
        }
    }
    if (carry_start_index.size()) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::cin >> S;
    std::cin >> T;
    // solve(N, S, T);
    solve(N);
    return 0;
}


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

int main()
{
    int N, X;
    string S;
    cin >> N >> X >> S;

    for (int i = 0; i < N; i++)
    {
        if (S.at(i) == 'o')
        {
            X++;
        }
        else
        {
            if (X > 0)
            {
                X--;
            }
        }
    }

    cout << X << endl;
}

#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#define MY_IS_DEBUG      (true)
#else
#define MY_NAMESPACE(ns)
#define MY_NAMESPACE_
#define MY_DEBUG(s)
#define MY_IS_DEBUG      (false)
#endif

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

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

constexpr int IMIN = numeric_limits<int>::min();
constexpr int IMAX = numeric_limits<int>::max();
constexpr ll LLMIN = numeric_limits<ll>::min();
constexpr ll LLMAX = numeric_limits<ll>::max();

template <typename T> bool chmax(T& maxval, T const& newval) { if (newval > maxval) { maxval = newval; return true; } return false; }
template <typename T> bool chmin(T& minval, T const& newval) { if (newval < minval) { minval = newval; return true; } return false; }

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

	int a, b, c, d;
	cin >> a >> b;
	cin >> c >> d;

	int ans = b - c;

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


#include <bits/stdc++.h>

using namespace std;
const int N = 1e3 + 5;

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

int main()
{
	int aa, bb;
	cin >> n;

	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	sort(a, a + n); sort(b, b + n);
	if (a[n - 1] <= b[0]) cout << b[0] - a[n - 1] + 1 << endl;
	else cout << 0 << endl;

	return 0;
}

#ifdef DBG_MACRO_NO_WARNING
#include <dbg.h>
#else
#define dbg(...) ((void)0)
#endif
#include <bits/stdc++.h>
#define all(c) begin(c), end(c)
#define isz(c) (int)(c).size()

using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main(void)
{
    ios::sync_with_stdio(false), cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        if (n % 2 == 0)
        {
            if (n % 4 == 0)
                cout << "Even" << endl;
            else
                cout << "Same" << endl;
        }
        else
            cout << "Odd" << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#define all(x) (x).begin(),(x).end()
using namespace std;

std::vector<int> Eratosthenes( const int N )
{
    std::vector<bool> is_prime( N + 1 );
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;
    }
    std::vector<int> p;
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            p.emplace_back( i );
        }
    }
    return p;
}

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

int main(){
    ll n;
    cin>>n;
    V x(n);
    rep(i,n)cin>>x[i];
    vector<int> pri=Eratosthenes(50);
    ll N=pri.size();
    ll ans=1e18;
    ll tmp=1;
    for(ll bit=0;bit<(1<<N);bit++){
        ll num=1;
        rep(k,N){
            if(1<<k&bit){
                num*=pri[k];
            }
        }
        if(num==1)continue;
        bool ok=true;
        rep(i,n){
            if(gcd(num,x[i])==1){
                ok=false;
                break;
            }
        }
        if(ok)ans=min(ans,num);
    }
    cout<<ans<<endl;
}

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

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

/*

 1/17/2021

 11:07-

 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N,M;

const LL Inf=1e18;
LL dp[MAX_N][3];
VI G[MAX_N];
void solve() {
  REP(i,N)REP(j,3) dp[i][j]=-Inf;
  REP(i,N) dp[i][0]=0;
  REP(u,N)REP(j,3) {
    FORR(v,G[u]) {
      SMAX(dp[v][j],dp[u][j]);
      if(j==0) SMAX(dp[v][1],dp[u][0]-A[u]);
      if(j==1) SMAX(dp[v][2],dp[u][1]+A[u]);
      //dump(u,j,v,dp[v][j+1]);
    }
  }
  REP(u,N) SMAX(dp[u][2],dp[u][1]+A[u]);

  LL res=-Inf;
  REP(u,N) SMAX(res,dp[u][2]);
  cout<<res<<endl;
}

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

  cin>>N>>M;
  REP(i,N) cin>>A[i];
  REP(_,M) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].push_back(v);
  }
  solve();

  return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<stack>
using namespace std;
#define ll long long
#define f(i,a,b) for(register ll i=a;i<=b;++i)

#define pb push_back
#define mp make_pair
#define N 2005
#define Mod 1000000007
inline ll read()
{
	ll s=0,w=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') { s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*w;
}
char Mat[N][N];
ll X[N][N],Y[N][N],sqr[N*N]={1ll};
stack<ll>st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n=read(),m=read(),sum=0,ans=0;

	f(i,1,n*m+2) sqr[i]=(sqr[i-1]*2)%Mod;
	f(i,1,n) scanf("%s",Mat[i]+1);

	f(i,1,n) f(j,1,m) if(Mat[i][j]=='.') ++sum;

	f(i,1,n)
	{
		while(st.size()) st.pop();
		for(ll j=1;j<=m+1;++j)
		{
			if(j==m+1||Mat[i][j]=='#')
			{
				ll siz=st.size();
				while(st.size())
					X[i][st.top()]=siz,st.pop();
			}
			else st.push(j);
		}
	}
	f(j,1,m)
	{
		while(st.size()) st.pop();
		for(ll i=1;i<=n+1;++i)
		{
			if(i==n+1||Mat[i][j]=='#')
			{
				ll siz=st.size();
				while(st.size())
					Y[st.top()][j]=siz,st.pop();
			}
			else st.push(i);
		}
	}
	/*cout<<"Test X:"<<endl;
	f(i,1,n){
		f(j,1,m) cout<<X[i][j]<<" ";cout<<endl;
	}
	cout<<"Test Y:"<<endl;
	f(i,1,n){
		f(j,1,m) cout<<Y[i][j]<<" ";cout<<endl;
	}*/
	f(i,1,n) f(j,1,m)
	{
		if(Mat[i][j]!='.') continue;
		ll x=sqr[sum-X[i][j]-Y[i][j]+1];
		ans=(ans+((sqr[sum]-x)%Mod+Mod)%Mod)%Mod;
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using i128 = __int128_t;
using u128 = __uint128_t;
using u64 = uint64_t;

//define
#define int long long
#define ll int
#define trav(i,v)   for(auto i: v)
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()
#define itn int
#define sz(x) (int)x.size()

//typedef
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< std::vector<int> > vvi;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long double PI = 3.141592653589793238;
const long long pi = 31415926;
const long long inf = 1000000000000000000;
const long long small_inf = INT_MAX;

int modpow(int x, int n, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;}
int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;}

void init(){

}

int ncr(int n, int r){
    if(r<0 || r>n){
        return 0;
    }
    if(n<0)
        return 0;
    ll x = n*(n-1);
    x/=2;
    return x;
}

void solve()
{
/*Don't hurry, nothing good comes if you rush*/
    int n, k;
    cin>>n>>k;
    repu(x1,3,3*n){
        int x = x1-3;
        int tot = 0;
        tot+=1ll*ncr(2+(x), 2);
        tot-=3ll*ncr(2+(x-n), 2);
        tot+=3ll*ncr(2+(x-2*n), 2);
        tot-=1ll*ncr(2+(x-3*n), 2);
        if(tot<k){
            k-=tot;
            continue;
        }
        x = x1;
        // cout<<k<<endl<<endl;
        repu(i,1,n){
            int left = x-i;
            if(left<=1 || left>2*n)
                continue;
            int mx = min(n,left-1ll);
            int mn = max(1ll,left-mx);
            // cout<<mx<<" "<<mn<<" "<<mx-mn+1<<endl;
            if(k>mx-mn+1){
                k-=mx-mn+1;
                continue;
            }
            // cout<<i<<endl;
            repu(j,1,n){
                if(x-i-j<=0 || x-i-j>n)
                    continue;
                k--;
                if(k==0){
                    cout<<i<<" "<<j<<" "<<x-i-j<<endl;
                    return;
                }
            }
            return;
            // break;
        }
    }
    // cout<<k<<endl;
}

signed main(){
    // #ifndef ONLINE_JUDGE
    //    freopen("./input.txt", "r", stdin);
    //    freopen("./output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t23 = 1, tt23 = 1;
    // cin>>t23;
    init();
    while(tt23<=t23)
    {
        // cout<<"Case #"<<tt23<<": ";
        solve();
        tt23++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

using ll=long long;
const int M=10000;

ll f(){
  ll res=0;
  string s;cin>>s;
  if(s[0]=='-')s=s.substr(1);
  bool ok=false;
  REP(i,s.size())
    if(s[i]=='.')s+=string(4-((int)s.size()-i-1),'0'),ok=true;
    else res=res*10+s[i]-'0';
  if(!ok)res*=M;
  return res;
}

ll ceilM(ll a){
  if(a>0)return (a-1)/M*M+M;
  return ((-a)/M)*-M;
}

ll floorM(ll a){
  return a/M*M;
}

int main(){
  ll x=f(),y=f(),r=f(),ans=0;
  for(ll i=ceilM(x-r);i<=x+r;i+=M){
    ll tmp=sqrt(r*r-(x-i)*(x-i)),d;
    for(ll _=-10;_<=10;_++)if((tmp+_)*(tmp+_)+(x-i)*(x-i)<=r*r)d=tmp+_;
    ans+=(floorM(y+d)-ceilM(y-d))/M+1;
  }
  cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
long 	double   x,y,r;
	cin>>x>>y>>r;
	r+=1e-14;
//	cout<<setprecision(10)<<mny<<" "<<setprecision(10)<<mxy<<endl;
	long double   mnyy=ceil(y-r);
	long double   mxyy=floor(y+r);
	//cout<<mnyy<<" "<<mxyy<<endl;
	unsigned long long count=0.0;
	while(mnyy<=mxyy){
		long double   sq=sqrt((r*r)-((y-mnyy)*(y-mnyy)));
	//	cout<<sq<<endl;
		//cout<<x<<endl;
		long double   s=ceil(x-sq);
		long double   f=floor(x+sq);
	//	cout<<s<<" "<<f<<endl;
	//	cout<<s<<" "<<f<<endl;
			count+=((f-s+1));
		mnyy=mnyy+1.0000000000;
	//	cout<<count<< " count"<<endl;
	}
	cout<<count<<endl;
	return 0;
}


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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> xy(m);
    rep(i, m) cin >> xy[i].first >> xy[i].second;
    sort(all(xy));
    set<int> s;
    s.insert(n);
    int l = 0;
    while (l < m) {
        int r = l, xi = xy[l].first;
        while (r < m) {
            if (xi == xy[r].first) ++r;
            else break;
        }
        set<int> a, e;
        rep3(i, l, r) {
            int yi = xy[i].second;
            if ((s.find(yi-1)!=s.end()||s.find(yi+1)!=s.end()) && s.find(yi)==s.end()) a.insert(yi);
            if ((s.find(yi-1)==s.end()&&s.find(yi+1)==s.end()) && s.find(yi)!=s.end()) e.insert(yi);
        }
        for (int ai : a) s.insert(ai);
        for (int ei : e) s.erase(ei);
        l = r;
    }
    cout << (int)(s.size()) << endl;
    return 0;
}

#include "iostream"
using namespace std;

int main()
{
	auto n = 0, k = 0, r = 0;

	cin >> n >> k;
	n *= 100;
	for (auto i = 100; i <= n; i+=100) {
		for (auto j = 1; j <= k; j++) {
			r += (i + j);
		}
	}
	cout << r << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n , k ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>k ;
	long long a = n * (n + 1ll) / 2ll ;
	long long b = k * (k + 1ll) / 2ll ;
	return cout<<100ll * a * k + b * n<<"\n" , 0 ;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define          pb                push_back
#define          eb                emplace_back
#define          all(x)            x.begin(), x.end()
#define          sz(x)             int(x.size())
#define          pii               pair<int, int>
#define          pll               pair<ll, ll>
#define          ff                first
#define          ss                second

const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 2e5+7;
const double PI = 3.1415926535897932384626;

void solve() {
    int n, k; cin >> n >> k;
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) sum += i*100+j;
    }
    cout << sum;
}

void fastIO(string name = "") {
    cin.tie(0)->sync_with_stdio(0);
    if (sz(name)) {
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
}

int main() {
    fastIO("");

    int tc = 1; //cin >> tc;
    while (tc--) solve();
    return 0;
}


#include <iostream>

using namespace std;

long long n;

int cnt1, cnt2;

int main() {
  scanf("%lld", &n);
  for (long long i = 1, a, b; i * i - i <= 2 * n; i++) {
    a = 2 * n - i * i + i;
    b = 2 * i;
    if (!(a % b) && a / b >= 1) {
      cnt1 += 2;
    }
  }
  printf("%d", cnt1);
  return 0;
}

//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

VL dvsr(LL n){VL ret;for(LL i=1;i*i<=n;++i){if(n%i==0){ret.PB(i);if(i*i!=n)ret.PB(n/i);}}SORT(ret);return ret;}

int main(){
    FAST;
    LL i,ans=0,N;
    cin>>N;
    VL v=dvsr(N);
    for(LL z:v){
        if(z&1)ans+=2;
        //if(z%2==0&&)
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  int n;
  cin>>n;
  VVI slo(n + 2);
  REP (i, n) {
    int a = (2 * i + 1) % n;
    int b = (2 * i + 2) % n;
    cout<<a + 1<<" "<<b + 1<<"\n";
    slo[i].PB(a);
    slo[i].PB(b);
  }
//   VI dis(n +2);
   int ma_dis = 0;
//   REP (i, n) {
//     REP (j, n) {
//       dis[j] = n;
//     }
//     dis[i] = 0;
//     VI que{i};
//     for (int ii = 0; ii < SZ(que); ii++) {
//       int v = que[ii];
//       for (auto nei : slo[v]) {
//         if (dis[nei] == n) {
//           dis[nei] = dis[v] + 1;
//           que.PB(nei);
//         }
//       }
//     }
//     REP (j, n) {
//       maxi(ma_dis, dis[j]);
//     }
//   }
  debug(n, ma_dis);
  //cout<<ma_dis<<endl;

  return 0;
}

#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>
#include <random>
#include <sstream>
#include <bitset>
#include <complex>
#include <chrono>
#include <cassert>

using namespace std;

int main() {
	int n; cin >> n;
	for (auto i = 1; i <= n; ++i) {
		cout << (i * 2 - 1) % n + 1 << ' ' << (i * 2) % n + 1 << '\n';
	}
}


#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
#define maxn 3e5+10
#define inf32 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int,int>pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

vector<vector<int>>adj(1e5+10);
int sub[100000+10];
int dp[100000+10];

void dfs(int u){
   vector<int>X[2];
   sub[u] = 1;
   for(auto i:adj[u]){
      dfs(i);
      sub[u] += sub[i];
      X[sub[i]&1].push_back(dp[i]);
   }
   dp[u] = 1;
   sort(X[0].begin(),X[0].end());
   sort(X[1].begin(),X[1].end());
   for(auto i:X[0]){
       if(i<=0) dp[u] += i;
   }
   int sgn = 1;
   for(auto i:X[1]){
       dp[u] += sgn*i;
       sgn *= -1;
   }
   for(auto i:X[0]){
       if(i>0) dp[u] += sgn*i;
   }
}
void solve(){
     int n;cin >> n;
     for(int i = 0;i<n-1;i++){
        int v;cin >> v;
        adj[v].push_back(i+2);
     }
     memset(dp,0,sizeof(dp));
     memset(sub,0,sizeof(sub));
     dfs(1);
     cout << (dp[1]+sub[1])/2;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  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はできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
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;};

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

// 0以上UINT_MAX(0xffffffff)以下の整数をとる乱数 xorshift https://ja.wikipedia.org/wiki/Xorshift
static uint32_t randXor()
{
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123;
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

// 0以上1未満の小数をとる乱数
static double rand01()
{
    return (randXor() + 0.5) * (1.0 / UINT_MAX);
}

// Time
#include <sys/time.h>
ll getTime() {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  ll result =  tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
  return result;
}
ll start_time, time_limit = 1950;
void setTime(){ start_time = getTime();}
ll nowTime(){ return getTime() - start_time;}
bool timeup(){ return nowTime() > time_limit;}

int si, sj;
int t[50][50];
int p[50][50];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string cdir = "DRUL";

struct STATE{
	int x, y;
	set<int> visited;
	int score;
	string path;
};

void init(STATE &state){
	state.x = si;
	state.y = sj;
	state.visited.insert(t[si][sj]);
	state.score = p[si][sj];
	state.path = "";
}

bool modify(STATE &state){
	int x = state.x;
	int y = state.y;
	int mx = -1, mxdir = -1;
	int mx_nx = -1, mx_ny = -1;
	for(int dir = 0; dir < 4; dir++){
		int nx = x + dx[dir], ny = y + dy[dir];
		if(nx >= 50 || ny >= 50 || nx < 0 || ny < 0) continue;
		if(state.visited.count(t[nx][ny])) continue;
		if(mx <= p[nx][ny]){
			mx = p[nx][ny];
			mxdir = dir;
			mx_nx = nx;
			mx_ny = ny;
		}
	}
	if(mxdir == -1) return false;
	state.visited.insert(t[mx_nx][mx_ny]);
	state.path += cdir[mxdir];
	state.score += mx;
	state.x = mx_nx;
	state.y = mx_ny;
	return true;
}

bool modify2(STATE &state){
	int x = state.x;
	int y = state.y;
	int mx = -1, mxdir = -1;
	int mx_nx = -1, mx_ny = -1;
	int dir = randXor() % 4;
	int nx = x + dx[dir], ny = y + dy[dir];
	if(nx >= 50 || ny >= 50 || nx < 0 || ny < 0) return false;
	if(state.visited.count(t[nx][ny])) return false;
	mxdir = dir;
	mx_nx = nx;
	mx_ny = ny;
	if(mxdir == -1) return false;
	state.visited.insert(t[mx_nx][mx_ny]);
	state.path += cdir[mxdir];
	state.score += mx;
	state.x = mx_nx;
	state.y = mx_ny;
	return true;
}

string mountain(){
	STATE state;
	init(state);
	while(!timeup()){
		STATE new_state = state;
		if(rand01() > 1){
			if(modify(new_state)) {
				state = new_state;
			}
		}else{
			if(modify2(new_state)){
				state = new_state;
			}
		}
	}
	return state.path;
}

signed main(){
	setTime();
    cin >> si >> sj;
	rep(i,50)rep(j,50) cin >> t[i][j];
	rep(i,50)rep(j,50) cin >> p[i][j];
	string ans = mountain();
	cout << ans << endl;
}


#include <iostream>
#include <iomanip>
using namespace std;

int main(void){
    int A, B;
    cin >> A >> B;
    cout << setprecision(10) << 100.0L-100.0L*(long double)B/(long double)A << endl;
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	int A, B;
	cin >> A >> B;
	cout << (A + B) / 2<<"\n";
	cout << (A - B) / 2;
	return 0;
}


#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const double GS = 1e-7;

int main() {
	int n;
	cin >> n;
	vector<int>x(n), y(n);
	rep(i, n)cin >> x[i] >> y[i];
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				int tmp = min(y[i], y[j]);
				int mi = min(y[k], tmp);
				double k1 = 0, k2 = 0;
				if (mi == y[i]) {
					 k1 = (double)(y[j] - y[i]) / (x[j] - x[i]);
					 k2 = (double)(y[k] - y[i]) / (x[k] - x[i]);
				}
				else if (mi == y[j]) {
					 k1 = (double)(y[i] - y[j]) / (x[i] - x[j]);
					 k2 = (double)(y[k] - y[j]) / (x[k] - x[j]);
				}
				else {
					 k1 = (double)(y[i] - y[k]) / (x[i] - x[k]);
					 k2 = (double)(y[j] - y[k]) / (x[j] - x[k]);
				}
				if (abs(k1 - k2) <= GS || ((x[i] == x[j]) && (x[k] == x[i]))) {
					cout << "Yes" << endl;
					//cout << i << j << k << endl;
					//printf("%.16f", k1);
					//cout << endl;
					//printf("%.16f", k2);
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

// DeNsE - EcLiPsE //
// WHAT is DEAD may NEVER die //

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <set>
#include <cstring>
#include <stack>
#include <sstream>
#include <queue>
#include <unordered_set>
#include <cstdlib>

using namespace std;

#define nitro ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define double long double
#define endl " \n"

const int inf = (1ll << 62) - 1;
const int mod = 998244353;
const int N = 25;
const double pi = 3.14159265358979323846;

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

int gcd(int a, int b)
{
    if(a < b)
        swap(a, b);
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

vector<int> fact(N, 0ll);
void factorial(){
    fact[0] = 1, fact[1] = 1;
    for(int i = 2; i < N; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
}

int ncr(int n, int r){
    if(r > n)
        return 0;
    int ans = fact[n] % mod;
    ans *= bPow(fact[r], mod - 2) % mod;
    ans %= mod;
    ans *= bPow(fact[n - r], mod - 2) % mod;
    ans %= mod;
    return ans;
}

vector<int> primes(N, -1);
void sieve(){
    iota(primes.begin(), primes.end(), 0);
    for (int i = 2; i * i <= N; ++i) {
        if(primes[i] == i){
            for (int j = 2 * i; j < N; j += i) {
                primes[j] = i;
            }
        }
    }
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> pts;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        pts.emplace_back(x, y);
    }
    for (int i = 0; i < n; ++i) {
        int x = pts[i].first, y = pts[i].second;
        map<double, int> slopes;
        bool haveInfinite = false;
        for (int j = i + 1; j < n; ++j) {
            int dx = pts[j].first - x, dy = pts[j].second - y;
            if(dx == 0 and haveInfinite) {
                cout << "Yes" << endl;
                return;
            }else if(dx != 0){
                double val = (double) dy / (double) dx;
                if(slopes.count(val)){
                    cout << "Yes" << endl;
                    return;
                }
                slopes[val]++;
            }
            if(dx == 0)
                haveInfinite = true;
        }
    }
    cout << "No" << endl;
}

signed main(){
    nitro
    int tc = 1, test = 1;
    //cin >> tc;
    while(tc--){
        //cout << "Case #" << test++ << ": ";
        solve();
    }
}


#include <bits/stdc++.h>

using ll = long long;
const int maxn = 1e6 + 222;
int n;
ll a[maxn],s[maxn];
ll ans = 9e18;

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; ++ i)
		scanf("%lld",&a[i]);
	std::sort(a + 1,a + n + 1);
	for (int i = n; i >= 1; i --)
		s[i] = s[i + 1] + a[i];
	for (int i = 0; i <= n; ++ i) {
		// 2x = a[i]
		ans = std::min(ans,n * a[i] + s[i + 1] * 2 - 2 * a[i] * (n - i));
	} printf("%.10Lf",(long double) ans / (n * 2.0));
	return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<vi> vvi;

typedef set<int> si;

#define vt vector
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ts to_string
#define EACH(x, a) for (auto& x: a)

template<class T> void read(T &x){ cin >> x; }
template<class A> void read(vt<A> &v){ EACH(x, v) read(x); }
template<class H, class... T> void read(H& h, T& ...t){ read(h); read(t...); }

str to_string(const char* c){ return (str)c; }
str to_string(char c){ return (str)""+c; }
str to_string(str s){ return s; }
str to_string(bool b){ return b?"True" : "False"; }
template<class A> str to_string(vt<A> v){ str s; EACH(x, v) s+= to_string(x) + " "; return s; }
template<class H, class... T> str to_string(H& h, T& ...t){ str s; s+=to_string(h); s+=" "; s+=to_string(t...); return s; }
void print(str s){ cout << s << "\n"; }
template<class... A> void print(A ...a){ print(to_string(a...)); }

int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); }
str tb(int x) {str ans; int c = x; for(int i = log2(x); i >= 0; --i){if(pow(2,i) <= c){ ans += "1"; c-=pow(2,i); } else { ans += "0"; } } return ans;}
bool ispr(int x){if(x <= 1){return false;} for(int i = 2; i <= sqrt(x); ++i){ if(x%i == 0){ return false; } }return true; }

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const double EPS = 2e-7;

//tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> T;

void solve(){
	int n; cin >> n;
	vd v(n); read(v);
	double l = 0, r = 2e11;
	double bes = double(INF);

	while(r-l > EPS){
		double mid1 = l+(r-l)/3;
		double mid2 = r-(r-l)/3;
		double cur1 = 0;
		double cur2 = 0;
		for(int i = 0; i < n; ++i){
			cur1+=(mid1+v[i]-min(v[i],2*mid1));
		}
		for(int i = 0; i < n; ++i){
			cur2+=(mid2+v[i]-min(v[i],2*mid2));
		}
		if(cur1 < cur2){
			bes = min(bes,cur1);
			r = mid2;
		}
		else{
			bes = min(bes,cur2);
			l = mid1;
		}
	}

	printf("%.6f\n", bes/(db)n);
}

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

	bool isT = 0;
	if(isT){
		int t; cin >> t; while(t--){
			solve();
		}
		return 0;
	}
	solve();
	return 0;
}


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

//editorial

int main(){
    int n;
    string s, x;
    cin >> n >> s >> x;

    vi dp(n+1, 0);
    dp[n] = 1;//dp[n] = {0};
    for(int i=n-1; i>=0; i--){
        if(x[i]=='T'){
            rep(r, 7){
                if( ( 1<<(10*r%7) )&dp[i+1] )dp[i] |= 1<<r;
                if( ( 1<<((10*r + s[i]-'0')%7) )&dp[i+1] )dp[i] |= 1<<r;
            }
        }
        else{
            rep(r, 7){
                if( ( 1<<(10*r%7) )&dp[i+1] && ( 1<<((10*r + s[i]-'0')%7) )&dp[i+1] )dp[i] |= 1<<r;
            }
        }
    }
    cout << (dp[0]&1?"Takahashi":"Aoki") << endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long, long long>
using namespace std;

const int mod = 1e9+7;
#define INF INT_MAX

int sum(int x, int y)
{
	return (x+y)%mod;
}

int mult(int x, int y)
{
	return (1ll * x * y)% mod;
}

int fastpow(int val, int pow)
{
	int res = 1;
	while(pow > 0)
	{
		if(pow % 2 != 0)
			res = mult(res, val);
		val = mult(val, val);
		pow/=2;
	}
	return res;
}

vector<vector<int>> matmult(vector<vector<int>> &mat1, vector<vector<int>> &mat2)
{
	vector<vector<int>> res(mat1.size(),vector<int>(mat1[0].size(),0));
	int m = mat1.size(), n = mat1[0].size();
	for(int i=0;i<m;i++)
	{
		for(int j = 0; j < n; j++)
		{
			for(int k=0;k<n;k++)
			{
				res[i][j] = sum(res[i][j], mult(mat1[i][k], mat2[k][j]));
			}
		}
	}

	return res;
}

vector<vector<int>> matexp(vector<vector<int>> mat, int pow)
{
	vector<vector<int>>res(mat.size(), vector<int>(mat[0].size(),0));

	for(int i=0;i<mat.size();i++)
		res[i][i] = 1;

	while(pow > 0)
	{
		if(pow%2!=0)
			res  = matmult(res, mat);
		pow/=2;
		if(pow == 0)
			break;
		mat = matmult(mat, mat);

	}

	return res;
}

vector<int> deg(105);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> a(n);

	int inv_2 = fastpow(2,mod-2);
	int inv_m = fastpow(m,mod-2);
	vector<vector<int>> mat(n, vector<int>(n,0));
	for(int i=0;i<n;i++)
		cin>>a[i];

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		deg[x]++;
		deg[y]++;
		mat[x][y] = mult(inv_2, inv_m);
		mat[y][x] = mult(inv_2, inv_m);

	}

	for(int i=0;i<n;i++)
	{
		mat[i][i] = mult(sum(mult(2,m), -deg[i]),mult(inv_2,inv_m));
	}
	mat = matexp(mat,k);
	vector<int> res(n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			res[i] = sum(res[i], mult(a[j],mat[j][i]));
	}
	for(int i=0;i<n;i++)
		cout<<res[i]<<"\n";

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
vi matmul(vi dp,vvi mt,int n){
    vi res(n);
    rep(i,n)rep(j,n)res[i]+=mt[i][j]*dp[j]%mod;
    rep(i,n)res[i]%=mod;
    return res;
}
vvi update(vvi mt,int n){
    vvi res(n,vi(n));
    rep(i,n)rep(j,n)rep(k,n)res[i][j]+=mt[i][k]*mt[k][j]%mod;
    rep(i,n)rep(j,n)res[i][j]%=mod;
    return res;
}
void matpow(vi &dp,vvi mt,ll k,int n){
    while(k){
        if(k&1)dp=matmul(dp,mt,n);
        mt=update(mt,n);
        k>>=1;
    }
}
/*
int main(){
    ll n,k;cin>>n>>k; //nは分かってる項数、kは求めたいのが何項目か
    vi dp(n);
    rep(i,n)cin>>dp[n-i-1];
    if(k<=n)dame(dp[n-k]); //分かっている
    vvi mt(n,vi(n));
    rep(i,n)cin>>mt[0][i]; //遷移の式
    REP(i,1,n)mt[i][i-1]=1; //こうすると上手くいく
    matpow(dp,mt,k-n,n);
    out(dp[0]);
}
*/

//ABC009D 漸化式
int main(){
    ll n,m,k;cin>>n>>m>>k;
    vvi mt(n,vi(n));
    vi dp(n);rep(i,n)cin>>dp[i];
    ll tmp=modpow(m,mod-2);
    ll tmp2=modpow(2,mod-2);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        mt[a][b]=tmp2;
        mt[b][a]=tmp2;
    }
    rep(i,n){
        ll sum=0;
        rep(j,n)sum+=mt[i][j];
        mt[i][i]=(m+mod-sum%mod)%mod;
    }
    rep(i,n)rep(j,n)mt[i][j]=mt[i][j]*tmp%mod;
    matpow(dp,mt,k,n);
    for(ll x:dp)out(x);
}


#include<bits/stdc++.h>
using namespace std;
inline long long read(){
    long long x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
struct node{
	long long A,B;
}v[200100];
bool cmp(node a,node b){
	return a.A<b.A;
}
int main(){
	long long n=read(),k=read();
	for(int i=1;i<=n;++i)v[i].A=read(),v[i].B=read();
	sort(v+1,v+1+n,cmp);
	int i;
	v[0].A=0;
	for(i=1;i<=n;++i){
		if(k<v[i].A-v[i-1].A){
			break;
		}
		k-=v[i].A-v[i-1].A;k+=v[i].B;
	}
	--i;
	cout<<v[i].A+k<<endl;
    return 0;
}

#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int MAXN = (1 << 18);
int n, m;
bool matrix[18][18], good[MAXN];
int dp[MAXN];

bool check(int x) {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (j != i)
                if (((x >> i) & 1) && ((x >> j) & 1) && !matrix[i][j])
                    return false;
    return true;
}

signed main() {
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        matrix[a][b] = matrix[b][a] = 1;
    }
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i < (1 << n); i++)
        if (check(i)) good[i] = 1, dp[i] = 1;
    for (int i = 1; i < (1 << n); i++) {
        if (good[i]) continue;
        for (int j = i; j; j = (j - 1) & i)
            dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
    }
    cout << dp[(1 << n) - 1];
    return 0;
}


 #include <bits/stdc++.h>
#define ll         long long int
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007ll
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(ll i=0;i<n;i++)
#define f1(i,x,y)  for(ll i=x;i<=y;i++)
#define f2(i,x,y)  for(ll i=x;i>=y;i--)
#define yes        cout<<"Yes"<<"\n"
#define no         cout<<"No"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
#define moddif(a,b)  ((a%mod)-(b%mod)+mod)%mod
#define modsumt(a,b,c) modsum(a,modsum(b,c))
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes
//__builtin_ctz(x)      to count the number of trailing zeroes
//__gcd(a,b)
using namespace std;
ll fac[200025];
ll modIfac[200025];
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=modpro(result,x);
        x=modpro(x,x);
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    // This is checked so that we can skip
    // middle five numbers in below loop
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
// Returns n^(-1) mod p
ll  modInverse(ll n, ll p)
{
    return modularExponentiation(n, p - 2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCrModPFermat(unsigned long long n,
                                 ll r, ll p)
{
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

bool compare(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.F==b.F)
        return a.S<b.S;
    else
        return a.F>b.F;
}
ll check(ll x,ll y)
{
    ll z=1;
    ll ans=0;
    while(z<x){ans++;z*=y;}
    return ans;
}
ll countbits(ll n)
{
    ll x=0;
    while(n>0)
    {
        x++;
        n=(n&(n-1));
    }
    return x;
}
int main()
{
 ios_base::sync_with_stdio(false);
 ll t,n;
 cin>>t>>n;
 ll x=100*n;
 ll y=x/t;
 if(x%t) y++;
 cout<<y+n-1;
}

#include <bits/stdc++.h>

using namespace std;

using ll=long long;
#define pb push_back

int main()
{
    ll tc,n,t;
    cin>>t>>n;
    cout<<(n*100)/t-((n*100)%t==0) + n<<" ";

    return 0;
}


#include<map>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 100005
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
	LL f = 1,x = 0;char s = getchar();
	while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
	while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
	return f * x;
}
const int MOD = 1000000007;
int n,m,i,j,s,o,k;
int a[MAXN];
int dp[MAXN];
int main() {
	n = read();
	int sum = 0,sum2 = 0;
	dp[0] = 1; dp[1] = 1;
	for(int i = 2;i <= n;i ++) {
		dp[i] = (dp[i-1]+dp[i-2]) % MOD;
	}
	for(int i = 1;i <= n;i ++) {
		a[i] = read();
		(sum += a[i]) %= MOD;
		if(i > 1) {
			(sum2 += dp[i-2] *1ll* dp[n-i] % MOD *2ll* a[i] % MOD) %= MOD;
		}
	}
	printf("%lld\n",(sum*1ll*dp[n]%MOD+MOD-sum2) % MOD);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=INF;
const ll MAX=100010;

signed main(){
    ll n;cin>>n;
    ll ans=n;
    ll k=1;
    ll cnt=0;
    while(n>=k){
        ans=min(ans,n/k+cnt+n%k);
        cnt++;
        k*=2LL;
    }
    cout<<ans<<endl;
}


# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using tl = tuple<ll, ll, ll, ll>;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
using ld = long double;

int N, dp[1 << 7][200001];
string S, X;

int mod(int i){
    i = i % 7;
    return i < 0 ? i + 7 : i;
}
int solution(int mask, int n){
    if(dp[mask][n]) return dp[mask][n];
    if(n == N) return dp[mask][n] = (mask & 1) ? 1: - 1;
    int tmp = 0;
    rep(i, 0, 7){
        if(mask & (1 << i)){
            tmp |= 1 << mod(i * 10 + S[n] - '0');
            tmp |= 1 << mod(i * 10);
        }
    }
    //if(n < N - 1 && X[n] == X[n + 1]) return dp[mask][n] = solution(tmp, n + 1);
    rep(i, 0, 7){
        if(tmp & (1 << i)){
            if(X[n] == 'A') if(solution(1 << i, n + 1) == -1) return dp[mask][n] = -1;
            if(X[n] == 'T') if(solution(1 << i, n + 1) == 1) return dp[mask][n] = 1;
        }
    }
    if(X[n] == 'A') return dp[mask][n] = 1;
    return dp[mask][n] = -1;
}

int main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> S >> X;
    cout << (solution(1, 0) == 1 ? "Takahashi" : "Aoki");
}

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

#define ll long long
#define print(a)          \
    for (auto x : a)      \
        cout << x << " "; \
    cout << endl
#define print_upto(a, n)        \
    for (ll i = 1; i <= n; i++) \
        cout << a[i] << " ";    \
    cout << endl
#define take(a, n)              \
    for (ll i = 1; i <= n; i++) \
        cin >> a[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"

void my_debugger(string s, int LINE_NUM)
{
    cerr << endl;
}
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
    if (s.back() != ',')
    {
        s += ',';
        cerr << "LINE(" << LINE_NUM << "): ";
    }
    int i = s.find(',');
    cerr << s.substr(0, i) << " = " << x;
    s = s.substr(i + 1);
    if (!s.empty())
        cerr << ", ";
    my_debugger(s, LINE_NUM, y...);
}
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(15) << ans << nl;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> ppll;

const ll N = 200009;

void solve()
{
    ll m, h;
    cin >> m >> h;

    if (h % m == 0)
    {
        cout << "Yes" << nl;
    }
    else
    {
        cout << "No" << nl;
    }
}

int main()
{

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

    ll T = 1;
    // cin >> T;

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

    return 0;
}


#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
using namespace std;

int main(){
  long int N;
  cin >> N;
  int p=1;
  long long a;
  vector<long long> B(N);
  for (int i=0; i<N; i++){
    cin >> a;
    B[i]=p*a;
    p=-p;
  }
  vector<long long> S(N+1);
  S[0]=B[0];
  for (int i=1; i<N; i++){
    S[i]=S[i-1]+B[i];
  }
  S[N]=0;
  sort(S.begin(), S.end());
  long long M=0;
  long int m=1;
  for (int i=1; i<N+1; i++){
    if ((i==N)&(S[i]==S[i-1])){
      m++;
      M=M+(m*(m-1))/2;
    }
    else if (S[i]==S[i-1]){
      m++;
    }
    else {
      M=M+(m*(m-1))/2;
      m=1;
    }
  }
  cout << M << endl;
}

#include<bits/stdc++.h>
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define ps() cout << "\n"
#define pb push_back
#define ff first
#define ss second

typedef long long ll;

using namespace std;
const int MOD = 1e9 + 7, MOD1 = (119 << 23) | 1;
const int INF = 1e9 + 5, MAX = 2e5 + 5;
int main(){
   cpu();
   int n; cin >> n;
   map<ll, int> m;
   ll cur[2] = {};
   ll ans = 0;
   m[0] = 1;
   for(int i = 0; i < n; i++){
      ll x; cin >> x;
      cur[i & 1] += x;
      ans += (m[cur[1] - cur[0]]++);
   }
   cout << ans << "\n";
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,p,ans,bs;
long long MOD=1000000007;
int main()
{
	cin>>n>>p;
	if(p==2)
	{
		if(n==1)cout<<"1";
		else cout<<"0";
	}
	else if(p==3)cout<<"2";
	else
	{
		ans=(p-1)%MOD;
		bs=(p-2)%MOD;
		n--;
		while(n)
		{
			if(n&1==1)ans=(ans*bs)%MOD;
			bs=(bs*bs)%MOD;
			n>>=1;
		}
		cout<<ans%MOD;
	}
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep1(i, n) for (int i = n; i >= 1; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define eb emplace_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef long long int ll;
typedef pair<int, int> P;
// typedef modint1000000007 mint;

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

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/*--------------------------------------------------*/
const int INF = 1e9;
// const ll INF = 1e18;
const int MAX = 1e5;

ll power_mod(ll n, ll p, ll mod) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        ll t = power_mod(n, p / 2, mod);
        return t * t % mod;
    }
    return n * power_mod(n, p - 1, mod) % mod;
}

const ll mod = 1000000007;

void solve() {
    ll n, p;
    cin >> n >> p;
    ll ans = p - 1;
    ans = ans * power_mod(p - 2, n - 1, mod) % mod;
    cout << ans << "\n";
}

int main() {
    speedUpIO();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        // cout << solve() << "\n";
        // cout << fixed << setprecision(15) << solve() << "\n";
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> a >> b;
  ans = n - a + b;
  out(ans);
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

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

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g,w,h;
    string ss;
    cin>>h>>w>>x>>y;
    string s[h];
    for0(h)cin>>s[i];
    x--;
    y--;
    if(s[x][y]=='#')f=0;
    for(i=x+1;i<h;i++)
    {
        if(s[i][y]=='#')break;
        else f++;
    }
    for(i=x-1;i>=0;i--)
    {
        if(s[i][y]=='#')break;
        else f++;
    }
    for(i=y+1;i<w;i++)
    {
        if(s[x][i]=='#')break;
        else f++;
    }
    for(i=y-1;i>=0;i--)
    {
        if(s[x][i]=='#')break;
        else f++;
    }
    cout<<f<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxS = 41;
int arr[maxS];
vector<long long>A[2];

void rec(int currentPos,int size,int idx,long long sum){
	if(currentPos > size){
		A[idx].push_back(sum);
		return ;
	}
	rec(currentPos + 1,size,idx,sum + arr[currentPos]);
	rec(currentPos + 1,size,idx,sum);
}

void tc(){
	int N , T;
	cin >> N >> T;
	for(int i = 1 ; i <= N ;i ++){
		cin >> arr[i];
	}
	rec(1,N/2,0,0);
	rec((N/2)+1,N,1,0);
	sort(A[1].begin(),A[1].end());
	long long MAX = 0;
	for(int i = 0 ; i < (int)A[0].size(); i ++){
		long long TEMP = A[0][i];
		long long REM = T - TEMP;
		if(REM > 0){
			auto itr = lower_bound(A[1].begin(),A[1].end(),REM);
			if(itr==A[1].begin()&&*itr!=REM)
				continue;
			if(itr==A[1].end())
				--itr;
			else{
				if(*itr!=REM)
					--itr;
			}
			MAX = max(MAX , *itr + TEMP);
		}
		}
		cout << MAX << "\n";
	}

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

}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n, m; cin >> n >> m;
    vector<int> c(n);
    vector<vector<int>> g(n, vector<int>());
    vector<int> a(m), b(m);
    vector<int> ans(m, -1);
    map<P, P> mp;
    rep(i, m) {
        cin >> a[i] >> b[i]; -- a[i], -- b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        mp[{a[i], b[i]}] = {i, 1}, mp[{b[i], a[i]}] = {i, 0};
    }
    rep(i, n) {
        cin >> c[i];
    }
    vector<bool> used(m, 0);
    rep(i, m) {
        if(c[a[i]] < c[b[i]]) {
            // <-
            ans[i] = 0;
            used[i] = 1;
        } else if(c[a[i]] > c[b[i]]) {
            // ->
            ans[i] = 1;
            used[i] = 1;
        }
    }
    auto rec = [&](auto && self, int p, int v) -> void {
        for(int nv: g[v]) {
            if(nv == p) continue;
            if(c[v] == c[nv]) {
                // v -> nv
                if(mp.count({v, nv})) {
                    P p = mp[{v, nv}];
                    int i = p.fr, val = p.sc;
                    if(used[i]) continue;
                    used[i] = 1;
                    ans[i] = val;
                    self(self, v, nv);
                }
            }
        }
    };
    rep(i, m) {
        if(!used[i]) {
            assert(c[a[i]] == c[b[i]]);
            used[i] = 1;
            ans[i] = 1;
            rec(rec, a[i], b[i]);
        }
    }
    rep(i, m) {
        assert(ans[i] != -1);
        if(ans[i] == 1) cout << "->" << "\n";
        else cout << "<-" << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define getchar_unlocked getchar

int A[100005];
int B[100005];
int offset[100005];
int minLevel1[100005];
int minLevel2[100005];
int N, L;

inline int nextInt(){
    int x=0;
    char ch=0;
    do{
        ch=getchar_unlocked();
    }while(ch<'0'||ch>'9');
    while(ch>='0'&&ch<='9'){
        x=10*x+(ch-'0');
        ch=getchar_unlocked();
    }
    return x;
}

int main(){
    N = nextInt();
    L = nextInt();
    for(int i = 1; i <= N; i ++){
        A[i] = nextInt();
        offset[i] = A[i]-i;
    }
    for(int i = 1; i <= N; i ++){
        B[i] = nextInt();
    }

    for(int i = 1; i <= N; i ++){
        minLevel1[i] = 0;
        minLevel2[i] = 0;
        //printf("offset[%d]=%d\n", i, offset[i]);
    }

    long long ans = 0;
    int lo = 1;
    int hi2 = 1;
    for(int i = 1; i <= N; i ++){
        if(A[i] == B[i]){continue;}
        if(B[i] == i || B[i] == L-N+i){
            ans ++;
        }else{
            while(offset[lo] < B[i]-i && lo < N+2){
                lo ++;
            }

            if((lo == N+2) || (offset[lo] != B[i]-i)){
                printf("-1");
                return 0;
            }

            //hi2 = max(hi2, lo);
            while(offset[hi2] <= B[i]-i && hi2 < N+2){
                hi2 ++;
            }

            int hi = hi2-1;
            //int hi = upper_bound(offset+1, offset+(1+N), B[i]-i) - offset - 1;

            if(lo > i){
                minLevel2[lo] = max(minLevel2[lo], lo - i);
            }else{
                minLevel1[hi] = max(minLevel1[hi], i - hi);
            }

            //printf("i=%d [%d, %d]\n", i, lo, hi);
            //ans += min(abs(lo - i), abs(hi - i));
        }
    }

    for(int i = 1; i <= N; i ++){
        ans += minLevel1[i] + minLevel2[i];
    }

    printf("%lld\n", ans);
    return 0;
}


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

const int N = 20;

mt19937 mt;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    mt.seed(time(nullptr));
    int n, m;
    cin >> n >> m;
    vector<string> v(m);
    for (auto& i : v) {
        cin >> i;
    }
    //sort(v.begin(), v.end(), [](string a, string b){return a.size() < b.size();});
    shuffle(v.begin(), v.end(), mt);
    int ind[10] = {};
    for (auto& i : v) {
        for (auto& j : i) {
            ++ind[j - 'A'];
        }
    }
    char a[N][N];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            a[i][j] = char(mt() % 8 + int('A'));
        }
    }
    /*int i = 0, j = 0;
    for (auto s : v) {
        if (j + s.size() >= n) {
            j = 0;
            ++i;
        }
        if (i >= n) {
            break;
        }
        for (int k = 0; k < s.size(); ++k, ++j) {
            a[i][j] = s[k];
        }
    }*/
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << a[i][j];
        }
        cout << '\n';
    }
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << "{ " << p.first << ',' << p.second << " } ";
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e: v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e: v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

int n, m;
V<string> s;

// fstream out("AHC004_out.txt");

int main() {

    clock_t start = clock();

    cin >> n >> m;
    s.resize(m);
    cin >> s;

    V<P> cnts(m); // pair = (count, index);
    V<V<int>> ins(m);

    rep(i,m) {
        int cnt = 0;
        rep(j,m) {
            bool isin = ( s[i].find(s[j]) != string::npos );
            if(isin) {
                cnt++;
                ins[i].push_back(j);
            }
        }
        cnts[i] = make_pair(cnt,i);
    }
    sort(rall(cnts));

    V<bool> used(m);
    V<string> ans(n);

    rep(i,n) { // 初期解生成
        string str = "";
        rep(j,m) {
            int x = cnts[j].se;
            if(used[x]) continue;
            string plus = s[x];
            for(int k = min(sz(str), sz(s[x])); k >= 0; k--) {
                if( str.substr(sz(str)-k,k) == s[x].substr(0,k) ) {
                    plus = s[x].substr(k,sz(s[x])-k);
                    break;
                }
            }
            if(sz(str) + sz(plus) > n) continue;
            str += plus;
            for(int y: ins[x]) used[y] = true;
        }
        str.resize(n,'.');
        ans[i] = str;
    }

    V<int> v(n); iota(all(v), 0);
    pair<int,V<int>> mx = make_pair(0,v);

    random_device seed_gen;
    mt19937 engine(seed_gen());

    while(clock() - start < 2980000) {
        V<bool> nused = used;
        int cnt = 0;
        rep(j,n) { // yoko
            string ns = "";
            rep(i,n) ns += string(1,ans[v[i]][j]);
            ns += ns;
            rep(j,m) {
                if(nused[j]) continue;
                if( ns.find(s[j]) != string::npos ) {
                    cnt++;
                    nused[j] = true;
                }
            }
        }
        chmax(mx, make_pair(cnt, v));
        shuffle(all(v), engine);
    }

    rep(i,n) {
        cout << ans[mx.se[i]] << endl;
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  for(int i=0;i<N;i++){
    cin >> A.at(i+1);
    A.at(i+1)+=A.at(i);
  }
  long long maxans=0;
  long long C=0;
  long long D=0;
  for(int i=0;i<N+1;i++){
    D=max(D,A.at(i));
    maxans=max(maxans,C+D);
    C+=A.at(i);
  }
  cout << maxans << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

const ll MOD = 1e9 + 7;

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

    vll x(n, 0);
    x[0] = a[0];
    for(int i = 1; i < n; i++) x[i] = x[i-1] + a[i];

    vll maxx(n, 0);
    ll mx = 0;
    rep(i, n) {
        maxx[i] = max(mx, x[i]);
        chmax(mx, x[i]);
    }

    vll p(n+1, 0);
    rep(i, n) p[i+1]=p[i]+x[i];

    ll ans = 0;
    for(int i = 0; i < n; i++) chmax(ans, p[i]+maxx[i]);

    cout << ans << endl;

    //for(int t:maxx) cout << t << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

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

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

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

void solve() {
    int N, W;
    cin >> N >> W;
    int lim = 212345;
    vector<ll> neri(lim);

    for (int i = 0; i < N; ++i) {
        ll s, t, p;
        cin >> s >> t >> p;
        neri[s] += p;
        neri[t] -= p;
    }
    for (int i = 0; i + 1 < lim; ++i) {
        neri[i + 1] += neri[i];
    }
    for (int i = 0; i < lim; ++i) {
        if (neri[i] > W) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, w, ans = 0;
  cin >> n >> w;
  vector<ll> imos(200005, 0);

  rep(i, n) {
    ll s, t, p;
    cin >> s >> t >> p;
    imos[++s] += p;
    imos[++t] -= p;
  }

  bool ok = true;
  rep(i, 200004) {
    imos[i + 1] += imos[i];
    if (imos[i + 1] > w) ok = false;
  }

  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


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

# define endl "\n"
# define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef unsigned long long int ulli;
typedef long long int lli;
typedef unsigned int ui;

int a[3];

int main(){
    cin >> a[0] >> a[1] >> a[2];
    if(2 * a[1] == a[2] + a[0]) cout << "Yes" << endl;
    else if(2 * a[0] == a[2] + a[1]) cout << "Yes" << endl;
        else if(2 * a[2] == a[0] + a[1]) cout << "Yes" << endl;
        else cout << "No" << endl;
    return 0;
}

#include<bits/stdc++.h>
#define endl '\n'
#define ri register
#define QAQ(m, n) for(ri ll i = m;i <= n;i++)
#define QWQ(m, n) for(ri ll j = m;j <= n;j++)
#define uQAQ(n, m) for(ri ll i = n;i >= m;--i)
#define uQWQ(n, m) for(ri ll j = n;j >= m;--j)
#define ALL(a) a.begin(), a.end()
#define all(a, n) a + 1, a + n + 1
#define fin(a) freopen(a, "r", "stdin")
#define fout(a) freopen(a, "w", "stdout")
#define pb push_back
#define mkp make_pair
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll a[4];
int main ()
{
	std::cin.tie (0);
	std::ios::sync_with_stdio (false);
	cin >> a[1] >> a[2] >> a[3];
	sort(all(a,3));
  	cout << ((a[3]-a[2]==a[2]-a[1])?("Yes"):("No"));
	return 0;
}


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

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

#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}
ll lcm(ll a, ll b) { //最小公倍数
    return a * b / gcd(a, b);
  }

ll digit_sum(ll a){ //10進桁和
    ll ans=0;
    while(a>0){
      ans+=a%10;
      a/=10;
    }
    return ans;
  }

int main(){
    ll a,b;
    cin >> a >> b ;
    cout << 2*a+100-b << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,k;cin>>n>>k;
    vector<pair<ll,ll>> a(n);
    rep(i,n) cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    ll tmp=0;
    rep(i,n){
        ll x=a[i].first,y=a[i].second;
        if(k<x-tmp){
            cout<<tmp+k<<endl;
            return 0;
        }
        k+=y;
    }
    cout<<tmp+k<<endl;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main(){
  long long k, n;
  pair<long long, long long> m[(int)2e5];
  scanf("%lld%lld", &n, &k);

  for (int i=0;i<n;++i){
  	scanf("%lld%lld", &m[i].first, &m[i].second);
  }

  sort(m,m+n);

  long long current = 0;
  for (int i=0;i<n;i++){
    if (m[i].first-current > k) break;
    k -= m[i].first - current;
    current = m[i].first;
    k += m[i].second;
  }
  cout << current + k <<endl;
  return 0;
}


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

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define MAX(v) (*max_element((v).begin(), (v).end()))
#define MIN(v) (*min_element((v).begin(), (v).end()))
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

inline void modsum(int&a, int b){a += b;if(a >= mod) a -= mod;if(a < 0) a += mod;}
inline void modmul(int&a, int b){a = 1ll*a*b % mod;}
inline int modexp(ll b, ll p){b %= mod;int res = 1;int mul = b;while(p){if(p&1) modmul(res, mul);p >>= 1;modmul(mul, mul);}return res;}

const int N = 1e5 + 5;
struct E{
	int u, c, d;
};
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin>>n>>m;
	vector<E> g[n+1];
	FOR(i, m){
		int a, b, c, d; cin>>a>>b>>c>>d;
		g[a].pb(E{b, c, d});
		g[b].pb(E{a, c, d});
	}
	set<pair<long long, int>> q;
	q.insert({0, 1});
	long long dist[n+1];
	FOR(i, n+1) dist[i] = 1e18;
	bool vis[n+1] = {};
	dist[1] = 0;
	while(!q.empty()){
		pair<long long, int> foo = *q.begin();
		q.erase(q.begin());
		int cur = foo.second;
		if(vis[cur]) continue;
		vis[cur] = true;
		ll cur_t = dist[cur];
		for(E& nxt: g[cur]){
			int u = nxt.u, c = nxt.c, d = nxt.d;
			//init. cost = c + (d/(cur_t+1))
			//min(x + d/(cur_t+1+x)) ?
			ll x = max(0ll, (ll)sqrt(d) - cur_t);
			ll mn = c + d/(cur_t+1);
			for(ll i = max(0ll, x-500); i <= x+500; i++){
				mn = min(mn, c + i + d/(cur_t+1+i));
			}
			if(dist[u] <= dist[cur] + mn) continue;
			dist[u] = dist[cur] + mn;
			q.insert({dist[u], u});
		}
	}
	if(!vis[n]) cout<<-1;
	else cout<<dist[n];
}

//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define SET set<int>
#define dq deque<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x);  ->  printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;
int c[maxn],d[maxn];
vc<P>have;
void change(int z,int y)
{
    have.pb({z,y});
    swap(c[z],c[y]);
    d[c[z]]=z,d[c[y]]=y;
}
void deal(int x)
{
    if(b[c[x]]<a[d[x]]){
        change(x,d[x]);
        return ;
    }
    while(b[c[x]]>=a[d[x]] && d[x]!=x)deal(d[x]);
    if(d[x]!=x)change(x,d[x]);
}
void solve()
{
    cin>>n;
    fun(i)cin>>a[i];
    fun(i)cin>>b[i];
    fun(i) {
        cin >> c[i], d[c[i]] = i;
        if(c[i]!=i && b[c[i]]>=a[i]){out(-1)return;}
    }
    fun(i)
    {
        if(d[i]!=i)deal(i);
    }
    out(have.size())
    fa(i,have)cout<<i.fi<<" "<<i.se<<endl;
    return ;
}
main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'

#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define tr(c, it) for (auto it = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      // for sets, multisets, maps etc.
#define cpres(c, val) (find((c).begin(), (c).end(), val) != (c).end()) // for others

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)

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

const int INF = 9e18;
const int N = 1000000007;
//const int N = 998244353;
const double eps = 1e-9;

const auto start_time = std::chrono::high_resolution_clock::now();

void zark() {
  #ifdef ZARK
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time - start_time;
    cerr << "Time Taken: " << diff.count() << "s\n";
  #endif
}

#ifdef ZARK
  #include "/home/aranjan/Desktop/CP/header.h"
  #else
  #define debug(args...) 42
#endif

/* ------------------ Actual Coding Starts ------------------ */

int mpow(int a, int n) {
  a %= N;
  if(n == 0) return 1;
  else if(n&1) return (mpow(a, n-1)*a)%N;
  else {
    int k = mpow(a, n/2)%N;
    return (k*k)%N;
  }
}

int inv(int a) {
  a %= N;
  return mpow(a, N-2);
}

void solve() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  fo(i, n) cin >> a[i];
  int s = accumulate(all(a), 0);
  int p1 = 1, p2 = 1;
  forf(i, m-s+1, m+n+1) p1 = (p1*i)%N;
  forf(i, 1, s+n+1) p2 = (p2*i)%N;
  int ans = p1;
  ans = (ans * inv(p2)) % N;
  cout << ans << '\n';
}

int32_t main() {
  fastio;
  #ifdef ZARK
    freopen("input.in", "r", stdin);
  #endif

  //freopen("sort.in", "r", stdin);
  //freopen("txt.out", "w", stdout);
  //cout << fixed << setprecision(10);

  solve();
  zark();
  return 0;
}

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

template<ll mod = 1000000007LL>
ll modpow(ll a, ll b){
    if (b == 0) return 1LL;
    ll tmp = modpow(a * a % mod, b / 2);
    if (b % 2 == 0) return tmp;
    return tmp * a % mod;
}

template<ll mod = 1000000007LL>
ll comb(ll a, ll b){
    ll n = 1, d = 1;
    for (ll i = 0; i < b; ++i){
        n = n * (i + 1) % mod;
        d = d * (a - i) % mod;
    }
    return d * modpow<mod>(n, mod - 2) % mod;
}

int main(void){
    int N; ll M;
    cin >> N >> M;
    ll S = 0;
    for (int i = 0; i < N; ++i){
        ll ai; cin >> ai;
        S += ai;
    }
    ll ans = comb(N + M, S + N);
    cout << ans << endl;
    return 0;
}