#include <bits/stdc++.h>
#include<tuple>
#pragma GCC optimize("Ofast")

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

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

ll modpow(ll x, ll y) {
    if(y == 1) {
        return x;
    }
    ll ans;
    if(y % 2 == 1) {
        ll r = modpow(x,(y-1)/2);
        ans = r * r % MOD;
        ans = ans * x % MOD;
    }
    else {
        ll r = modpow(x,y/2);
        ans = r * r % MOD;
    }
    return ans;
}

ll modncr(ll N, ll K) {
    ll res = 1;
    ll p=1;
    for (ll n = 0; n < K; ++n) {
      res = (res*(N - n))%MOD;
      p = (p*(n + 1))%MOD;
    }
    return (res*modpow(p,MOD-2))%MOD;
}

signed main() {
	ll n;
	cin >> n;
	vll a(n), b(n);
	vll s(n);
	map <ll, ll> mp;
	vector<tuple<ll, ll, ll> > tp(n);

	ll ss = 0;
	ll as = 0;
	rep(i, n) {
		cin >> a[i] >> b[i];
		s[i] = 2*a[i] + b[i];
		tp.pb(make_tuple(s[i], a[i], a[i]+b[i]));
		ss += a[i] + b[i];
		as += a[i];
	}

	rSort(tp);
	ll sum = 0;
	ll pos = 1;
	while(sum <= as) {
		sum += get<2>(tp[pos-1]);
		as -= get<1>(tp[pos-1]);
		pos++;
	}

	mes(pos-1);

}

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/*
 * WA.
 * Some overflow?
 * Got the statement wrong?
 * -> villages are not sorted :/
 */
void solve() {
    cini(n);
    cini(k);

    vector<pii> ab(n);

    for(int i=0; i<n; i++)
        cin>>ab[i].first>>ab[i].second;

    sort(all(ab));

    int pos=0;
    for(int i=0; i<n; i++) {
        pos+=k;
        k=0;
        if(pos>=ab[i].first) {
            k+=ab[i].second;
        } else {
            break;
        }
    }
    pos+=k;
    cout<<pos<<endl;
}

signed main() {
    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define x1 first
#define y1 second
#define frb(i,a,b) for(ll (i)=(a);(i) <= (b); (i)+=(i)&-(i))
#define rfrb(i,a) for(ll (i)=(a);(i) > 0;(i)-=(i)&-(i))
#define fr(i,a,b) for(ll (i) = (a); (i) <= (b); (i)++)
#define rep(i,c) for(auto (i) : (c))
#define mini(a,b) ((a) < (b)) ? (a) : (b)
#define maxi(a,b) ((a) > (b)) ? (a) : (b)
#define par pair<ll,ll>
#define vp vector<par>
#define vi vector<ll>

const ll mod = 1e9+7;
ll n;
vi g;
map<ll,ll>ar;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.setf(ios::fixed);cout.precision(0);
    cin>>n;
    ll a;
    g.push_back(0);
    fr(i,1,n){
        cin>>a;
        ar[a]++;
        if(ar[a]==1)g.push_back(a);
    }
    sort(g.begin(),g.end());
    ll id = 0,sol=1;
    rep(v,g){
        sol = ((v-id+1)*(sol))%mod;
        sol%=mod;
        id = v;
    }
    cout<<sol;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
// const int MOD = 998244353;
struct mint {
	ll x;
	mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
	mint operator-() { return mint(-x); }
	mint operator+=(mint rhs) {
		x += rhs.x;
		if (x >= MOD) x -= MOD;
		return *this;
	}
	mint operator-=(mint rhs) {
		x -= rhs.x;
		if (x < 0) x += MOD;
		return *this;
	}
	mint operator*=(mint rhs) {
		x = x * rhs.x % MOD;
		return *this;
	}
	mint operator+(mint rhs) { return mint(*this) += rhs; }
	mint operator-(mint rhs) { return mint(*this) -= rhs; }
	mint operator*(mint rhs) { return mint(*this) *= rhs; }
	mint pow(ll n) {
		mint r = 1;
		for (mint t = (*this); n; t *= t, n >>= 1)
			if (n & 1) r *= t;
		return r;
	}
	mint inv() { return (*this).pow(MOD - 2); }
	mint operator/=(mint rhs) { return *this *= rhs.inv(); }
	mint operator/(mint rhs) { return mint(*this) /= rhs; }
};
ostream &operator<<(ostream &os, const mint &dt) {
	os << dt.x;
	return os;
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	set<int> s;
	for (int i = 0; i < n; i++) {
		s.insert(a[i]);
	}
	mint ans = 1;
	int pre = 0;
	for (auto v : s) {
		ans *= v - pre + 1;
		pre = v;
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;

const int MOD = 1e9 + 7;

void E(){
     int n;
      cin>>n;
      vector<int> elems;
      ll sum = 0;
      ll res = 0;
      for(int i = 0; i < n; i++){
          int elem;
          cin>>elem;
          sum += elem;
          elems.push_back(elem);
      }
      for(int i = 0; i < n; i++){
          sum -= elems[i];
          res = (res%MOD + (elems[i]%MOD * sum%MOD))%MOD;
      }
      cout<<res<<endl;
}
void F(){
    int n, m;
    cin>>n>>m;
    int mn = 1e9;
    int grid[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int elem;
            cin>>elem;
            mn = min(mn, elem);
            grid[i][j] = elem;
        }
    }
    int res = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            res += grid[i][j] - mn;
        }
    }
    cout<<res<<endl;

}
int main(){
      F();
}

#include<bits/stdc++.h>
#define ll long long
#define mod 998244353ll
using namespace std;
ll mem[5003][5003], inv;
char str[5003][5003];
int n, m;
ll dp(int x, int y)
{
    if(x==n-1 && y==m-1)return 1;
    if(x==n || y==m)return 0;
    if(mem[x][y]!=-1)return mem[x][y];

    if(!str[x][y])mem[x][y]= (((2ll*(dp(x+1, y)+dp(x, y+1)))%mod)*inv)%mod;
    else
    {
        if(str[x][y]=='R')mem[x][y]= dp(x, y+1);
        else if(str[x][y]=='D')mem[x][y]= dp(x+1, y);
        else mem[x][y]= (dp(x+1, y)+dp(x, y+1))%mod;
    }

    return mem[x][y];
}
ll bigmod(int b, int p)
{
    if(!p)return 1;
    ll ret= bigmod(b, p/2);
    ret= (ret*ret)%mod;
    if(p&1ll)ret= (ret*b)%mod;
    return ret;
}
int main()
{
    inv= bigmod(3, mod-2);

    int k;
    scanf("%d %d %d", &n, &m, &k);

    ll external= 1ll;
    for(int i=0; i<(n*m)-k; i++)
    external= (3ll*external)%mod;

    while(k--)
    {
        char c;
        int x, y;
        scanf("%d %d %c", &x, &y, &c);
        str[x-1][y-1]= c;
    }

    memset(mem, -1, sizeof mem);
    printf("%lld\n", (external*dp(0, 0))%mod);

    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }

void Main(){
    int n, m, t; cin >> n >> m >> t;
    int tot = n;
    int prev = 0;
    rep(i, m){
        int a, b; cin >> a >> b;
        tot -= (a-prev);
        if(tot <= 0){
            Yes(0);
            return;
        }
        tot += (b-a);
        if(tot > n) tot = n;
        prev = b;
    }
    tot -= t - prev;
    Yes(tot > 0);
    return;
}

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

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

    using namespace std;
    using namespace __gnu_pbds;

    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>

    #define re(t) ll t;cin>>t;
    #define all(value) value.begin(),value.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)

    #define what(value) cerr << #value << " is " << value << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;

    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;

/*.....................................................................................................................*/

    //a.erase(unique(a.begin(),a.end()),a.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const int  mod=1e9+7,  mod2=998244353,  inf =1e18;

    long long binpow(int a,int b,int m)
    {
        a %= m;int res = 1;
        while (b > 0)
        {
            if (b & 1)res=(res*a)%m;
            a=(a*a)%m  ;    b/=2;
        }
        return res;
    }
    int modinv(int n,int m) {return binpow(n,m-2,m);}
    const ll  man =(int)2e5+5;

/*......................................................................................................................*/

signed main()
{
    fast;
    int n,m,t ;

    cin>>n>>m>>t;int n0=n;
    vector<pii>a(m);
    for(int i=0;i<m;i++)cin>>a[i].first>>a[i].second;
    int last=0;
    for(int i=0;i<m;i++)
    {
        if(a[i].first-last>=n)
        {
            // what(i)
            // what(n)
            cout<<"No"<<endl;
            return 0;
        }
        else
        {
            n-=(a[i].first-last);
            last=a[i].second;
            n+=(a[i].second-a[i].first);
            if(n>n0)n=n0;
        }
    }
    if(t-last>=n)
    {
        cout<<"No"<<endl;
        return 0;
    }

    cout<<"Yes"<<endl;
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include <iostream> // cout, endl, cin
// string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#include <string>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 998244353 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end();
#define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout;
//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

ll f(ll &k,ll &m,ll x){
    FORD(i,m,0){
        k-=nCr(m-i+x-1,m-i);
        if(k<0){k+=nCr(m-i+x-1,x-1)
        ;m-=i;return i;};

    };
    return 0;
}
signed main(){
    ll n;cin>>n;
    vector<ll> M(n+1,0),A(n+1,0);
    ll x,m=0;
    REP(i,n){
        cin>>x;
        m+=x;
        A[i+1]=A[i]+m;
        M[i+1]=max(M[i],x);
    };
    REP(i,n){
        cout<<A[i+1]+M[i+1]*(1+i)<<endl;
    }
}

/**So..a**/
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define __lcm(a, b) (a/__gcd(a, b)*b)

#define PI acos(-1)
#define EXP 10e-6
#define what_is(x) cerr << #x << " is " << x << endl;

template<typename item>
item abs(item i)
{
    if(i < 0) i= -i;
    return i;
}
ll mod = 1000000000+7;
template<class typea>
typea POW(typea b, typea p)
{
    typea res = 1;
    while(p)
    {
        if(p&1)
        {
            res*=b;
            res%=mod;
        }
        b*=b;
        b%=mod;

        p/=2;
    }
    return res;
}

int  tc =0;
#define ull unsigned long long int

#define maxn 2*100000+10
ll arr[maxn], sum[maxn], n;

int main()
{
    cin >> n;
    for(ll i=1; i<=n; i++) cin >> arr[i];
    for(ll i=1; i<=n; i++) sum[i] = arr[i]+sum[i-1];
    for(ll i= 2; i<=n; i++) sum[i]+=sum[i-1];
    ll mx =0;
    for(ll i=1; i<=n; i++)
    {
        mx = max(mx, arr[i]);
        cout<< sum[i]+(i*mx)<<NL_;
    }

}


// Problem: D - Cooking
// Contest: AtCoder - AtCoder Beginner Contest 204
// URL: https://atcoder.jp/contests/abc204/tasks/abc204_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll>
#define pl pair<ll,ll>
#define pb push_back
#define F first
#define S second
using namespace std;

ll findMin(ll arr[], ll n)
{
    // Calculate sum of all elements
    ll sum = 0;
    for (ll i = 0; i < n; i++)
        sum += arr[i];

    // Create an array to store results of subproblems
    bool dp[n+1][sum+1];

    // Initialize first column as true. 0 sum is possible
    // with all elements.
    for (ll i = 0; i <= n; i++)
        dp[i][0] = true;

    // Initialize top row, except dp[0][0], as false. With
    // 0 elements, no other sum except 0 is possible
    for (ll i = 1; i <= sum; i++)
        dp[0][i] = false;

    // Fill the partition table in bottom up manner
    for (ll i=1; i<=n; i++)
    {
        for (ll j=1; j<=sum; j++)
        {
            // If i'th element is excluded
            dp[i][j] = dp[i-1][j];

            // If i'th element is included
            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }

    // Initialize difference of two sums.
    ll diff = 10000000000;

    // Find the largest j such that dp[n][j]
    // is true where j loops from sum/2 t0 0
    for (ll j=sum/2; j>=0; j--)
    {
        // Find the
        if (dp[n][j] == true)
        {
            diff = sum-2*j;
            break;
        }
    }
    return diff;
}

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

        ll t,n,i,j,k,s=0,d;
        cin >> n;
        ll a[n];
        for(i=0;i<n;i++)
        {
        cin >> a[i];
        s+=a[i];
        }
        d=findMin(a,n);
        cout << (s+d)/2;

        return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

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

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

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

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

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

public:
    static const int MOD = MOD_;

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

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

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

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

using num = modnum<998244353>;

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

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

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

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

const int N = 105;

num dp[N][N][50 * N];

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

    int n;
    cin >> n;

    init();

    vi a(n);
    fori(i, n) cin >> a[i];

    int sum = accumulate(all(a), 0);
    if (sum % 2)
    {
        cout << 0 << endl;
        return 0;
    }

    dp[0][0][0] = 1;
    fori(i, n)
    {
        fori(j, i + 1)
        {
            fori(k, min(50 * N, 100 * j + 1))
            {
                if (dp[i][j][k] == 0)
                    continue;
                dp[i + 1][j][k] += dp[i][j][k];
                if (k + a[i] < 50 * N)
                    dp[i + 1][j + 1][k + a[i]] += dp[i][j][k];
            }
        }
    }

    num ans = 0;
    sum >>= 1;
    fori(i, n + 1){
        ans += dp[n][i][sum] * fact[i] * fact[n - i];
    }

    cout << int(ans) << endl;

    time_taken();
    return 0;
}


// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

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

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

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

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

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

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> da(n*4, -2), daa(n*2, 0);
    rip(i,n,0) {
        int a,b; cin >> a >> b;
        --a;--b;
        if((a>=0  && da[a] != -2) || (b >= 0 &&da[b] != -2) || (a > b && a>= 0 && b >= 0)) {
            cout << "No" << endl;
            return 0;
        }
        if(a >= 0 && b >= 0) {
            da[a] = b;
            da[b] = a;
        }
        else if(a >= 0) {
            da[a] = -1;
            daa[a] = i+1;
        }
        else if(b >= 0) {
            da[b] = -3;
            daa[b] = i+1;
        }
    }
    vector<vector<bool>> dp(n*2, vector<bool>(n*2));
    // vdeb(da);
    rip(ii,n+1,1) {
        rip(jj,n+1-ii,0) {
            int i = jj, j = ii + jj, x = j-i;
            bool flg = true;
            // cout << i MM j MM x<< endl;
            rip(k, x, 0) {
                // cout << 2*i+k MM 2*i+k+x << endl;
                if(da[2*i+k] == 2*i+k+x || ((da[2*i+k] == -1 || da[2*i+k] == -2) && (da[2*i+k+x] == -2 || da[2*i+k+x] == -3))) {
                    if(da[2*i+k] == -1 && da[2*i+k+x] == -3) {
                        flg = false;
                        break;
                    }
                }
                else {
                    flg = false;
                    break;
                }
            }
            if(flg) dp[i][j] = true;
            else {
                rip(k, j, i+1) {
                    // cout << i MM k MM j << endl;
                    if(dp[i][k] && dp[k][j]) dp[i][j] = true;
                }
            }
        }
    }
    // vdeb(dp);
    if(dp[0][n]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

int N, A[105], B[105];

int out_pos[205];

int IN[205], OUT[205];

bool dp[205];

int check[205];

int tmp_in[205], tmp_out[205];

/*bool IsPossible(int I, int J, int K) {

	for (int i = I; i <= J; i++) { check[i] = 0; tmp_in[i] = IN[i]; tmp_out[i] = OUT[i]; }

	int id = 105;

	for (int i = I; i <= J; i++) {
		if (check[i] != 0) { continue; } // すでに出力済み

		if (tmp_out[i] != -1) {   return false; } // 入力の前に出力があるのは不合理

		if (tmp_in[i] > 0) { // 乗る人が確定している場合

			if (i + K + 1 > J) { return false; }
			else if (out_pos[i]>0) {
				if (out_pos[i] != i + K + 1) { return false; }
				else { tmp_out[i + K + 1] = tmp_in[i]; check[i + K + 1] = 1; }
			}
			else if (tmp_in[i+K+1]>0) {
				return false;
			}
			else if (tmp_out[i + K + 1] == -1 || tmp_out[i+K+1]==tmp_in[i]) {
				tmp_out[i + K + 1] = tmp_in[i]; check[i + K + 1] = 1;
			}
			else {  return false; }

		}
		else if (tmp_out[i+K+1]!=-1) { //降りる人が確定している場合
			tmp_in[i] = tmp_out[i + K + 1]; check[i + K + 1] = 1;
		}
		else { // 乗る人も降りる人も未確定の場合

			tmp_in[i] = id++;
			if (i + K + 1 > J) { return false; }
			else {
				tmp_out[i + K + 1] = tmp_in[i]; check[i + K + 1] = 1;
			}

		}

	}

	return true;
}*/

bool IsPossible(int I, int J, int K) {

	for (int i = I; i <= J; i++) { check[i] = 0; tmp_in[i] = IN[i]; tmp_out[i] = OUT[i]; }

	for (int i = I; i <= J; i++) {
		if (check[i] != 0) { continue; }

		if (i + K + 1 > J) { return false; }

		if (tmp_in[i] > 0 && tmp_out[i+K+1] > 0) { // 乗る人と降りる人が確定
			if (out_pos[i] > 0 && out_pos[i] != i + K + 1) { return false; }

			if (tmp_in[i] != tmp_out[i + K + 1]) { return false; }

			check[i + K + 1] = 1;
		}
		else if (tmp_in[i]>0 && tmp_out[i+K+1]==-1) { // 乗る人のみ確定
			if (out_pos[i] > 0) { return false; }
			if (tmp_in[i + K + 1] > 0) { return false; }
			else { check[i + K + 1] = 1; }
		}
		else if (tmp_in[i] == -1 && tmp_out[i + K + 1] > 0) { // 降りる人のみ確定
			check[i + K + 1] = 1;
		}
		else {//乗る人も降りる人も未確定
			if (tmp_in[i + K + 1] > 0) { return false; }
			check[i + K + 1] = 1;
		}

	}

	return true;
}

int main(void) {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
	}

	for (int i = 1; i <= 2*N; i++) {
		IN[i] = -1; OUT[i] = -1;
	}

	for (int i = 1; i <= N; i++) {
		if (A[i]>0 && B[i]>0 && A[i] >= B[i]) { cout << "No" << endl; return 0; }

		if (A[i] > 0) {
			if (IN[A[i]] != -1) { cout << "No" << endl; return 0; }
			else { IN[A[i]] = i; }
		}

		if (B[i] > 0) {
			if (OUT[B[i]] != -1) { cout << "No" << endl; return 0; }
			else { OUT[B[i]] = i; }
		}
	}

	for (int i = 1; i <= 2 * N; i++) {
		if (IN[i] > 0 && OUT[i] > 0) { cout << "No" << endl; return 0; }
	}

	for (int i = 1; i <= 2 * N; i++) { out_pos[i] = -1; }
	for (int i = 1; i <= N; i++) {
		if (A[i] > 0 && B[i] > 0) { out_pos[A[i]] = B[i]; }
	}

	for (int i = 1; i <= N*2; i++) { dp[i] = false; }

	dp[0] = true;

	for (int i = 0; i < N*2; i+=2) {
		if (dp[i] == false) { continue; }

		for (int j = i + 2; j <= 2 * N; j += 2) {
			for (int k = 0; k <= N; k++) {
				if (IsPossible(i + 1, j, k)) { dp[j] = true; break; }
			}
		}
	}

	if (dp[2 * N] == true) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }

	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=2e18;

bool overf(ll a,ll b){
  if(a>INF/b) return true;
  return false;
}

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

  string S;
  cin>>S;
  ll M;
  cin>>M;
  ll N=S.size();

  int madig=0;
  rep(i,N) chmax(madig,S[i]-'0');

  auto calc = [&](ll d){
    ll milim=1;
    bool ng=false;
    rep(i,N-1){
      if(overf(milim,d)){
        ng=true;
        break;
      }
      milim*=d;
    }
    if(ng) return -INF;

    ll num=0;
    bool ov=false;
    rep(i,N){
      if(overf(num,d)){
        ov=true;
        break;
      }
      num*=d;
      ll c=S[i]-'0';
      num+=c;
    }

    if(ov) return -INF;
    if(num>M) return -INF;
    return num;
  };

  if(calc(madig+1)==-INF){
      cout<<0<<endl;
      return 0;
  }

  {
      ll high=M+1,low=madig+1;
      while(abs(high-low)>3){
          ll mid=(high+low)/2;
          ll prev=calc(mid);
          ll nexv=calc(mid+1);
          if(prev==-INF) high=mid;
          else if(nexv==-INF) high=mid+1;
          else if(prev==nexv) high=mid;
          else low=mid;
      }

      for(ll d=low;d<=high;d++){
          ll prev=calc(d);
          ll nexv=calc(d+1);
          if(nexv==-INF||prev==nexv){
              cout<<d-madig<<endl;
              return 0;
          }
      }
  }

  return 0;
}


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

__attribute__((constructor))
void fast_io() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main() {
    int r, c;
    cin >> r >> c;
    vector<int> a(r * (c - 1)), b((r - 1) * c), dist(2 * r * c, INT_MAX);
    for (int i = 0; i < r; ++i) for (int j = 0; j < c - 1; ++j) cin >> a[i * (c - 1) + j];
    for (int i = 0; i < r - 1; ++i) for (int j = 0; j < c; ++j) cin >> b[i * c + j];
    using P = pair<int, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    auto update = [&](int id, int d) {
        if (dist[id] > d) {
            dist[id] = d;
            pq.emplace(d, id);
        }
    };
    update(0, 0);
    while (!pq.empty()) {
        auto [d, id] = pq.top();
        pq.pop();
        if (dist[id] < d) continue;
        if (id >= r * c) {
            update(id - r * c, d);
            int i = (id - r * c) / c, j = (id - r * c) % c;
            if (i > 0) update((i - 1 + r) * c + j, d + 1);
        } else {
            int i = id / c, j = id % c;
            if (j < c - 1) update(i * c + j + 1, d + a[i * (c - 1) + j]);
            if (j > 0) update(i * c + j - 1, d + a[i * (c - 1) + j - 1]);
            if (i < r - 1) update((i + 1) * c + j, d + b[i * c + j]);
            update(id + r * c, d + 1);
        }
    }
    cout << dist[r * c - 1] << '\n';
}

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    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; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=998244353;

    struct mint {
      ll x;
      mint(ll x=0):x((x%mod+mod)%mod){}
      mint operator-() const { return mint(-x);}
      mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
      }
      mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
      }
      mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
      mint operator+(const mint a) const { return mint(*this) += a;}
      mint operator-(const mint a) const { return mint(*this) -= a;}
      mint operator*(const mint a) const { return mint(*this) *= a;}
      mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
      }

      mint inv() const { return pow(mod-2);}
      mint& operator/=(const mint a) { return *this *= a.inv();}
      mint operator/(const mint a) const { return mint(*this) /= a;}
     };
      istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
      ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
      struct combination {
      vector<mint> fact, ifact;
      combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
      }
      mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
      }
     } c(2000005);

    int main() {
      int N,K;
      cin>>N>>K;
      vector<ll>A(N);
      rep(i,N){cin>>A[i];}
      vector<mint>sum(K+1);//sum[k]=A[0]^k+A[1]^k+A[2]^k+...
      rep(i,N){
        mint now=1;
        rep(j,K+1){
          sum[j]+=now;
          now*=A[i];
        }
      }
      for(int i=1;i<=K;i++){
        mint ans=0;
        for(int j=0;j<=i;j++){
          ans+=c(i,j)*sum[j]*sum[i-j];
        }
        ans-=mint(2).pow(i)*sum[i];
        ans/=2;
        cout<<ans<<endl;
      }
      return 0;
    }


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

template<class T>
vector<T> make_vec(size_t a){
	return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
	return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vi a(2*N);
    rep(i,2*N) cin>>a[i];
    vector<pi> b;
    rep(i,2*N){
        b.emplace_back(a[i],i);
    }
    vector<bool> marked(2*N);
    sort(rall(b));
    rep(i,N) marked[b[i].se]=true;

    stack<bool> st;
    string S="";
    rep(i,N){
        bool f1 = marked[2*i];
        bool f2 = marked[2*i+1];
        if (f1 xor f2){
            S+="()";
        }else{
            if (!st.empty() && (st.top() xor f1)){
                st.pop();
                S+="))";
            }else{
                if (f1) st.push(true);
                else st.push(false);
                S+="((";
            }
        }
    }
    cout<<S<<"\n";

    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cmath>
#include <map>

using ll=long long;
using namespace std;

int main(){
    int N;
    cin>>N;
    N*=2;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    vector<ll> B = A;
    sort(B.begin(), B.end());

    map<ll,int> cnt;
    for(int i=0;i<N/2;i++){
        cnt[B[i]]++;
    }

    vector<int> col(N,0);
    for(int i=0;i<N;i++){
        if(cnt[A[i]] > 0){
            col[i] = 1;
            cnt[A[i]]--;
        }
    }

    vector<int> ans(N,-1);
    vector<int> st;
    st.push_back(-1);
    for(int i=0;i<N;i++){
        if(*st.rbegin() == -1){
            ans[i] = 0;
            st.push_back(col[i]);
        }else if(*st.rbegin() == col[i]){
            ans[i] = 0;
            st.push_back(col[i]);
        }else{
            ans[i] = 1;
            st.pop_back();
        }
    }

    for(int i=0;i<N;i++){
        if(ans[i]){
            cout<<")";
        }else{
            cout<<"(";
        }
    }
    cout<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

//typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int mod = 1e9 + 7;
//const ll INF = 1e18;
const double EPSILON = 1e-10;
const int N = 2005;
char t[N][N];
int l[N][N], c[N][N], d[2][N][N];
vi ll[N], cc[N], dd[2][N];
int add(int a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}
int sub(int a, int b){
    a -= b;
    if(a < 0)
        a += mod;
    return a;
}
int main(){
    fastio;
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> t[i][j];
    for(int i = 0; i < N; i++)
        ll[i].pb(0), cc[i].pb(0), dd[0][i].pb(0), dd[1][i].pb(0);
    if(n == 1 and m == 1){
        cout << 1 << '\n';
        return 0;
    }
    l[1][1] = c[1][1] = d[0][0][1] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(i == 1 and j == 1)continue;
            if(t[i][j] == '#'){
                ll[i].pb(i);
                cc[j].pb(j);
                if(i-j >= 0){
                    dd[0][i-j].pb(i);
                }else{
                    dd[1][j-i].pb(i);
                }
            }else{
                int tmp = 0;
                tmp = add(tmp, sub(l[i-1][j], (ll[i][sz(ll[i])-1] > 0 ? l[ ll[i][sz(ll[i])-1] ][j] : 0)));
                tmp = add(tmp, sub(c[i][j-1], (cc[j][sz(cc[j])-1] > 0 ? c[i][ cc[j][sz(cc[j])-1] ] : 0)));

                if(i-j>=0){
                    tmp = add(tmp, sub(d[0][i-j][i-1], (dd[0][i-j][sz(dd[0][i-j])-1] > 0 ? d[0][i-j][ dd[0][i-j][sz(dd[0][i-j])-1] ] : 0)));
                }else{
                    tmp = add(tmp, sub(d[1][j-i][i-1], (dd[1][j-i][sz(dd[1][j-i])-1] > 0 ? d[1][j-i][ dd[1][j-i][sz(dd[1][j-i])-1] ] : 0)));
                }
                if(i == n and j == m){
                    cout << tmp << '\n';
                }
                l[i][j] = add(l[i-1][j], tmp);
                c[i][j] = add(c[i][j-1], tmp);
                if(i-j >= 0){
                    d[0][i-j][i] = add(d[0][i-j][i-1], tmp);
                }else{
                    d[1][j-i][i] = add(d[1][j-i][i-1], tmp);
                }
            }
        }
    }
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

#define int long long
#define ll long long
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; ++i)
#define Fo(i, k, n) for (int i = k; i < n; ++i)
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define lcm(a, b) (a / __gcd(a, b) * b)
#define F first
#define S second
#define ull unsigned long long

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

const ll mod = 1e9 + 7;
const ll N = (ll)2e3 + 4;

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

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

void vjudge()
{
#ifndef RTE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
string s[N];
int dp[N][N];
int phor[N][N];
int pver[N][N];
int pdig[N][N];

bool wall(int x, int y)
{
    if (s[x - 1][y - 1] == '#')
        return 1;
    return 0;
}
void solve()
{
    int h, w;
    cin >> h >> w;
    for (int i = 1; i < h + 1; i++)
        cin >> s[i - 1];
    dp[1][1] = 1;
    pdig[1][1] = 1;
    pver[1][1] = 1;
    phor[1][1] = 1;

    for (int i = 1; i < h + 1; i++)
    {
        for (int j = 1; j < w + 1; j++)
        {
            if ((i == 1 and j == 1) or wall(i, j))
                continue;

            dp[i][j] = (phor[i][j - 1] + pver[i - 1][j] + pdig[i - 1][j - 1]) % mod;

            phor[i][j] = (dp[i][j] + phor[i][j - 1]) % mod;
            pver[i][j] = (dp[i][j] + pver[i - 1][j]) % mod;
            pdig[i][j] = (dp[i][j] + pdig[i - 1][j - 1]) % mod;
        }
    }
    cout << dp[h][w];
}
int32_t main()
{
    clock_t start, end;
    start = clock();
    vjudge();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    end = clock();
    double waste = double(end - start) / double(CLOCKS_PER_SEC);
    cerr << "Time wasted by program is : " << fixed
         << waste << setprecision(15);
    cerr << " sec " << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = int64_t;

vector<vector<ll>> prod_mat(vector<vector<ll>> a1, vector<vector<ll>> a2){
    vector<vector<ll>> m(3, vector<ll>(3));
    for(int i=0; i<3; ++i){
        for(int j=0; j<3; ++j){
            for(int k=0; k<3; ++k){
                m[i][j] += a1[i][k] * a2[k][j];
            }
        }
    }

    return m;
}

vector<ll> prod_vec(vector<vector<ll>> a1, vector<ll> vec){
    vector<ll> ret(3, 0);
    for(int i=0; i<3; ++i){
        for(int j=0; j<3; ++j){
            ret[i] += a1[i][j] * vec[j];
        }
    }

    return ret;
}

int main(){
    ll N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for(int i=0; i<N; ++i) cin >> X[i] >> Y[i];

    ll M;
    cin >> M;
    vector<int> op;
    map<int, ll> cood;
    for(int i=0; i<M; ++i){
        int o;
        cin >> o;
        op.push_back(o);
        if(o >= 3){
            cin >> o;
            cood[i] = o;
        }
    }

    int Q;
    cin >> Q;
    vector<ll> A(Q), B(Q);
    for(int i=0; i<Q; ++i) cin >> A[i] >> B[i];

    vector<vector<vector<ll>>> stat_matrix(M+1, vector<vector<ll>>(3, vector<ll>(3)));
    stat_matrix[0] = {{1,0,0},{0,1,0},{0,0,1}};

    for(int i=1; i<M+1; ++i){
        vector<vector<ll>> matrix_step(3, vector<ll>(3));
        if(op[i-1] == 1)
            matrix_step = {{0,1,0},{-1,0,0},{0,0,1}};
        else if(op[i-1] == 2)
            matrix_step = {{0,-1,0},{1,0,0},{0,0,1}};
        else if(op[i-1] == 3){
            ll p = cood[i-1];
            matrix_step = {{-1,0,p*2},{0,1,0},{0,0,1}};
        } else {
            ll p = cood[i-1];
            matrix_step = {{1,0,0},{0,-1,p*2},{0,0,1}};
        }
        stat_matrix[i] = prod_mat(matrix_step, stat_matrix[i-1]);
    }

    for(int i=0; i<Q; ++i){
        vector<ll> v = {X[B[i]-1], Y[B[i]-1], 1};
        vector<ll> ans = prod_vec(stat_matrix[A[i]], v);
        cout << ans[0] << " " << ans[1] << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pdd pair<ld, ld>
#define ft first
#define sd second
#define i2 array<int,2>
#define i3 array<int,3>
#define i6 array<int,6>
#define i4 array<int,4>
#define l2 array<ll,2>
#define l3 array<ll,3>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template<class T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N = 200100;
const int M = 300100;
const int BIG = int(5e8) + 10;
const int oo = 2e9;
const ll OO = 1e18;
const int md = int(1e9) + 7;
const int PW = 60;
const ld E = 1e-9;
const int MX = 1000100;
vector<l2> qr[N];
l2 ans[N];
ll n, x[N], y[N], op[N], P[N], q, m, ad[2], TP, sgn[2];

mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());

void BAD(){
    cout << -1;
    exit(0);
}

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

int sum(int x, int y){
    x += y;
    if (x >= md)
        x -= md;
    return x;
}

int main(){
#ifdef _LOCAL
    freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout);
#else
//    freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
#endif

    cin >> n;

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

    cin >> m;

    for (int i = 1; i <= m; i++){
        cin >> op[i];

        if (op[i] > 2)
            cin >> P[i];
    }

    cin >> q;

    // sgn == 0 -- + else -
    // TP == 0 (X;Y) else (Y;X)

    for (int i = 1; i <= q; i++){
        int A, B; cin >> A >> B;

        qr[A].PB({B, i});
    }

    for (int i = 0; i <= m; i++){
        if (i > 0){
            if (op[i] == 1){
                TP ^= 1;
                swap(sgn[0], sgn[1]);
                swap(ad[0], ad[1]);

                sgn[1] ^= 1;
                ad[1] = -ad[1];
            } else if (op[i] == 2){
                TP ^= 1;
                swap(sgn[0], sgn[1]);
                swap(ad[0], ad[1]);

                sgn[0] ^= 1;
                ad[0] = -ad[0];
            } else if (op[i] == 4){
                sgn[1] ^= 1;
                ad[1] = -ad[1];
                ad[1] += P[i] * 2;
            } else {
                sgn[0] ^= 1;
                ad[0] = -ad[0];
                ad[0] += P[i] * 2;
            }
        }

        for (l2 cr : qr[i]){
            l2 res = {x[cr[0]], y[cr[0]]};

            if (TP) swap(res[0], res[1]);

            if (sgn[0]) res[0] = -res[0];
            if (sgn[1]) res[1] = -res[1];

            res[0] += ad[0];
            res[1] += ad[1];

            ans[cr[1]] = res;
        }
    }

    for (int i = 1; i <= q; i++)
        cout << ans[i][0] << " " << ans[i][1] << '\n';

    return 0;
}


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

int main() {
	int n; cin >> n;
	int a[n], b[n];
	REP(i, n) cin >> a[i] >> b[i];
	int res = 1e6+1;
	REP(i, n) REP(j, n)
		res = min(res, (i==j) ? a[i]+b[j] : max(a[i],b[j]));
	cout << res << '\n';
	return 0;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<cstdio>

#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const int maxN = 1e6 + 1;
const int mod = 1e9 + 7;
ll a, b, w;
inline void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
void ReadInput()
{
    cin >> a >> b >> w;
}
void Solve()
{
    w *= 1000;
    if(w % b == 0) cout << w / b << " ";
    else
    {
        int r = b * (w / b + 1) - w;
        int mul = w / b + 1;
        int diff = b - a;
        if(r <= mul * diff) cout << w / b + 1 << " ";
        else
        {
            cout << "UNSATISFIABLE";
            return;
        }
    }
    if(w % a == 0) cout << w / a;
    else
    {
        int r = w - (a * w / a);
        int mul = w / a;
        int diff = b - a;
        if(r <= mul * diff) cout << w / a << " ";
        else
        {
            cout << "UNSATISFIABLE";
            return;
        }
    }
}
int main()
{
    FastInput();
    ReadInput();
    Solve();

}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  vector<int> p(n+1, 0);
  for(auto i : a){
    p[i]++;
  }
  vector<int> mns(n+1, 1001001001);
  mns.front() = p.front();
  rep2(i, 1, n+1){
    mns.at(i) = min(p.at(i), mns.at(i-1));
  }
  ll ans = 0, now = 0;
  rrep(i, n+1){
    if(mns.at(i) > now){
      ll d = mns.at(i) - now;
      ll adc = min((ll)k, d);
      ans += (ll)adc*(i+1);
      k -= d;
      if(k <= 0) break;
      now = mns.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#define ll long long
using namespace std;
ll mod = 1e9+7;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,x;
    cin >> n >> x;
    x*=100;
    ll i=1;
    ll ans=0;
    bool drunk=false;
    while(n--){
        ll a,b;
        cin >> a >> b;
        ans+=a*b;
        if(ans>x){
            drunk=true;
            break;
        }
        i++;
    }
    if(drunk==true){
        cout << i;
    }
    else{
        cout << -1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;//大きなint型
using P = pair<int,int>;//pair型の型エイリアス
#define rep(i,n) for (int i = 0; i < (n); ++i)//iをnまですすめる。

int main(){
    int n;
    int sum = 0;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n){
        cin >> a.at(i);
    }
    rep(i,n){
        cin >> b.at(i);
    }
    rep(i,n){
        sum += a.at(i)*b.at(i);
    }
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000009
#define pb push_back
#define mp make_pair
#define endl '\n'
#define N 100005
using namespace std;
int a[N],p[N];
//https://www.geeksforgeeks.org/program-decimal-octal-conversion/
int decToOctal(int n)
{
     int f= 1;
    // array to store octal number
    int octalNum[50];

    // counter for octal number array
    int i = 0;
    while (n != 0) {

        // storing remainder in octal array
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }

    // printing octal number array in reverse order
    for (int j = i - 1; j >= 0; j--)
	{
		if(octalNum[j] == 7)
			f = 0;
	}
	return f;
}
int dig (int n)
{
	int f=1;
	while(n){
		int d = n%10;
		if(d==7) f = 0 ;
		n/=10;
	}
	return f;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	int f1=0,f2=0;
    	f2 = dig(i);
    	f1 = decToOctal(i);
    	if(f1 && f2){
    		//cout<<i<<' ';
    		p[i]+=p[i-1]+1;
    	}
    	else{
    		p[i] = p[i-1];
    	}
    }
   // cout<<endl;
    cout<<p[n]<<endl;
 }


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

void solve() {
    int a,b,c;
    cin >> a >> b >> c;
    if (a==b){
        cout << "=\n";
        return;
    }
    if(c%2==0){
        if(abs(a)==abs(b)){
            cout << "=\n";
        }else if(abs(a)<abs(b)){
            cout << "<\n";
        }else{
            cout << ">\n";
        }
    }else{
        if(a>=0 && b>=0){
            if(a==b){
                cout << "=\n";
            }else if(a>b){
                cout << ">\n";
            }else{
                cout << "<\n";
            }
        }else if(a<0 && b>=0){
            cout << "<\n";
        }else if(a>=0 && b<0){
            cout << ">\n";
        }else{
            if(a==b){
                cout << "=\n";
            }else if(a>b){
                cout << "<\n";
            }else{
                cout << ">\n";
            }
        }
    }
    return;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<deque>
#include <algorithm>

using namespace std;

#define mem(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define ft first
#define sd second
#define endl '\n'
#define PI acos(-1.0)
#define lcm(a,b) a/gcd(a,b)*b
#define INF_INT 0x3f3f3f3f
#define debug(a) cout<<#a<<"="<<a<<endl;
#define _for(i,a,b) for( int i=(a); i<(b); ++i)
#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)

//inline void print(__int128 x){if(x<0){putchar('-');x=-x;}if(x>9) print(x/10);putchar(x%10+'0');}
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
int exgcd(int a, int b, int &x, int &y){if(!b){x = 1; y = 0;return a;}int d = exgcd(b, a % b, y, x);y -= (a/b) * x;return d;}
ll qmi(ll m, ll k, ll p){ll res = 1 % p, t = m;while (k){if (k&1) res = res * t % p;t = t * t % p;k >>= 1;}return res;}
inline int read(){int s=0,x=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') x=-1; ch=getchar();}while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar(); }return s*x;}

const int NN = 1e6+7;
const int mod = 1e9+7;

int N,M,k;

ll C(int n, int m){
    if(n<0||m<0) return 0;
    ll res = 1;

    _rep(i,1,n+m){
        res = (res*i)%mod;
    }

    _rep(i,2,m){
        ll ni = qmi(i,mod-2,mod);
        res = (res*ni) %mod;
    }
    _rep(i,2,n){
        ll ni = qmi(i,mod-2,mod);
        res = (res*ni) %mod;
    }
    return res;
}
void solve()
{
    cin >> N >> M >> k;
    if(N-k-M > 0) puts("0");
    else{
        cout << (C(N,M)-C(N-k-1,M+k+1)+mod)%mod << endl;
    }
}
int main()
{
    //ios::sync_with_stdio(0);
    int T = 1;

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


/*input

*/
#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>
#include <iomanip>
#include <climits>
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x,y)   fixed<<setprecision(y)<<x
#define ss(s) scanf(" %[^\n]%*c", s)
#define ps(s) printf("%s\n",s)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

void nl() {printf("\n");}
void sc(int&n) {int number; scanf("%d", &number); n = number;}
void sc(ll&n) {ll number; scanf("%lld", &number); n = number;}
void _print(ll t) {printf("%lld ", t);}
void _print(int t) {printf("%d ", t);}
void _print(string t) {cout << t;}
void _print(char t) {printf("%c\n", t);}
void _print(lld t) {cout << t;}
void _print(double t) {cout << t;}
void _print(ull t) {cout << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cout << "{"; _print(p.F); cout << ","; _print(p.S); cout << "}";}
template <class T> void _print(vector <T> v) {cout << "vec->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T> void _print(set <T> v) {cout << "set->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T> void _print(multiset <T> v) {cout << "multiset->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T, class V> void _print(map <T, V> v) {cout << "map->[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";}

const ll inf = (ll)2e18 + 10;
const int N = (int)1e6 + 10;
bool possible(vector<ll>&a, ll val, ll k) {
	int n = sz(a);
	int l = 0, r = n - 1, ind = -1;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (a[mid] <= val) {
			ind = mid;
			l = mid + 1;
		}
		else {
			r = mid - 1;
		}
	}
	ll rem = (val - (ind + 1));
	if (rem >= k)return true;
	return false;
}
void solve()
{
	int n, q;
	sc(n), sc(q);
	std::vector<ll>a(n);

	for (int i = 0; i < n; ++i)
	{
		sc(a[i]);
	}
	while (q--) {
		ll k;
		sc(k);
		ll l = 1, r = inf, ans = -1;
		while (l <= r) {
			ll mid = (l + r) / 2;
			if (possible(a, mid, k)) {
				ans = mid;
				r = mid - 1;
			}
			else {
				l = mid + 1;
			}
		}
		_print(ans);
		nl();
	}
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int t = 1;
	// sc(t);
	while (t--) {
		solve();
	}
	return 0;

}

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

int main() {
    ll x, y, a, b;
    cin >> x >> y >> a >> b;
    ll exp = 0;
    while (x * (a - 1) < b) {
        if (x >= LONG_LONG_MAX / a) {
            break;
        }
        x *= a;
        if (x >= y) {
            cout << exp << endl;
            return 0;
        }
        exp++;
    }
    exp += (y - x - 1) / b;
    cout << exp << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
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(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< "]";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,set<T> a){
  os << "{ ";
  for(auto itr=a.begin();itr!=a.end();++itr){
    os<< *itr << " ";
  }
  os<< "}";
  return os;
}
template<class T>
void ans_array(T begin,T end){
  if(begin==end)return;
  auto itr=begin;
  cout<<*itr;
  ++itr;
  for(;itr!=end;++itr){
    cout<<' '<<*itr;
  }
  cout<<endl;
}
template<class T>
void ans_array_newline(T begin,T end){
  if(begin==end)return;
  for(auto itr=begin;itr!=end;++itr){
    cout<<*itr<<endl;
  }
}

const long long MOD = 1000000007;
void solve(long long N, std::vector<long long> A){
  vector<vector<ll>> dp(N+1,vector<ll>(N+1));
  ll rotated[3001];
  dp[0][0]=1;
  auto idx2real = [&](ll x,ll j){
    return ((x+j+1-rotated[j])%(j+1)+j+1)%(j+1);
  };
  REP(N-1){
    Rev(j,i+1){
      ll& tmp=dp[idx2real(A[i+1],j+1)][j+1];
      tmp=(tmp+dp[idx2real(0,j)][j])%MOD;
      rotated[j]=(rotated[j]+A[i+1])%(j+1);
    }
  }
  ll ans=0;
  REP(N){
    ans=(ans+dp[idx2real(0,i)][i])%MOD;
  }
  dump(dp);
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long N;
    std::scanf("%lld", &N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &A[i]);
    }
  solve(N, std::move(A));
  return 0;
}

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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;

	static_mint() : val() {}

	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }

	static_mint pow(long long n) const {
		static_mint ans = 1, x(*this);
		for (; n > 0; n /= 2) {
			if (n & 1) ans *= x;
			x *= x;
		}
		return ans;
	}

	static_mint inv() const {
		return pow(M - 2);
	}

	static_mint operator+() const {
		static_mint m;
		m.val = val;
		return m;
	}

	static_mint operator-() const {
		static_mint m;
		m.val = (val == 0 ? 0 : M - val);
		return m;
	}

	static_mint &operator+=(const static_mint &m) {
		if ((val += m.val) >= M) val -= M;
		return *this;
	}

	static_mint &operator-=(const static_mint &m) {
		if ((val -= m.val) < 0) val += M;
		return *this;
	}

	static_mint &operator*=(const static_mint &m) {
		val = (long long) val * m.val % M;
		return *this;
	}

	static_mint &operator/=(const static_mint &m) {
		val = (long long) val * m.inv().val % M;
		return *this;
	}

	friend static_mint operator+(const static_mint &lhs, const static_mint &rhs) {
		return static_mint(lhs) += rhs;
	}

	friend static_mint operator-(const static_mint &lhs, const static_mint &rhs) {
		return static_mint(lhs) -= rhs;
	}

	friend static_mint operator*(const static_mint &lhs, const static_mint &rhs) {
		return static_mint(lhs) *= rhs;
	}

	friend static_mint operator/(const static_mint &lhs, const static_mint &rhs) {
		return static_mint(lhs) /= rhs;
	}

	friend bool operator==(const static_mint &lhs, const static_mint &rhs) {
		return lhs.val == rhs.val;
	}

	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) {
		return lhs.val != rhs.val;
	}

	static_mint &operator++() {
		return *this += 1;
	}

	static_mint &operator--() {
		return *this -= 1;
	}

	static_mint operator++(int) {
		static_mint result(*this);
		*this += 1;
		return result;
	}

	static_mint operator--(int) {
		static_mint result(*this);
		*this -= 1;
		return result;
	}

	template<typename T>
	explicit operator T() const {
		return T(val);
	}

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x;
		return is >> x, m = x, is;
	}
};

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

	using mint = static_mint<1000000007>;

	int n;
	cin >> n;

	vector<long long> a(n);
	for (auto &x : a) cin >> x;

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

	mint ans = 0;
	for (int i = 1; i <= n; i++) {
		vector<mint> new_dp(n + 1), sum_dp(i);

		long long sum = 0;
		sum_dp[0] = dp[0];
		for (int j = 1; j <= n; j++) {
			sum += a[j - 1];
			new_dp[j] = sum_dp[sum % i];
			sum_dp[sum % i] += dp[j];
		}
		dp.swap(new_dp);
		ans += dp.back();
	}
	cout << ans << '\n';
	return 0;
}


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

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

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

typedef vector<int> vi;
typedef vector<ll> vll;

#define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
#define FORD(i,j,k,in) for(int i=(j); i >=(k);i-=in)
#define REP(i,b) FOR(i,0,b,1)
#define REPD(i,b) FORD(i,b,0,1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define MANY_TESTS int tcase; cin >> tcase; while(tcase--)

const double EPS = 1e-9;
const int MOD = 1e9+7;
const ll INFF = 1e18;
const int INF = 1e9;
const ld PI = acos((ld)-1);
const vi dy = {1, 0, -1, 0, -1, 1, 1, -1};
const vi dx = {0, 1, 0, -1, -1, 1, -1, 1};

void DBG(){cout << "]" << endl;}
template<typename T, typename ...U> void DBG(const T& head, const U... args){ cout << head << "; "; DBG(args...); }
#define dbg(...) cout << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__);
#define chk() cout << "Check at line(" << __LINE__ << ") hit." << endl;

template<class T, unsigned int U>
ostream& operator<<(ostream& out, const array<T, U> &v){out << "[";  REP(i, U) out << v[i] << ", ";  out << "]"; return out;}
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "[" << par.first << ";" << par.second << "]"; return out;}
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template<class T>
ostream& operator<<(ostream& out, const vector<T> &v){ out << "[";  REP(i, v.size()) out << v[i] << ", ";  out << "]"; return out;}

template<class T>
istream& operator>>(istream& in, vector<T> &v){ for(auto &x : v) in >> x; return in; }

int main(){
 	ios_base::sync_with_stdio(false);
 	cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vi a(n), p(n), x(n);
    REP(i, n){
        cin >> a[i] >> p[i] >> x[i];
    }
    int mini = INF + 10;
    REP(i, n){
        if(x[i] - a[i] > 0)
            mini = min(mini, p[i]);
    }
    if(mini == INF + 10){
        cout << -1 << "\n";
    }
    else{
        cout << mini << "\n";
    }
    return 0;
}


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

int main(){
  int N,i,sum=0;
  cin >> N;
  for(i = 1;sum < N;){
    sum += i;
    i++;
  }
  cout << i - 1 << endl;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

struct person {
    ll id;
    ll a;
    ll b;
};

ll check(ll N, ll start, ll end, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix) {
    if (end > 2 * N) {
        return 0;
    }
    if (end_fix[start] >= 0) {
        return 0;
    }
    if (start_fix[end] >= 0) {
        return 0;
    }
    if (start_fix[start] >= 0) {
        return 2;
    }
    if (end_fix[end] >= 0) {
        return 2;
    }
    if (start_end[start * 1000 + end] >= 0) {
        return 2;
    }
    return 1;
}

bool recursive1(ll N, ll start, ll cnt, vector<ll>& start_end, vector<ll>& start_fix, vector<ll>& end_fix, ll anypt, vector<ll>& memo) {
    //print(cnt, start);

    if (memo[start] >= anypt) {
        return false;
    }
    memo[start] = anypt;

    if (cnt == N) {
        return true;
    }
    if (start >= 2 * N) {
        return false;
    }
    for (ll end = start + 1; end <= min(start + N, 2 * N); end++) {
        bool success = true;
        ll anyy = anypt;
        for (ll ss = start; ss <= end - 1; ss++) {
            if (!success) {
                break;
            }
            ll ee = end - start + ss;
            ll result = check(N, ss, ee, start_end, start_fix, end_fix);
            // string rmsg = "success";
            // if (result == 0) {
            //     rmsg = "failure";
            // }
            // if (result == 1) {
            //     rmsg = "any";
            // }
            //print(rmsg, ss, ee, "check!");
            if (result == 0) {
                success = false;
            } else if (result == 1) {
                anyy--;
                if (anyy < 0) {
                    success = false;
                }
            } else {
                ;
            }
        }
        //print(start, end, success);
        if (success) {
            bool ok = recursive1(N, end + end - start, cnt + (end - start), start_end, start_fix, end_fix, anyy, memo);
            if (ok) {
                return true;
            }
        }
    }
    return false;
}

bool solve(ll N, vector<person>& persons) {
    set<ll> duplicate;
    for (auto p : persons) {
        if (p.a >= 0) {
            if (duplicate.count(p.a)) {
                return false;
            }
            duplicate.insert(p.a);
        }
        if (p.b >= 0) {
            if (duplicate.count(p.b)) {
                return false;
            }
            duplicate.insert(p.b);
        }
    }
    vector<ll> start_end(300000, -1);
    vector<ll> start_fix(300, -1);
    vector<ll> end_fix(300, -1);
    ll anypt = 0;
    for (auto p : persons) {
        if (p.a == -1 && p.b == -1) {
            anypt++;
        }
        if (p.a >= 0 && p.b == -1) {
            start_fix[p.a] = p.id;
        }
        if (p.a == -1 && p.b >= 0) {
            end_fix[p.b] = p.id;
        }
        if (p.a >= 0 && p.b >= 0) {
            start_end[p.a * 1000 + p.b] = p.id;
        }
    }
    vector<ll> memo(2 * N + 2, -1);
    return recursive1(N, 1, 0, start_end, start_fix, end_fix, anypt, memo);
}

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

    vector<person> persons(N);
    for (ll i = 0; i < N; i++) {
        person p;
        cin >> p.a >> p.b;
        p.id = i;
        persons[i] = p;
    }
    if (solve(N, persons)) {
        print("Yes");
    } else {
        print("No");
    }
}

#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define F first
#define S second
typedef long long ll;
typedef vector< int > vi;
typedef vector< ll > V;
typedef unordered_map<int, int > mp;
#define debug cout << -1 << endl;
#define REP(i, a, b) for(int i=a; i<b; i++)
#define pop pop_back
const ll MOD = 1000000007;
int cc = 1;
const int maxN = 2001;

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

void solve()
{
	int n;
	cin >> n;
	int arr[n];
	REP(i, 0, n) cin >> arr[i];
	int mnXOR = INT_MAX;
	for(int mask = 0; mask<(1<<n); mask++) {
		int ored = 0;
		int xored = 0;
		for(int i=0; i<n; i++) {
			ored |= arr[i];
			if(mask & (1<<i)) {
				xored ^= ored;
				ored = 0;
			}
		}
		xored ^= ored;
		mnXOR = min(mnXOR, xored);
	}
	cout << mnXOR << endl;
}

int main()
{
	FastIO;
	//freopen("tttt.in", "r", stdin);
	//freopen("tttt.out", "w", stdout);
	int t;
	t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


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

using ll = long long;
using ii = pair<int, int>;

#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mp make_pair

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int dr4[] = {1, -1, 0, 0};
const int dc4[] = {0, 0, 1, -1};
const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};

void solve() {
  string s; cin >> s;
  bool valid = 1;
  for(int i = 0; i < s.size(); i++) {
    if(i & 1 && ('a' <= s[i] && s[i] <= 'z')) valid = 0;
    else if(!(i & 1) && ('A' <= s[i] && s[i] <= 'Z')) valid = 0;
  }

  cout << (valid ? "Yes\n" : "No\n");
}

int main() {

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

  int T = 1;
  // cin >> T;
  for(int tc = 1; tc <= T; tc++) {
    solve();
  }

}

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

int main() {
	// your code goes here
	ll n;
	cin>>n;
	set<ll> output;
	for(ll i = 1; i*i <= n; i++){
		if((n%i)!=0){
			continue;
		}
		else
		{
		    output.insert(i);
			output.insert(n/i);
		}
	}

	for(auto itr: output)
		cout<<itr<<endl;
}


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

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	auto reduce = [&](vector<int> &v) -> void {
		for (int i = 1; i < v.size(); i++) {
			v[i - 1] = (6 - v[i - 1] - v[i]) % 3;
		}
		v.pop_back();
	};

	vector<int> a(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		if (s[i] == 'B') a[i] = 0;
		else if (s[i] == 'W') a[i] = 1;
		else if (s[i] == 'R') a[i] = 2;
	}

	while (true) {
		while (a.size() % 3 != 1) {
			reduce(a);
		}
		if (a.size() == 1) {
			break;
		}
		vector<int> new_a;
		new_a.reserve(a.size() / 3 + 1);

		for (int i = 0; i < a.size(); i += 3) {
			new_a.push_back(a[i]);
		}
		a.swap(new_a);
	}

	if (a.front() == 0) cout << 'B' << '\n';
	else if (a.front() == 1) cout << 'W' << '\n';
	else cout << 'R' << '\n';
	return 0;
}

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std;

#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx2")

#define sync ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
#define unq(a) sort(all(a));a.resize(unique(all(a)) - a.begin())
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define endl '\n'
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng(1);
using pii = pair<int , int>;

int inline max(const int x, const int y){return (x > y ? x : y);}
int inline min(const int x, const int y){return (x < y ? x : y);}
int inline abs(const int x){return (x < 0 ? -x : x);}
const int mxn = 4e5 + 5;

const int mod = 3; // check mod!
vector<ll> fac, inv;

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

int main(){

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

    sync

    int t = 1;
    //cin >> t;
    while(t--){
      int n;
      cin >> n;
      string s;
      cin >> s;
      // bwr
      vector<int> e(n);
      for (int i = 0; i < n; i++){
        if (s[i] == 'B') e[i] = 0;
        if (s[i] == 'W') e[i] = 1;
        if (s[i] == 'R') e[i] = 2;
      }
      int sm = 0, cnt = 1;
      sm += e[0];
      int three = 0;
      for (int up, dn, i = 1; i < n; i++){
        up = (n - i); dn = i;
        while(up % 3 == 0){
          up /= 3; three++;
        }
        while(dn % 3 == 0){
          dn /= 3; three--;
        }
        cnt *= up; cnt *= power(dn, mod - 2);
        cnt %= mod;
        if (!three){
          sm += (cnt * e[i]) % mod; sm %= mod;
        }
      }
      sm *= power(2, n - 1);
      sm %= mod;
      if (sm == 0){
        cout << 'B' << endl;
      }
      else if (sm == 1){
        cout << 'W' << endl;
      }
      else{
        cout << 'R' << endl;
      }
    }
    cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s    ";
    return 0;
}


#include<bits/stdc++.h>
#define maxn 100005
#define mod 1000000007
using namespace std;
long long check(long long k)
{
	return (k+1)*k/2;
}
int main()
{
	long long n;
	cin>>n;
	long long now=0;
	for (long long step=1<<30;step>=1;step=step>>1)
	if (check(now+step)<=n+1)
		now+=step;
	cout<<(n+1-now)<<endl;
}


//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) begin(x),end(x)
#define Fixed fixed << setprecision(12)
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7;
constexpr int mod2 = 998244353;

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class K, class V> using Umap = gp_hash_table<K, V>;
using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>;

inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

//}}}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

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

    for(int i = -1000; i <= 1000; ++i){
        for(int j = -1000; j <= 1000; ++j){
            if(i + j == a && i - j == b){
                return cout << i << ' ' << j << '\n', 0;
            }
        }
    }

    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int A,B,temp,X=0,Y=0;
    cin >> A >> B;
    temp = A + B;
    X = temp /2;
    Y = A - X;
    cout << X << " "<< Y <<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
unsigned long long kaijou(unsigned long long k){
    unsigned long long sum = 1;
    for (unsigned long long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
unsigned long long bekijou(unsigned long long p, unsigned long long q){
    unsigned long long sum = 1;
    for (unsigned long long i = 1; i <= q; ++i)
    {
        sum = sum * p;
    }
    return sum;
}
int main() {
  unsigned long long x;
  cin >> x;
  vector<unsigned long long> y(x);
for (unsigned long long i = 0; i < x; i++) {
  cin >> y.at(i);
}
  vector<unsigned long long> s(x+1, 0);
        for (unsigned long long i = 0; i < x; ++i){s[i+1] = s[i] + y[i];}
unsigned long long k = 0;
  unsigned long long n = 0;
  unsigned long long m = 0;
  unsigned long long p = 0;
  for (unsigned long long i = 1; i <= x; i++) {
    k=max(k, y.at(i - 1));
    n = n + s.at(i - 1);
    cout << k * i + n + s.at(i) << endl;
}

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#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 per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >> N;
	V<ll> a(N); rep(i,N) cin >> a[i];
	ll ans = 0, s = 0, x = 0;
	rep(i,N){
		chmax(x,a[i]);
		s += a[i];
		ans += s;
		cout << ans+x*(i+1) << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	bool sequence = false;
	for(int i = 0; i < n-1; i++) {
		if(a.at(i+1) - a.at(i) == 1) {
			sequence = true;
		} else {
			sequence = false;
			break;
		}
	}
	if(a.size() < 2) sequence = true;
	if(sequence) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	return 0;
}

#include <bits/stdc++.h>
//#include "debugger.h"
#define int long long
#define pb push_back
#define pp pop_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
using namespace std;

signed main() {

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

	int n;
	cin >> n;

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		string s;
		cin >> s;

		if (s == "OR") {
			ans += (1ll << i);
		}
	}

	cout << ans + 1 << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  cout << (N + (100 - 1)) / 100 << endl;

  return 0;
}

#include <iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<math.h>
#include<iomanip>
#include<string>
#include <cassert>
#include <complex>
#include<math.h>
#include<bits/stdc++.h>

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

using namespace std;

typedef long long ll; //10e18くらい
typedef long double ld;
typedef __int128_t lll;
typedef pair<ll, ll> pll;

const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };
const ll LongINF = 1e13 + 7;
const int INF = 1e9 + 7;
const ll LL_MAX = 9223372036854775807;
const ll LL_MIN = -9223372036854775807;

int dsp[3] = {-1,0,1};

int keta(ll i){

  int keta = 0;
  do{
    keta++;
  }while(i /= 10);

  return keta;
}
//素因数分解　O(√n)
vector<pair<ll,ll>> pfactor(ll n){
  vector<pair<ll,ll>> factor;
   ll ex; //指数
   for(ll a = 2; a * a <= n; a++){
     if(n % a != 0)continue;

     ll ex = 0;

     while(n % a == 0){
       n /= a;
       ex++;
     }

     factor.push_back({a,ex});
   }

   if(n != 1) factor.push_back({n,1});

  return factor;
}

int main(void){

  ll n;
  cin >> n;
  set<ll> s;

  for(ll a = 2; a*a <= n;a++){
    ll x = a * a;
    while(x <= n){
      s.insert(x);
      x *= a;
    }
  }
  cout << n-s.size();

  return 0;
}


#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const i64 INF = (i64) 1e18 + 42;
const int MOD = (int) 1e9 + 7;

inline int add(int a, int b, int mod = MOD) {
  a += b; return a >= mod ? a - mod : a;
}
inline int sub(int a, int b, int mod = MOD) {
  a -= b; return a < 0 ? a + mod : a;
}
inline int mul(int a, int b, int mod = MOD) {
  return int((long long) a * b % mod);
}
inline int mpow(int base, long long ex, int mod = MOD) {
  int res = 1;
  for (; ex > 0; ex >>= 1) {
    if (ex & 1) res = mul(res, base, mod);
    base = mul(base, base, mod);
  }
  return res;
}
inline int inv(int a, int mod = MOD) {
  return mpow(a, mod - 2, mod);
}
inline int mdiv(int a, int b, int mod = MOD) {
  return mul(a, mpow(b, mod - 2,  mod));
}
inline void adds(int &a, int b, int mod = MOD) {
  a += b; if (a >= mod) a -= mod;
}
inline void subs(int &a, int b, int mod = MOD) {
  a -= b; if (a < 0) a += mod;
}
inline void muls(int &a, int b, int mod = MOD) {
  a = int((long long) a * b % mod);
}
inline void mdivs(int &a, int b, int mod = MOD) {
  a = mdiv(a, b, mod);
}

char a[2010][2010];
int dp[4][2010][2010];

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);

  int k = 0;
  int n, m; cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      if (a[i][j] == '.') {
        dp[0][i][j] = 1 + dp[0][i - 1][j];
        dp[1][i][j] = 1 + dp[1][i][j - 1];
        ++k;
      }
    }
  }
  int ans = 0;
  for (int i = n; i > 0; --i) {
    for (int j = m; j > 0; --j) {
      if (a[i][j] == '.') {
        dp[2][i][j] = 1 + dp[2][i + 1][j];
        dp[3][i][j] = 1 + dp[3][i][j + 1];
        int tot = k - (dp[0][i][j] + dp[1][i][j] + dp[2][i][j] + dp[3][i][j] - 3);
        adds(ans, mpow(2, tot));
      }
    }
  }
  ans = sub(mul(k, mpow(2, k)), ans);
  kek(ans);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dd;
#define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++)
#define nl cout<<"\n";
#define forn(a,b) for (int ii=a;ii<b;ii++)
const ll MOD1=1e9+7;
const ll MOD2=998244353;
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define hhh cout<<"here"<<endl;

ll mod=MOD1;
ll po(ll x,ll y) {if(y<0)return 0;y%=mod;ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
ll gcd(ll a, ll b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);}

void dfs(int u,vi&a,vector<vi>&adj,vi&vis,vi&dp){
	vis[u]=1;
	if(adj[u].size()==0){
		dp[u]=-1e9;return;
	}
	for(auto v:adj[u]){
		if(!vis[v])dfs(v,a,adj,vis,dp);
		dp[u]=max(dp[u],max(a[v],dp[v]));
	}
}
void solve(){
	int n,m;cin>>n>>m;
	vi a(n+1);forn(0,n)cin>>a[ii+1];
	vector<vi>adj(n+1);
	forn(0,m){
		int u,v;cin>>u>>v;
		adj[u].pb(v);
	}vi dp(n+1);
	vi vis(n+1);
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i,a,adj,vis,dp);
			vis[i]=1;
		}
	}int mx=-1e9;
	forn(1,n+1){
		mx=max(mx,dp[ii]-a[ii]);
	}cout<<mx;
}
int main(){
    // fastio
    // ++*(int*)0;// crash
    // freopen("in.txt","r",stdin);freopen("outt.txt","w",stdout);
    // tst
    {
        solve();nl;
    }
}
/*

4
 13 12   7  11 16   15 2  14

*/


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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;

long long LLINF = 1e18;
int INF = 1e9+1e6;
#define MAXN (5006)
int n, m, mod=998244353, ans, gap[MAXN], memo[MAXN];
ll qexp(ll x,ll e) {
	ll sum=1;
	for(;e;e>>=1,x*=x,x%=mod) if(e&1) sum*=x, sum%=mod;
	return sum;
}
int main() {
	FAST
	cin>>n>>m;
	ans = qexp(m, n) * n % mod;
	// cerr<<ans<<'\n';
	FOR(i,0,m) memo[i]=1;
	FOR(i,0,n) {
		FOR(j,0,m-1) {
			gap[i] += memo[j];
			if(gap[i] >= mod) gap[i] -= mod;
			memo[j] = ll(memo[j]) * j % mod;
		}
	}
	memo[0] = 1; FOR(i,1,n) memo[i] = ll(memo[i-1]) * m % mod;
	FOR(i,1,n) {
		DEC(j,i-1,1) {
			// cerr<<gap[i-j]<<'\n';
			// cerr<<i<<' '<<j<<": "<<qexp(m, j-1 + n-i) * gap[i-j-1] % mod<<'\n';
			ans -= ll(memo[j-1 + n-i]) * gap[i-j-1] % mod;
			if(ans < 0) ans += mod;
		}
	}
	cout<<ans<<'\n';
}

/**
*   author:  akifpathan
*   created: Wednesday 23.06.2021 01:28:14 PM
**/

#ifdef akifpathan
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mx=1e6+5;

ll f(int n)
{
	return 1LL*n*n;
}

ll dp[mx];
int fre[mx];

int range(int l,int r,int i)
{
	return r/i-(l-1)/i;
}

void solve()
{
	int l,r;
	cin>>l>>r;

	for(int i=l;i<=r;i++)
	{
		int x=i;
		for(int j=1;j*j<=x;j++)
		{
			if(x%j==0)
			{
				fre[j]++;
				fre[x/j]++;
				if(j*j==x) fre[j]--;
			}
		}
	}

	for(int i=r;i>=1;i--)
	{
		dp[i]=f(fre[i]);
		for(int j=2*i;j<=r;j+=i) dp[i]-=dp[j];
	}

	for(int i=l;i<=r;i++)
	{
		int temp=range(l,r,i);

		dp[i]--;
		temp--;

		dp[i]-=(2*temp);
	}

	cout<<accumulate(dp+2,dp+r+1,0LL);
}

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

	int testcase=1;
	//cin>>testcase;

	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}

	#ifdef akifpathan
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;
using LL = long long;

const int kMaxN = 2e5 + 1;
const int kMaxM = 101;
const int kM = 1e9 + 7;

LL n, ans, u, v, w;
LL c[kMaxN], d[kMaxM];

bool vis[kMaxN];

vector<LL> a[kMaxN], b[kMaxN];

void Dfs(LL x, LL y) {
  if (vis[x]) {
    return;
  }
  vis[x] = true;
  c[x] = y;
  for (LL i = 0; i < a[x].size(); i++) {
    Dfs(a[x][i], y ^ b[x][i]);
  }
}

int main() {
  cin >> n;
  for (LL i = 1; i < n; i++) {
    cin >> u >> v >> w;
    a[u].push_back(v), b[u].push_back(w);
    a[v].push_back(u), b[v].push_back(w);
  }
  Dfs(1, 0);
  for (LL i = 1; i <= n; i++) {
    for (LL j = 0; j <= 61; j++) {
      if (c[i] & (1ll << j)) {
        d[j]++;
      }
    }
  }
  for (LL i = 0; i <= 61; i++) {
    ans = (ans + 1ll * (n - d[i]) * d[i] % kM * ((1ll << i) % kM) % kM) % kM;
  }
  cout << ans;
  return 0;
}

#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;

#define eb emplace_back

#define F first
#define S second

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))

const ll MOD = 1e9 + 7;

vector<vector<pair<int, ll>>> adj(200001);
vector<ll> val(200001, 0);

void dfs(int n, int m = -1) {
    for (auto b : adj[n]) {
        if (b.F != m) {
            val[b.F] = val[n] ^ b.S;
            dfs(b.F, n);
        }
    }
}

void solve() {
    int n; cin >> n;
    ice (i, 0, n - 1) {
        int u, v; ll w; cin >> u >> v >> w; --u; --v;
        adj[u].eb(v, w);
        adj[v].eb(u, w);
    }
    dfs(0);
    ll ans = 0;
    ice (i, 0, 60) {
        ll zero = 0, one = 0;
        ice (j, 0, n) {
            val[j] & (1LL << i) ? one++ : zero++;
        }
        ll cnt = (((zero * one) % MOD) * ((1LL << i) % MOD)) % MOD;
        ans = (ans + cnt) % MOD;
    }
    cout << ans;
}

int main() {
    solve();
}


#include<bits/stdc++.h>
#define int long long
#define ri register signed
#define rd(x) x=read()
using namespace std;
const int N=2e5+5;
const int M=21;
const int maxn=5e6+5;
const int mod=998244353;
const int inf=0x3f3f3f3f3f3f3f3f;
inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if (ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline int ksm(int x,int y=mod-2,int z=mod){if (y==0) return 1;int ret=1;while (y){if (y&1) ret=(ret*x)%z;x=(x*x)%z;y>>=1;}return ret;}

int n,m,ans;
signed main()
{
	rd(n);rd(m);
	ans=n*ksm(m,n)%mod;
	for (int l=0;l<=n-2;l++) for (int v=1;v<=m;v++)
	{
		ans-=ksm(m,n-l-2)*ksm(m-v,l)%mod*(n-1-l);
		//printf("l=%lld,v=%lld,-=%lld\n",l,v,ksm(m,n-l-2)*ksm(m-v,l));
		ans%=mod;
	}
	cout<<(ans+mod)%mod<<endl;
}

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

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

const int mod = 1e9 + 7;
int A[100001];

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

	int N;
	cin >> N;
	rep1(i, N) cin >> A[i];
	sort(A + 1, A + N + 1);

	int kotae = 1;
	rep(i, N) {
		kotae = kotae * ll(A[i + 1] - A[i] + 1) % mod;
	}

	co(kotae);

	Would you please return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
#define For(i,k,n) for(int i=k;i<n;i++)
#define Forll(i,k,n) for(long long int i=k;i<n;i++)
#define Forull(i,k,n) for(long long int i=k;i<n;i++)

const ll MOD = 1e9 + 7;
const ll INF = 1e9;

void solve(){
   int a,b,c;
   cin>>a>>b>>c;

   if(a*a+b*b<c*c)
   cout<<"Yes"<<"\n";
   else
   cout<<"No"<<"\n";

    }

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

     ll int tc=1;
    //cin >> tc;
    for (ll int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();

    }
}

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

int main(){
    int v,t,s,d,p;
    cin>>v>>t>>s>>d;

    if (t*v<=d &&  d<=s*v)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define ll long long
#include <cmath>
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vii vector<vector<int>>
#define tp tuple<double,ll,ll>
#define sd(a) scanf("%lld",&a)
#define pr(a) printf("%d ",a)
//#define mod 1000000007
const double EPS = 1e-9;
#define f(o,g,h) for(ll o=g;o<h;o++)
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
const int M = 1e9+7;
int mod(int a){return (a%M + M)%M;}
int add(int a,int b){return mod(mod(a)+mod(b));}
namespace number_theory {
  int gcd(int x, int y) {
    if (x == 0) return y;
    if (y == 0) return x;
    return gcd(y, x % y);
  }
  bool isprime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

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

    return true;
  }

  bool prime[15000105];
  void sieve(int n) {
    for (int i = 0; i <= n; i++) prime[i] = 1;
    for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p)
      prime[i] = false;
    }
    }
    prime[1] = prime[0] = 0;
  }

  vector<int> primelist;
  bool __primes_generated__ = 0;

  void genprimes(int n) {
    __primes_generated__ = 1;
    sieve(n + 1);
    for (int i = 2; i <= n; i++) if (prime[i]) primelist.push_back(i);
  }

  vector<int> factors(int n) {
    if (!__primes_generated__) {
    cerr << "Caint genprimes you dope" << endl;
    exit(1);
    }
    vector<int> facs;

    for (int i = 0; primelist[i] * primelist[i] <= n && i < primelist.size(); i++) {
    if (n % primelist[i] == 0) {
      while (n % primelist[i] == 0) {
      n /= primelist[i];
      facs.push_back(primelist[i]);
      }
    }
    }
    if (n > 1) {
    facs.push_back(n);
    }
    sort(facs.begin(), facs.end());
    return facs;
  }

  vector<int> getdivs(int n) {
    vector<int> divs;
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        divs.push_back(i);
        divs.push_back(n / i);
      }
    }

    getunique(divs);
    return divs;
  }
}
using namespace number_theory;

void solve(){
   double a,b; cin>>a>>b;
   cout<<(a*b/100);
 }
int32_t main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // genprimes(1e7);
    //init();
    int t; //cin>>t;
    t=1;
     while(t--)
       solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数

uniform_real_distribution<double> rnd(0.00,1.00);

int main(){

	ll N,X;
	string s;
	cin >> N >> X;
	cin >> s;

	FOR(i,0,N){
		if(s[i]=='o')X++;
		if(s[i]=='x')X--;
		if(X<0)X=0;
	}
	cout << X << endl;
}