#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

template<long long M, typename T=long long>
struct modint {
  modint(T v=T(0)) : val((v >= 0 ? v : (M - ((-v) % M))) % M) {}
  using this_type = modint<M, T>;
  T val;
  this_type operator++(int) {
    this_type ret = *this;
    val++; val %= M;
    return ret;
  }
  this_type operator--(int) {
    this_type ret = *this;
    val += M-1; val %= M;
    return ret;
  }
  this_type &operator++() {
    val++; val %= M;
    return *this;
  }
  this_type &operator--() {
    val += M-1; val %= M;
    return *this;
  }
  this_type operator+() const { return *this; }
  this_type operator-() const { return this_type(M-val); };
  friend this_type operator+(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) += rhs;
  }
  friend this_type operator-(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) -= rhs;
  }
  friend this_type operator*(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) *= rhs;
  }
  friend this_type operator/(const this_type &lhs, const this_type &rhs) {
    return this_type(lhs) /= rhs;
  }
  this_type pow(long long b) const {
    this_type ret = 1, a = *this;
    while(b != 0) {
      if(b % 2 != 0) {
        ret *= a;
      }
      b /= 2;
      a = a * a;
    }
    return ret;
  }
  this_type inv() const {
    return pow(M-2);
  }
  this_type& operator+=(const this_type &rhs) {
    val += rhs.val; val %= M; return *this;
  }
  this_type& operator-=(const this_type &rhs) {
    val += M - rhs.val; val %= M; return *this;
  }
  this_type& operator*=(const this_type &rhs) {
    val *= rhs.val; val %= M; return *this;
  }
  this_type& operator/=(const this_type &rhs) {
    *this *= rhs.inv(); return *this;
  }
  friend bool operator==(const this_type &lhs, const this_type &rhs) {
    return lhs.val == rhs.val;
  }
  friend bool operator!=(const this_type &lhs, const this_type &rhs) {
    return lhs.val != rhs.val;
  }
  T mod() const {return M;}
};

using mi = modint<1000000007>;
using vmi = vector<mi>;
using vvmi = vector<vmi>;

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M; cin >> N >> M;
  vi A(N); RVI(A);
  i64 S = accumulate(all(A), 0LL);
  mi ans = 1;
  REP(0, S+N, i) {
    ans *= (N + M - i);
    ans /= i + 1;
  }
  WI(ans.val);

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int N=3e5+5;
int n,m,k,cnt,tot,cas,ans;
int a[N];
bool vis[N];
char s[N];
#define ll long long
long long qmi(long long a,long long b)
{
	long long ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		b>>=1;a=a*a%mod;
	}
	return ans;
}
ll C(ll n,ll r)
{
	if(r>n||r<0) return 0;
	ll fz=1,fm=1;
	for(int i=1;i<=r;i++)
		fz=fz*(n-i+1)%mod,fm=fm*i%mod;
	return fz*qmi(fm,mod-2)%mod;
}
int main()
{
	long long sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i],sum+=a[i];
	printf("%lld\n",C(n+m,sum+n));
	return 0;
}


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

typedef long long ll;
#define int ll
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb emplace_back
#define pii pair<int , int>
#define F first
#define S second
const int mod = 1000000007;
const int MAXX = 1e5 + 5;

const int N = 1e5;

int t , n , m;
int a[MAXX];

signed main()
{
    _FastIO;
    cin >> n;
    a[1] = 1;
    for(int i = 2; i <= n; i++){
        int cnt = 1;
        for(int j = 1; (j * j) <= i; j++){
            if(i % j == 0){
                cnt = max(cnt , a[j]);
                cnt = max(cnt , a[i / j]);
            }
        }
        a[i] = cnt + 1;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}

#include<bits/stdc++.h>

#define int long long
int n,now,ans;
using namespace std;

signed main()
{
	scanf("%lld",&n);
	int p=sqrt((n+1)*2);
	while(p*(p+1)/2<=n+1)
	{
		p++;
	}
	p--;
	//cout<<p<<endl;
	//if(p*p==n*2) p--;
	//cout<<p<<endl;
	printf("%lld\n",n-p+1);
	return 0;
}


#include <iostream>
#include <deque>
#include <climits>
#include <cmath>

using namespace std;

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

    double x0, y0, xh, yh;
    std::cin >> x0 >> y0 >> xh >> yh;

    double dx = x0 - (x0 + xh) / 2;
    double dy = y0 - (y0 + yh) / 2;

    double ox = cos(M_PI * 2 / N);
    double oy = sin(M_PI * 2 / N);

    double x1 = dx * ox - dy * oy + (x0 + xh) / 2;
    double y1 = dy * ox + dx * oy + (y0 + yh) / 2;

    std::cout << x1 << ' ' << y1 << std::endl;

    // std::deque<int> A;
    // for (int i = 0; i < N; i++) {
    //     int n;
    //     std::cin >> n;
    //     A.push_back(n);
    // }
    // // std::cout << N << std::endl;
    // // for (int i = 0; i < A.size(); i++) {
    // //     std::cout << i << std::endl;
    // // }
    // const int result = search(0, A);
    // std::cout << result << std::endl;
    return 0;
}

/** P L E X I U S ** 2021 Jan 29 17:22:53 **/

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

void solve(){
  int n; cin>>n;
  int cnt = 0;
  for(int i= 1; i*(i+1)<=2*n; i++) {
    if((n-i*(i-1)/2)%i==0) cnt++;
  }
  cout<<cnt*2<<"\n";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);}
template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

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

int main() {
    ll N, M; cin >> N >> M;
    vector<vector<ll>> a(N,vector<ll>(N,inf));
    rep(i,M) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        chmin(a[x][y],z);
    }

    vector<vector<ll>> dp(N+1,vector<ll>(1<<N));
    dp[0][0] = 1;
    rep(i,N) {
        rep(bit,1<<N) {
            if (dp[i][bit]==0) continue;
            rep(j,N) {
                if ((bit>>j)&1) continue;
                ll nbit = bit | (1<<j);
                bool ng = false;
                ll cnt = 0;
                rep(k,N) {
                    if ((nbit>>k)&1) cnt++;
                    if (cnt>a[i][k]) ng = true;
                }
                if (ng) continue;
                dp[i+1][nbit] += dp[i][bit];
            }
        }
    }
    ll X = (1<<N)-1;
    ll ans = dp[N][X];
    Cout(ans);
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int h = ri();
	int w = ri();
	int x = ri() - 1;
	int y = ri() - 1;
	std::string s[h];
	for (int i=0; i<h; i++) std::cin >> s[i];

	int cnt = -3;
	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
	printf("%d\n", cnt);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

signed main(){

    int H, W, X, Y; cin >> H >> W >> X >> Y;
    X--; Y--;
    vector<string> S(H); cin >> S;

    int ans = 1;
    IFOR(i, 0, X){
        if(S[i][Y] == '.') ans++;
        else break;
    }
    FOR(i, X + 1, H){
        if(S[i][Y] == '.') ans++;
        else break;
    }
    IFOR(j, 0, Y){
        if(S[X][j] == '.') ans++;
        else break;
    }
    FOR(j, Y + 1, W){
        if(S[X][j] == '.') ans++;
        else break;
    }
    Out(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define max(x,y) ((x)>(y)?(x):(y))
inline int read(){
	int f=1,r=0;char c=getchar();
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar();
	return f?r:-r;
}
const int N=2e5+5;
int mx[N<<2],tg[N<<2];
#define ls (p<<1)
#define rs (p<<1|1)
inline void spread(int p){
	if(!tg[p])return;
	tg[ls]+=tg[p],mx[ls]+=tg[p];
	tg[rs]+=tg[p],mx[rs]+=tg[p];
	tg[p]=0;
}
inline void change(int p,int l,int r,int x,int y,int val){
	if(x<=l && r<=y){tg[p]+=val,mx[p]+=val;return;}
	spread(p);int mid=(l+r)>>1;
	if(x<=mid)change(ls,l,mid,x,y,val);
	if(y>mid)change(rs,mid+1,r,x,y,val);
	mx[p]=max(mx[ls],mx[rs]);
}
int main(){
	int n=read(),w=read();
	while(n--){
		int l=read()+1,r=read(),x=read();
		change(1,1,2e5,l,r,x);
		if(mx[1]>w)puts("No"),exit(0);
	}
	puts("Yes");
	return 0;
}

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

const int N=4e5+100;
int head[N],ver[N],Next[N],tot;
int depth[N],len[N];
int son[N];
int ans[N],cnt;
int root,n;

inline void add(int u,int v){
    ver[++tot]=v;
    Next[tot]=head[u];
    head[u]=tot;
}

void init(int x,int fa){
    depth[x]=depth[fa]+1;
    if(depth[root]<depth[x]) root=x;
    for(rei i=head[x];i;i=Next[i]){
        rei y=ver[i];
        if(y==fa) continue;
        init(y,x);
    }
}

void dfs(int x,int fa){
    for(rei i=head[x];i;i=Next[i]){
        rei y=ver[i];
        if(y==fa) continue;
        dfs(y,x);
        len[x]=max(len[x],len[y]+1);
        if(!son[x] || len[y]>len[ son[x] ]) son[x]=y;
    }
}

void calc(int x,int fa){
    ans[x]=++cnt;
    for(rei i=head[x];i;i=Next[i]){
        rei y=ver[i];
        if(y==fa || y==son[x]) continue;
        calc(y,x);
        ++cnt;
    }
    if(son[x]) calc(son[x],x),++cnt;
}

int main(){
    scanf("%d",&n);
    for(rei i=1;i<n;++i){
        rei x,y;
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
    }
    init(1,0);
    dfs(root,0);
    calc(root,0);
    for(rei i=1;i<=n;++i)
        printf("%d ",ans[i]);
    puts("");
    getchar();
    getchar();
    return 0;
}


#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

int main() {
    fastIO;
    string s;
    cin >> s;

    map<int, int> digits;
    for (int i = 0; i < s.length(); i++) {
        int d = s[i] - '0';
        digits[d]++;
    }

    bool possible = false;
    int i;
    if (s.length() == 1) i = 8;
    else if (s.length() == 2) i = 16;
    else i = 104;
    for (; i < 1000; i += 8) {
            map<int, int> temp;
            int num = i;
            while (num > 0) {
                temp[num % 10]++;
                num /= 10;
            }
            bool poss = true;
            for (pii p : temp) {
                if (digits[p.first] < p.second) poss = false;
            }
            possible |= poss;
    }

    if (possible) cout << "Yes";
    else cout << "No";
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626433;

ll Str2Long(string s){
    reverse(ALL(s));
    ll n = 0;
    rep(i, s.size()){
        n += (s[i]-'0')*pow(10, i);
    }
    return n;
}
string Long2Str(ll x){
    if(x <= 0)return "";
    char c = '0' + x % 10;
    return Long2Str(x/10) + c;
}

int main(){
    string s;
    cin >> s;

    if(s.size() == 1){
        if(s == "8" || s=="0")cout << "Yes";
        else cout << "No";
        return 0;
    }
    if(s.size() == 2){
        if(Str2Long(s) % 8 == 0)cout << "Yes";
        else {
            reverse(ALL(s));
            if(Str2Long(s) % 8 == 0)cout << "Yes";
            else cout << "No";
        }
        return 0;
    }

    vector<ll> cnt(10, 0);
    for(char c: s){
        cnt[c - '0']++;
    }

    for(ll i = 104; i <= 992; i += 8){
        string s_i = Long2Str(i);
        ll cnt_0 = cnt[s_i[0] - '0'];
        ll cnt_1 = cnt[s_i[1] - '0'];
        ll cnt_2 = cnt[s_i[2] - '0'];

        if(cnt_0 * cnt_1 * cnt_2 == 0)continue;

        bool ok = false;

        if(s_i[0] == s_i[1] && s_i[0] == s_i[2]){
            if(cnt_0 >= 3)ok = true;
        }
        else if(s_i[0] == s_i[1]){
            if(cnt_0 >= 2 && cnt_2 >= 1)ok = true;
        }
        else if(s_i[1] == s_i[2]){
            if(cnt_0 >= 1 && cnt_1 >= 2)ok = true;
        }
        else if(cnt_0 >= 1 && cnt_1 >= 1 && cnt_2 >= 1)ok = true;

        if(ok){
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i=0; i<(ll)n; i++)
#define ALL(obj) begin(obj), end(obj)
typedef long long ll;
int n, m, a, b, cnt;
vector<vector<int> > G(22);
vector<int> color(22, -1), ts;
vector<bool> vit(22, 0);

void dfs(int now){
	ts.push_back(now);
	vit[now]=1;

	for(int i : G[now]){
		if(!vit[i])
		    dfs(i);
	}
}

ll DFS(int i){
	if(i==ts.size())
	    return 1;

	ll ret=0;
	rep(j, 3){
		bool f=1;
		for(int v:G[ts[i]]){
			if(color[v]==j)
			    f=0;
		}

		if(!f)
		    continue;

		color[ts[i]]=j;
		ret+=DFS(i+1);
		color[ts[i]]=-1;
	}

	return ret;
}

int main()
{
	cin>>n>>m;
	ll ans=1;
	rep(i, m){
		cin>>a>>b;
		a--;
		b--;

		G[a].push_back(b);
		G[b].push_back(a);
	}

	rep(i, n){
		if(vit[i])
		    continue;

		dfs(i);
		fill(ALL(color), -1);
		ans*=DFS(0);
		ts.clear();
	}

	cout<<ans<<endl;
	return 0;
}

#pragma GCC optimize("O3")
#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 ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define BS(v,n) binary_search(v.begin(),v.end(),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater <ll>())
#define uni(v) v.resize(unique(v.begin(),v.end())-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)

int main(){

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
     #endif

    FAST

    ll n;cin>>n;
    string s,t;
    cin>>s>>t;
    ll ans = 0;
    ll k1 = 0,k2 = 0;
    FOR(i,0,n){
    	if(s[i]-'0'==0)k1++;
    	if(t[i]-'0'==0)k2++;
    }
    if(k1!=k2)ans=-1;
    else{
	    ve <ll> z(2);
	    ll don  = 0;
	    FOR(i,0,n){
	    	ll x1 = s[i]-'0';
	    	ll x2 = t[i]-'0';
	    	if(z[x2]>0){
	    		z[x2]--;
	    	}
	    	else{

	    		ll c1 = 0;
	    		while(s[don]-'0'!=x2){
	    			c1++;don++;
	    		}
	    		don++;
	    		z[1-x2]+=c1;
	    		if(x2==0){
	    			if(c1!=0||(c1==0&&z[1]!=0))ans++;
	    		}
	    		else{
	    			if(c1!=0)ans+=c1;
	    		}
	    	}
	    }
	}
    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i=a;i<(ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
void YN(bool a) { cout << (a ? "Yes" : "No") << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
void show(){ cout << endl; }
template <class Head, class... Tail>
void show(Head&& head, Tail&&... tail){ cout << head << " "; show(std::forward<Tail>(tail)...); }
template<class T> inline void showall(T& a) { for(auto v:a) cout<<v<<" "; cout<<endl; }

void solve()
{
  ll t;
  cin >> t;
  rep(ti, t)
  {
    ll l, r;
    cin >> l >> r;

    ll ans = 0;
    if (r < l * 2) ans = 0;
    else if (r == l * 2) ans = 1;
    else {
      r -= (l - 1) * 2 + 1;
      ans = (r) * (r + 1) / 2;
    }
    show(ans);
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

#include <bits/stdc++.h>
/*#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <sstream>*/

#define ll long long
#define fop(i,m,n) for(int i=m; i<n; i++)
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define ep emplace_back

using namespace std;

const long long MOD = 1e9+7;
const long long N = 1e9+5;
const long long Nlog = 17;
const long long Hash = 257;

const double PI = 2.0*acos(0.0);//<cmath>
//const double PI = 3.141592653;
const double E = 2.718281828;

bool cmp(pair<ll, int> a, pair<ll, int> b){
    return a.X<b.X;
}

void solve(){

    int k;
    ll n, m;
    cin >> k >> n >> m;
    ll a[k];
    fop(i,0,k) cin >> a[i];

    ll l[k], num = m;
    pair<ll, int> c[k];
    fop(i,0,k){
        l[i] = m*a[i]/n;
        c[i].X = (n*l[i])-(m*a[i]);
        c[i].Y = i;
        num-=l[i];
    }

    ll ans[k];
    fop(i,0,k) ans[i] = l[i];
    sort(c, c+k, cmp);
    fop(i,0,num) ans[c[i].Y]++;

    fop(i,0,k) cout << ans[i] << ' ';

}

int main()
{
    fastIO;

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

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[200005],parent[200005],s=0;
int findparent(int x)
{
    if (x==parent[x]) return x;
     return parent[x]=findparent(parent[x]);
}
void Union(int u,int v)
{
    int p=findparent(u);//find parents of u
    int q=findparent(v);//find parents of v;
    if(p!=q)parent[q]=p;
}
int main()
{
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i],parent[a[i]]=a[i];
    for (int i=1; i<=n; i++)
    {
        int x=findparent(a[i]);
        int y=findparent(a[n-i+1]);
        if (x!=y)
        {
            s++;
            Union(x,y);
        }
    }
    cout<<s<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const ll n_max = 2e5 + 1;

vector<vector<ll>> G(n_max);
vector<bool> check(n_max, false);
ll dfs(ll v){
    if(check[v]) return 0;
    check[v] = true;
    ll ret = 0;
    for(ll u : G[v]){
        if(check[u]) continue;
        ret += dfs(u) + 1;
    }
    return ret;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    for(ll i = 0; i <= (n-1)/2; i++){
        if(a[i] != a[n-1-i]){
            G[a[i]].pb(a[n-1-i]);
            G[a[n-1-i]].pb(a[i]);
        }
    }
    ll ans = 0;
    drep(i, 1, n_max-1){
        if(check[i]) continue;
        ans += dfs(i);
    }
    cout << ans << endl;
}


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

void amain()
{
    long long n; cin >> n;
    if (n%4==0) cout << "Even" << endl;
    if (n%4==2) cout << "Same" << endl;
    if (n%2) cout << "Odd" << endl;
    return;

}

int main()
{
    ios_base::sync_with_stdio(0);
    int t; cin >> t;
    while (t--) amain();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

#define all(a) (a).begin(), (a).end()
#define mp make_pair

template<typename T1, typename T2>
inline void chkmin(T1& x, const T2& y) {
    if (y < x) x = y;
}

template<typename T1, typename T2>
inline void chkmax(T1& x, const T2& y) {
    if (x < y) x = y;
}

int getLen(ll x) {
    int ans = 0;
    while (x) {
        ans++;
        x /= 10;
    }
    return ans;
}

int getPow(int len) {
    int ans = 1;
    for (int i = 0; i < len; ++i) {
        ans *= 10;
    }
    return ans;
}

ll get(ll x) {
    return x * getPow(getLen(x)) + x;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout.precision(20), cout.setf(ios::fixed);
    ll n;
    cin >> n;
    int ans = 0;
    int x = 1;
    while (true) {
        ll have = get(x);
        if (have > n) break;
        ++ans;
        ++x;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;

constexpr char newl = '\n';

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

    int n, m;
    cin >> n >> m;

    vector<ll> w(n);
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }

    vector<P> vl(m);
    for (int i = 0; i < m; i++) {
        cin >> vl[i].second >> vl[i].first;
        vl[i].second = -vl[i].second;
    }
    sort(vl.begin(), vl.end());

    {
        ll maxw = 0;
        for (int i = 0; i < n; i++) {
            maxw = max(maxw, w[i]);
        }
        if (maxw > vl[0].first) {
            cout << -1 << newl;
            return 0;
        }
    }

    map<ll, ll> memo;
    {
        ll maxl = 0;
        for (int i = 0; i < m; i++) {
            if (maxl < -vl[i].second) {
                maxl = -vl[i].second;
                memo[vl[i].first] = maxl;
            }
        }
    }

    vector<int> ids(n);
    iota(ids.begin(), ids.end(), 0);

    ll ans = 1e18;
    ll foo = 0;
    do {
        vector<ll> dp(n, 0);
        for (int ii = 0; ii < n; ii++) {
            int i = ids[ii];
            ll wsum = w[i];
            for (int jj = ii + 1; jj < n; jj++) {
                int j = ids[jj];
                wsum += w[j];
                auto it = memo.lower_bound(wsum);
                if (it == memo.begin()) continue;
                dp[jj] = max(dp[jj], dp[ii] + prev(it)->second);
            }
        }
        ans = min(ans, dp.back());
    } while (next_permutation(ids.begin(), ids.end()));
    cout << ans << newl;
    return 0;
}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
//#include <bits/stdc++.h>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> X(H, vector<int>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> X[i][j];
        }
    }

    int min_val = X[0][0];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if(min_val > X[i][j]){
                min_val = X[i][j];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            ans = ans + X[i][j] - min_val;
            }
    }

    cout << ans;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define     ll              long long
#define     mp              make_pair
#define     rep(i,a,b)      for( i=a;i<b;++i)
#define     repr(i,a,b)     for( i=a;i>=b;i--)
#define     up              upper_bound
#define     lb              lower_bound
// #define     t()             int test;cin>>test;while(test--)
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

ll dp[2000][2000];
ll down[2000][2000];
ll rig[2000][2000];
ll diag[2000][2000];
const ll mod = 1000000007;

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS;
    ll h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char> (w));
    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            cin >> a[i][j];
        }
    }
    dp[0][0] = 1;
    for(ll i = 0;i < h;i++){
        for(ll j = 0;j < w;j++){
            if(i == 0 && j == 0){
                continue;
            }
            if(a[i][j] == '#'){
                continue;
            }
            if(j > 0){
                rig[i][j] = (rig[i][j-1] + dp[i][j-1])%mod;
            }
            if(i > 0){
                down[i][j] = (down[i-1][j] + dp[i-1][j])%mod;
            }
            if(i > 0 && j > 0){
                diag[i][j] = (diag[i-1][j-1] + dp[i-1][j-1])%mod;
            }
            dp[i][j] = (rig[i][j] + down[i][j] + diag[i][j])%mod;
        }
    }
    cout << dp[h-1][w-1] << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007;
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll mul(ll x, ll y)
{
    return (x * 1ll * y) % MOD;
}

ll fastpow(ll x, ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}
ll modinv(ll n,ll p)
{
	return fastpow(n,p-2) ;
}
struct Comp {
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
    if (a.first != b.first) {
      return a.first > b.first;
    }
    return a.second >b.second;
  }
};

int main(int argc, char** argv)
{   sws ;
  cout<<setprecision(10);

//  ll google=0 ;

 // tcase
    {
    ll a,b,c ;
    cin>>a>>b>>c;
    if(a<=0&&b<=0)
    {   a*=-1 ;
        b*=-1;
    	if(c%2)
    	{
    		if(a==b)
    		cout<<"=" ;
    		else if(a>b)
    		cout<<"<" ;
    		else
    		cout<<">" ;
		}
		else
		{
				if(a==b)
    		cout<<"=" ;
    		else if(a>b)
    		cout<<">" ;
    		else
    		cout<<"<" ;
		}
	}
	else if(a>=0&&b>=0)
	{
			if(a==b)
    		cout<<"=" ;
    		else if(a>b)
    		cout<<">" ;
    		else
    		cout<<"<" ;
	}
	else if(a>=0&&b<=0)
	{
		if(c%2)
		cout<<">" ;
		else
		{
			b*=-1 ;
				if(a==b)
    		cout<<"=" ;
    		else if(a>b)
    		cout<<">" ;
    		else
    		cout<<"<" ;
		}
	}
	else
	{
			if(c%2)
		cout<<"<" ;
		else
		{
			a*=-1 ;
				if(a==b)
    		cout<<"=" ;
    		else if(a>b)
    		cout<<">" ;
    		else
    		cout<<"<" ;
		}
	}
    }

return 0 ;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
#define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() )
#define memset1(v) memset(v,-1,sizeof(v))
#define memset0(v) memset(v,0,sizeof(v))
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n,m;
vector<pii>ed[2005];
void solve(){
	cin>>n>>m;
	rep(i,m){
		int u,v,c;
		cin>>u>>v>>c;
		ed[u].pb(pii(v,c));
	}
	for(int i=1;i<=n;i++){
		int d[n+1];
		for(int i=1;i<=n;i++)d[i]=inf;
		priority_queue<pii>pq;
		for(pii p:ed[i]){
			pq.push(pii(-p.se,p.fi));
			d[p.fi]=min(d[p.fi],p.se);
		}
		while(!pq.empty()){
			pii p=pq.top();
			int u=p.se;
			int d1=-p.fi;
			pq.pop();
			if(d1>d[u])continue;
			for(pii p:ed[u]){
				if(d[p.fi]>d1+p.se){
					d[p.fi]=d1+p.se;
					pq.push(pii(-d[p.fi],p.fi));
				}
			}
		}
		if(d[i]>=inf)cout<<-1<<"\n";
		else cout<<d[i]<<"\n";
	}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}


# include<bits/stdc++.h>

using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

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

#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const bool MULTIPLE_TEST_CASES = false;

const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;

l H,W,A,B;

void cnt(vector<vector<bool> > &visited, l A_rem, l B_rem, l &ans) {
	if(A_rem<0 || B_rem<0) {
		return;
	}
	if(A_rem==0 && B_rem==0) {
		ans++;
		return;

	}
	bool found = false;
	l i=-1,j=-1;
	for(l x=0;x<H;x++) {

		for(l y=0;y<W;y++) {
			if(visited[x][y]==false) {
				i=x;
				j=y;
				found = true;
				break;
			}
		}
		if(found) {
			break;
		}
	}
	if(i==-1 || j==-1) {
		return;
	}
	dbg(i,j);
	visited[i][j]=true;
	cnt(visited, A_rem, B_rem-1,ans);

	if(i+1<H && visited[i+1][j]==false) {
		visited[i+1][j]=true;
		cnt(visited, A_rem-1, B_rem,ans);
		visited[i+1][j]=false;
	}

	if(j+1<W && visited[i][j+1]==false) {
		visited[i][j+1]=true;
		cnt(visited, A_rem-1, B_rem,ans);
		visited[i][j+1]=false;
	}
	visited[i][j] = false;
}

void solve() {

	cin>>H>>W>>A>>B;

	vector<vector<bool> > visited(H, vector<bool>(W, false));

	l ans = 0;
	cnt(visited, A, B, ans);
	cout<<ans<<"\n";

	return;
}

int main(){
	io;
	int t=1;
	if (MULTIPLE_TEST_CASES) cin>>t;
	rep(i,0,t) {
		solve();
	}

	return 0;
}

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

using VI = vector<int>;

int h, w;

int g(VI& a, int i, int d);

int f(VI& v) {
    int i = find(cbegin(v), cend(v), 0) - cbegin(v);
    return i < v.size() ? g(v, i, 0) + g(v, i, 1) : 1;
}

int g(VI& v, int i, int d) {
    int j = i + (d ? w : 1);
    if (!d && i % w == w - 1 || d && i / w == h - 1 || v[j]) {
        return 0;
    }
    v[i] = v[j] = 1;
    int r = f(v);
    v[i] = v[j] = 0;
    return r;
}

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

    int a, b;
    cin >> h >> w >> a >> b;
    VI v(2 * a);
    v.insert(end(v), b, 1);
    int r = 0;

    do r += f(v);
    while (next_permutation(begin(v), end(v)));

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


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#ifndef PRELUDE_H
#define PRELUDE_H

#define M_PI 3.14159265358979323846
#define EPS 1e-9

#include <algorithm>
#include <cmath>
#include <numeric>

#include <vector>
#include <set>
#include <map>
#include <queue>

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef std::pair<int, int> ii;
typedef std::pair<ll, ll> llll;
typedef std::pair<int, ll> ill;
typedef std::pair<double, double> dd;

typedef std::vector<int> vi;
typedef std::vector<ii> vii;
typedef std::vector<vi> vvi;
typedef std::vector<vvi> vvvi;
typedef std::vector<vii> vvii;
typedef std::vector<ill> vill;
typedef std::vector<vill> vvill;

typedef std::vector<bool> vb;

typedef std::vector<char> vc;
typedef std::vector<std::vector<char>> vvc;

typedef std::vector<ll> vll;
typedef std::vector<vll> vvll;
typedef std::vector<llll> vllll;
typedef std::vector<double> vd;
typedef std::vector<dd> vdd;

typedef std::string ss;
typedef std::vector<ss> vss;
typedef std::vector<vss> vvss;

typedef std::set<int> si;
typedef std::set<ii> sii;
typedef std::set<ll> sll;

typedef std::map<int, int> mii;
typedef std::map<char, int> mci;

typedef std::queue<int> qi;

typedef std::vector<std::pair<int, ii>> EdgeList;

#define REP(i,n) for(int i=0;i<n;++i)
#define DEBUG(a) #a << ": " << (a) << " " <<
#define ENDL "\n"
#define REPLL(l,n) for(ll l=0;l<n;++l)
#define FOR(i,s,n) for(int i=s;i<=n;++i)
#define FOREACH(it,a) for(auto it=a.begin(); it != a.end(); ++it)

#endif //PRELUDE_H

class EWhiteAndBlackBalls {
public:
    vll fac, invfac;
    ll mod = 1'000'000'000 + 7;
    std::tuple<ll, ll, ll> extendedEuclid(ll a, ll b) {
        if (b == 0) {
            return {a, 1, 0};
        }
        auto [d, x, y] = extendedEuclid(b, a % b);
        ll x1 = y;
        ll y1 = x - (a / b) * y;
        return {d, x1, y1};
    }

    ll modularInverse(ll a, ll n) {
        auto [d, x, y] = extendedEuclid(a, n);
        return (x + n) % n;
    }
    ll choose (ll n, ll k) {
        if (k > n) {
            return 0;
        }
        return fac[n] * invfac[k] % mod * invfac[n-k] % mod;
    }
    void solve(std::istream& in, std::ostream& out) {
        ll n, m, k;
        in >> n >> m >> k;
        if (n > m + k) {
            out << 0; return;
        }

        fac = vll(n+m+1);
        invfac = vll(n+m+1);
        fac[0] = 1; invfac[0] = 1;
        for(int i = 1; i <= n+m; ++i) {
            fac[i] = i * fac[i-1] % mod;
            invfac[i] = modularInverse(fac[i], mod);
        }
        ll ans = choose(n+m, n) - choose(n+m, m+k+1);
        ans = (ans + mod) % mod;

        out << ans;
    }
};

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

	EWhiteAndBlackBalls solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include <bits/stdc++.h>
#define MAXN  2000005
#define ll long long
#define F first
#define S second
#define MOD 1000000007
#define ll long long

using namespace std;

ll n, m, k;
ll gt[MAXN], inv[MAXN];

ll poW(ll A, ll B)
{
    ll C = 1;

    for(; B; B /= 2, A = (A * A) % MOD)
    {
        if(B % 2) C = (C * A) % MOD;
    }
    return C;
}

ll C(ll A, ll B)
{
    if(B < A) return 0;
    ll res = (((gt[B] * inv[A] ) % MOD ) * inv[B - A] ) % MOD;
    return res;
}

void solve()
{
    cin >> n >> m >> k;
    //if(n < m) swap(n, m);
    if(n > m + k)
    {
        cout << 0;
        return;
    }
    gt[0] = 1;
    for(int i = 1; i <= n + m; ++i)
    {
        gt[i] = (gt[i-1] * i) % MOD;
    }

    inv[n+m] = poW(gt[n + m], MOD - 2);

    for(int i = n + m - 1; i >= 0; --i)
    {
        inv[i] = (inv[i + 1] * (i + 1)) % MOD;
    }

    ll ans = C(m, n + m) % MOD;
    ans = (ans - C(m + k  + 1, n + m)) % MOD;
    if(ans < 0 ) ans += MOD;
    cout << ans;
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie();
    cout.tie();
    if(fopen(".inp", "r"))
    {
        freopen(".inp", "r", stdin);
        freopen(".out", "w", stdout);
    }
    int t;
    t = 1;
    //cin >> t;
    while(t--)
    {
        //cerr << t << '\n';
        solve();
    }
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
#define PB push_back
#define pb pop_back

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
  	int a,b; cin>>a>>b;
  	a *=2; a += 100;
  	cout<< a - b;

	return 0;
}

#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	fastio
	int n,k;
	cin >> n >> k;
	auto f = [&](int a, int b){
		return min(b-1,2*a+1-b);
	};
	int ans = 0;
	for(int i = 2;i <= 2*n;i++){
		if(i-k < 2 || i-k > 2*n) continue;
		ans += f(n,i)*f(n,i-k);
	}
	cout << ans << "\n";
}


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

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0ll;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float 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 debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD
// #define TIME

/******************************************************************************************************************************/

const ll inf = 2e18;
const ll mod = 1e9+7;
const ll N = 1e6+3;

int main()
{
    auto start_time = Clock;
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    ll n,x;
    string s;
    cin>>n>>x>>s;
    for(auto i: s) {
        if(i=='o') ++x;
        else --x;
        chmax(x,0ll);
    }
    cout<<x;

    auto end_time = Clock;
    #ifndef TIME
    	return 0;
    #endif
	cout << "\nTime elapsed: "
	<< (double)duration_cast<milliseconds>(end_time-start_time).count()
	<< "ms";

    return 0;
}

#include <iostream>

using namespace std;

int main()

{

  int N,X;

  cin >> N >> X;

  string s;

  cin >> s;

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

    if(s[i]=='x' && X==0)

    {

      continue;

    }

    else if(s[i]=='x' && X!=0) {

      X--;

    }

    else if(s[i]=='o') {

      X++;

    }

  }

  cout << X << endl;

  return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <map>
#include <bitset>
#include <numeric>

using namespace std;
using ll = long long;

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    bool same(int x, int y)
    {
        x = find(x), y = find(y);
        return x == y;
    }
    int find(int k)
    {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k)
    {
        return (-data[find(k)]);
    }
};

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> P(N);

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

    priority_queue<ll> odd_plus;
    priority_queue<ll> odd_minus;
    ll odds = 0;
    ll ans = 0;
    for(int i = 0;i < N;i++){
        if (A[i] > B[i]){
            ans += A[i];
            if (i % 2 == 0){
                odds--;
                odd_plus.push(B[i]-A[i]);
            }else{
                odds++;
                odd_minus.push(B[i]-A[i]);
            }
        }else{
            ans += B[i];
            if (i % 2 == 0){
                odd_minus.push(A[i]-B[i]);
            }else{
                odd_plus.push(A[i]-B[i]);
            }
        }
    }
    while(odds > 0){
        ans += odd_minus.top();
        odd_minus.pop();
        odds--;
    }

    while(odds < 0){
        ans += odd_plus.top();
        odd_plus.pop();
        odds++;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define lc (x << 1)
#define rc (x << 1 | 1)
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i,n) rep(i,1,n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const ll INF = 1e15;

// char buf[size],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
TP void qw(o x) {
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(' ');
}
TP void pr2(o x) {
    if (x < 0)
        x = -x, putchar('-');
    qw(x);
    putchar(10);
}

// math
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
    ll c = 1;
    while (b) {
        if (b & 1)
            c = c * a % p;
        b /= 2;
        a = a * a % p;
    }
    return c;
}

TP void cmax(o& x, o y) {
    if (x < y)
        x = y;
}
void cmax(int& x, int y) { x = x - y >> 31 ? y : x; }
TP void cmin(o& x, o y) {
    if (x > y)
        x = y;
}
void cmin(int& x, int y) { x = x - y >> 31 ? x : y; }
TPP void ad(t1& x, t2 y) {
    x += y;
    if (x >= mod)
        x -= mod;
}
TPP void dl(t1& x, t2 y) {
    x -= y;
    if (x < 0)
        x += mod;
}

// dbinom
ll jc[N], inv[N];
void jc_init(int n) {
    jc[0] = 1;
    for (int i = 1; i <= n; i++)
        jc[i] = jc[i - 1] * i % mod;
    inv[n] = power(jc[n]);
    for (int i = n; i; i--)
        inv[i - 1] = inv[i] * i % mod;
}
ll C(int x, int y) {
    if (x < y || y < 0)
        return 0;
    return jc[x] * inv[y] % mod * inv[x - y] % mod;
}

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

void solve() {
    qr(n);
    FOR(i,n) qr(a[i]),ans += a[i];
    FOR(i,n) qr(b[i]),c[i&1][(i+1)>>1]=b[i]-a[i];
    sort(c[0]+1,c[0]+n/2+1);
    sort(c[1]+1,c[1]+n/2+1);
    REP(i,1,n/2) {
        ll x=c[0][i]+c[1][i];
        if(x<0) break;
        ans += x;
    }
    pr2(ans);
}

int main() {
    int T = 1;
    // qr(T);
    while (T--)
        solve();
    return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>

#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
  #include <vector>

#include <cstring>
#include <ostream>
#include <type_traits>
#include <utility>
#include <chrono>
#include <random>

#ifdef ONLINE_JUDGE
#pragma GCC optimize ("O3")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  #endif

using namespace std;

using uint64 = uint64_t;
using int64 = int64_t;
using uint32 = uint32_t;
using vi = vector<int>;

#define seq(i,a,b) for (auto i = (a); i < (b); ++i)
#define rev(i,a,b) for (auto i = (b)-1; i >= (a); --i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) {cerr << #x << ": " << x << endl;}

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

  int64 s,p; cin >> s >> p;
  int64 i = 1;
  while (i*i <= p) {
    if (p%i == 0) {
      if (i + p/i == s) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    ++i;
  }
  cout << "No" << endl;
}

///OM
///SUVOM SHAHA
///AUST CSE 39

#include<bits/stdc++.h>
#define loo(i, n) for(int i = 0; i < n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define sc second
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define ll long long int
#define inf 1000000000
#define mpch map<char, int>
#define mpint map<int, int>
#define endl '\n'
//to iterate map :for (auto i : mp):

using namespace std;

int main(void)

{
    int a, b, i, j = 0;
    cin>>a>>b;
    int ara[a+b], n = a+b;
    if(a >= b){
        for(i = 0; i < a; i++){
            ara[i] = i+1;
            j += ara[i];
        }
        for(i = a; i < n-1; i++){
            ara[i] = -(ara[i-a]);
            j += ara[i];
        }
        ara[n-1] = -(j);
    }
    else{
        for(i = 0; i < b; i++){
            ara[i] = -(i+1);
            j -= ara[i];
        }
        for(i = b; i < n-1; i++){
            ara[i] = -(ara[i-b]);
            j -= ara[i];
        }
        ara[n-1] = j;
    }
    for(i = 0; i < n; i++){
        if(i == n-1)cout<<ara[i]<<endl;
        else cout<<ara[i]<< " ";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SZ(v) ((int)(v.size()))
const int N = 2e5+9;
void run () {
    int a, b, c;
    cin >> a >> b >> c;
    int sum = 6 * 7 / 2;
    sum -= a;
    sum -= b;
    sum -= c;
    cout << sum << endl;
}
int main () {
    int tt;
    tt = 1;
//    cin >> tt;
    while (tt--)
        run();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=3e5;
const int inf=1e9;
int main(){
	int a,b,c; cin>>a>>b>>c;
	cout<<21 - a - b - c<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

//#include <atcoder/all>

//using namespace atcoder;
//typedef modint998244353 mint;

ll inf=1001001001001001001;

ll pls(ll a,ll b){
  if(inf-a<b) return inf;
  return a+b;
}

ll mul(ll a,ll b){
  if(a==0 or b==0) return 0;
  if(inf/a<b) return inf;
  return a*b;
}

int main(){
  string S;
  cin>>S;
  ll M;
  cin>>M;
  if(S.size()==1){
    if(stoi(S)<=M) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
  }
  ll ok=0;
  ll ng=inf;
  VL X(0);
  for(auto e:S) X.pb(e-'0');
  ll ans=*max_element(all(X))+1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    ll sum=0;
    ll tmp=1;
    rep(i,S.size()){
      ll nu=mul(stoi(S.substr(S.size()-1-i,1)),tmp);
      sum=pls(sum,nu);
      tmp=mul(tmp,mid);
    }
    if(sum==inf or sum>M) ng=mid;
    else ok=mid;
  }
  cout<<max(0ll,ok-ans+1)<<endl;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

using C = complex<double>;

C inC() {
    double x, y;
    cin >> x >> y;
    return C(x, y);
}

int main() {
    int N;
    cin >> N;
    C p0 = inC();
    C ph = inC();
    C core = (p0 + ph) / 2.0;
    double PI = acos(-1);
    double rad = 2 * PI / N;
    C r(cos(rad), sin(rad));
    C ans = core + (p0 - core) * r;
    printf("%.10f %.10f\n", ans.real(), ans.imag());
    return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;

void solve() {
    double X,Y,Z; cin >> X >> Y >> Z;
    double t = Y / X;
    REPR(i,1e8) {
        double snuke = (double)i / Z;
        if (snuke < t) {
            cout << i << endl;
            return;
        }
    }
}

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

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <cmath>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double EPS = 1e-10;
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const char eol = '\n';
// --------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X,Y,Z;
    cin >> X >> Y >> Z;
    for(int i=1000000; i>=0; i--){
        if(Y*Z > (ll)i*X){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

template< typename T >
T mod_pow(T x, T n, const T &p) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 2);
    vector<vector<ll>> cross(h + 2, vector<ll>(w+2));
    s[0] = string(w + 2, '#');
    s[h+1] = string(w + 2, '#');
    for (int i = 1; i <= h; ++i) {
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    ll l = 0;
    for (int i = 1; i <= h; ++i) {
        ll temp = 0;
        for (int j = 0; j <= w; ++j) {
            if (s[i][j] == '.') {
                cross[i][j] += temp - 1;
                l++;
                continue;
            }
            temp = 0;
            for (int k = j + 1; k <= w; ++k) {
                if (s[i][k] == '.') temp++;
                else break;
            }
        }
    }
    for (int j = 1; j <= w; ++j) {
        ll temp = 0;
        for (int i = 0; i <= h; ++i) {
            if (s[i][j] == '.') {
                cross[i][j] += temp;
                continue;
            }
            temp = 0;
            for (int k = i + 1; k <= h; ++k) {
                if (s[k][j] == '.') temp++;
                else break;
            }
        }
    }
    ll result = 0;
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            result += (mod_pow(2ll, cross[i][j], mod) - 1) * (mod_pow(2ll, l - cross[i][j], mod)) % mod;
            result %= mod;
        }
    }
    cout << result << endl;
}

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

#define ll long long int
#define ld double
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAXIM 4000001
ll mod = 1e9 + 7;

vector<vll> v,row,col;
vll pw2(MAXIM);

ll bin_exp(ll a, ll b){
    a = a % mod;
    ll ans = 1;
    while(b > 0){
        if(b & 1 == 1) ans = (a * ans) % mod;
        a = (a * a) % mod;
        b = b >> 1;
    }
    return ans;
}

void calc(){
    pw2[0] = 1;
    rep(i,1,MAXIM){
        pw2[i] = pw2[i - 1]*2;
        while(pw2[i] > mod) pw2[i] -= mod;
    }
}

void solve(){
    ll n,m;
    cin >> n >> m;
    v.assign(n,vll(m));
    row.assign(n,vll(1,-1)),
    col.assign(m,vll(1,-1));
    ll dot = 0;
    rep(i,0,n){
        rep(j,0,m){
            char c;
            cin >> c;
            if(c == '.'){
                v[i][j] = 1;
                dot++;
            }
            else{
                v[i][j] = 0;
                row[i].pb(j);
                col[j].pb(i);
            }
        }
    }
    rep(i,0,n) row[i].pb(m);
    rep(j,0,m) col[j].pb(n);
    ll ans = 0;
    rep(i,0,n){
        rep(j,0,m){
            if(v[i][j] == 0) continue;
            ll x1 = upper_bound(all(row[i]),j) - row[i].begin();
            ll x2 = upper_bound(all(col[j]),i) - col[j].begin();
            ll temp = (row[i][x1] - row[i][x1 - 1] - 1) + (col[j][x2] - col[j][x2 - 1] - 1) - 1;
            ll t1 = (pw2[temp] - 1 + mod);
            ll t2 = pw2[dot - temp];
            ll t = t1*t2;
            if(t > mod) t %= mod;
            ans += t;
            if(ans > mod) ans -= mod;
        }
    }
    cout << ans << br;
}

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

	ll t = 1;
    calc();
	// cin >> t;
	rep(i,0,t){
        // cout << "Case #" << i + 1 << ": ";
		solve();
	}

}


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

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (b >= c*d) {
        cout << -1 << '\n';
        return 0;
    }
    for (int i=0; ; i++) {
        if ((a + i*b) <= (i*c*d)) {
            cout << i << '\n';
            break;
        }
    }

    return 0;
}

#include<bits/stdc++.h>
#define ll int
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// I wanna be withma youlu
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(   ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 2e9 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,w;
    cin>>a>>b>>w;
    w*=1000;
    ll mini = INF,maxi = -1;
    for(int i = 1;;i++){
        ll minv = a*i;
        ll maxv = b*i;
        if(minv > w)
            break;
        if(minv<=w && maxv>=w){
            mini = min(mini,i);
            maxi = max(maxi,i);
        }
    }
    if(mini == INF) cout<<"UNSATISFIABLE"<<'\n';
    else cout<<mini<<" "<<maxi<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

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

const ll   N     =  1e5 + 5;
const ll   mod   =  1e9 + 7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N) + 1;

ll n, m, d[25][25], vis[25], ans = 0, v[25];
vector <int> s;

void dfs(int x) {
	vis[x] = 1;
	s.pb(x);
	for (int i = 1; i <= n; i++) {
		if (vis[i] == 1 || d[x][i] == 0) continue;
		dfs(i);
	}
}

void rec(int i) {
	if (i == s.size()) {
		ans++;
		return;
	}
	vector <int> p(n + 1, 0);
	if (v[s[i]] == 7) return;
	for (int k = 1; k <= n; k++) p[k] = v[k];
	for (int j = 0; j < 3; j++) {
		if (v[s[i]]&(1<<j)) continue;
		for (int k = 1; k <= n; k++) {
			if (d[s[i]][k] == 0) continue;
			v[k] |= (1<<j);
		}
		rec(i + 1);
		for (int k = 1; k <= n; k++) v[k] = p[k];
	}
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b; cin >> a >> b;
		d[a][b] = d[b][a] = 1;
	}
	ll res = 1;
	for (int i = 1; i <= n; i++) {
		if (vis[i] == 0) {
			s.clear();
			ans = 0;
			dfs(i);
			rec(0);
			res *= ans;
		}
	}
	deb1(res)
}

int main() {
	GODSPEED;
	int test = 1;
	// cin >> test;
	for (int i = 1; i <= test; i++) {
		solve();
	}
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<ll,ll>;

vector<ll> bipartite(const vector<vector<ll>>& hen) {
	ll n = hen.size();
	vector<ll> col(n, -1);
	col[0] = 0;
	stack<ll> st;
	for(ll i = n - 1; i >= 0; i--) st.push(i);
	while(st.size()) {
		ll v = st.top(); st.pop();
		// print(v);
		if(col[v] == -1) col[v] = 0;
		for(auto i : hen[v]) {
			if(col[i] != -1) {
				if(col[i] == col[v]) return {-1};
				continue;
			} else {
				col[i] = !col[v];
				st.push(i);
			}
		}
		// print(col);
	}
	vector<ll> red;
	red.reserve(count(col.begin(), col.end(), 0));
	for(ll i = 0; i < (ll)col.size(); i++) if(col[i] == 0) red.push_back(i);
	return red;
}

#pragma region UnionFind
#define UNIONFIND
class UnionFind{
  private:
	vector<ll> data;
  public:
	UnionFind(ll n) : data(n,-1) {}
	ll root(ll i) { return data[i] < 0 ? i : data[i] = root(data[i]); }
	ll size(ll i) { return -data[root(i)]; }
	bool same(ll x, ll y) {return root(x) == root(y); }
	bool connected() {return size(0) == (ll)data.size(); }

	bool unit(ll i,ll j){
		i = root(i);
		j = root(j);
		if(i != j){
			data[i] += data[j];
			data[j] = i;
		}
		return i != j;
	}
};
#pragma endregion

#define bitget(n,k) (((n)>>(k))&1) /*nのk bit目*/

int main()
{
	ll N, M; cin >> N >> M;
	vector<vector<ll>> hen(N);
	for(ll i = 0; i < M; i++) {
		ll u, v; cin >> u >> v;
		u--,v--;
		hen[u].push_back(v);
		hen[v].push_back(u);
	}

	ll sum = 0;

	for(ll bit = 0; bit < (1<<N); bit++) {
		vector<ll> vers;
		vector<vector<ll>> edge(N);

		bool ok = true;
		for(ll i = 0; i < N; i++) {
			if(bitget(bit, i)) {

				for(auto j : hen[i]) {
					if(bitget(bit, j)) {
						ok = false;
						break;
					}
				}

			} else {

				for(auto j : hen[i]) {
					if(bit & (1<<j)) continue;
					edge[i].push_back(j);
				}

			}
		}

		if(ok == false)continue;

		// print(bit, edge);

		auto v = bipartite(edge);
		if(v == vector<ll>{-1})continue;

		UnionFind uni(N);

		for(ll i = 0; i < N; i++) {
			for(auto j : edge[i]) {
				uni.unit(i, j);
			}
		}

		set<ll> st;
		for(ll i = 0; i < N; i++) {
			if(bit & (1<<i))continue;
			st.insert(uni.root(i));
		}
		sum += (1LL<<(int)st.size());
	}

	cout << sum << endl;

}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std; //using namespace atcoder;
template<typename T>  using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n)  for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;

ll divceil (ll x, ll div) { return (x/div) + (x%div>0); }
ll divfloor(ll x, ll div) { return (x/div) - (x%div<0); }
int main() {
    ll kn; cin >> kn;
    ll nn; cin >> nn;
    ll mn; cin >> mn;

    vll a1(kn);
    rep(i,kn) {
        ll x;
        cin >> x; a1[i]=x;
    }

    // 1. 剰余なしの値を設定B=(floor(MA/N))
    ll ct=0;
    vll b1(kn);
    ve<ld> lb1(kn, 0);
    rep(i,kn) {
        b1[i]  =divfloor(mn*a1[i],nn);
        if(a1[i]) lb1[i] =(ld)(mn*a1[i])/(ld)nn;
        ct+=b1[i];
    }

    // 2. 誤差とidxのpairの配列を作成(floorなしB-B)
    vector<pair<ld,ll>> vp1;
    rep(i,kn) {
        vp1.push_back({lb1[i]-(ld)b1[i],i});
    }

    // 3. 配列を誤差で降順ソート
    sort( vp1.begin(), vp1.end(), greater<pair<ld,ll>>() );

    // 4. 剰余分を更新
    rep(i,mn-ct) {
        b1[vp1[i].second]++;
    }

    rep(i,kn) {
        cout << b1[i] << " ";
    }
    cout << endl;

}

// B - Village of M People
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)

int main(){
	int k, n, m; cin>>k>>n>>m;
	vector<ll> B;
	vector<pair<ll,ll>> R;
	ll rest = m;
	rep(i, k){
		ll a; cin>>a;
		ll b = a*m / n;
		rest -= b;
		B.push_back(b);
		R.emplace_back(a*m % n, i);
	}
	sort(R.rbegin(), R.rend());
	rep(i, rest) B[R[i].second] += 1;
	rep(i, k) cout<< B[i] <<(i < k-1? " ":"\n");
}


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

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

  ll ans=0;
  rep(i,n){
    ll sum=a[i];
    int k=i-1;
    while(0<=k){
      if(a[k]<a[i]) break;
      sum+=a[i];
      k--;
    }
    k=i+1;
    while(k<n){
      if(a[k]<a[i]) break;
      sum+=a[i];
      k++;
    }
    ans=max(ans,sum);
  }

  cout << ans << endl;

}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

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

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

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;

int main() {
  int N, A[SIZE];

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    int minA = INF;
    for (int j = i + 1; j <= N; j++) {
      chmin(minA, A[j - 1]);
      chmax(ans, minA * (j - i));
    }
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;
vll temp;

void prec(){
    ll x=1;
    while(x<=1e16){
        x*=1000;
        temp.pb(x);
    }
}
int main()
{
    prec();
    ll n;
    cin >> n;
    ll res=0;
    for(auto a:temp){
        if(a>n) break;
        ll dist=n-a+1;
        res+=dist;
    }
    cout << res <<"\n";
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

int n;
int arr[3005][5];

int val[3005];

int memo[3005][32][4];

int dp(int i,int j,int k){
	if (k==4) return 0;
	if (i==n) return j==31;
	if (memo[i][j][k]!=-1) return memo[i][j][k];

	return memo[i][j][k]=max(dp(i+1,j,k),dp(i+1,j|val[i],k+1));
}

bool can(int i){
	rep(x,0,n){
		val[x]=0;
		rep(y,0,5) if (arr[x][y]>=i) val[x]|=(1<<y);
	}

	//cout<<i<<endl;
	//rep(x,0,n) cout<<val[x]<<" "; cout<<endl;

	memset(memo,-1,sizeof(memo));
	return dp(0,0,0);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n;
	rep(x,0,n) rep(y,0,5) cin>>arr[x][y];

	int lo=0,hi=1e9+5,mi;
	while (hi-lo>1){
		mi=hi+lo>>1;

		if (can(mi)) lo=mi;
		else hi=mi;
	}

	cout<<lo<<endl;
}


#include <bits/stdc++.h>
#define int long long
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loope(i, a, b) for (int i = a; i <= b; i++)
#define bloop(i, a, b) for (int i = a; i >= b; i--)
#define FastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define PRECISION                      \
    std::cout.unsetf(std::ios::fixed); \
    std::cout.precision(9)
#define scan(a, n)              \
    for (int i = 0; i < n; i++) \
    cin >> a[i]
#define print(a, n)             \
    for (int i = 0; i < n; i++) \
    {                           \
        cout << a[i] << ' ';    \
    }                           \
    cout << '\n'
using namespace std;
int mod = 1e9 + 7;

void solve()
{
    long double a,b;
    cin>>a>>b;
    cout<<a*(b/100)<<"\n";
}

int32_t main()
{
    FastIO;
    PRECISION;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ld a, b;
    cin >> a >> b;
    a /= 100;
    cout << fixed << setprecision(20);
    cout << a * b << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cerr << #x << " = " << (x) << endl
#define show2(x,y) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
//const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dy[4] = {1, 0, -1,  0};
const int dx[4] = {0, 1,  0, -1};

int main () {
	int n;
	cin >> n;
	vi x(n), y(n), z(n);
	rep(i,n) cin >> x[i] >> y[i] >> z[i];

	int n2 = 1<<n;
	vvi dp(n2,vi(n,INF));
	vvi dist(n,vi(n));
	rep(i,n)rep(j,n) {
		int now = abs(x[i]-x[j]);
		now += abs(y[i]-y[j]);
		now += max(0, z[j]-z[i]);
		dist[i][j] = now;
	}

	rep(i,n) {
		//if (i == 0) continue;
		dp[1<<i][i] = dist[0][i];
	}
	rep(i,n2)rep(j,n) {
		// j: 現在いる都市
		if (~i>>j&1) continue; // 既に訪れているかの確認
		rep(k,n) {
			// k: 次に訪れる都市
			if (i>>k&1) continue; // まだ訪れていないかの確認
			chmin(dp[i|1<<k][k], dp[i][j]+dist[j][k]);
		}
	}

	cout << dp[n2-1][0] << endl;
	return 0;
}

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

const int MAXN=20;
int n;
int d[MAXN][MAXN];
int dp[1<<MAXN][MAXN];

int rec(int S, int v) {
    if(dp[S][v] >= 0) return dp[S][v];
    if(S==(1<<n)-1 && v==0) return dp[S][v]=0;
    int tmp=INF;
    REP(u,n) if(!(S>>u & 1)) tmp=min(tmp, rec(S|1<<u,u)+d[v][u]);
    return dp[S][v]=tmp;
}

int main() {

    cin>>n;
    REP(i,n) REP(j,n) d[i][j]=d[j][i]=INF;

    vector<tuple<int,int,int>> data(n);
    REP(i,n){
        int x,y,z;
        cin>>x>>y>>z;
        data.at(i)=make_tuple(x,y,z);
    }

    REP(s,n){
        REP(t,n){
            d[s][t]=abs(get<0>(data.at(t))-get<0>(data.at(s)))+abs(get<1>(data.at(t))-get<1>(data.at(s)))+max(0,get<2>(data.at(t))-get<2>(data.at(s)));
        }
    }

    fill((int *)dp, (int *)(dp+(1<<MAXN)), -1);
    cout << rec(0,0) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0)
void Print(int *a,int n){
	for(int i=1;i<n;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n]);
}
bitset<N>vis;
int p[N],cnt;
void ss(int n){
	vis[0]=vis[1]=1;
	for(int i=2;i<=n;i++){
		if(!vis[i]) p[++cnt]=i;
		for(int j=1;j<=cnt&&i*p[j]<=n;j++){
			vis[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
ll dp[1<<20];
int main(){
	ss(72);
	ll A,B;scanf("%lld%lld",&A,&B);
	dp[0]=1;
	//Print(p,cnt);
	for(ll i=A;i<=B;i++){
		int msk=0;
		for(int j=1;j<=cnt;j++) if(i%p[j]==0) msk|=(1<<(j-1));
		for(int j=0;j<(1<<cnt);j++)
			if(!(msk&j)) dp[msk|j]+=dp[j];
	}
	ll s=0;
	for(int i=0;i<(1<<cnt);i++) s+=dp[i];
	printf("%lld\n",s);
	return 0;
}

#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lb;
#define rep(i, f, t) for(int i = f; i <= t; i ++)
#define urep(i, f, t) for(int i = f; i >= t; i --)
#define pb push_back
#define eb emplace_back
#define pq priority_queue
#define umap unordered_map
#define addr(v) v.begin(), v.end()
#define uaddr(v) v.rbegin(), v.rend()
#define mst(arr, val) memset(arr, val, sizeof arr)
#define qstream std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//when qstream exists , cout and printf can't be used together
//
#define ls(t) (t << 1)
#define rs(t) (t << 1 | 1)
#define lowbit(x) ((x) & (-(x)))
#define ceil_div(a, b) ((a) + (b) - 1) / (b)
const ll INF = 1e18 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1050;
const int Maxn = 5e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 100003;
const int Mod = 998244353;
const int D = 233;//HASH
const double PI = acos(-1.0);
// tips: i int for_loop i*i can't be used for long long

int n, m;

struct Edge {
	int to, next;
	char w;
}e[Maxn];

int head[maxn], id;

struct nd {
	int a, b;
};

int dis[maxn][maxn];

void add(int u, int v, char w) {
	e[id].to = v;
	e[id].w = w;
	e[id].next = head[u];
	head[u] = id ++;
}

queue<nd> q;

int main() {
	qstream;
	mst(dis, inf);
	mst(head, -1);
	cin >> n >> m;
	rep(i, 1, m) {
		int u, v;
		char w;
		cin >> u >> v >> w;
		add(u, v, w);
		add(v, u, w);
	}
	rep(i, 1, n) {
		dis[i][i] = 0;
		q.push({i, i});
	}
	rep(j, 1, n) {
		for(int i = head[j]; i != -1; i = e[i].next) {
			int v = e[i].to;
			if(j >= v) continue;
			dis[j][v] = dis[v][j] = 1;
			q.push({j, v});
		}
	}
	while(!q.empty()) {
		int x = q.front().a, y = q.front().b;
		q.pop();
		//cout << x << " " << y << endl;
		for(int i = head[x]; i != -1; i = e[i].next) {
			int tx = e[i].to;
			for(int j = head[y]; j != -1; j = e[j].next) {
				int ty = e[j].to;
				if(e[i].w == e[j].w && tx != ty) {
					if(dis[tx][ty] > dis[x][y] + 2) {
						dis[ty][tx] = dis[tx][ty] = dis[x][y] + 2;
						q.push({tx, ty});
					}
				}
			}
		}
	}
	cout << (dis[1][n] == inf ? -1 : dis[1][n]) << endl;
	// #ifndef ONLINE_JUDGE
	//     system("pause");
    // #endif
    return 0;
}


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

typedef long long ll;

const int Maxn = 1000005;

char tmp[Maxn];
int n;
string A;
string B;

void Read(string &s)
{
	scanf("%s", tmp); s = tmp;
}

int main()
{
	cin >> n;
	Read(A);
	Read(B);
	int asum = 0, bsum = 0;
	int add = 0, neutr = 0;
	ll res = 0;
	for (int i = 0; i < n; i++) if (A[i] != '1' || B[i] != '1') {
		asum += A[i] == '1';
		bsum += B[i] == '1';
		if (A[i] == '0' && B[i] == '1') add++;
		if (A[i] == '0' && B[i] == '0') neutr++;
		if (asum == bsum) {
			if (add > 0) res += add + neutr;
			add = neutr = 0;
		}
	}
	printf("%lld\n", asum != bsum? -1ll: res);
    return 0;
}

 #include<iostream>
 #include<algorithm>

 using namespace std;
 const int N=100010;

 typedef long long ll;

 int n;
 char a[N];
 int sum1[N];
 int sum2[N];

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

    for(int i=1;i<=n;i++)
    {
        if(a[i]=='A')
        {
            sum1[i]=1;
        }
        else if(a[i]=='T')
        {
            sum1[i]=-1;
        }
        else if (a[i]=='C')
        {
            sum2[i]=1;
        }
        else if (a[i]=='G')
        {
            sum2[i]=-1;
        }
    }

    for(int i=1;i<=n;i++)
    {
        sum1[i]+=sum1[i-1];
        sum2[i]+=sum2[i-1];
    }

    //只有5000，可以枚举两个区间

    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
        {
            if(sum1[j]-sum1[i-1]==0&&sum2[j]-sum2[i-1]==0)ans++;
        }
    cout<<ans;

    return 0;
 }


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

int main() {
  double A, B;
  cin >> A >> B;
  double f = 0.00;
  f = B /A;
  f = 1-f;
  f=f*100;
  cout << f << endl;
}

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

int main() {
    fastio;
    double ans{};
    ll a,b;
    cin >> a >> b;
    ans = (1-(double)b/a)*100;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)

using ll = long long;
using ld = long double;
using namespace std;

string a = "atcoder#";

int f(int pref, int c, string s) {
	int ans = 0, n = sz(s);
	rep(i, 0, pref) {
		char C = (i == pref ? (char)('a' + c) : a[i]);
		int g = -1;
		rep(j, i, n - 1) {
			if (s[j] == C) {
				g = j;
				break;
			}
		}
		if (g == -1) return 1e9;
		per(j, i + 1, g) {
			ans++;
			swap(s[j - 1], s[j]);
		}
	}
	return ans;
}

int main() {
	int t;
	cin >> t;
	while (t--) {
		string s;
		cin >> s;
		int n = sz(s);
		int res = 1e9;
		rep(i, 0, 7)
			rep(c, 0, 25) {
				if (i + 1 > n) continue;
				if ((char) ('a' + c) <= a[i]) continue;
				//~ cout << i << " " << c << " " << f(i, c, s) << endl;
				res = min(res, f(i, c, s));
			}
		if (res == 1e9) res = -1;
		printf ("%d\n", res);
	}

	return 0;
}

#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;

void solve() {
    int N,S,D; cin >> N >> S >> D;
    REP(_,N) {
        int X,Y; cin >> X >> Y;
        if (S > X && D < Y) {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
// template <class T = ll> using P = pair< T,T>;
template <class T = ll> using V = vector<T>;
template <class T = ll> using VV = V<V<T>>;
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()

int main()
{
    int n;
    cin >> n;
    V<pair<int,int>> x(n);
    V<pair<int,int>> y(n);
    rep(i, n) {
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }
    sort(all(x), greater<pair<int,int>>());
    sort(all(y), greater<pair<int,int>>());

    V<pair<pair<int,int>,int>> ans;
    {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[0].second;
        a.second = x[n-1].second;
        can.first = a;
        can.second = x[0].first - x[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[0].second;
        a.second = y[n-1].second;
        can.first = a;
        can.second = y[0].first - y[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[1].second;
        a.second = x[n-1].second;
        can.first = a;
        can.second = x[1].first - x[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = x[0].second;
        a.second = x[n-2].second;
        can.first = a;
        can.second = x[0].first - x[n-2].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[1].second;
        a.second = y[n-1].second;
        can.first = a;
        can.second = y[1].first - y[n-1].first;
        ans.push_back(can);
    }
        {
        pair<pair<int,int>,int> can;
        pair<int,int> a;
        a.first = y[0].second;
        a.second = y[n-2].second;
        can.first = a;
        can.second = y[0].first - y[n-2].first;
        ans.push_back(can);
    }
    sort(all(ans), [](auto lhs, auto rhs){return lhs.second > rhs.second;});
    ll cnt = 0;
    pair<int,int> pre;
    for(auto abc : ans){
        if(pre == abc.first) continue;
        cnt++;
        pre = abc.first;
        if(cnt == 2){
            cout << abc.second << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define lowbit(x) (x & (-x))

const LL inf  = 1e17+9;
const LL mod  = 1e9+7;
const LL maxn = 3e5+8;

LL n, m, a[maxn], bit[maxn];

void add(LL x, LL v) {
    while (x <= n) {
        bit[x] += v;
        x += lowbit(x);
    }
}

LL query(LL x) {
    LL ans = 0;
    while (x > 0) {
        ans += bit[x];
        x -= lowbit(x);
    }
    return ans;
}

void solve() {
    LL i, cnt = 0;
    scanf("%lld", &n);
    for (i = 1; i <= n; i++) {
        scanf("%lld", &a[i]); a[i]++;
        cnt += query(n) - query(a[i]);
        add(a[i], 1);
    }
    printf("%lld\n", cnt);
    for (i = 1; i < n; i++) {
        cnt += (n - a[i]) - (a[i] - 1);
        printf("%lld\n", cnt);
    }
}

signed main() {
    LL t;
    //scanf("%lld", &t);
    //while (t--)
    solve();
    return 0;
}


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

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

    for (int i = 0; i < n; i++)
    {
        if (x > 0 && s[i] == 'x')
            x--;
        else if (s[i] == 'o')
            x++;
    }

    cout << x << endl;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> t(N);
	vector<double> l(N), r(N);
	for (int i = 0; i < N; i++) scanf("%d %lf %lf", &t[i], &l[i], &r[i]);

	int Ans = 0;
	for (int i = 0; i < N - 1; i++) {
		double l1, r1;
		if (t[i] == 1) l1 = l[i], r1 = r[i];
		else if (t[i] == 2) l1 = l[i], r1 = r[i] - 0.1;
		else if (t[i] == 3) l1 = l[i] + 0.1, r1 = r[i];
		else l1 = l[i] + 0.1, r1 = r[i] - 0.1;

		for (int j = i + 1; j < N; j++) {
			double l2, r2;
			if (t[j] == 1) l2 = l[j], r2 = r[j];
			else if (t[j] == 2) l2 = l[j], r2 = r[j] - 0.1;
			else if (t[j] == 3) l2 = l[j] + 0.1, r2 = r[j];
			else l2 = l[j] + 0.1, r2 = r[j] - 0.1;

			if (r1 < l2 || r2 < l1) continue;
			Ans++;
		}
	}

	cout << Ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//using Bint = mp::cpp_int;

#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(12) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
inline void ose(string x){ os(x); oe(); }
inline void maxin(ll &a, ll b){ a=max(a,b); }
inline void minin(ll &a, ll b){ a=min(a,b); }

int main(){
    ll N=ii(), M=ii();
    if(N==M){
        oie(0);
        return 0;
    }
    if(M==0){
        oie(1);
        return 0;
    }
    vector<ll> A;
    REP(i,0,M){
        A.push_back(ii());
    }
    sort(A.begin(), A.end());
    ll cur=1;
    ll k=112345678901;
    vector<ll> B;
    for(ll a:A){
        if(a>cur){
            B.push_back(a-cur);
            minin(k,a-cur);
        }
        cur=a+1;
    }
    if(N>=cur){
        B.push_back(N-cur+1);
        minin(k,N-cur+1);
    }
    ll ret=0;
    for(ll b:B){
        ret+=b/k;
        if(b%k>0){ret++;}
    }
    oie(ret);

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 200000;
const int INF = 1e18;
int n, m;
int x, y;
int a[MAXN+1];
vector <int> path[MAXN+1];
int mmin[MAXN+1];
int ans = -INF;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    path[x].pb(y);
  }
  for (int i = 1; i <= n; i++)
    mmin[i] = INF;
  for (int i = 1; i <= n; i++) {
    if (mmin[i] != INF)
      ans = max(ans, a[i] - mmin[i]);
    mmin[i] = min(mmin[i], a[i]);
    for (int j : path[i])
      mmin[j] = min(mmin[j], mmin[i]);
  }
  cout << ans << "\n";
}

        #include <bits/stdc++.h>
        using namespace std;
        #include <math.h>
        #include <iomanip>
        #include <cstdint>
        #include <string>
        #include <sstream>
        template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
        template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
        #define rep(i,n) for (int i = 0; i < (n); ++i)
        typedef long long ll;
        using P=pair<int,int>;
        const int INF=1001001001;
        const int mod=1e9+7;

        int main(){
          int n,m;
          cin>>n>>m;
          vector<ll>a(n);
          rep(i,n){cin>>a[i];}
          vector<vector<int>>G(n);
          rep(i,m){
            int x,y;
            cin>>x>>y;
            x--;y--;
            G[x].push_back(y);
          }
          vector<ll>buy(n,1e18);
          ll ans=-1e18;
          rep(i,n){
            chmax(ans,a[i]-buy[i]);
            for(int u:G[i]){
              chmin(buy[u],min(buy[i],a[i]));
            }
          }
          cout<<ans<<endl;
          return 0;
        }