/*input
2021

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){

    if(b<=0) return 1;
    if(a<=0) return 0;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    cout<<((n+99)/100);
}

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

using namespace __gnu_pbds;
using namespace std;

#define ff                  first
#define ss                  second
#define pb                  push_back
#define eb                  emplace_back
#define mp                  make_pair
#define lb                  lower_bound
#define ub                  upper_bound
#define setbits(x)          __builtin_popcountll(x)
#define zrobits(x)          __builtin_ctzll(x)
#define sz(v)               (int)v.size()
#define ps(y)               cout << fixed << setprecision(y)
#define ms(arr, v)          memset(arr, v, sizeof(arr))
#define all(v)              v.begin(), v.end()
#define rall(v)             v.rbegin(), v.rend()
#define trav(x, v)          for(auto &x: v)
#define w(t)                int t; cin >> t; while(t--)
#define rep0(i, n)          for(int i = 0; i < n; i++)
#define rrep0(i, n)         for(int i = n - 1; i >= 0; i--)
#define rep1(i, n)          for(int i = 1; i <= n; i++)
#define rrep1(i, n)         for(int i = n; i > 0; i--)
#define inp(arr, n)         rep0(i, n) cin >> arr[i];
#define rep(i, a, b)        for(int i = a; i <= b; i++)
#define rrep(i, a, b)       for(int i = a; i >= b; i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef priority_queue<ll> pq_mx;
typedef priority_queue<ll, vi, greater<>> pq_mn;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*
 * find_by_order(i) -> returns an iterator to the element at ith position (0 based)
 * order_of_key(i)  -> returns the position of element i (0 based)
 */

const int N = 2e6 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll inf = 1e18;

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

void fio() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}

const int M = 1e7 + 5;
ll spf[M], mobius[M];
vi primes;

void sieve() {
    rep(x, 2, 1e7) {
        if (spf[x] == 0) spf[x] = x, primes.pb(x);
        for (int y = 0; y < sz(primes) and primes[y] <= spf[x] and x * primes[y] <= 1e7; y++)
            spf[x * primes[y]] = primes[y];
    }
}

void Mobius() {
    /*
     * mobius[x] =  1 => x is a square-free +ve int with even no. of prime factors
     * mobius[x] = -1 => x is a square-free +ve int with odd no. of prime factors
     * mobius[x] =  0 => x has a squared prime factor
     */

    rep1(x, 1e7) {
        if (x == 1) mobius[x] = 1;
        else {
            if (spf[x] == spf[x / spf[x]]) mobius[x] = 0;
            else mobius[x] = -mobius[x / spf[x]];
        }
    }
}

int main() {
    fio();
    sieve();
    Mobius();

    int l, r;
    cin >> l >> r;
  	if(l == 1) ++l;

    ll res = 0;
    rep(x, 2, r) {
        ll cur = r / x - (l - 1) / x;
        res -= cur * cur * mobius[x];
    }
//    cout << res << endl;
    rep(x, l, r) {
        --res;
        for (int y = 2 * x; y <= r; y += x) res -= 2;
    }
    cout << res;

    return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define int LL
using namespace std;
//const int N   = ;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,n) for (int i=1;i<=n;++i)
#define repp(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

int solve(int x)
{
	int tmp=0;
	for (int i=1;i<=x;++i)
	{
		int j=x/(x/i);
		tmp+=(j-i+1)*(x/i);
		i=j;
	}
	return tmp;
}
int ans,K;
int qsm(int a,int b,int mod)
{
	int tmp=1;
	while (b)
	{
		if (b&1) tmp=tmp*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return tmp;
}
int a,b,c,cnt[30];
char s[2000000+2];
signed main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int nxt=n+1;
	cnt[s[n]-'a']++;
	cnt[s[n-1]-'a']++;
	for (int i=n-2;i>=1;--i)
	{
		if (s[i]==s[i+1]&&s[i+1]!=s[i+2])
		{
			ans+=n-i-cnt[s[i]-'a'];
			memset(cnt,0,sizeof(cnt));
			cnt[s[i]-'a']=n-i;
		}
		cnt[s[i]-'a']++;
	}
	printf("%lld",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ostream &operator<<(ostream &os, const vector<lli> &x){
    os << "{";
    for(int i = 0; i < x.size(); i++){
        if(i < x.size()-1) os << x[i] << ", ";
        else os << x[i];
    }
    os << "}";
    return os;
}

int main(void){
    string s;
    cin >> s;
    lli n = s.size();
    lli ans = 0;
    char last = '!';
    vector<lli> count(26);
    for(int i = n-1; i >= 0; i--){
      char c = s[i];
      count[c-'a']++;
      if(last == c){
        lli tot = 0;
        for(int j = 0; j < 26; j++){
          char now = 'a'+j;
          lli val = count[now-'a'];
          count[now-'a'] = 0;
          if(now == c) continue;
          tot+=val;
        }
        ans += tot;
        count[c-'a'] = n-i;
        last = '!';
      }
      last = c;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
    int ret = 1;
    while(y) {
        if(y & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return ret;
}
template<int md> struct modint{
    int x;
    modint(int v = 0) {x = v; if(x >= md || x < 0) {x %= md; if(x < 0) x += md;}}
    operator int() const {return x;}
    friend modint operator +=(modint &a,const modint &b) {
        a.x += b.x;
        if(a.x >= md) a.x -= md;return a;
    }
    friend modint operator +(modint a,const modint &b) {
        return a += b;
    }
    friend modint operator -=(modint &a,const modint &b) {
        a.x -= b.x;a.x += md;
        if(a.x >= md) a.x -= md;return a;
    }
    friend modint operator -(modint a,const modint &b) {
        return a -= b;
    }
    friend modint operator *=(modint &a,const modint &b) {
        a.x = (ll)b.x * a.x % md;
        return a;
    }
    friend modint operator *(modint a,const modint &b) {
        return a *= b;
    }
    friend modint operator *(modint a,int b) {
        return a *= modint(b);
    }
    friend modint operator /=(modint &a,const modint &b) {
        a.x = (ll)b.x * qpow(a.x, md - 2) % md;
        return a;
    }
    friend modint operator /(modint a,const modint &b) {
        return a /= b;
    }
    friend modint operator /(modint a,int b) {
        return a /= modint(b);
    }
    friend modint operator ^(modint a,int b) {
        return qpow(a.x, b);
    }
};
int n,m,k,a[5005][5005],pre[5005][5005];modint<998244353> dp[5005][5005][3],pw[5005];
char s[5];
int main()
{
    pw[0] = 1;
    rep(i,1,5000) pw[i] = pw[i - 1] * 3;
    scanf("%d%d%d",&n,&m,&k);
    rep(i,1,k) {
        int x,y;
        scanf("%d%d%s",&x,&y,s);
        if(s[0] == 'X') a[x][y] = 1;
        if(s[0] == 'R') a[x][y] = 3;
        if(s[0] == 'D') a[x][y] = 2;
    }
    rep(i,1,n) {
        rep(j,1,m) pre[i][j] = pre[i][j-1] + (a[i][j] == 0);
    }
    dp[1][1][0] = dp[1][1][1] = dp[1][1][2] = 1;
    rep(i,1,n) rep(j,1,m) {
        int u = a[i][j] - 1;
        if(u == 0) dp[i][j][1] = dp[i][j][2] = 0;
        if(u == 1) dp[i][j][0] = dp[i][j][2] = 0;
        if(u == 2) dp[i][j][0] = dp[i][j][1] = 0;
        dp[i+1][j][0] += (dp[i][j][0] + dp[i][j][1]) * pw[pre[i][m] - pre[i][j] + pre[i + 1][j - 1]];
        dp[i+1][j][1] = dp[i+1][j][2] = dp[i+1][j][0];
        dp[i][j+1][0] += dp[i][j][0] + dp[i][j][2];
        dp[i][j+1][1] = dp[i][j+1][2] = dp[i][j+1][0];
        //printf("%d %d %d %d %d\n",i,j,dp[i][j][0],dp[i][j][1],dp[i][j][2]);
    }
    modint<998244353> ans = dp[n][m][0] + dp[n][m][1] + dp[n][m][2];
    printf("%d\n",ans.x);
    return 0;
}

#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

struct union_find {
	ll par[MAX_N];
	ll Size[MAX_N];
	union_find(ll n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			Size[i] = 1;
		}
	}
	ll root(ll x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	bool same(ll x, ll y) {
		return root(x) == root(y);
	}
	void unite(ll x, ll y) {
		if (same(x, y))return;
		Size[root(x)] += Size[root(y)];
		par[root(y)] = root(x);
	}
};

int main(){
    int n,q;
    cin>>n>>q;
    vector<int> c(n);
    vector<int> ans(0);
    vector<map<int,int> > mps(n);
    struct union_find U(n);

    for(int i=0;i<n;i++){
        cin>>c[i];
        c[i]--;
        mps[i][c[i]]=1;
    }

    while(q){
        q--;
        int type;
        cin>>type;
        if(type==1){
            int a,b;
            cin>>a>>b;
            a--; b--;
            if(U.same(a,b)) continue;
            if(U.Size[U.root(a)] > U.Size[U.root(b)]){
                for(auto p : mps[U.root(b)]){
                    mps[U.root(a)][p.first] += p.second;
                }
                U.unite(a,b);
            }else{
                for(auto p : mps[U.root(a)]){
                    mps[U.root(b)][p.first] += p.second;
                }
                U.unite(b,a);
            }
        }else{
            int x,y;
            cin>>x>>y;
            x--; y--;
            ans.push_back(mps[U.root(x)][y]);
        }
    }
    for(int a:ans) cout<<a<<endl;
}


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

/*
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define mod 1000000007
//#define maxx 200006
#define ll long long
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long >
#define listi vector< int>
#define pii   pair<int , int>
#define pll pair<long long , long long >
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define memo(a) memset( a, 0 ,sizeof ( a) )

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

ll power( ll a, ll n, ll m= 1000000007){
  ll ans = 1;
  while(n){
  if(n&1)
  {
  ans *= a;
  ans%=m;
  }
  a*=a;
  a%=m;
  n/=2;
  }
  return ans ;
}

vector< int > prm ;
vector < bool > vsp ;

void prime ( int nn = 100000 ) {
	vsp = vector < bool > ( nn+1, 0 );
	int size_prime = nn;
	for( ll i =2; i*i < size_prime ; i++){

		if( vsp[i] == 1)
		continue;
		for(ll j = i*i; j < size_prime ;j+=i){

			vsp[j] =1;

		}

	}

	for( int i= 2; i < size_prime ; i++)
	if (vsp[i] == 0)
	prm.pb(i);

}

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

// end of #define

// define globals ...
const int maxx = 2e5+26;

//write function from here ...
// never forget  to recheck your predefined function in template ..
// already defined ::  prime , power , gcd : ( ll )..

int Main(){

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

cout<<a*d - b*c <<endl;

return 0;

}

int main(){
 quick;
int t =1;
//cin>>t;
while(t-- )
 Main();

 return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int c,d;
  cin>>c>>d;
  cout<<a*d-b*c<<endl;
}


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

int main(){
  int N;
  cin >> N;
  int ans;
  if (N != 1) ans = N - 1;
  else ans = 0;

  cout << ans << endl;
}

#include <bits/stdc++.h>
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
#define ll long long
using namespace std;

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
// look for  all edge cases
//search for a pattern

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

	int n;
	cin >> n;
	if(n < 2){
		cout << 0;
		return 0;
	}

	set<pair<int,int>> s;
	for(int i=1; i<n; i++){
		int a = i;
		int b = n - i;
		s.insert({a,b});
	}
	cout << s.size();

	return 0;
}


// Hail god Yato

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

#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
pair<ll, ll> calc(ll b, ll c){
    if(c&1)
        return {-b-c/2, -b+c/2};
    else{
        if(c == 0)
            return {b, b};
        return {b-c/2, b+c/2-1};
    }
}
void solve(){
    ll b, c;
    cin>>b>>c;
    // b = abs(b);
    pair<ll, ll> fst = calc(b, c);
    pair<ll, ll> snd = calc(b, c-1);
    // cout<<fst.second<<" "<<fst.first;
    // cout<<snd.second<<" "<<snd.first<<" ";
    ll ans = fst.second - fst.first + 1 + snd.second - snd.first + 1;
    // if((fst.first <= snd.first && fst.second >= snd.first) || (fst.first >= snd.first && fst.second <= snd.second))
        ans -= max(0ll, min(snd.second, fst.second) - max(fst.first, snd.first) + 1);
    // else{
    //     swap(fst, snd);
    //     if((fst.first <= snd.first && fst.second >= snd.first) || (fst.first >= snd.first && fst.second <= snd.second))
    //         ans -= min(snd.second, fst.second) - max(fst.first, snd.first) + 1;
    // }

    cout<<ans;
}
signed main(){
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0;
}

#include <vector>
#include <iostream>

#define int         long long
#define double      long double
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

signed main() {
    tezz

    vector<int> primes;
    for (int i = 2; i < 72; i++) {
        bool flag = true;
        for (int j = 2; j < i; j++) {
            if (i % j == 0) flag = false;
        }
        if (flag) primes.emplace_back(i);
    }

    int A, B;
    cin >> A >> B;
    vector<int> v(B - A + 1);
    for (int i = A; i <= B; i++) {
        int mask = 0;
        for (int j = 0; j < primes.size(); j++) {
            if (i % primes[j] == 0) {
                mask |= (1 << j);
            }
        }
        v[i - A] = mask;
    }

    vector<int> dp(1<<primes.size());
    dp[0] = 1;
    for (int x: v) {
        for (int mask = 0; mask < (1 << primes.size()); mask++) {
            if (dp[mask]&&(mask & x)==0) {
                dp[mask ^ x] += dp[mask];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << primes.size()); i++) ans += dp[i];
    cout << ans;
}


 #include <bits/stdc++.h>
 #define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
 #define rep(i, n) repi(i, 0, n)
 #define SZ(x) ((int)(x).size())
 typedef long long ll;
 typedef unsigned long long ull;
 typedef unsigned int uint;
 using namespace std;
 using P = pair<int, int>;
 struct Vec{
         double x, y;
 };
 template<class T> inline bool chmin(T& a, T b) {
         if (a > b) {
             a = b;
             return true;
         }
         return false;
 }
 template<class T> inline bool chmax(T& a, T b) {
         if (a < b) {
             a = b;
             return true;
         }
          return false;
 }

 double norm(int x1, int x2, int y1, int y2){
     return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2- y1);
 }

 int main()
 {
         cin.tie(nullptr);
         ios_base::sync_with_stdio(false);
         // cout << fixed << setprecision(15);
         int n;
         cin >> n;
         vector<vector<int>> xy(n, vector<int>(2));
         rep(i,n) cin >> xy[i][0] >> xy[i][1];
         rep(i, n) repi(k, i+1, n) repi(l, k + 1, n){
             int dx1, dx2, dy1, dy2;
             dx1 = xy[i][0] - xy[k][0];
             dy1 = xy[i][1] - xy[k][1];
             dx2 = xy[l][0] - xy[k][0];
             dy2 = xy[l][1] - xy[k][1];
             if (dx2 * dy1 == dx1 * dy2) {
                 cout << "Yes" << endl;
                 return 0;
             }
         }
         cout << "No" << endl;
         return 0;
 }

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define disp(x) cout << #x << " : " << x << endl
#else
#define disp(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    int a, b, x, y; cin >> a >> b >> x >> y;

    if(a > b) {
        int d = a - b;
        cout << min((d - 1)*y + x, (2*d - 1)*x) << endl;
    } else if(a < b) {
        int d = b - a;
        cout << min(d*y + x, (2*d + 1)*x) << endl;
    } else {
        cout << x << endl;
    }

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
vector<vector<int>> solve(int n){
    if(n==1){
        vector<vector<int>> v;
        v.resize(1);
        v[0].push_back(0); v[0].push_back(1);
        return v;
    }
    vector<vector<int>> u = solve(n - 1);
    vector<vector<int>> v;
    int x = (1<<n) - 1;
    v.resize(x);
    int s = 0;
    for(int i=0;i<u.size();i++){
        for(int k=0;k<2;k++){
            for(int j=0;j<u[i].size();j++){
                v[s].push_back(u[i][j]);
            }
            for(int j=0;j<u[i].size();j++){
                v[s].push_back(u[i][j]^k);
            }
            s++;
        }
    }
    for(int i=0;i<(1<<n);i++){
        if(i<(1<<(n - 1))) v[s].push_back(0);
        else v[s].push_back(1);
    }
    return v;
}

int main(){
    int i,n; cin >> n;
    vector<vector<int>> v = solve(n);
    cout << (1<<n) - 1 << endl;
    for(i=0;i<(1<<n) - 1;i++){
        for(int j: v[i]){
            if(j==0) cout << "A";
            else cout << "B";
        }
        cout << endl;
    }
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
inline int BIT_popcount_L(const int x){
  return __builtin_popcount(x);
}
inline int BIT_popcount_L(const long long x){
  return __builtin_popcountll(x);
}
char res[300][300];
int ok;
int ng;
int main(){
  int N;
  rd(N);
  int p;
  int i;
  int j;
  int k;
  N = (1<<N);
  for(i=(0);i<(N-1);i++){
    for(j=(0);j<(N);j++){
      res[i][j] =BIT_popcount_L(j&(i+1))% 2;
    }
  }
  for(i=(0);i<(N-1);i++){
    for(j=(0);j<(N);j++){
      res[i][j] += 'A';
    }
  }
  wt_L(N-1);
  wt_L('\n');
  for(i=(0);i<(N-1);i++){
    wt_L(res[i]);
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210103-1 [bug fixed 1]

// --- original code ---
// char res[300][300];
// int ok, ng;
// {
//   int @N, p, i, j, k;
//   N = (1<<N);
//
//   rep(i,N-1){
//     rep(j,N) res[i][j] = BIT_popcount(j&(i+1)) % 2;
//   }
//   rep(i,N-1) rep(j,N) res[i][j] += 'A';
//
//   // rep(i,N) rep(j,i+1,N){
//   //   ok = ng = 0;
//   //   rep(k,N-1) if(res[k][i]==res[k][j]) ok++;
//   //   rep(k,N-1) if(res[k][i]!=res[k][j]) ng++;
//   //   wt(i,j,ok,ng);
//   // }
//
//   wt(N-1);
//   rep(i,N-1) wt(res[i]);
// }


#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
	cin.tie(NULL);
    long long n,m,k,l,j,p,i;
    cin>>n;
    for(i=1; powl(3,i)+5<=n; i++)
    {
        for(j=1; powl(5,j)+3<=n; j++)
        {
            k=powl(3,i);
            m=powl(5,j);
            p=m%10;
            //if(p==4)m++;
            if(k+m==n)
            {
                cout<<i<<" "<<j;
                return 0;
            }

        }
    }
    cout<<-1;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(long long i=k;i<=n;i++)
#define per(i,n,k) for(long long i=n;i>=k;i--)
#define pb push_back
#define fi first
#define se second
///#pragma GCC optimize(3,"Ofast","inline")
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<ll,ll> P;
ll gcd(ll a,ll b)
{
    ll r;
    while(b>0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
inline void write(ll x)
{
    if(x<0)
        putchar('-'),x=-x;
    if(x>9)
        write(x/10);
    putchar(x%10+'0');
}
inline ll read()
{
    ll x=0;
    char f=1,c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
            f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}

inline ll fp(ll a,ll b,ll mod)
{
    ll ans=1LL;
    while(b)
    {
        if(b&1LL)
            ans=ans*a%mod;
        a=a*a%mod;
        b>>=1LL;
    }
    return ans;
}
inline ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
ll a[1000005];
ll b[1000005];
int main()
{
    ll n=read();
    rep(i,1,n)a[i]=read();
    rep(i,1,n)b[i]=read();
    ll sum=0;
    rep(i,1,n)sum+=a[i]*b[i];
    if(sum==0)printf("Yes\n");
    else printf("No\n");
    return 0;
}


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);

	int ans = 1;
	int H, W;
	vector<string> S;
	vector<vector<int>> con;

	cin>>H>>W;

	S.resize(H);
	con.resize(H+W+1,vector<int>(3));

	for(int i = 0; i < H; i++){
		cin>>S[i];

		for(int j = 0; j < W; j++) {
			if(S[i][j] == 'R') {
				con[i+j][0]++;
			} else if(S[i][j] == 'B'){
				con[i+j][1]++;
			} else {
				con[i+j][2]++;
			}
		}
	}

	for(int i = 0; i+1 < H+W; i++){
		if(con[i][0] && con[i][1]) {
			ans = 0;
		} else if(con[i][0] || con[i][1]) {
			ans *= 1;
		} else {
			// cout<<i<<endl;
			ans *= 2;
		}
		ans %= MOD;
	}

	cout<<ans<<endl;

	return 0;
}

#include<stdio.h>
#include<iostream>
using namespace std;
const int maxH=505,mod=998244353;
int H,W,ans;
int val[maxH<<1];
string s;
int main(){
	scanf("%d%d",&H,&W);
	for(int i=1;i<=H;i++){
		cin>>s;
		for(int j=1;j<=W;j++)
			val[i+j]|=(s[j-1]=='R'? 1:(s[j-1]=='B'? 2:0));
	}
	ans=1;
	for(int i=2;i<=H+W;i++){
		if(val[i]==3){
			puts("0");
			return 0;
		}
		else ans=1ll*ans*(val[i]==0? 2ll:1ll)%mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll b, c;
    cin >> b >> c;
    ll b1l = b - c / 2;
    ll b1r = b + (c - 2) / 2;
    ll b2l = -b - (c - 1) / 2;
    ll b2r = -b + (c - 1) / 2;
    ll ans = b1r - b1l + 1 + b2r - b2l + 1;
    if (b1r < b2l) {
        // nop
    }
    else if (b2r < b1l) {
        // nop
    }
    else {
        ans = max(b1r, b2r) - min(b1l, b2l) + 1;
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <unordered_set>

using namespace std;

#define ll long long
#define ld long double
#define vecint vector<int>
#define vec2int vector<vector<int>>
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecdouble vector<double>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define vec2pairll vector<vector<pair<long long,long long>>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
#define forbit(s,a) for(int s = 0; s < (1 << a); s++)

#define sortLower(vec) sort(vec.begin(),vec.end())
#define sortGreater(vec,type) sort(vec.begin(),vec.end(),greater<type>())

const ll INF = 1000000000000;
const ld Pi = acos(-1.0);
const ll mod = 1000000007;
const ld EPS = 0.0000000001;

#define out_(s) cout << s << " "
#define out(s) cout << s << "\n"

class UnionFind
{
public:
	vecll par;

	UnionFind(ll n)
	{
		par.resize(n, -1);
	}

	ll root(ll pos)
	{
		if (par[pos] == -1) return pos;
		par[pos] = root(par[pos]);
		return par[pos];
	}

	void unite(ll u, ll v)
	{
		u = root(u); v = root(v);
		if (u == v) return;
		par[u] = v;
	}

	bool same(ll u, ll v)
	{
		if (root(u) == root(v)) return true;
		return false;
	}
};

ll gcd(ll a, ll b)
{
	if (min(a, b) == 0)
		return max(a, b);

	return gcd(min(a, b), max(a, b) % min(a, b));
}

ll lcm(ll a, ll b)
{
	ll buf = gcd(a, b);

	return abs(a * b) / buf;
}

string toBaseNum(ll n, ll base)
{
	string s;

	while (n > 0)
	{
		if (base > 10)
		{
			if (n % base >= 10)
			{
				string buf;
				buf.push_back(n % base - 10 + 'A');
				s = buf + s;
			}
			else
			{
				s = to_string(n % base) + s;
			}
		}
		else
		{
			s = to_string(n % base) + s;
		}
		n /= base;
	}

	if (s.empty())
		s = "0";

	return s;
}

ll toDecNum(string n, ll base)
{
	ll num = 0;

	forll(i, 0, n.size())
	{
		ll buf = 0;
		buf = n[i] >= 'A' ? n[i] - 'A' + 10 : n[i] - '0';
		num += pow(base, n.size() - i - 1) * buf;
	}

	return num;
}

vecpairll primeFactorize(ll n)
{
	vecpairll buf;

	forll(i, 2, sqrt(n + 1))
	{
		if (n % i != 0)
			continue;

		long long ex = 0;

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

		buf.push_back({ i, ex });
	}

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

	return buf;
}

bool isInField(pairll next, ll row, ll col)
{
	return (0 <= next.second && next.second < col) && (0 <= next.first && next.first < row);
}

//逆元((1÷b) mod p、bを掛けるとmod pで1となる数)を求める
ll modinv(ll a, ll m)
{
	ll b = m, u = 1, v = 0;

	while (b)
	{
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}

	u %= m;

	if (u < 0)
		u += m;

	return u;
}

ll Combination(ll n, ll r)
{
	ll num = 1;

	for (ll i = 1; i <= r; i++)
	{
		num = num * (n - i + 1) / i;
		num %= mod;
	}

	return num;
}

int main() {
	ll n, m, l, ans = 0;
	string s = "No";
	bool flag = false;

	cin >> n;

	vecll ans2 = {6,10,15};

	ll six = 12, ten = 20,fif=30;

	while (ans2.size() < n)
	{
		if (six <= ten && six <= fif)
		{
			ans2.push_back(six);
			six += 6;
		}
		else if(ten <= six && ten <= fif)
		{
			ans2.push_back(ten);
			ten += 10;
		}
		else
		{
			ans2.push_back(fif);
			fif += 15;
		}

		sortLower(ans2);

		if (ans2[ans2.size() - 1] == ans2[ans2.size() - 2])
			ans2.pop_back();
	}

	sortLower(ans2);

	forll(i,0,ans2.size())
		out_(ans2[i]);
}


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

ll x,y,a,b;

void solve()
{
	ll ans = 0;
	while(x<y && x<=(b/(a-1))){
        x*=a;
        ans++;
	}
	if(x>=y){
		cout<<ans-1<<'\n';
		return;
	}
	ans+=(y-x)/b;
	if((y-x)%b == 0) ans--;
	cout<<ans<<'\n';
}

int main()
{
	cin >> x >> y >> a >> b;
	solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

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

    ll x, y, a, b;
    cin >> x >> y >> a >> b;

    // a 倍 x -> ax dif = (a - 1) * x
    // y / x
    ll res = 0;
    while (1) {
        if (a > y / x + 10) break;
        if ((a - 1) * x <= b) x *= a;
        else break;
        if (x >= y) break;
        res++;
    }
    if (x < y) res += (y - x - 1) / b;
    cout << res << endl;
    return 0;
}


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

int main(){
    ll S , P ;
    cin >> S >> P;

    // M = S - Nを代入して N*(S-N) = Pをルートまで

    for(ll i = 0; i*i <= P; i++){
        if(i* (S-i) == P){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using ll = long long;
using lint = long long;
typedef vector<long long> vint;
typedef pair<long long, long long> pint;
#define MD 1000000007
#define INF INT32_MAX / 2
#define INF64 INT64_MAX / 2
#define EPS 0.001
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define c(n) cout<<n<<endl;
#define cf(n) cout<<fixed<<setprecision(15)<<n<<endl;
template <class T>inline bool chmin(T&a,T b) {if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T&a,T b) {if(a<b){a=b;return true;}return false;}
template<class T>inline T sum(T n){return n*(n+1)/2;}
map<ll,ll> prime_fac(ll A) {map<ll,ll>mp;for(ll i=2;i*i<=A;i++){while(A%i== 0){mp[i]++;A/=i;}}if(A!=1){mp[A]=1;}return mp;}
bool is_prime(ll N){if(N<=1)return false;for(ll i=2;i*i<=N;i++){if(N%i==0) return false;}return true;}
template<class T>inline T myceil(T a,T b){return (a+(b-1))/b;}
bool is_product_overflow(long long a,long long b) {long prod=a*b;return (prod/b!=a);}

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

void solve(long long S, long long P){
    auto map = prime_fac(P);
    vint vec;
    ll sum = 1;
    for (auto m : map) {
        REP (i, m.second) {
            vec.push_back(m.first);
            sum *= m.first;
        }
    }
    ll size = vec.size();
    for (int bit = 0; bit < (1 << size); bit++) {
        ll cur = 1;
        ll sm = sum;
        for (int i = 0; i < size; i++) {
            if (bit & (1 << i)) {
                cur *= vec[i];
                sm /= vec[i];
            }
        }
        if (cur + sm == S) {
            c(YES)
            return;
        }
    }
    c(NO)
}

int main(){
    long long S;
    scanf("%lld",&S);
    long long P;
    scanf("%lld",&P);
    solve(S, P);
    return 0;
}


#include<bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define ahen(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii = pair<int,int>;
const int N = 10000000000LL;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    char A[200200]; cin>>(A+1);
    int res = 0;
    bool yes = true;
    int cur = 0;
    int th = 1;
    for (int i=1; i<=n&&yes; i++) {
        if (!cur) {
            if (A[i]=='1') {
                cur=1;
            }
            else yes=false;
        }
        else if (cur==1) {
            if (A[i]=='1') {
                cur=2;
            }
            else yes=false;
        }
        else {
            if (A[i]=='0') {
                cur=0;
                if (i<n) th++;
            }
            else yes=false;
        }
    }
    if (yes) {
        res += N-th+1;
    }
    cur = 1;
    yes = true;
    for (int i=1; i<=n&&yes; i++) {
        if (!cur) {
            if (A[i]=='1') {
                cur=1;
            }
            else yes=false;
        }
        else if (cur==1) {
            if (A[i]=='1') {
                cur=2;
            }
            else yes=false;
        }
        else {
            if (A[i]=='0') {
                cur=0;
                if (i<n) th++;
            }
            else yes=false;
        }
    }
    if (yes) {
        res += N-th+1;
    }
    cur = 2;
    yes = true;
    for (int i=1; i<=n&&yes; i++) {
        if (!cur) {
            if (A[i]=='1') {
                cur=1;
            }
            else yes=false;
        }
        else if (cur==1) {
            if (A[i]=='1') {
                cur=2;
            }
            else yes=false;
        }
        else {
            if (A[i]=='0') {
                cur=0;
                if (i<n) th++;
            }
            else yes=false;
        }
    }
    if (yes) {
        res += N-th+1;
    }
    cout<<res<<'\n';
    return 0;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0() {}
template<typename H,typename... T> void print0(H h,T... t){cout<<fixed<<setprecision(15)<<h;print0(t...);}
void print() { print0("\n"); }
template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i <= 9999; i++) {
        string t = to_string(i);
        vector<bool> exist(10);
        for (auto c : t) {
            ll n = c - '0';
            exist[n] = true;
        }
        if (i < 1000) {
            exist[0] = true;
        }

        bool ok = true;
        for (ll d = 0; d <= 9; d++) {
            if (s[d] == 'o' && !exist[d]) ok = false;
            if (s[d] == 'x' && exist[d]) ok = false;
        }
        if (ok) {
            ans++;
        }
    }
    print(ans);
}


#include <bits/stdc++.h>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && !std::isdigit(ch)) ch = std::getchar();
	if (ch == '-') w = -1, ch = std::getchar();
	while (std::isdigit(ch)) data = data * 10 + (ch ^ 48), ch = std::getchar();
	return data * w;
}

const int N(3e5 + 10);
int n;
long long s[N], ans;
std::map<long long, int> c;

int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(), c[0] = 1;
	for (int i = 1, x; i <= n; i++)
		x = read(), (i & 1) ? s[i] = s[i - 1] - x : s[i] = s[i - 1] + x;
	for (int i = 1; i <= n; i++) ans += c[s[i]]++;
	printf("%lld\n", ans);
	return 0;
}

#include"bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define fir first
#define sec second
#define popcount __builtin_popcount
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")a
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll=long long int;
using ld=long double;
#define mp make_pair
#define mt make_tuple
#define bit(x,j) (((ll)x>>j)&1)
#define um unordered_map
#define mem(a,val) memset(a,val,sizeof(a))
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(ld 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...);}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#ifndef ONLINE_JUDGE
#define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debugt(...) 42
#endif
constexpr ll inf=2223372036854775807;
constexpr int mod1=(1e9+7);
constexpr int mod2=(998244353);
constexpr int MAX=(1e4+3);
constexpr int N=2e5+5;
void solve()
{
 int n; cin>>n; vector<int>a(n);
 for(int i=0;i<=n-1;i++) cin>>a[i];
 ll ans=0; vector<ll>ps(n,0);
 for(int i=0;i<=n-1;i++)
 {
  if(i) ps[i]=ps[i-1];
  if(i&1) ps[i]+=a[i]; else ps[i]-=a[i];
 }
 map<ll,int>g;
 for(int i=0;i<=n-1;i++)
 {
  if(!ps[i]) ans++;
  ans+=g[ps[i]]; g[ps[i]]++;
 }
 cout<<ans<<"\n";
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1; int c=1;
  while(t--)
  {
    solve(); c++;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<"\n";
}
int main()
{

    FastIO

    ll n,q,k; cin>>n>>q;
    ll a[n],c[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        if(i==0)c[i]=a[i]-1;
        else c[i]=c[i-1]+a[i]-a[i-1]-1;
    }

    while(q--)
    {
        cin>>k;
        int m,l=0,r=n-1;

        if(k>c[n-1])
        {
            cout<<a[n-1]+k-c[n-1]<<nl;
            continue;
        }

        while(l<r)
        {
            m=(l+r)/2;
            if(c[m]<k)l=m+1;
            else r=m;
        }

        if(l==0)cout<<k<<nl;
        else cout<<a[l-1]+k-c[l-1]<<nl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
const int INF=1<<28;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;
#define int3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define int4(x,y,z,w) int x,y,z,w;cin>>x>>y>>z>>w;
#define ll1(x) ll x;cin>>x;
#define ll2(x,y) ll x,y;cin>>x>>y;
#define vint1(a,n) vint a(n);rep(i,n)cin>>a[i];
#define vint2(a,b,n) vint a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
#define vll1(a,n) vll a(n);rep(i,n)cin>>a[i];
const double pi=acos(-1.0);
const ll infl=1LL<<60;

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;
x*x <=n;x++){if(n%x == 0)return false;}return true;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}
unsigned keta(unsigned num){
    return log10(num)+1;
}
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main(){
cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);

int2(n,q);
ll a[n];
rep(i,n)cin>>a[i];
ll k[q];
rep(i,q)cin>>k[i];
ll b[n];
rep(i,n)b[i]=a[i]-(i+1);
rep(i,q){
    auto iter=lower_bound(b,b+n,k[i])-b;

cout<<((iter==n)?a[n-1]+k[i]-b[n-1]:a[iter]-(b[iter]-k[i]+1))<<endl;

}

}


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

typedef vector<long long> VL;

int main()
{
  long long K, N, M, A, B, count;
  cin >> K >> N >> M;
  count = M;
  priority_queue <VL> pque;
  VL now;
  for (int i = 0; i < K; i++)
  {
    cin >> A;
    B = A*M;
    B /= N;
    count -= B;
    pque.push(VL{A*M-B*N,B,i});
  }
  vector<long long> ans(K);
  while(!pque.empty())
  {
    now = pque.top();
    pque.pop();
    if (count > 0)
    {
      now.at(1)++;
      count--;
    }
    ans.at(now.at(2)) = now.at(1);
  }
  for (auto x : ans)
    cout << x << " ";
  cout << endl;
}

#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

int main() {
    ll k, n, m;
    cin >> k >> n >> m;
    vector<ll> a(k);
    a.resize(k, 0);
    for(auto &x: a) cin >> x;

    ll l = -1, r = (ll)1e18+1;
    // cout << -7074 / 10006 << endl;
    while(r-l>1){
        ll mid = (l+r) / 2LL;
        // cout << mid << endl;
        ll lsum = 0LL, rsum = 0LL;
        bool ok = true;
        rep(i, k){
            ll tmpr = (mid + a[i]*m) / n, tmpl = a[i]*m - mid;
            rsum += tmpr;
            if((a[i]*m-mid)%n){
                if(tmpl < 0){
                    tmpl /= n;
                    tmpl--;
                }else{
                    tmpl /= n;
                }
                lsum += max(0LL, tmpl + 1LL);
            }else{
                if(tmpl < 0){
                    tmpl /= n;
                    tmpl--;
                }else{
                    tmpl /= n;
                }
                lsum += max(0LL, tmpl);
            }
            // cout << lsum << " " << rsum << endl;
        }

        if(!ok){
            l = mid;
        }

        if(lsum <= m && m <= rsum){
            r = mid;
        }else{
            l = mid;
        }
    }
    ll upper = r;
    // cout << upper << endl;
    vector<ll> llim(k, 0), rlim(k, 0);
    ll mrem = m;
    rep(i, k){
        rlim[i] = (upper + a[i]*m) / n;
        ll tmpl = a[i]*m - upper;
        if((a[i]*m-upper)%n){
            if(tmpl < 0){
                tmpl /= n;
                tmpl--;
            }else{
                tmpl /= n;
            }
            llim[i] = max(0LL, tmpl + 1LL);
        }else{
            if(tmpl < 0){
                tmpl /= n;
                tmpl--;
            }else{
                tmpl /= n;
            }
            llim[i] = max(0LL, tmpl);
        }
        // if((a[i]*m-upper)%n){
        //     llim[i] = max(0LL, (a[i]*m - upper) / n + 1LL);
        // }else{
        //     llim[i] = max(0LL, (a[i]*m - upper) / n);
        // }
        mrem -= llim[i];
    }

    rep(i, k){
        ll out = min(rlim[i], mrem+llim[i]);
        cout << out << " ";
        mrem -= out - llim[i];
    }
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  long double inx, iny, inr;
  cin >> inx >> iny >> inr;
  long double x = inx + 200005, y = iny + 200005, r = inr;
  long long ans = 0;
  for (long double p = ceil(x - r); p <= floor(x + r); p += 1) {
    long double d = x - p;
    long double h = sqrtl(r * r - d * d);
    long long top = floor(y + h);
    long long bottom = ceil(y - h);
    ans += top - bottom + 1;
  }
  cout << ans << endl;
}

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

int main(){
    string X,Y,R; cin >> X >> Y >> R;
    ll x,y,r; //cin >> x >> y >> r;
    auto f = [](string s) -> ll{
        int cnt = 4;
        ll res = 0;
        bool f = false;
        for(auto c : s){
            cnt -= f;
            if(c == '-') continue;
            if(c != '.') res = res * 10 + c - '0';
            else f = true;
        }
        rep(i,cnt) res *= 10;
        if(s[0] == '-') res = -res;
        return res;
    };
    x = f(X);
    y = f(Y);
    r = f(R);
    x += 2000000000LL;
    ll ans = 0;
    for(ll i=-2000000000; i<=2000000000; i+=10000){
        if(y-r > i || y+r < i) continue;
        ll d = abs(y-i);
        ll ok = 0, ng = r+1;
        while(ng-ok > 1){
            ll mid = (ok+ng) / 2;
            if(mid*mid <= r*r-d*d) ok = mid;
            else ng = mid;
        }
        //debug(x,ok);
        ll p = (x-ok+9999) / 10000;
        ll q = (x+ok) / 10000;
        //debug(i,p,q);
        ans += q-p+1;
    }
    cout << ans << "\n";
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;

int k;
int res[10], mul[6];
char s[10], t[10];

int cal(char *s){
    int num[10], val = 0;
    for(int i = 1; i <= 9; ++i)  num[i] = 0;
    for(int i = 1; i <= 5; ++i)  ++num[s[i] - '0'];
    for(int i = 1; i <= 9; ++i)  val += mul[num[i]] * i;
    return val;
}

int main(){
    scanf("%d%s%s", &k, s + 1, t + 1);
    mul[0] = 1;
    for(int i = 1; i <= 5; ++i)  mul[i] = mul[i - 1] * 10;
    for(int i = 1; i <= 9; ++i)  res[i] = k;
    for(int i = 1; i <= 5; ++i){
        --res[s[i] - '0'];
        --res[t[i] - '0'];
    }
    int ret = 9 * k - 8;
    double ans = 0;
    for(int i = 1; i <= 9; ++i)
        for(int j = 1; j <= 9; ++j){
            if((i == j && res[i] < 2) || res[i] < 1 || res[j] < 1)  continue;
            int zz = 0;
            if(i == j)  zz = 1;
            s[5] = '0' + i, t[5] = '0' + j;
            if(cal(s) > cal(t)){
                ans += 1.0 * res[i] / ret * (res[j] - zz) / (ret - 1);
            }
        }
    printf("%lf", ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int k;
    cin >> k;
    int a[10];
    for(int i=1;i<=9;i++) a[i] = k;
    string s,t;
    cin >> s >> t;
    int b[10]={},c[10]={};
    for(auto i:s){
        if(i!='#'){
            a[i-'0']--;
            b[i-'0']++;
        }
    }
    for(auto i:t){
        if(i!='#'){
            a[i-'0']--;
            c[i-'0']++;
        }
    }
    double ans = 0;
    for(int s=1;s<=9;s++){
        if(a[s]==0) continue;
        b[s]++;
        double d1 = double(a[s])/double(9*k-8);
        a[s]--;
        for(int j=1;j<=9;j++){
            long pt=0,pa=0;
            if(a[j]==0) continue;
            c[j]++;
            double d2 = double(a[j])/double(9*k-9);
            a[j]--;
            rep(i,10) pt += i*pow(10,b[i]);
            rep(i,10) pa += i*pow(10,c[i]);
            if(pt>pa) ans += d1*d2;
            c[j]--;
            a[j]++;
        }
        a[s]++;
        b[s]--;
    }
    cout <<fixed << setprecision(10) << ans << endl;
}


//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
#define fi first
#define se second
#define PI 3.14159265
#define mod  11092019
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
///order_of_key find_by_order
const ll INFLL = 1e18;
const ll INF =1e9;
const ll EPS =1e-9;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll lcm(ll a,ll b){ return (a*b)/gcd(a,b);}
ll ncr(ll n,ll r){ ll ans=1;for(ll i=1;i<=r;i++) ans=(ans*(n-i+1))/i;return ans;}
ll cost[2005][2005],vis[2005],n,m;
vector<ll> v[2005];
ll dijsktra(int s)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
    vector<int> dis(n+1,INF);
    pq.push({0,s}); // distance from source node,node number
    dis[s]=0;
    ll ans=INT_MAX;
    while(!pq.empty())
    {
        int num=pq.top().se;
        int num_d=pq.top().fi;
        pq.pop();
        if(num_d!=dis[num]) continue;
        for(int i=0;i<v[num].size();i++)
        {
            if(num_d+cost[num][v[num][i]]<dis[v[num][i]])
            {
                dis[v[num][i]]=num_d+cost[num][v[num][i]];
                pq.push({dis[v[num][i]],v[num][i]});
            }
            if(v[num][i]==s) ans=min(ans,num_d+cost[num][v[num][i]]);
        }
    }
    if(ans==INT_MAX) return -1;
    else return ans;
}
int main()
{

    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        ll x,y,w;
        cin>>x>>y>>w;
        if(cost[x][y]==0)
        cost[x][y]=w;
        else
        cost[x][y]=min(w,cost[x][y]);
        v[x].push_back(y);
    }
    for(int j=1;j<=n;j++)
    {
        cout<<dijsktra(j)<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}

const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
template<class T>
class Heap{
    vector<T> v;
    int _size;
    function<bool(T,T)> f;
    int par(int x){return (x-1)>>1;}
    int lch(int x){return (x<<1)+1;}
    int rch(int x){return (x<<1)+2;}
    void downheapify(int i){
        while(1){
        int lchid=lch(i),rchid=rch(i);
        int smallest=i;
        if(lchid<_size&&f(v[lchid],v[smallest]))smallest=lchid;
        if(rchid<_size&&f(v[rchid],v[smallest]))smallest=rchid;
        if(smallest!=i){
            T temp=v[smallest];
            v[smallest]=v[i];
            v[i]=temp;
            i=smallest;
        }
        else break;
        }
    }
    void upheapify(int i){
        T x =v[i];
        while(1){
        if(i==0)break;
        int parid=par(i);
        if(f(x,v[parid])){v[i]=v[parid];}
        else break;
        i=parid;
        }
        v[i]=x;
    }
    public:
    Heap(function<bool(T,T)> _f):v(vector<T>()),_size(0),f(_f){}
    bool empty(){return _size==0;}
    T top(){return v[0];}
    T pop(){
        T res=v[0];
        --_size;
        v[0]=v[_size];
        v.pop_back();
        downheapify(0);
        return res;
    }
    void push(T x){
        v.push_back(x);
        upheapify(_size);
        ++_size;
    }
    vector<T>& get_heap(){return v;}

};

void Main();
int main(){cout<<fixed<<setprecision(15);Main();}

void Main(){
  int N,M;
  cin>>N>>M;
  vector<vector<pair<int,int>>> G(N);
  rep(i,M){
      int A,B,C;
      cin>>A>>B>>C;
      A--;B--;
      G[A].push_back({B,C});

  }
  int ans[N];
  rep(i,N){
      Heap<pair<int,int>> heap([](pair<int,int> p1,pair<int,int> p2){return p1.second<p2.second;});
    ans[i]=INF;
    int dist[N];
    rep(j,N)dist[j]=INF;
    dist[i]=0;
    heap.push({i,0});
    while(!heap.empty()){
        auto p=heap.pop();
        int v=p.first;
        int now=p.second;
        for(auto edge:G[v]){
            int nv=edge.first;
            int len=edge.second;
            int next=now+len;
            if(nv==i){
                chmin(ans[i],next);
            }
            if(next<dist[nv]){
                dist[nv]=next;
                heap.push({nv,next});
            }
        }
    }
  }
  rep(i,N){
      if(ans[i]==INF)cout<<-1<<endl;
      else cout<<ans[i]<<endl;
  }
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)

ll INF = 1ll << 60;

ll t[8][8];

int main(){
  int n, k;
  cin >> n >> k;
  rep(i, 0, n){
    rep(j, 0, n){
      cin >> t[i][j];
    }
  }

  vi index(0);
  rep(i, 0, n)
    index.push_back(i);

  ll cnt = 0;

  do{
    ll sum  = 0;
    rep(i, 0, n){
      sum += t[index[i]][index[(i+1)%n]];
    }
    if(sum == k)
      cnt++;
  }while(next_permutation(index.begin()+1, index.end()));

  cout << cnt << endl;

  return 0;

}

#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<climits>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m); //青色のマスの場所(初期値1)
    rep(i,m) cin >> a[i]; //青色のマスへの入力
    if(m==0){
        cout << 1 << endl; //全て白マスの場合
    }else{
        sort(a.begin(), a.end()); //昇順にソート
        int val = INT_MAX;

        /*白マスの最小値を求める*/
        if(a[0]-1 > 0) val = min(val, a[0]-1); //左端と青色のマスとの間の白マスの数を求める
        rep(i,m-1){
            //青色のマスと青色のマスとの間の白マスの数を求める
            if(a[i+1]-a[i]-1 > 0) val = min(val, a[i+1]-a[i]-1);
        }
        if(n-a[m-1] > 0) val = min(val, n-a[m-1]); //青色のマスと右端との間の白マスの数を求める
        /*塗りつぶす回数を求める*/
        if(val == INT_MAX) cout << 0 << endl; //全てのマスが青色のマスの場合の塗りつぶす回数
        else{
            int sum;
            if((a[0]-1)%val==0) sum=(a[0]-1)/val;
            else sum=(a[0]-1)/val+1;
            rep(i,m-1){
                if((a[i+1]-a[i]-1)%val==0) sum+=(a[i+1]-a[i]-1)/val;
                else sum+=(a[i+1]-a[i]-1)/val+1;
            }
            if((n-a[m-1])%val==0) sum+=(n-a[m-1])/val;
            else sum+=(n-a[m-1])/val+1;
            cout << sum << endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long l;
  cin >> l;
  long long result = 1;
  int a;
  for (int i = 1; i < 12; i++)
  {
    a = l - i;
    result *= a;
    result /= i;
  }
  cout << result << endl;
  return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>//fill
#include<iomanip>
#include<functional>//https://cpprefjp.github.io/reference/functional/function.html
#include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html
#include<queue>
#include<deque>
#include<cassert>
#include<stack>
#include <iterator>     // std::back_inserter
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
const double PI = acos(-1);
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n)for(ll i=0;i<(n);i++)
#define repp(x,arr) for(auto& x:arr)
#define repp2(x,y,arr) for(auto& [x,y]:arr)
#define all(a) (a.begin()),(a.end())
const ll MOD = 1e9 + 7;
const ll inf = 1e18+6;

// デフォルトは整数部も含めた桁数指定
//cout <<setprecision();
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
int main() {
	ios::sync_with_stdio(false);
	double N;
	cin >> N;
	if ((int)(N * 1.08) < 206)cout << "Yay!";
	else if ((int)(N * 1.08) == 206)cout << "so-so";
	else cout << ":( ";
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

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

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

signed main() {
  int ans = -1;

  int N, X;
  cin >> N >> X;

  X *= 100;

  int now = 0;
  REP(i, N){
    int v, p;
    cin >> v >> p;
    now += v*p;
    if(now > X){
      cout << i+1 << "\n";
      return 0;
    }
  }

  cout << ans << "\n";

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

// string->num
//   stoll(str)
// num->string
//   to_string(i)

int main() {
  ll H, W;
  cin >> H >> W;
  vector<vector<ll>> A(H, vector<ll>(W - 1));
  vector<vector<ll>> B(H - 1, vector<ll>(W));
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W - 1; j++) {
      cin >> A[i][j];
    }
  }
  for (ll i = 0; i < H - 1; i++) {
    for (ll j = 0; j < W; j++) {
      cin >> B[i][j];
    }
  }
  const ll INF = 1e10;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<>> q;
  vector<ll> dist(H * W, INF);

  auto push = [&](ll i, ll j, ll cost) {
    ll node = i * W + j;
    if (dist[node] > cost) {
      dist[node] = cost;
      q.emplace(cost, node);
    }
  };
  push(0, 0, 0);
  while (!q.empty()) {
    auto [cost, node] = q.top();
    q.pop();
    if (dist[node] != cost) continue;
    ll i = node / W;
    ll j = node % W;
    if (j + 1 < W) push(i, j + 1, cost + A[i][j]);
    if (j - 1 >= 0) push(i, j - 1, cost + A[i][j - 1]);
    if (i + 1 < H) push(i + 1, j, cost + B[i][j]);
    for (ll k = 0; k < i; k++) {
      push(k, j, cost + (i - k) + 1);
    }
  }
  cout << dist.back() << endl;
  return 0;
}


#include <cstdio>

int main(){
	int a[4];
	for(int i=0; i < 4;i++){
		scanf("%d", &a[i]);
	}
	int min_a = a[0];
	for(int i = 1; i < 4; i++)
		if(a[i] < min_a)
			min_a = a[i];
	printf("%d\n", min_a);
}

#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  string s;
  cin >> s;

  cout << s[1] << s[2] << s[0] << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <complex>

using namespace std;

using C = complex<double>;
C rotate(C center, C vec, double rad) {
    C r = {cos(rad), sin(rad)};
    return center + (vec-center) * r;
}

int main() {
    int N; cin >> N;
    double x, y;
    cin >> x >> y;
    C s = {x, y};
    cin >> x >> y;
    C t = {x, y};
    C center = (s+t)/2.0;
    double pi = acos(-1);
    double rad = 2*pi/N;
    auto res = rotate(center, s, rad);
    printf("%.10f %.10f\n", res.real(), res.imag());
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define reve(i,n) for(int i=n-1;i>=0;i--)
#define vec(a,n) vector<long long> a(n,0);
#define ALL(a)  (a).begin(),(a).end()
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef int long long ll;
using namespace std;
typedef pair<ll,ll> P;

typedef priority_queue<ll> PQ;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dx8[8]={1,0,-1,0,1,1,-1,-1};
int dy8[8]={0,1,0,-1,1,-1,1,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);

template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
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; }

// vector<int> a(51,0);
// vector<vector<int> > tate(a,vector<int>(b)) ;

ll spp(ll cnt,ll dis , ll r){

    if (dis%r == 0 && dis >= r ){
        cnt = dis/r;
        return cnt;
    }
    else if(2*r >= dis ){
        cnt += 2;
        return cnt;
    }
    else{
        cnt = spp(cnt+1,dis-r,r);
    }
    return cnt;
}

int main(){
    ll r,x,y; cin >> r >> x >> y;
    double dis = sqrt(x*x+y*y);

    ll cnt = 0;

    // else if(dis < r){
    //     cnt = 2;
    // }
    // else{
    //     cnt = spp(cnt,dis,r);
    // }

    cnt = ceil(double(dis/r));
    if(dis < r) cnt = 2;
    if(x == 0 && y == 0){
        cnt = 0;
    }

    cout << cnt << endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>

using namespace std;

int main() {
  long long int R;
  long long int X;
  long long int Y;
  cin >> R >> X >> Y;
  double Z;
  Z = sqrt(X*X + Y*Y);
  if(Z==R){
    cout << 1 << endl;
  }
  else if(Z<2*R){
    cout << 2 << endl;
  }
  else{
    cout << ceil(Z/R) << endl;
  }
}


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

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

int main(){
    FAST;
    LL i,j,b,ans=0,N,M,K,a;
    cin>>N>>M;
    VL A(M),B(M);
    rep(i,M){
        cin>>A[i]>>B[i];
        --A[i],--B[i];
    }
    cin>>K;
    VL C(K),D(K);
    rep(i,K){
        cin>>C[i]>>D[i];
        --C[i],--D[i];
    }
    rep(b,1<<K){
        a=0;
        VL v(N);
        rep(i,K){
            if((1<<i)&b)++v[C[i]];
            else ++v[D[i]];
        }
        rep(i,M)if(v[A[i]]&&v[B[i]])++a;
        chmax(ans,a);
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define pb emplace_back
#define MP make_pair
using namespace std;
using ll = long long;
using ii = pair<int,int>;

const int maxn = 1000 + 5;
const int maxk = 16 + 5;

int G[maxn][maxn] = {};
int a[maxk][2];
int seq[maxk];
map<int,int> mp;
int ans = 0;

void dfs(int N, int ith){
    if(ith == N){
        int tmp = 0;
        vector<int> v;
        for(auto p : mp){
            if(p.second != 0) v.pb(p.first);
        }

        for(int i = 0; i < SZ(v); i++){
            for(int j = i+1; j < SZ(v); j++){
                if(G[v[i]][v[j]]){
//                    printf("[%d][%d], += %d\n", v[i], v[j], G[v[i]][v[j]]);
                    tmp += G[v[i]][v[j]];
                }
            }
        }
//        printf("%d\n", tmp);
        ans = max(ans, tmp);
        return;
    }
    for(int i = 0; i < 2; i++){
        mp[a[ith][i]]++;
        dfs(N, ith+1);
        mp[a[ith][i]]--;
    }
}

void solve(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        G[a][b]++;
        G[b][a]++;
    }
    int K;
    cin >> K;
    for(int i = 0; i < K; i++){
        cin >> a[i][0] >> a[i][1];
    }

    dfs(K, 0);
    cout << ans << '\n';
}

int main(){
    solve();
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= 1000000; ++i){
        sum += i;
        if(sum >= n){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()

template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
    os << '{';
    string sep;
    for (const T &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
void dbg_out()
{
    cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353

void solve()
{
	ll n;
	cin >> n;
	ll l = 1, r = 1e6, ans = 0;
	while(l<=r){
		ll m = l+(r-l)/2;
		if (m*(m+1)/2>=n){
			ans = m;
			r = m-1;
		}else l = m+1;
	}
	cout << ans << "\n";
}

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


/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=4*1e5+100;
int n,a[N];
char s[N];
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline int cal(int n,int m)
{
	if (m>n) return 0;
	int ans=1;
	for (int i=1;i<=m;i++) ans=ans*(n-i+1)/i;
	return ans;
}
int C(int n,int m)
{
	if (n<3&&m<3) return cal(n,m);
	return C(n/3,m/3)*cal(n%3,m%3)%3;
}
signed main()
{
	n=read();
	scanf("%s",s+1);
	for (int i=1;i<=n;i++)
	{
		if (s[i]=='B') a[i]=0;
		if (s[i]=='R') a[i]=1;
		if (s[i]=='W') a[i]=2;
	}
	int ans=0;
	for (int i=1;i<=n;i++) ans=(ans+a[i]*C(n-1,i-1)%3)%3;
	if (n%2==0) ans=3-ans;
	ans%=3;
	if (ans==0) printf("B\n");
	if (ans==1) printf("R\n");
	if (ans==2) printf("W\n");
}

#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
  int n,i;
  ll res=0,x=0,y=1,t;//(n-1)ci=3^x*(3*z+y)
  string s,tm="BWR";
  cin >> n >> s;
  for(i=0;i<n;i++){
    if(x==0){
      if(s[i]=='W')
        res+=y;
      else if(s[i]=='R')
        res+=y*2;
    }
    res%=3;
    if(i==n-1)
      break;
    t=n-1-i;
    while(t%3==0){
      t/=3;
      x++;
    }
    y=(y*t)%3;
    t=i+1;
    while(t%3==0){
      t/=3;
      x--;
    }
    y=(y*t)%3;
  }
  if(n%2==0)
    res=(3-res)%3;
  cout << tm[res] << endl;
  return 0;
}


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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 1e5+10;
double dp[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i = 1; i<n; i++){
		dp[i] = (double)((n-i)*(1+dp[i-1])+i)/(n-i);
	}
	cout << fixed << setprecision(10) << dp[n-1] << "\n";
}

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

double check(double d, vector<double>& A) {
  double val=0;
  for(auto& e:A) val+=(d+e-min(e,2*d))/A.size();
  return val;
}

int main() {
  ll N; cin>>N;
  vector<double> A(N);
  for(auto& e:A) cin>>e;
  // 三分探索かなあ
  double low=0, high=1e10;
  ll cnt=1000;
  while(cnt--) {
    double d1=(low*2+high)/3;
    double d2=(low+high*2)/3;
    if(check(d1,A)>check(d2,A)) low=d1;
    else high=d2;
  }
  cout<<fixed<<setprecision(20)<<check(low,A)<<endl;
}


#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()

typedef std::vector<int> VI;
typedef long long ll;
typedef std::pair<int, int> ii;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

template <typename T> void read(std::vector<T>& A) { for (T& x: A) std::cin >> x; }
template <typename T> void readv(std::vector<T>& A) { int N; std::cin >> N; A.resize(N); read(A); }

using namespace std;

int solve(const string& S) {
    if (S[0] != S.back())
        return 1;
    for (int i = 1; i + 1 < S.length(); i++) {
        if (S[i] != S[0] && S[i+1] != S[0])
            return 2;
    }
    return -1;
}

int main(int argc, const char* argv[]) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); cout.setf(ios::fixed);
    int N;
    string S;
    cin >> N >> S;
    cout << solve(S) << endl;
    return 0;
}

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

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

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

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

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

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

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

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

signed main() {
  init();
  ll N;
  string S;
  cin >> N >> S;
  if (S[0] != S[N - 1]) {
    COUT(1);
    return 0;
  }

  bool ok = false;
  char c = S[0];
  rep2(i, 1, N - 1) {
    if (S[i] != c and S[i + 1] != c) ok = true;
  }

  if (ok) {
    COUT(2);
  } else {
    COUT(-1);
  }

  return 0;
}


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

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

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

int main() {
    int n, m;
    cin >> n >> m;
    V<V<P>> ps(n+1);
    rep(i,m) {
        int x, y, z;
        cin >> x >> y >> z;
        ps[x].emplace_back(y,z);
    }

    V<lint> dp(1<<n);
    dp[0] = 1;
    rep(s,1<<n) {
        int x = __builtin_popcount(s);
        for(P p: ps[x]) {
            int s2 = s&((1<<p.fi)-1);
            int cnt = __builtin_popcount(s2);
            if(cnt > p.se) dp[s] = 0;
        }
        rep(i,n) {
            if(~s>>i&1) dp[s|1<<i] += dp[s];
        }
    }
    cout << dp[(1<<n)-1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<int> X;
vector<vector<pair<int,int>>> B;
ll fact[20];
ll memo[18][1<<18];
bool visited[18][1<<18];
ll f(int p, int q) {
	if (p == (int)X.size()-1) return fact[N-X.back()];
	if (visited[p][q]) return memo[p][q];
	visited[p][q] = true;
	int mask = ((1<<N)-1)^q;
	int c = X[p+1]-X[p];
	ll res = 0;
	for (int m = mask; m > 0; m = (m-1)&mask) if (__builtin_popcount(m) == c) {
		for (auto [y, z] : B[p]) {
			if (__builtin_popcount((q|m)&((1<<y)-1)) > z) goto next;
		}
		res += f(p+1, q|m);
		next:;
	}
	return memo[p][q] = res * fact[c];
}
int main() {
	fact[0] = 1;
	for (int i = 1; i < 20; ++ i) fact[i] = fact[i-1] * i;
	int M;
	cin >> N >> M;
	map<int, vector<pair<int,int>>> A;
	for (int i = 0; i < M; ++ i) {
		int x, y, z;
		cin >> x >> y >> z;
		A[x].push_back({y,z});
	}
	X.push_back(0);
	for (auto& x : A) {
		X.push_back(x.first);
		B.push_back(x.second);
	}
	cout << f(0, 0) << endl;
}


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

const int N = 1e5+7;
bitset<N> pos;
long long a[N];
long long upto[N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, q;
    cin>>n>>q;

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

    while (q--) {
        long long z;
        cin>>z;

        int id = lower_bound(upto, upto+n+1, z) - upto - 1;
        assert(upto[id] <= z);
        cout<<a[id] + z - upto[id]<<endl;
    }
}

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

int gcd(int a, int b)
{
   int t =min(a,b);
    a=max(a,b);
    b =t;
    while(a%b!=0)
    {
       int temp =b;
        b=a%b;
        a=temp;
    }
    return b;
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    vector<long long >a(n);

    for(int i =0; i<n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    unordered_map<long long int,long long int>mp;
    // unordered_map<long long int,long long int>dc;
    for(int i =0; i<q;i++)
    {
        long long k;
        cin>>k;

        if(mp.find(k)!=mp.end())
        {
            cout<<mp[k]<<'\n';
        }
        else
        {
            int id =int(upper_bound(a.begin(),a.end(),k)-a.begin());
            if(id ==0)
            {
                mp[k]=k;

                cout<<k<<"\n";
            }else
            {
                if(id ==n)
                {
                    mp[k]=k+id;

                    cout<<k+id<<'\n';
                }
                else
                {
                    while(id<n&&(k+id) >=a[id])
                    {
                        id++;
                        // mp[k+id] =k;
                    }
                    mp[k]=k+id;
                    cout<<k+id<<'\n';;
                }
            }
        }

    }

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 50001
#define MOD 1000000007

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

ll mult(ll a, ll b, ll m) {
    ll x = a;
    ll s = 0;
    while (b != 0) {
        if (b % 2 == 1) s = (s + x) % m;
        b /= 2;
        x = (x + x) % m;
    }
    return s;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y, ll mod)
{

    if (a == 0)
    {
        *x = 0;
        *y = 1;
        return b;
    }

    ll x1, y1; // To store results of recursive call
    ll gcd = gcdExtended(b%a, a, &x1, &y1, mod);

    // Update x and y using results of
    // recursive call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll minT(ll t1 ,ll m1, ll t2, ll m2) {
    if(t1 == t2) return t1;
    if (t1 > t2) {
        swap(t1,t2);
        swap(m1,m2);
    }
    ll k1, k2;
    ll g = gcd(m1,m2);
    ll t = t2 - t1;
    if (t % g != 0) return LLONG_MAX;
    ll g2 = m2 / g;
    gcdExtended(m1, m2, &k1, &k2, g2);
    //k1 = (((k1 % g2) + g2) % g2);
    k1 *= t / g;
    k2 *= t / g;
    ll lcm = m1 * g2;
    ll v1 = ((mult(k1,m1, lcm) + t1) % lcm + lcm) % lcm;
    //if (k1 < 0 || k2 < 0) return LLONG_MAX;
    if (v1 % m1 != t1) {
        while(1) {}
    }
    return v1;
}

ll x, y, p, q;

void solve() {
    cin >> x >> y >> p >> q;
    ll m1 = (x + y) * 2;
    ll m2 = p + q;
    ll b = LLONG_MAX;
    rep(i, y) rep(j, q) {
        ll t1 = x + i;
        ll t2 = p + j;
        ll bb = minT(t1, m1, t2, m2);
        if (bb == LLONG_MAX) continue;
        //if(bb % m1 == t1 && bb % m2 == t2) {
            chmin(b, bb);
        //}
    }
    if (b == LLONG_MAX) {
        out("infinity");
    }
    out(b);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int test = 1;
    // #ifdef _OLIMPOLOCAL
         cin >> test;
    // #endif
    rep(testCase, test) {
        #ifdef _OLIMPOLOCAL
            cout << "------------------ TESTCASE: " << testCase << " -------------\n";
        #endif
        solve();
    }
    return 0;
}

//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    Forn(i,n) for(int i=1;i<=n;i++)
#define    Fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    sum(v) accumulate(all(v),0)
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    Max(a)  *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define    Min(a)  *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    mod    1e9+7 //1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    YES    printf("YES\n")
#define    NO     printf("NO\n")
#define    Erase(s) s.erase(unique(s.begin(),s.end()),s.end())
//%%%%%%%%%%%%%p%%%a%%%r%%%v%%%e%%%z%%%%%%%%%%%%%//

int main()
{
MP;
    //int T;cin >> T;while (T--)
    {
        int n, m, sm = 0, sm1 = 0;
        cin >> n >> m;
        if (n <= m) {
            for (int i = 1; i <= m; i++) {
                cout << -i << " ";
                sm += i;
            }
            for (int i = 1; i < n; i++) {
                cout << i << " ";
                sm1 += i;
            }
            cout << sm - sm1;
        }
        else {
            for (int i = 1; i <= n; i++) {
                cout << i << " ";
                sm += i;
            }
            for (int i = 1; i < m; i++) {
                cout << -i << " ";
                sm1 += i;
            }
            cout << sm1 - sm;
        }
    }
    cerr<<endl<<(float)clock()/(float)CLOCKS_PER_SEC<<" sec"<<endl;
End;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9+7;

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

int64_t modInverse(int64_t a) {
  int64_t x, y;
  gcdExtended(a, MOD, &x, &y);
  return (x % MOD + MOD) % MOD;
}

int addmod(int x, int y) {
  int result = x+y;
  if (result >= MOD) {
    result -= MOD;
  }
  return result;
}

int multmod(int x, int y) {
  return (x * int64_t(y)) % MOD;
}

int addmodto(int& x, int y) {
  x += y;
  if (x >= MOD) {
    x -= MOD;
  }
  return x;
}

int solve_slow(int N, int M, int K) {
  vector<vector<int>> dp(N+M+1, vector<int>(N+1, 0));
  dp[0][0] = 1;
  for (int i = 1; i <= N+M; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j <= (i-j+K)) {
	dp[i][j] = dp[i-1][j];
	if (j > 0) {
	  addmodto(dp[i][j], dp[i-1][j-1]);
	}
      }
    }
  }
  return dp[N+M][N];
}

const int MAXVAL = 2e6;
int factorial[MAXVAL+1];

int choose(int n, int k) {
  if (n < k) {
    return 0;
  }
  return multmod(factorial[n], modInverse(multmod(factorial[n-k], factorial[k])));
}

int solve(int N, int M, int K) {
  if (N > (M+K)) {
    return 0;
  }
  return addmod(choose(N+M, N), MOD - choose(M+N, M+K+1));
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  factorial[0] = 1;
  for (int i = 1; i <= MAXVAL; ++i) {
    factorial[i] = multmod(factorial[i-1], i);
  }
  int N, M, K;
  cin >> N >> M >> K;
  cout << solve(N, M, K) << endl;
}

// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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 alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

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

//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示

const ll MAX = 3000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}

int main(){
    COMinit();
    ll n, m, k; cin >> n >> m >> k;
    if(n > m + k){
        cout << 0 << endl;
        return 0;
    }
    ll mid = 0;
    cout << (COM(n+m, n) + MOD - COM(n+m, m+k+1)) % MOD << endl;
}