#define ll long long
#define dd long double
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define tri tuple<ll ,ll ,ll>
#define tll tuple<ll ,ll , ll , ll>
#define pll pair<ll ,ll>
#include<bits/stdc++.h>
/*#include<iomanip>
#include<cmath>
#include<cstdio>
#include<utility>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<bitset>*/
dd pi = acos(-1) ;
ll z =  1000000007 ;
ll inf = 100000000000000000 ;
ll p1 = 37 ;
ll p2 = 53 ;
ll mod1 =  202976689 ;
ll mod2 =  203034253 ;
ll fact[1000005] ;
ll gdp(ll a , ll b){return (a - (a%b)) ;}
ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ;    return (a - (a%b)) ;} // greatest number <= a divisible by b
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
ll x1 , y1 , g; g = e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return g ;}
ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
ll max(ll a , ll b){if(a > b) return a ; return b ;}
ll min(ll a , ll b){if(a < b) return a ; return b ;}
ll left(ll i){return ((2*i)+1) ;}
ll right(ll i){return ((2*i) + 2) ;}
ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
//ios_base::sync_with_stdio(0);
//cin.tie(0); cout.tie(0);
using namespace std ;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
//__builtin_popcount(n) -> returns number of set bits in n
ll seed;
mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits

void solve()
{

    ll n , m ;
    cin >> n >> m ;
    string str ;
    ll even = 0 , odd = 0 ;
    fo(i , n)
    {
        cin >> str ;
        ll cnt = 0 ;
        fo(j , m)
            if(str[j] == '1')
                cnt++ ;
        if(cnt%2 == 0)
            even++ ;
        else
            odd++ ;
    }
    cout << even*odd << '\n' ;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("errorf.txt" , "w" , stderr) ;
    #endif*/

    ll c ;
    //cin >> c ;
    c = 1 ;

    for(ll x = 1 ; x <= c ; x++)
    {
       solve() ;
    }
    //cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;
}

// Created by ...
#include <bits/stdc++.h>

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define sz(x) (int)(x).size()
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define per(i,a,b) for(ll i = a; i >= b; --i)
#define pii pair<ll,ll>
#define vec(a) vector<a >
#define all(a) (a).begin(),(a).end()
#define EACH(x, a) for (auto& x:a)
#define se second
#define fi first
#define inf 0xffffffff
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
template<class T> T Min(T a,T b){if(a<b)return a; return b;}
template<class T> T Max(T a,T b){if(a>b)return a; return b;}
string x,mstr;
int m,n;

string Add(string s,string t)
{
	vll ans(Max(s.size(),t.size())+5,0);
	reverse(all(s)); reverse(all(t));
	rep(i,0,Max(s.size(),t.size())-1)
	{
		int x=0;
		if(i<s.size())x+=(s[i]-'0');
		if(i<t.size())x+=(t[i]-'0');
		ans[i]=x;
	}
	rep(i,0,ans.size()-2)
	{
		int x=ans[i]/10;
		ans[i+1]+=x;
		ans[i]%=10;
	}
	int val;
	reverse(all(ans));
	rep(i,0,ans.size()-1)if(ans[i]!=0){val=i;break;}
	string re="";
	rep(i,val,ans.size()-1)re+=(ans[i]+'0');
	return re;
}

string multiply(string s,int n){
	if(n==0 || s.empty())return "0";
	reverse(all(s));
	string ans;
	int carry=0;
	for(char c:s){
		int x=carry+(c-'0')*n;
		ans+=(x%10+'0');
		carry=x/10;
	}
	while(carry){
		ans+=(carry%10+'0');
		carry/=10;
	}
	reverse(all(ans));
	return ans;
}
bool check(int base){
	if(base==0)return true;
	string val;
	rep(i,0,n-1){
		val=Add(multiply(val,base),string(1,x[i]));
	}

	//cout<<val<<":"<<base<<endl;
	if(val.size()==mstr.size()){
		rep(i,0,sz(val)-1){
			if(val[i]!=mstr[i])
				return val[i]<mstr[i];
		}
		return true;
	}
	return val.size()<mstr.size();
}
int32_t main() {
    IOS;
    	cin>>x>>m;
    	n=sz(x);
    	if(n==1){
    		if(x[0]-'0'<=m)cout<<"1";
    		else cout<<"0";
    		return 0;
    	}
        int d=x[0]-'0';
        for(auto c:x){
        	int cc=c-'0';
        	d=Max(d,cc);
        }
        int temp=m;
        while(temp){
        	mstr+=(temp%10+'0');
        	temp/=10;
        }
        reverse(all(mstr));
        //cout<<mstr<<endl;
        int low=0,high=1e18,ans=low,mid;
       	while(low<=high){
        	mid=(low+high)>>1;
        	//cout<<mid<<endl;
        	if(check(mid)){
        		ans=mid;
        		low=mid+1;
        	}
        	else high=mid-1;
        }
        cout<<Max(0LL,ans-d);

        cout<<'\n';
    return 0;
}


#include<iostream>
#include<queue>
using namespace std;
priority_queue<long long , vector<long long>,greater<long long> >q;
long long n,v[400015];
int main()
{
	cin>>n;
	long long sum=0;
	for(int i=1;i<=2*n;i++)
	{
		cin>>v[i];
		sum+=v[i];
	}
	long long l=n;
	long long r=n+1;
	while(l>=1)
	{
		q.push(v[l--]);
		q.push(v[r++]);
		sum-=q.top();
		q.pop();
	}
	cout<<sum<<endl;
	return 0;
}

// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;
using namespace std ;

typedef long long ll ;
typedef long double ldb ;

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

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<pair<ll,int> > vpli ;
typedef vector<int,pil> edges ;
typedef vector<vi> matrix ;
typedef priority_queue<int> pqu ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define per(i,b,a) for (int i = (b); i >= (a); i--)

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define ins insert
#define bk back
#define con continue
#define lbd lower_bound
#define ubd upper_bound

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

#define pr cout << // I don't like this but my laptop's 'O' key is not functioning well

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 4e18 ;
const int infi = 2e9 ;
const int maxn = 5e5 + 5 ;
const int block = 500 ;
const int logn = 60 ;
const int alpha = 27 ;
const ldb pi = acos(-1) ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
int rng_lr(int a, int b)
{
    int ret ;
    ret = uniform_int_distribution<int>(a, b)(rng) ;
    return ret ;
    // For shuffling use shuffle(all, rng) ;
}

ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }
int icast(char ch) { return int(ch-'a') ; }
void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; }
void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; }

// Check constraints + overflows + types in typedef

int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    int n ;
    cin >> n ;
    vi a(2*n) ;
    rep(i,0,2*n-1) {
        cin >> a[i] ;
    }
    ll res = 0 ;
    int l = n-1, r = n ;
    multiset<int> s ;
    //s.insert(max(a[l], a[r])) ;
    while(l >= 0) {
        s.insert(max(a[l], a[r])) ;
        if(*s.begin() < min(a[l], a[r])) {
            s.erase(s.begin()) ;
            s.insert(min(a[l], a[r])) ;
        }
        l-- ;
        r++ ;
    }
    for(multiset<int>::iterator itr = s.begin() ; itr != s.end() ; itr++) {
        res += *itr ;
    }
    pr res << "\n" ;

    return 0 ;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
static const ll mod=1000000007;

int pow_mod(long long n,long long m,long long p){
  if(p==0) return 1;
  else if(p%2==1){
    return pow_mod(n,m,p-1)*n%m;
  }
  else{
    long long t=pow_mod(n,m,p/2);
    return t*t%m;
  }
}

signed main() {
  ll na,pa;
  cin>>na>>pa;
  ll ans=pa-1;
  ans*=pow_mod(pa-2,mod,na-1);
  ans%=mod;
  cout<<ans<<endl;
  return 0;
}

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

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


//https://oeis.org/search?q=0%2C0%2C1%2C2%2C4%2C6&language=english&go=Search
//https://smallpdf.com/result#r=dc43c99933feaa1c7f3a2f2e2036bc6a&t=pdf-to-word
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
using namespace std;
#define ll long long
#define INF 1000007
#define MAX 500007
#define nl "\n"
#define F first
#define S second
typedef vector<ll> vi;
typedef priority_queue<ll , vector<ll> , greater<ll> > pqmx;
typedef priority_queue<ll> pqmn;
typedef pair<ll , ll> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector< pair<int , int> > vpi;
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define yeS(GOOD)      GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define all(a) a.begin() , a.end()
#define pb push_back
#define ar array
ll mod = LLONG_MAX;
ll binpow(ll a, ll b){ll res=1;a%=mod;while(b>0){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll binmul(ll a, ll b){ll res=0;a%=mod;while(b>0){if(b&1)res=(res + a)%mod;a=(a + a)%mod;b>>=1;}return res;}
ll area(pi a, pi b,pi c){return abs(a.F * b.S + b.F * c.S + c.F*a.S - a.S * b.F - b.S * c.F - c.S * a.F);}
ll gcd (ll a,ll b){if(b==0)return a;else return gcd (b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll min(ll a,ll b){if(a < b){return a;}return b;}
ll max(ll a,ll b){if(a > b){return a;}return b;}
double intlog(ll n ,ll base){return (double)log(n)/log(base);}
ll n , t , m , temp , temp2, root , p ,q , k , i , j , r , u , v , w;
struct comp {
    bool operator()( pair<int, int> const& a, pair<int, int> const& b) {
        return a.first < b.first || (a.first == b.first && a.second > b.second);
    }
};

bool is_valid(int i , int j , vector<vc> & a){
    if(i < 0 || j < 0 || i >= n || j >= m){
        return false;
    }
    return a[i][j] == '.';
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
#endif
    cin>>n>>m;
    cin>>p>>q;
    vector<vc> a(n + 1, vc(m + 1));
    fr(i , n){fr(j , m)cin>>a[i][j];}
    p--;q--;
    ll res = 0;
    if(a[p][q] == '.')res++;
    int i = p;int j = q;
    int k = 1;
    while(is_valid(i - k, j , a)){k++;res++;}
    k = 1;
 //   cout<<"yes"<<nl;
    while(is_valid(i , j - k , a)){k++;res++;}
    k = 1;
    while(is_valid(i + k, j , a)){k++;res++;}
    k = 1;
    while(is_valid(i , j + k , a)){k++;res++;}
    cout<<res<<nl;
#ifndef ONLINE_JUDGE
    cout << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s .\n";
#endif
}

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
void solve()
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    x--,y--;
    string s[n];
    for(int i=0;i<n;i++) cin>>s[i];
    int ans=0;
    if(s[x][y]=='.')
    {
        ans++;
        int x1 = x;
        x--;
        while(x>=0 && s[x][y]=='.') x--,ans++;
        x=x1;
        x++;
        while(x<n && s[x][y]=='.') x++,ans++;
        int y1 = y;
        y--;
        x=x1;
        while(y>=0 && s[x][y]=='.') y--,ans++;
        y=y1;
        y++;
        while(y<m && s[x][y]=='.') y++,ans++;
    }
    cout<<ans;

}
int main()
{
    int t=1;
    while(t--)
    {
        solve();
    }
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
  for (auto val : vec) {
    if (std::is_fundamental<T>::value)
      stream << " " << val;
    else
      stream << std::endl << val;
  }
  return stream;
}

struct Edge {
  int to;
  long long C;
  long long D;
  Edge(int to, long long c, long long d) : to(to), C(c), D(d) {}
};

using Graph = std::vector<std::vector<Edge>>;

int main() {
  int N, M;
  std::cin >> N >> M;

  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    long long c, d;
    std::cin >> a >> b >> c >> d;
    a--, b--;
    G[a].push_back(Edge(b, c, d));
    G[b].push_back(Edge(a, c, d));
  }

  std::vector<long long> dist(N, LINF);

  using qval = std::pair<long long, int>;
  std::priority_queue<qval, std::vector<qval>, std::greater<qval>> pque;

  int s = 0;
  dist[s] = 0;
  pque.push(std::make_pair(dist[s], s));

  while (!pque.empty()) {
    // 未確定のノードの中から暫定値が最小のものを取り出す
    int v = pque.top().second;
    long long d = pque.top().first;
    pque.pop();

    // dist[v] < d はゴミを意味する
    if (dist[v] < d)
      continue;

    // 選択されたノードから出ている辺を緩和する
    for (auto &e : G[v]) {
      int nv = e.to;
      long long C = e.C;
      long long D = e.D;

      // weight の計算
      long long w = LINF;
      long long val = int(std::sqrt(D)) - 1 - d;
      long long l = val - 5;
      if (l < 0)
        l = 0;
      for (int k = 0; k < 10; ++k) {
        long long x = l + k;
        long long tmp = x + C + (long long)(D / (1 + d + x));
        w = std::min(w, tmp);
      }

      if (dist[v] + w < dist[nv]) {
        dist[nv] = dist[v] + w;
        pque.push(std::make_pair(dist[nv], nv));
      }
    }
  }

  if (dist[N-1] == LINF)
    std::cout << -1 << std::endl;
  else
    std::cout << dist[N-1] << std::endl;

}

#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <string>
#include <fstream>
#include <ios>
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdlib>
#include <cstddef>
#include <cstdarg>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cwchar>
#include <cwctype>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
using ll = long long;
using ull = unsigned long long;

#define ALL(c) (c).begin(), (c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ABS(a) ((a)>0?(a):-(a))
template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }

constexpr int mo = 1000000007;
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct Edge {
	int to;
	ll C, D;
};

ll Cost(ll t, ll C, ll D) {
	ll left = t;
	ll right = t + 2000000000ll;
	while (left + 2 < right) {
		ll middle_low = (left * 2 + right) / 3;
		ll cost_middle_low = middle_low + C + D / (middle_low + 1);
		ll middle_high = (left + right * 2) / 3;
		ll cost_middle_high = middle_high + C + D / (middle_high + 1);
		if (cost_middle_low < cost_middle_high) {
			right = middle_high;
		}
		else {
			left = middle_low;
		}
	}
	ll result = numeric_limits<ll>::max();
	for (ll tt = max(t, left - 500); tt <= left + 500; ++tt) {
		MIN_UPDATE(result, tt + C + D / (tt + 1));
	}
	return result;
}

int main() {
	std::ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<Edge>> graph(N + 1);
	REP(m, M) {
		int A, B, C, D;
		cin >> A >> B >> C >> D;
		graph[A].push_back({ B, C, D });
		graph[B].push_back({ A, C, D });
	}

	// -cost, current
	priority_queue<pair<ll, int> > q;
	q.emplace(0, 1);
	vector<ll> dp(N + 1, numeric_limits<ll>::max() / 2);
	dp[1] = 0;
	while (!q.empty()) {
		ll cost = -q.top().first;
		int current = q.top().second;
		q.pop();

		if (dp[current] != cost) {
			continue;
		}

		for (auto& edge : graph[current]) {
			ll next_cost = Cost(cost, edge.C, edge.D);
			if (dp[edge.to] > next_cost) {
				dp[edge.to] = next_cost;
				q.emplace(-next_cost, edge.to);
			}
		}
	}

	if (dp[N] == numeric_limits<ll>::max() / 2) {
		cout << -1 << endl;
	}
	else {
		cout << dp[N] << endl;
	}
}


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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

#define int long long
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define precise(x) fixed << setprecision(x)

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    if(a == 0) return 0;
    b %= (M - 1);  //M must be prime here

    int res = 1;

    while(b > 0)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }

    return res;
}

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

   string s,t;
    cin >> s >> t;

   int states[n+1][7];

   f(i,n+1) f(j,7) states[i][j] = 0;

   states[n][0] = 1;

   int pw = 1;

   for(int i=n-1;i>=0;i--)
   {
       int one = (pw*(s[i] - '0'))%7;
       int two = 0;

       f(j,7)
       {
           if(t[i] == 'T')
           {
               if(states[i+1][(j + one)%7] || states[i+1][(j + two)%7])
                   states[i][j] = 1;
           }
           else
           {
               if(states[i+1][(j + one)%7] && states[i+1][(j + two)%7])
                   states[i][j] = 1;
           }
       }

       pw = (pw*10)%7;
   }

   if(states[0][0]) cout <<"Takahashi\n";
    else cout <<"Aoki";

}

signed main()
{
    fast;

    int t = 1;

//    cin >> t;

    while(t--)

    solve();
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll M, H;
    cin >> M >> H;
    if(H % M == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <numeric>

typedef long long ll;

ll stringToFixedPoint(const std::string s, const int digitAfterDecimalPoint)
{
    ll fp = std::stoi(s) * pow(10, digitAfterDecimalPoint);
    const auto pos = s.find('.');
    if (pos != std::string::npos) {
        std::string afterDecimalPoint = s.substr(pos + 1);
        fp += std::stoi(afterDecimalPoint) * pow(10, digitAfterDecimalPoint - afterDecimalPoint.length());
    }

    return fp;
}

int main(int argc, char *argv[])
{
    std::string strX, strY, strR;

    std::cin >> strX >> strY >> strR;

    ll cx, cy, cr;
    const int digitAfterDecimalPoint = 4;
    const ll k = pow(10, digitAfterDecimalPoint);
    cx = stringToFixedPoint(strX, digitAfterDecimalPoint);
    cy = stringToFixedPoint(strY, digitAfterDecimalPoint);
    cr = stringToFixedPoint(strR, digitAfterDecimalPoint);

    ll ans = 0;
    for (ll y = (((cy + cr) / k) * k); y >= cy - cr; y -= k) {
        ll dy = y - cy;
        ll dxp = sqrt(cr * cr - dy * dy) + k;

        bool xmaxFound = false;
        ll xmax;
        for (ll x = (((cx + dxp) / k) * k); x >= cx - dxp; x -= k) {
            ll dx = x - cx;
            ll r2 = dy * dy + dx * dx;
            if (r2 <= cr * cr) {
                xmaxFound= true;
                xmax = x;
                break;
            }
        }
        if (!xmaxFound) {continue;}
        ll xmin;
        for (ll x = (((cx - dxp) / k) * k); x <= cx + dxp; x += k) {
            ll dx = x - cx;
            ll r2 = dy * dy + dx * dx;
            if (r2 <= cr * cr) {
                xmin = x;
                break;
            }
        }
        ll ansAdd = (xmax - xmin) / k + 1;
        ans += ansAdd;
    }

    std::cout << ans << std::endl;

    return 0;
}

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

int main() {
	long long N, K, M, COUNT = 0, A;
	cin >> N >> K >> M;
	COUNT = N * M;
	for (int i = 0; i < N - 1; i++) cin >> A, COUNT -= A;
	cout << (COUNT > K ? -1 : max(0LL, COUNT)) << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long ;

const int N = 4e6 + 7;
const int mod = 1e9 + 7 ;

int n , m, k ;

long long fact[N] ;

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

ll inv(ll x) { return faspow(x, mod - 2); }
ll ncr(ll x, ll y) { return 1ll * fact[x] * inv(fact[y]) % mod * inv(fact[x - y]) % mod; }

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
       freopen("in.in", "r", stdin);
#endif
       fact[0] = 1ll ;
       for(int i = 1;i < N ; ++ i)fact[i] = 1ll * i * fact[i -1 ] % mod ;
       cin >> n >> m >> k ;
       if(n > m + k)return cout << 0 , 0;
       cout << (ncr(n + m , n) - ncr(n + m , m + k + 1) + mod) % mod ;
       return 0;
}

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 <<23;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n, m, k; cin >> n >> m >> k;
	if (n > m + k) {
		cout << 0 << "\n";
		return;
	}
	modint ans = comb(n + m, n);
	ans -= comb(n+m, n-k-1);
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	init_f();
	//init(); cout << ps.size() << "\n";
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


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

double dp[101][101][101];
bool vis[101][101][101];
double func(int a,int b,int c){
         if(a==100 || b==100 || c==100)
            return 0;
         if(vis[a][b][c]==1)
            return dp[a][b][c];
         vis[a][b][c]=1;
         int cnt=a+b+c;
         double ans=0;
         if(a>0)
         ans+=(1+func(a+1,b,c)*1.0)*a/cnt;
         if(b>0)
         ans+=(1+func(a,b+1,c)*1.0)*b/cnt;
         if(c>0)
         ans+=(1+func(a,b,c+1)*1.0)*c/cnt;
         return dp[a][b][c]=ans;
}
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    memset(vis,0,sizeof(vis));
    cout<<setprecision(10)<<func(a,b,c)<<endl;

}

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

int main() {
    long long x, y, a, b;
    cin >> x >> y >> a >> b;
    long long now = 0;
    long long tar = b / (a - 1);
    while (x < tar && x * a < y) {
        x *= a;
        now++;
    }
    if (y - x - 1 > 0)
        now += (y - x - 1) / b;
    cout << now;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

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

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

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	rep(i, N) cin >> A[i];
	sort(A.begin(), A.end());
	ll sum = 0;
	rep(i, N) sum += A[i];

	ll ans = 0;
	rep(i, N) {
		sum -= A[i];
		ans += max(0LL, sum - A[i] * (N - 1 - i));
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &mp) { os << '['; string sep; for (const auto &x : mp) os << sep << x, sep = ", "; return os << ']'; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }

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

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] =", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define mod 1000000007
#define inf 1e18
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

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

int sumPairs(vector<int> &arr, int n)
{
    int sum = 0;
    for (int i = n - 1; i >= 0; i--)
        sum += i * arr[i] - (n - 1 - i) * arr[i];
    return sum;
}

void solve()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //cout << fixed << setprecision(10);
    int n; cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(all(v));
    cout << sumPairs(v, n) << endl;
}

int32_t main()
{
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type >
ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

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

    int n; cin >> n;
    int ans = 0;
    if (n >= 2)
        ans = n - 1;
    cout << ans;
    return 0;
}

/*

*/

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

int main()
{
    double n,d;
    cin>>n;

    cout<<n-1;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法

//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート

int main() {
  int h,w;

  cin >>h>>w;

vector<string> s(h);
int ans=0;
rep(i,0,h){
    string ss;
    cin>>ss;
    s.at(i)=ss;
}
rep(i,0,h){
    rep(j,0,w-1){
       if(s.at(i).at(j)=='.'&&s.at(i).at(j+1)=='.') {
           ans++;
       }
    }
}
rep(i,0,h-1){
    rep(j,0,w){
       if(s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.') {
           ans++;
       }
    }
}

cout<<ans;

 return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<vector>
#include<algorithm>
constexpr unsigned long long MOD = 998244353;
constexpr unsigned long long IM = 18479187003;
constexpr unsigned long long MOD32 = 665496236;

    unsigned long long dp[5001];
int main(){
    int H=0, W=0, K=0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}
    std::vector<std::vector<std::pair<int, char>>> f(H);
    unsigned long long y = H * W - K;
    while(--K>=0){
        int h=0, w=0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
        --h; --w;
        f[h].emplace_back(w, getchar_unlocked());
        getchar_unlocked();
    }
    --H; --W;
    dp[0] = 1;
    for(int i = 0; i < H; ++i){
        std::sort(f[i].begin(), f[i].end());
        auto itr = f[i].begin();

        for (int j = 0; j <= W; ++j){
            if(itr != f[i].end() and itr->first == j){
                char c = itr->second;
                if(c != 'D') dp[j + 1] += dp[j];
                if(c == 'R') dp[j] = 0;
                ++itr;
            }
            else{
                {
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] = dp[j] - x * MOD+MOD;
             }
                dp[j + 1] += dp[j];
            }
        }
    }

  {
        std::sort(f[H].begin(), f[H].end());
        auto itr = f[H].begin();
        for (int j = 0; j < W; ++j){
            if(itr != f[H].end() and itr->first == j){
                char c = itr->second;
                if(c != 'D') dp[j + 1] += dp[j];
                ++itr;
            }
            else{
                 {
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] = dp[j] - x * MOD+MOD;
             }
                dp[j + 1] += dp[j];
            }
        }
  }

    unsigned long long x = 3;
    while(y) {
      if(y & 1) {
        dp[W] *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(dp[W], IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64);
#endif
        dp[W] = dp[W] - x2 * MOD+MOD;
               }
      {
        x *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(x, IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(x)*IM) >> 64);
#endif
        x = x- x2 * MOD + MOD;}
      y >>= 1;
    }
    printf("%d", dp[W] % MOD);

    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(z, v.size()) cerr << " " << v[z]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;

template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  rep(j, v.size()) i >> v[j];
  return i;
}

template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}

template <class T>
void chmin(T& a, const T& b) {
  if (b < a) a = b;
}

ll N, M;
vll done, keiro;
vvll to;

void dfs(ll i) {
  if (done[i]) return;
  done[i] = 1;
  keiro.pb(i);
  for (ll t : to[i]) dfs(t);
}

vll colors;
ll cnt = 0;
void dfs2(ll i) {
  if (i == (ll)keiro.size()) {
    cnt++;
    return;
  }
  ll index = keiro[i];
  vll ng(3, 0);
  for (ll t : to[index])
    if (colors[t] != 0) ng[colors[t] - 1] = 1;
  rep(c, 3) {
    if (ng[c]) continue;
    colors[index] = c + 1;
    dfs2(i + 1);
    colors[index] = 0;
  }
}

signed main() {
  init();
  cin >> N >> M;
  done.resize(N);
  to.resize(N);
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].pb(b);
    to[b].pb(a);
  }

  ll ans = 1;
  colors = vll(N, 0);
  rep(i, N) {
    if (done[i]) continue;
    keiro = vll();
    dfs(i);
    cnt = 0;
    dfs2(0);
    ans *= cnt;
  }
  ANS;

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

int n,m;
vector <int> f[233];

long long Ans = 1;
bool vis[233];
vector <int> v;
long long Now = 0;

void Find(int x)
{
	v.push_back(x);
	vis[x] = true;
	for(auto X : f[x])
	{
		if(vis[X]) continue;
		Find(X);
	}
}

int c[233];

void DFS(int Ind)
{
	if(Ind == v.size())
	{
		Now++;
		return ;
	}
	int x = v[Ind];
	for(int i=1;i<=3;i++)
	{
		bool flag = false;
		for(auto X : f[x])
		{
			if(c[X] == i) flag = true;
		}
		if(flag) continue;
		c[x] = i;
		DFS(Ind + 1);
		c[x] = 0;
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		f[x].push_back(y);
		f[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		v.clear();
		Find(i);
		DFS(0);
		Ans = Ans * Now;
		Now = 0;

	}
	cout << Ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	cout << fixed << setprecision(15);

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

	long ans1=0;
	for(int i=0;i<n;i++)ans1+=abs(x[i]);
	cout << ans1 << endl;

	long ans2=0;
	for(int i=0;i<n;i++)ans2+=abs(x[i])*(long)abs(x[i]);
	cout << sqrt(ans2) << endl;

	int ans3=0;
	for(int i=0;i<n;i++)ans3=max(ans3,abs(x[i]));
	cout << ans3 << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll        long long int
#define ld        long double
#define mod             1000000007
#define inf             1e18
#define endl      "\n"
#define pb        push_back
#define vi              vector<ll>
#define vs        vector<string>
#define pii             pair<ll,ll>
#define ump       unordered_map
#define mp        make_pair
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define all(n)      n.begin(),n.end()
#define ff        first
#define ss        second
#define mid(l,r)        (l+(r-l)/2)
#define bitc(n)     __builtin_popcount(n)
#define loop(i,a,b)   for(long long i=(a);i<=(b);i++)
#define loopr(i,a,b)  for(long  long i=(a);i>=(b);i--)
const ll N = 1e5 + 5 ;
ll prime[N];
vector<long long>ans;
void sieve()
{
  for ( int i = 0 ; i < N; i++)
    prime[i] = i;

  prime[1] = 1 ;

  for (long long i = 2 ; i < N ; i++  ) // always use long long here !!
  {
    if (prime[i] == i)
    {
    	ans.push_back(i);
      for (long long j = i*i ; j < N; j += i)
      {
        prime[j] = i ;
      }
    }
  }

}

long long powr(int x, int y)
{
    if (y == 0)  return 1;
    long long res=powr(x,y/2);
    if (y % 2)  return (res*res*x );
    return (res*res);
 }

void file_i_o()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
}

void solve()
{    ll n ;
	 cin>>n ;
	 ll a[n];
	 ll sum =0 ;
	 loop(i,0,n-1)
	 {
	 	cin>>a[i];
	 		if(a[i]>10)
	 		{
	 			sum+= (a[i]-10);
	 		}
 	 }
 	 cout<<sum;

	return ;
}

int main() {
  clock_t begin = clock();
  file_i_o();
  sieve();
  int t=1;
 	//cin>>t;
    while(t--)
    {
      solve();
    }

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


#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
int main(){
	ld x,y,r;
	cin >> x >> y >> r;
	r += 1e-14;
	long long ans = 0;
	for(int i=ceil(x-r);i<=floor(x+r);i++){
		ld sq = (x - i) * (x - i);
		ld  a = floor(y + sqrt(r * r - sq));
		ld b = ceil(y - sqrt(r * r - sq));
		ans += (a - b) + 1;
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define P pair<ll,ll>
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ld a,b,r;
  cin>>a>>b>>r;
  r=nextafter(r,1000000.0);
  ll ans=0;
  for(ll x=ceil(a-r);x<=floor(a+r);x++){
    ld d=sqrt(r*r-(x-a)*(x-a));
    ans+=floor(b+d)-ceil(b-d)+1;
  }
  cout<<ans<<endl;
}


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

#define int long long
//#define int unsigned int
//#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
//#define lb lower_bound
//#define ub upper_bound
//#define bs binary_search
#define mod 1000000007 // mod+2
#define double long double
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
const int inf=1e18;
const int maxu=200005;
//int d;
//vector <int> adj[maxu];
//vector <int> vis(maxu);
//vector <vector <int>> v(maxu);

/*
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}

int fun(int a,int b){
    if(b==0)return 1;
    else if(a==1)return 1;
    int temp=fun(a,b/2)%mod;
    temp=(temp*temp)%mod;
     if(b%2==1)temp=(temp*a)%mod;
    return temp%mod;
}

int inv(int a,int b){
    return (a*fun(b,mod-2))%mod;
}

void dfs(int s){
    if(vis[s])return;
    vis[s]=1;
    for(auto u:adj[s]){
        dfs(u);
    }
}*/

signed main()
{   /*
   #ifndef ONLINE_JUDGE
   freopen("inputhsr.txt", "r", stdin);
   freopen("outputhsr.txt", "w", stdout);
   #endif
   */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int i,j,k=0,n,t=1,m,l=0;

    //cin>>t;
    while(t--){
        cin>>n;
        vector <pair<int,string>> v(n);
        for(i=0;i<n;i++){
            cin>>v[i].second>>v[i].first;
            v[i].first*=-1;
        }

        sort(all(v));

        cout<<v[1].second<<"\n";
        /*
       for(i=0;i<=n;i++)vis[i]=0;
       for(i=0;i<=n;i++){
            adj[i].clear();
       }
       */

        /*string s;
        cin>>s;
        n=s.length();*/

        //memset(a,0,sizeof(a));
        //cout<<fixed<<setprecision(10)<<ans<<"\n";

    }
    return 0;
}

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

using namespace std;

int main() {

        int n;
        cin >> n;
        int t[n];
        string s[n];
        string a="string";
        string ans;
        int b=-1;
        int c=-1;
        rep(i,n){
            cin >> s[i] >> t[i];
           if(i==0){
                   b=t[i];
                   a=s[i];
           } else if(i>0 && b<t[i]){
                   c=b;
                   b=t[i];
                   ans=a;
                   a=s[i];
           }else if(c<t[i]&&b>t[i]){
                   c=t[i];
                   ans=s[i];
           }
        }

cout << ans << endl;

    return 0;
}


#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
    long a,b,c;
    cin >> a >> b >> c;
    a %= 10;
    b %= 4;
    long iIndex = 0;
    if(b == 0){
        iIndex = 4;
    } else if (b == 1){
        iIndex = 1;
    } else if (b == 2){
        iIndex = (c > 1) ? 4 : 2;
    } else {
        iIndex = (c % 2 == 0) ? 1 : 3;
    }

    long nAns = 1;
    for(long i = 0; i < iIndex; i++){
        nAns *= a;
        nAns %= 10;
    }

    cout << nAns << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i=a, _n=b; i<=_n; ++i)
#define FORD(i, a, b) for(int i=a, _n=b; i>=_n; --i)
using namespace std;

int mod = 0, m, p, k, e[20], vis[20];

int pw(int b, int c) {
    if (c == 1) {
        if (b > k) b %= m, mod = 1;
        return b;
    }

    int tmp = pw(b, c >> 1);
    tmp = tmp * tmp * (c&1 ? b : 1);
    if (mod || tmp > k) tmp %= m, mod = 1;
    return tmp;
}
int main()
{
    ios::sync_with_stdio();
    cin.tie(0); cout.tie(0);
    ///freopen("a.inp","r",stdin);

    int a, b, c;
    cin >> a >> b >> c;
    a %= 10;
    memset(vis, -1, sizeof(vis));
    e[0] = 1; vis[1] = 0;
    k = 0; while (-1 == vis[(e[k] * a) % 10]) {
        e[k+1] = (e[k] * a) % 10;
        k += 1; vis[e[k]] = k;
    }

    p = vis[(e[k] * a) % 10];
    m = k - p + 1;

    int tmp = pw(b, c);
    if (mod) while (tmp < p) tmp += m;

    cout << e[tmp];
}


#include <bits/stdc++.h>
using namespace std;
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 DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define repl(i, a, b) for(int i = a; i < int(b); i++)
#define rep(i, n) repl(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    int N;
    ll X;
    cin >> N >> X;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];

    vector<map<ll, ll>> dp(60);
    dp[0][X] = 1;

    rep(i, N) {
        for(const auto &[j, val] : dp[i]) {
            if(i < N - 1) {
                ll r = j % a[i + 1];
                dp[i + 1][j - r] += val;
                if(r > 0) dp[i + 1][j + a[i + 1] - r] += val;
            } else {
                dp[i + 1][0] += val;
            }
        }
    }

    cout << dp[N][0] << "\n";
}

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

const int N = 2005;

int n, m;
char s[N][N];

pair<int, int> st, en;
vector<pair<int, int>> teleports[26];

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

int dist[N][N];

bool used[26];
bool vis[N][N];
void bfs() {
  queue<pair<int, int>> q;
  q.push(st);
  vis[st.first][st.second] = true;
  dist[st.first][st.second] = 0;

  while (q.size()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();

    for (int k = 0; k < 4; ++k) {
      int nx = x + dx[k], ny = y + dy[k];

      if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
      if (s[nx][ny] == '#') continue;
      if (vis[nx][ny]) continue;
      vis[nx][ny] = true;
      dist[nx][ny] = dist[x][y] + 1;
      q.emplace(nx, ny);
    }

    if ('a' <= s[x][y] && s[x][y] <= 'z' && !used[s[x][y] - 'a']) {
      used[s[x][y] - 'a'] = true;

      for (pair<int, int> p : teleports[s[x][y] - 'a']) {
        int nx, ny;
        tie(nx, ny) = p;

        if (vis[nx][ny]) continue;
        vis[nx][ny] = true;
        dist[nx][ny] = dist[x][y] + 1;
        q.emplace(nx, ny);
      }
    }
  }
}

int solve() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'S') {
        st = make_pair(i, j);
      } else if (s[i][j] == 'G') {
        en = make_pair(i, j);
      } else if ('a' <= s[i][j] && s[i][j] <= 'z') {
        teleports[s[i][j] - 'a'].emplace_back(i, j);
      }
    }
  }

  bfs();

  if (!vis[en.first][en.second]) printf("-1\n");
  else printf("%d\n", dist[en.first][en.second]);
  return 0;
}

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


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x;
	scanf("%d",&x);
	printf("%d",100-x%100);
	return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
	char c=getchar();int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=0;
	for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?x:-x;
}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
int a[4];
int main(){
	for(int i=1;i<=3;i++)a[i]=read();
	sort(a+1,a+4);
	printf("%d",a[2]+a[3]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  for (int i = 0; i < N; i++){
    cin >> W[i];
  }
  int S = 0;
  for (int i = 0; i < N; i++){
    S += W[i];
  }
  if (S % 2 == 1){
    cout << 0 << endl;
  } else {
    vector<vector<long long>> dp(1, vector<long long>(S / 2 + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < N; i++){
      vector<vector<long long>> dp2(i + 2, vector<long long>(S / 2 + 1, 0));
      for (int j = 0; j <= i; j++){
        for (int k = 0; k <= S / 2; k++){
          if (dp[j][k] > 0){
            dp2[j][k] += dp[j][k];
            dp2[j][k] %= MOD;
            if (k + W[i] <= S / 2){
              dp2[j + 1][k + W[i]] += dp[j][k];
              dp2[j + 1][k + W[i]] %= MOD;
            }
          }
        }
      }
      swap(dp, dp2);
    }
    vector<long long> cnt(N + 1, 0);
    for (int i = 0; i <= N; i++){
      cnt[i] = dp[i][S / 2];
    }
    vector<long long> fact(N + 1, 1);
    for (int i = 1; i <= N; i++){
      fact[i] = fact[i - 1] * i % MOD;
    }
    long long ans = 0;
    for (int i = 0; i <= N; i++){
      ans += fact[i] * fact[N - i] % MOD * cnt[i] % MOD;
    }
    ans %= MOD;
    cout << ans << endl;
  }
}

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

const int MOD = 998244353;
int N, W[111], tot;
template<class T> struct mi {
	T val;
	mi() { val = 0; }
	mi(const ll& v) {
		val = (-MOD <= v && v <= MOD) ? v : v % MOD;
		if (val < 0) val += MOD;
	}
	mi operator + (const mi& m) {
		T tmp = (val + m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator - (const mi& m) {
		T tmp = (val - m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator * (const mi& m) {
		T tmp = (val * m.val) % MOD;
		return tmp;
	}
	mi& operator += (const mi& m) {
		if ((val += m.val) >= MOD) val -= MOD;
		return *this;
	}
	mi& operator -= (const mi& m) {
		if ((val -= m.val) < 0) val += MOD;
		return *this;
	}
	mi& operator *= (const mi& m) {
		val = (val * m.val) % MOD;
		return *this;
	}
};
mi<ll> f[111], dp[111][11111], ans;
int main() {
    cin.tie(0) -> sync_with_stdio(false); cout.tie(0);
    cin >> N;
    rep(i, 0, N) {
        cin >> W[i];
        tot += W[i];
    }
    if(tot & 1){cout << "0\n"; return 0;}
    tot >>= 1;
    f[0] = 1;
    rep(i, 1, N + 1) f[i] = f[i - 1] * i;
    dp[0][0] = 1;
    rep(i, 0, N) rep2(j, 0, i + 1) rep(k, W[i], 100 * N + 1) {
        dp[j + 1][k] += dp[j][k - W[i]];
    }
    rep(j, 0, N + 1) ans += f[j] * f[N - j] * dp[j][tot];
    cout << ans.val << endl;
}


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

const int f[3][3] = {
    {1, 0, 0},
    {1, 1, 0},
    {1, 2, 1}
};
const int mod = 3;

int lucas(int x, int y) {
    int res = 1;
    while (x) {
        res = res * f[x % mod][y % mod] % mod;
        x /= mod, y /= mod;
    }
    return res;
}

int mp[200];
void solve() {
    mp['B'] = 0, mp['W'] = 1, mp['R'] = 2;
    int n, res = 0; cin >> n; --n;
    for (int i = 0; i <= n; ++i) {
        char c; cin >> c;
        int x = mp[c];
        res = (res + lucas(n, i) * x) % mod;
    }
    if (n & 1) res = -res;
    res = (res + mod) % mod;
    if (res == 0) putchar('B');
    if (res == 1) putchar('W');
    if (res == 2) putchar('R');
}

int main() {
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define ENDL '\n'
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<x<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; ---"<<endl;for(auto c:vec)cout<<c<<" ";cout<<endl<<"----------------"<<endl;}
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const ld PI = 3.14159265358979323846L;

const ll MOD = 1000000007;

ll modpow(ll x,ll y,ll mod) { //繰り返し二乗法
    if(mod==1) return 1;//特殊処理
    if(y==0) return 1;
    if(y==1) return x%mod;
    if(y%2==1) return x*modpow(x,y-1,mod)%mod;
    ll rt = modpow(x,y/2,mod);
    return rt*rt%mod;
}

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

    ll n,p; cin>>n>>p;
    ll ans=p-1;
    ans = ans*modpow(p-2,n-1,MOD)%MOD;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 20;

int n , m , ans , cur , dp[1<<N];
bool edge[N][N] , good[1<<20];
vector<int> v;

void solve(int i)
{
    if (i == n)
    {
        for(int j=0; j<v.size(); j++)
        {
            for(int jj=j+1; jj<v.size(); jj++)
            {
                if (!edge[v[j]][v[jj]]) return;
            }
        }
        good[cur] = 1;
        return;
    }

    v.push_back(i);
    cur |= (1<<i);
    solve(i+1);
    v.pop_back();
    cur ^= (1<<i);
    solve(i+1);
}

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

    cin >> n >> m;

    for(int i=1; i<=m; i++)
    {
        int x,y;
        cin >> x >> y;
        x-- , y--;
        edge[x][y] = 1 , edge[y][x] = 1;
    }

    solve(0);

    ll tmp = 1<<n;

    for(int i=1; i<=tmp; i++)
    {
        dp[i] = 1e9;
    }

    for(int i=1; i<tmp; i++)
    {
        if (good[i]) dp[i] = min(dp[i] , 1);

        for(int j=i; j>0; j = ((j-1)&i) )
        {
            if (good[i^j])
                dp[i] = min(dp[i] , dp[j]+1);
        }
    }

    cout << dp[tmp-1] << '\n';

    return 0;
}

#include <cstdio>
#include <algorithm>
const int Maxn=200000;
const int Inf=0x3f3f3f3f;
int n,k;
int head[Maxn+5],arrive[Maxn<<1|5],nxt[Maxn<<1|5],tot;
void add_edge(int from,int to){
	arrive[++tot]=to;
	nxt[tot]=head[from];
	head[from]=tot;
}
int dis;
int num;
int f_1[Maxn+5],f_2[Maxn+5];
void work_dfs(int u,int fa){
	f_1[u]=-Inf;
	f_2[u]=Inf;
	for(int i=head[u];i;i=nxt[i]){
		int v=arrive[i];
		if(v==fa){
			continue;
		}
		work_dfs(v,u);
		f_1[u]=std::max(f_1[u],f_1[v]+1);
		f_2[u]=std::min(f_2[u],f_2[v]+1);
	}
	if(f_2[u]>dis){
		f_1[u]=std::max(f_1[u],0);
	}
	if(f_1[u]+f_2[u]<=dis){
		f_1[u]=-Inf;
	}
	if(f_1[u]>=dis){
		num++;
		f_2[u]=0;
		f_1[u]=-Inf;
	}
}
bool check(int x){
	dis=x;
	num=0;
	work_dfs(1,0);
	if(f_1[1]>=0){
		num++;
	}
	return num<=k;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	int left=1,right=n;
	while(left<right){
		int mid=(left+right)>>1;
		if(check(mid)){
			right=mid;
		}
		else{
			left=mid+1;
		}
	}
	printf("%d\n",left);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,n*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,k;
char s[201];
inline char doit(char ch1,char ch2) {
	if(ch1==ch2) return ch1;
	if(ch1>ch2) swap(ch1,ch2);
	if(ch1=='P'&&ch2=='R') return 'P';
	if(ch1=='P'&&ch2=='S') return 'S';
	return 'R';
}
int main()
{
	read(n),read(k),scanf("%s",s+1);
	rep(i,1,k) {
		if(n&1) {
			rep(i,n+1,n+n) s[i]=s[i-n];
			n*=2;
		}int len=0;
		for(res j=1;j<=n;j+=2) s[++len]=doit(s[j],s[j+1]);
		n=len;
	}
	putchar(s[1]),puts("");
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert
#define mp make_pair
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

#ifndef ONLINE_JUDGE
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl;
#else
#define deb(x)
#endif

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18;
const ld pie = acos((ld)-1);

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

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

void __print(int x) {cerr<<x;}
void __print(char x) {cerr<<x;}
void __print(string x) {cerr<<x;}
void __print(float x) {cerr<<x;}
void __print(double x) {cerr<<x;}
void __print(bool x) {cerr<<x;}
void __print(ll x) {cerr<<x;}

template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

int N;
vector<pair<ll,ll>> gr[200001];

vector<ll> bfs(ll src) {

	vector<ll> dis(N, -1);
	queue<ll> q;
	q.push(src);
	dis[src] = 0;

	while(!q.empty()) {
		ll node = q.front();
		q.pop();

		for(auto x:gr[node]) {
			if(dis[x.ff] == -1) {
				dis[x.ff] = dis[node] ^ x.ss;
				q.push(x.ff);
			}
		}
	}

	return dis;
}

int main(){

	scanf("%d", &N);

	rep(i, 0, N - 1) {
		ll X,Y,W;
		scanf("%lld%lld%lld", &X, &Y, &W);
		X--;Y--;
		gr[X].pb({Y, W});
		gr[Y].pb({X, W});
	}

	vector<ll> dis = bfs(0);

	ll ans = 0;

	for(int i = 0; i < 60; ++i) {
		vector<int> cnt(2);

		for(int j = 0; j < N; ++j) {
			cnt[dis[j]>>i&1]++;
		}

		ans += (1ll<<i)%mod*cnt[0]%mod*cnt[1]%mod;
		ans %= mod;
	}

	printf("%lld\n", ans);

	return 0;

	/*STUFF TO LOOK:
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


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

double eps = 1e-9;
double pi = acos(-1);

int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;
#define mem(a, b) memset(a, b, sizeof(a))
#define valid(nx, ny, row, col) nx >= 0 && nx < row && ny >= 0 && ny < col

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

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	int n, val, mx = 0;
	cin >> n;

	VECT(v);

	for(int i = 0; i < n; i++)
	{
		cin >> val;
		v.push_back(val);
		mx = max(mx, val);
	}

	ll ans;
	ll num = 0;
	for(int i = 2; i <= mx; i++)
	{
		int cnt = 0;
		for(int j = 0; j < n; j++)
		{
			if(v[j] % i == 0)
			{
				cnt++;
			}
		}

		if(cnt > num)
		{
			num = cnt;
			ans = i;
		}
	}
	cout << ans << en;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int N, c, r, i{2}, m;
int main()
  {cin >> N; int A[N]; for (int &a: A) cin >> a;
  for (; c = 0, i <= 1000; m = c > m ? r = i, c : m, ++i) for (int a : A) c += !(a % i);
  cout << r;}


// abc199_b
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];

    int a = *max_element(ALL(A));
    int b = *min_element(ALL(B));

    int ans = max(0, b - a + 1);
    print(ans);

    return 0;
}

//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    cout << n - a + b << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define N 400005
struct node{int pos,val;}b[N];
int a[N],n,i,val[N],st[N],hd;
char ans[N];
inline bool cmp(node aa,node bb){return aa.val<bb.val;}
int main(){
	cin>>n;
	for(i=1;i<=n+n;++i)cin>>a[i],b[i].pos=i,b[i].val=a[i];
	sort(b+1,b+n+n+1,cmp);
	for(i=n+1;i<=n+n;++i){
		val[b[i].pos]=1;
	}
	for(i=1;i<=n+n;++i){
		if(hd&&val[st[hd]]!=val[i]){
			ans[st[hd]]='(';
			ans[i]=')';
			--hd;
		}
		else st[++hd]=i;
	}
	for(i=1;i<=n+n;++i)cout<<ans[i];
}

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

void test_case()
{
	int N,curr;
  	cin>>N;
  	map<int,int> freq;
  	for (int index=0; index<N;index+=1){
  	    cin>>curr;
  	    freq[curr] += 1;
  	}

  	string res = "Second";

    if (N%2 == 0){
        // even
        // A goal is to break symmerty and B goal is to build symmetry of 2 columns
        // Symmetry can be achieved only if all num have duplicates
        for (auto &[_,value]:freq){
            if (value % 2 == 1){
                // no duplicate
                res = "First";
            }
        }
    }else{
        //odd
        // A goal is maintain symmerty of 2 columns
        // (possible if a+b == c, but on taking a, B can take b making it asymmetric)
        // therefore always B wins
    }
    cout<<res<<"\n";
}

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

  	while(N-->0){
    	test_case();
    }
    return 0;
}


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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e8;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int n; cin >> n;
	string s[100];
	rep(i, 0, n) cin >> s[i];
	ll ans = 1;
	for(int i=n-1;i>=0;i--){
		if(s[i]=="AND"){
			continue;
		}else{
			ll addans = 1;
			rep(j, 0, i+1){
				addans *= 2;
			}
			ans += addans;
		}
	}
	cout << ans << endl;
    return 0;
}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define tf(x) get<0>(x)
#define ts(x) get<1>(x)
#define tt(x) get<2>(x)
#define endl '\n'
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define tup tuple<int,int,int>
#define ve vector <int>
#define vep vector<pii >
#define mod 1000000007
#define maxn 2e5+5
#define ld long double
#define mem(x) memset(x,0,sizeof(x))
#define in insert
#define fr(i,a,b) for(int i=a;i<b;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define fora(m) for(auto it:m)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define input_array int n;cin>>n;int a[n];forn(i,n) cin>>a[i];
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int mull(int  a,int b)  {
    return ((a%mod)*(b%mod))%mod;
}

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

//--------------------------------SIEVE---------------------------//
/*bool prime[maxn];
int spf[maxn];
void sieve() {
	forn(i,maxn) {
		prime[i]=true;
		spf[i]=i;
	}
	fr(i,2,maxn) {
		if(prime[i]){
			for(int j=2*i;j<maxn;j+=i) {
				prime[j]=false;
				spf[j]=i;
			}
		}
	}
}*/

//-----------------------------End---------------------------------//

//------------------------------------------------DFS------------------------//
/*bool stat[maxn];
int depth[maxn],par[maxn];
void init_graph() {
	memset(stat,false,sizeof(stat);
	memset(depth,0,sizeof(depth);
	for(int i=0;i<maxn;i++) par[i]=i;
}
void dfs(int u,int p) {
	stat[u]=true;
	depth[u]=depth[p]+1;
	par[u]=p;
	for(auto it:g[u]) {
		if(stat[it]==false)
			dfs(it,u);
	}
}*/

//-------------------------------------DFS-END--------------------------------//

//-----------------------------------nCr%p-----------------------------------//
/*int nCr(int n, int r)
{
   if (r==0)
      return 1;
    int fac[n+1];
    fac[0] = 1;
    for (int i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%mod;

    return (fac[n]* modInverse(fac[r], mod) % mod *
            modInverse(fac[n-r], mod) % mod) % mod;
} */
//---------------------------------EnD---------------------------------------//

void solve() {
    int n;
    cin>>n;
    int a[n+1];
    fr(i,1,n+1) cin>>a[i];
    int dp[n+1][n+1],pre[n+1][n+1];
    mem(dp);
    memset(pre,-1,sizeof(pre));
    for(int i=1;i<=n;i++) pre[i][0] = 0;
    dp[1][1] = 1;
    // pre[1][0] = 1;
    int sum = a[1];
    for(int i=1;i<=n;i++) pre[i][sum%i] = 1;
    for(int i=2;i<=n;i++) {
        sum+=a[i];
        for(int j=1;j<=n;j++) {
            int mo = sum%j;
            if(pre[j][mo]==-1) {
                pre[j][mo] = i;
                continue;
            }
            // if(pre[j][mo]==0) {
            //     dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%mod;
            //     pre[j][mo] = i;
            //     continue;
            // }
            dp[i][j] = (dp[pre[j][mo]][j-1] + dp[pre[j][mo]][j])%mod;
            pre[j][mo] = i;
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }
    // for(int i=1;i<=n;i++) {
    //     for(int j=1;j<=i;j++) cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    int ans= 0;
    for(int i=1;i<=n;i++) ans = (ans+dp[n][i])%mod;
    cout<<ans;
}
signed main() {
	IOS
	int t=1;
	// cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

int n;

int main(){
	std::scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		std::printf("%d %d\n", i * 2 % n + 1, (i * 2 - 1) % n + 1);
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MTP make_tuple
typedef long long int ll;

constexpr int kN = int(1E3 + 10), kInf = int(1E9 + 10);

int a[kN], b[kN];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) a[i] = ((i - 1) << 1) % n + 1;
	for (int i = 1; i <= n; i++) b[i] = ((i - 1) << 1 | 1) % n + 1;

	for (int i = 1; i <= n; i++) printf("%d %d\n", a[i], b[i]);
}


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

int main()
{
    int n; cin >> n;
    vector<pair<int, int>> z;
    pair<int, int> c;
    for (int i=0; i<n; i++)
    {
        cin >> c.first >> c.second;
        z.push_back(c);
    }
    bool flag = false;
    for (int i1=0; i1<n; i1++)
    {
        for (int i2=i1+1; i2<n; i2++)
        {
            for (int i3=i2+1; i3<n; i3++)
            {
                int p = (z[i1].first - z[i2].first) * (z[i1].second - z[i3].second);
                int q = (z[i1].first - z[i3].first) * (z[i1].second - z[i2].second);
                if (p == q)
                {
                    flag = true;
                    break;
                }
            }
            if (flag) break;
        }
        if (flag) break;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll t;
	scanf("%lld",&t);
	while(t--){
		ll l,r;
		scanf("%lld %lld",&l,&r);
		ll t = (r-l)-l+1;
		ll res;
		if(t>0) res = (t+1)*t/2;
		else res = 0;
		printf("%lld\n",res);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
const ll LL_MAX=LLONG_MAX;

struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};
In in;

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

template <typename T>
T gcd(T x,T y){
    if (y == 0) return x;
    return gcd(y,x%y);
}

template <typename T>
T lcm(T x,T y){
    return x*y/gcd(x,y);
}

int main(){
    ull n=in,a,b;
    ull ans=0;
    for (int i=0;i<n;i++){
        a=in,b=in;
        ans+=(b*b+b-a*a+a)/2;
    }
    out(ans);
}

#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(0), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long  ull;

constexpr int INF = INT_MAX;

using namespace std;

int main(){
    fastIO;
    int N;
    cin >> N;
    ll sum = 0;
    while (N--)
    {
        ll a, b;
        cin >> a >> b;
        sum += ((b * (b + 1)) / 2) - ((a * (a + 1)) / 2) + a;
    }
    cout << sum;
    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 4020000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

template<typename T> struct BIT{
    vector<T> dat;
    ll sz;
    //all 1-indexed
    BIT(ll sz) : sz(sz){
        dat.assign(++sz, 0);
    }

    T sum(ll k){
        T ret = 0;
        for(++k; k > 0; k -= k & -k) ret += dat[k];
        return (ret);
    }

    void add(ll k, T x){
        for(++k; k < dat.size(); k += k & -k) dat[k] += x;
    }

    ll get(T k){
        if(k <= 0) return 0;
        ll ret = 0;
        int n = 1; while(n < sz) n *= 2;
        for(int i=n/2; i>0; i/=2){
            if(ret+i < sz && dat[ret+i] < k){
                k -= dat[ret+i];
                ret += i;
            }
        }
        return ret;
    }
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vl a(n); rep(i,n) cin >> a[i];
    vl cnt(n,0);
    BIT<int> bit(n);
    rep(i,m){
        cnt[a[i]]++;
        if(cnt[a[i]] == 1){
            bit.add(a[i],1);
        }
    }
    int mn = n;
    rep(i,n-m+1){
        int ok = m, ng = -1;
        while(ok-ng > 1){
            int mid = (ok+ng) / 2;
            if(bit.sum(mid) < mid+1) ok = mid;
            else ng = mid;
        }
        chmin(mn,ok);
        cnt[a[i]]--;
        if(cnt[a[i]] == 0){
            bit.add(a[i],-1);
        }
        if(i<n-m){
            cnt[a[i+m]]++;
            if(cnt[a[i+m]] == 1){
                bit.add(a[i+m],1);
            }
        }
    }
    cout << mn << "\n";
}

#include <bits/stdc++.h>
using namespace std;
int arr[1500002];
int krr[1500002];
int tree[4*1500002];
void update(int node,int b,int e,int i,int val)
{
    if(b==e&&b==i){
        tree[node]=val;
        return;
    }
    int mid=(b+e)>>1;
    int left=node*2;
    int right=left+1;
    if(i<=mid)update(left,b,mid,i,val);
    else update(right,mid+1,e,i,val);
    tree[node]=tree[left]+tree[right];
}
int query(int node,int b,int e)
{
    if(b==e){
        return b;
    }
    int mid=(b+e)>>1;
    int left=node<<1;
    int right=left+1;
    if(tree[left]>0)return query(left,b,mid);
    else return query(right,mid+1,e);
}
int main()
{
    int n,m;
    map<int,int>maps;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
        arr[i]++;
    }
    n+=10;
    for(int i=1;i<=n;i++)update(1,1,n,i,1);
    int ans=INT_MAX;
    for(int i=1;i<=m;i++){
        maps[arr[i]]++;
        if(maps[arr[i]]>0)update(1,1,n,arr[i],0);
    }
    ans=min(ans,query(1,1,n));
    for(int i=m+1;i<=n-10;i++){
        int l=i-m;
        int r=i;
        maps[arr[l]]--;
        if(maps[arr[l]]<=0)update(1,1,n,arr[l],1);
        maps[arr[r]]++;
        if(maps[arr[r]]>0)update(1,1,n,arr[r],0);
        ans=min(ans,query(1,1,n));
    }
    printf("%d\n",ans-1);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(10,1e8);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
//#define deb(x...) cerr << "[" << #x << "] = "; _print(x)
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END

const int N = 1e5 + 5;

pii f(int b, int c){
	int n = c / 2;
	if(c & 1){
		return {-b-n, -b+n};
	}else{
		if(!c)
			return {b, b};
		return {b-n, b+n-1};
	}
}

void solve(){

	int b, c;
	cin >> b >> c;

	auto [x, y] = f(b, c);
	auto [p, q] = f(b, c-1);

	cout << y-x+1 + q-p+1 - max(0ll, min(y, q) - max(x, p) + 1) << endl;

}

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

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

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define int long long
#define pb push_back
#define pii pair<int,int>
#define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7,mxn=1e5 + 5;

signed main(){
    gok

 int t=1;
 //cin>>t;
 while(t--)
 {
     int b,c;
     cin>>b>>c;
     if(c==1 && b!=0)
     {
         cout<<2;
         return 0;
     }
     int st = b - (c/2);
     int en = b + ((c-1)/2);
      if(c%2==0)
        st++;
      else
        en--;
     int an = 2*(en-st+1);
     int mi = abs(min(abs(st),abs(en)));
     if(st<=0 && en>=0){
           an -= 2*mi + 1;

           if(c%2==0)
           {
               if(abs(st-1) > abs(en))
                an++;
           }
           else
           {
               if(abs(en+1) > abs(st))
                an++;
           }

     }
     else
        an++;

     /*if(c%2==0 && st!=0)
        an--;

     if((c-1)%2==0 && en!=0)
        an--;*/
    //cout<<st<<" "<<en<<endl;
     cout<<an<<endl;
 }

    return 0;

}


//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
struct Init { Init(){
    cin.tie(0); ios::sync_with_stdio(false);
} } init;
//}}}

int main(){
    int n; cin >> n;
    string s; cin >> s;
    string s2;
    for(auto& c : s){
        s2 += c;
        int n2 = s2.size();
        if(n2 >= 3 && s2[n2 - 3] == 'f' && s2[n2 - 2] == 'o' && s2[n2 - 1] == 'x'){
            for(int i = 0; i < 3; i++){
                s2.pop_back();
            }
        }
    }
    cout << s2.size() << '\n';
}


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

const int maxSz = 2e5, maxCnt = 16;
char s[maxSz + 1];
int n[maxSz]; int sz, k;

const lli mod = 1e9 + 7;
lli memo[maxSz][maxCnt + 1][2][2];
lli solve(int mask = 0, int i = 0, bool equal = true, bool started = false)
{
  int cnt = __builtin_popcount(mask);
  if (cnt > k)
    return 0;
  if (i == sz)
  {
    return cnt == k && started;
  }

  lli &ans = memo[i][cnt][equal][started];
  if (ans != -1)
    return ans;

  ans = 0;
  for (int d = 0; d <= (equal ? n[i] : 15); d++)
    ans = (ans + solve(d == 0 && !started ? mask : mask | (1 << d), i + 1, equal & (d == n[i]), started | (d > 0))) % mod;
  return ans;
}

int main()
{
  while (~scanf(" %s %d", s, &k))
  {
    sz = strlen(s);
    for (int i = 0; i < sz; i++)
    {
      if (s[i] >= '0' && s[i] <= '9')
        n[i] = s[i] - '0';
      else
        n[i] = s[i] - 'A' + 10;
    }

    DEBUG
    {
      printf("%s\n", s);
      for (int i = 0; i < sz; i++)
        printf("%d ", n[i]);
      printf("\n");
    }

    memset(memo, -1, sizeof(memo));
    lli ans = solve();
    printf("%lld\n", ans);
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, x, y;
  while (cin >> a >> b >> x >> y)
  {
    int a2 = 0x7fffffff, a3 = 0x7fffffff, a4 = 0x7fffffff;
    int a1 = abs(a - b) * y + x;
    if (a > b)
      a2 = ((a - b) * 2 - 1) * x, a4 = (a - b - 1) * y + x;
    else
      a3 = ((b - a) * 2 + 1) * x;

    cout << min({a1, a2, a3, a4}) << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main()
{

	int a,b,c;
	cin>>a>>b>>c;
	cout<<a-b+c<<endl;

	return 0;
}

#include <iostream>
using namespace std;

int main() {

int n;
cin >> n;

int a;
cin >> a;

int b;
cin >> b;

int c;
c = n - a + b;

cout << c;

	return 0;
}


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

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

    vector<int> A(M + 2, 0);
    for (size_t i = 1; i <= M; i++)
    {
        cin >> A[i];
    }
    A.back() = N + 1;
    sort(A.begin(), A.end());

    map<int, size_t> count;
    int minimum = N;
    for (size_t i = 0; i <= M; i++)
    {
        if (A[i] + 1 == A[i + 1])
        {
            continue;
        }
        minimum = min(A[i + 1] - A[i] - 1, minimum);
        count[A[i + 1] - A[i] - 1]++;
    }
    int ans = 0;
    for (pair<int, size_t> c : count)
    {
        ans += (c.first + (minimum - 1)) / minimum * c.second;
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lop(j,n) for(ll j=0;j<n;j++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
ll dx[] = { 1,0,-1,0 };
ll dy[] = { 0,1,0,-1 };
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll arr[200005];
main()
{
   ll n,m;
   cin>>n>>m;
   lop1(i,m)
   {
       cin>>arr[i];
   }
   if(n==m)
   {
       cout<<0<<endl;
       return 0;
   }
   sort(arr+1,arr+m+1);
   ll mn=inf;
   ll x=0;
   lop1(i,m)
   {
       ll z=arr[i]-x-1;
       if(z>0) mn=min(mn,z);
       x=arr[i];
   }
   if(arr[m]!=n)
   {
       mn=min(mn,n-arr[m]);
   }
   if(mn==0 or mn==inf)
   {
       cout<<n;
       return 0;
   }
   x=0;
   ll ans=0;
    lop1(i,m)
   {
       ll z=arr[i]-x-1;
       if(z>0)
       {
           ll k=z+mn-1;
           ans+=(k/mn);
       }
       x=arr[i];
   }
   if(arr[m]!=n)
   {
       ll k=n-arr[m]+mn-1;
       ans+=(k/mn);
   }
   cout<<ans;

}