#include <bits/stdc++.h>
#include <iomanip>
#define M 100005
#define MAX 100000000000000001
#define MIN -10000000000000000
#define mod 1000000007
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ld fact(ld n){
	ld ans = 1;
	for(ld i = 2;i<=n;i++){
		ans *= i;
	}

	return ans;
}

int main(){
	ld coins[3],ans = 0,total =0;
	for(int i=0;i<3;i++){
		cin>>coins[i];
		total += coins[i];
	}
	for(ld n=1;n<=300;n++){
		for(int i=0;i<3;i++){
			ld tot = total;
			int other1=1,other2=2;
			if(i == 1){
				other1 = 0;
			}
			if(i == 2){
				other2 = 0;
			}
			if(100-coins[i]<= n && 200-(total-coins[i]) > n-(100-coins[i])){
				ld probability = 1,rest = n-(100-coins[i]),p2 = 0;
				for(ld j=coins[i];j<=99;j++){
					probability *= j;
					probability /= tot;
					tot += 1;
				}
				for(ld j=0;j<=rest;j++){
					if(j+coins[other1] < 100 && rest-j+coins[other2] < 100){
						ld p3 = 1,tot2 = tot;
						for(ld k=0;k<j;k++){
							p3 *= (coins[other1]+k);
							p3 /= tot2;
							tot2 += 1;
						}
						for(ld k=0;k<rest-j;k++){
							p3 *= (coins[other2]+k);
							p3 /= tot2;
							tot2 += 1;
						}
						p2 += (p3/fact(j))/fact(rest-j);
					}
				}
				probability *= p2;
				ans += n*probability*fact(n-1)/fact(100-coins[i]-1);
				// cout<<n<<" "<<ans<<"\n";
			}
		}
	}
	cout<<fixed;
	cout<<setprecision(15)<<ans<<"\n";

	return 0;
}

// Problem: D - increment of coins
// Contest: AtCoder - AtCoder Beginner Contest 184
// URL: https://atcoder.jp/contests/abc184/tasks/abc184_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vdb vector<double>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii >
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define bloop(i,a,b) for(int i = a;i>=b;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define CHECK1(a) cout<<a<<endl
#define CHECK2(a,b) cout<<a<<' '<<b<<endl;
#define br '\n'
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
// int extendedgcd(int a,int b,int &x,int &y){
	// if(a == 0){
		// x = 0; y = 1;
		// return b;
	// }
	// int x1,y1;
	// int d = extendedgcd(b%a,a,x1,y1);
	// x = y1 - (b/a)*x1;y = x1;
	// return d;
// }
// int expmod(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = expmod(a,b/2)%mod;
// 	if(b%2) return ((m1*m1)%mod*a%mod)%mod;
// 	return (m1*m1)%mod;
// }
// int power(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = power(a,b/2);
// 	if(b%2) return m1*m1*a;
// 	return m1*m1;
// }
// int logn(int n, int r)
// {
//     return (n > r - 1) ? 1 + logn(n / r, r) : 0;
// }

// int nCr(int n,int r)
// {
	// r = min(r,n-r);
	// if(r<0)
		// return 0;
	// if(r == 0)
		// return 1;
	// int ans = 1;
	// for(int i = 1;i<=r;i++)
	// {
		// ans = ans*(n-i+1)/i;
	// }
	// return ans;
//
// }
// vi factmod(int n)
// {
	// vi ans(n+1);
	// ans[0] = 1;
	// loop(i,1,n+1)
	// {
		// ans[i] = (ans[i-1]*i)%mod;
	// }
	// return ans;
// }
// int nCrmod(int n,int r,vi &fact)
// {
	// int x1,y1;
	// extendedgcd(fact[r],mod,x1,y1);
	// int x2,y2;
	// extendedgcd(fact[n-r],mod,x2,y2);
	// int ans = (fact[n]*((x1+mod)%mod))%mod;
	// ans = (ans*((x2+mod)%mod))%mod;
	// return ans;
// }

// void dfs(vector<vector<int> > &adj,int root,vbool &vis)
// {
// 	vis[root] = true;
// 	for(int i = 0;i<adj[root].size();i++){
// 		int v = adj[root][i];
// 		if(!vis[v])
// 			dfs(adj,v,vis);
// 	}
// }
double dp[101][101][101];
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	mem(dp,0);
	dp[a][b][c] = 1;
	for(int i = 0;i<100;i++)
	{
		for(int j = 0;j<100;j++)
		{
			for(int k = 0;k<100;k++)
			{
				double p = 0;
				if(i<a || j<b || k<c)
				{
					dp[i][j][k] = 0;
				}
				else if(i == a && j == b && k == c)
					p = 1;
				else
				{
					if(i>0)
						p += dp[i-1][j][k]*((double)(i-1)/(double)(i+j+k-1));
					if(j>0)
						p += dp[i][j-1][k]*((double)(j-1)/(double)(i+j+k-1));
					if(k>0)
						p += dp[i][j][k-1]*((double)(k-1)/(double)(i+j+k-1));
				}
				dp[i][j][k] = p;
			}
		}
	}
	double ans = 0;
	for(int i = 0;i<=99;i++)
	{
		for(int j = 0;j<=99;j++)
		{
			dp[i][j][100] = dp[i][j][99]*(99.0/(i+j+99));
			dp[i][100][j] = dp[i][99][j]*(99.0/(i+j+99));
			dp[100][i][j] = dp[99][i][j]*(99.0/(i+j+99));
			ans+= (dp[i][j][100]*((i-a)+(j-b)+(100-c)))	;
			ans+= (dp[i][100][j]*((i-a)+(j-c)+(100-b)))	;
			ans+= (dp[100][i][j]*((100-a)+(i-b)+(j-c)))	;
		}
	}
	cout<<ans<<'\n';

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

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

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll n;
		cin>>n;
		cout<<n-1;
	}
 	return 0;
}

#include<iostream>
#include<string>
#include<iomanip>
#include<set>
#include<queue>
#include<cmath>
#include<algorithm>
#include<vector>
#include<limits.h>
#include<math.h>
#include<map>
#include<cstring>
using ll = long long;

int main(){
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	int n;
	std::cin >> n;
	std::cout << n-1 << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll n;cin>>n;
    dd x[n];rep(i,0,n-1)cin>>x[i];
    dd res=0;
    rep(i,0,n-1){
        res+=fabs(x[i]);
    }
    cout<<setprecision(20)<<res<<endl;
    res=0;
    rep(i,0,n-1){
        res+=pow(x[i],2);
    }
    cout<<setprecision(20)<<pow(res,0.5)<<endl;
    res=0;
    rep(i,0,n-1){
        res=max(res,fabs(x[i]));
    }
    cout<<setprecision(20)<<res<<endl;
    return 0;
}

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

class union_find{
private:
  vector<ll> par;
  vector<ll> siz;

public:
  union_find(ll n) : par(n),siz(n,1LL){
    for (ll i=0;i<n;i++) par[i]=i;
  }

  ll root(ll x){
    ll i=x;
    queue<ll> line;
    while(i!=par[i]){
      line.push(i);
      i=par[i];
    }
    ll l=line.size();
    for (ll j=0;j<l;j++){
      par[line.front()]=i;
      line.pop();
    }
    return i;
  }

  ll size(ll x){
    return siz[root(x)];
  }

  bool unite(ll x,ll y){
    x=root(x);
    y=root(y);
    if (x==y) return false;
    if (size(x)<size(y)){
      par[x]=y;
      siz[y]+=siz[x];
    }
    else{
      par[y]=x;
      siz[x]+=siz[y];
    }
    return true;
  }

  bool same(ll x,ll y){
    if (root(x)==root(y)) return true;
    else return false;
  }
};

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

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

template <typename T>
void outl(T x){
  cout << x << endl;
}
template < >
void outl<int>(int x){
  printf("%d\n",x);
}
template < >
void outl<double>(double x){
  printf("%.16lf\n",x);
}
template < >
void outl<char>(char x){
  printf("%c\n",x);
}
template < >
void outl<string>(string x){
  printf("%s\n",x.c_str());
}
template < >
void outl<uint>(uint x){
  printf("%u\n",x);
}
template < >
void outl<ll>(ll x){
  printf("%lld\n",x);
}
template < >
void outl<ull>(ull x){
  printf("%llu\n",x);
}
void outl(){
  printf("\n");
}

template <typename T>
void out(T x){
  cout << x << flush;
}
template < >
void out<int>(int x){
  printf("%d",x);
}
template < >
void out<char>(char x){
  printf("%c",x);
}
template < >
void out<double>(double x){
  printf("%.16lf",x);
}
template < >
void out<string>(string x){
  printf("%s",x.c_str());
}
template < >
void out<uint>(uint x){
  printf("%u",x);
}
template < >
void out<ll>(ll x){
  printf("%lld",x);
}
template < >
void out<ull>(ull x){
  printf("%llu",x);
}

void outyes(){
  printf("Yes\n");
}
void outno(){
  printf("No\n");
}

void outyn(bool x){
  if (x) printf("Yes\n");
  else printf("No\n");
}

void outsp(){
  printf(" ");
}

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

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

template <typename T>
T npr(T x,T y){
  T loop=max(x-y,y),ans=1;
  for (T i=loop;i<=x;i++){
    ans*=i;
  }
  return ans;
}//xPy

template <typename T>
T ncr(T x,T y){
  T loop=min(x,x-y),ans=npr(x,y);
  for (T i=1;i<=loop;i++){
    ans/=i;
  }
  return ans;
}//xCy

template <typename T>
T fac(T x){
    if (x==1) return 1;
    return x*fac(x-1);
}

void div1(ll &x) {
    x%=1000000007;
}

ll mypow(ll x,ll n){
    ll ans=1;
    for (ll i=1;i<=n;i = i<<1){
        if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定
            ans*=x;
        }
        x*=x;
    }
    return ans;
}

ll divpow(ll x,ll n){
    ll ans=1;
    div1(x);
    for (ll i=1;i<=n;i = i<<1){
        if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定
            ans*=x;
            div1(ans);
        }
        x*=x;
        div1(x);
    }
    return ans;
}

int main(){
  int a=in,b=in,c=in,d=in;
  if (c*d-b<=0) outl(-1);
  else {
      outl((int)ceil((double)a/(c*d-b)));
  }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define type(x) ((siz[x] & 1) ? 2 : (f[x] <= (siz[x] - f[x]) ? 1 : 3))
const int maxn = 1e5 + 50;
int n,x,last[maxn],siz[maxn],f[maxn],p[maxn];
struct Edge{
	int v,nxt;
}e[maxn];
int read(){
	int x = 0;
	char c = getchar();
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar();
	return x;
}
inline void insert(int u,int v){
	static int cnt = 0;
	e[++cnt] = {v,last[u]},last[u] = cnt;
}
bool cmp(int u,int v){
	static int t1,t2;
	t1 = type(u),t2 = type(v);
	if(t1 != t2) return t1 < t2;
	else return siz[u] - 2 * f[u] > siz[v] - 2 * f[v];
}
void dfs(int u){
	siz[u] = 1,f[u] = 1;
	for(int i = last[u]; i; i = e[i].nxt){
		int v = e[i].v;
		dfs(v);
		siz[u] += siz[v];
	}
	int cnt = 0;
	for(int i = last[u]; i; i = e[i].nxt) p[++cnt] = e[i].v;
	sort(p + 1,p + cnt + 1,cmp);
	int cur = 1;
	while(cur <= cnt && type(p[cur]) == 1) f[u] += f[p[cur]],cur ++;
	int t = 0;
	while(cur <= cnt && type(p[cur]) == 2){
		if(!t) f[u] += f[p[cur]];
		else f[u] += siz[p[cur]] - f[p[cur]];
		t ^= 1,cur ++;
	}
	while(cur <= cnt){
		if(!t) f[u] += f[p[cur]];
		else f[u] += siz[p[cur]] - f[p[cur]];
		cur ++;
	}
	// cout << u << ' ' << f[u] << ' ' << type(u) << endl;
}
int main(){
	n = read();
	for(int i = 2; i <= n; i ++){
		x = read();
		insert(x,i);
	}
	dfs(1);
	printf("%d\n",f[1]);
	return 0;
}

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

typedef long long ll;
#define pb push_back

const int MOD = 998244353, N = 2e5 + 5;
int two[N];
int add(int x, int y)
{
    x += y;
    while (x >= MOD)
        x -= MOD;
    while (x < 0)
        x += MOD;
    return x;
}

int mul(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int solve()
{
    int n, res = 0, pre = 0;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr.begin(), arr.end());
    for (int i = 0; i < n; i++)
    {
        // self min max
        res = add(res, mul(arr[i], arr[i]));
        res = add(res, mul(pre, arr[i]));
        pre = mul(pre, 2);
        pre = add(pre, arr[i]);
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    two[0] = 1;
    for (int i = 1; i < N; i++)
        two[i] = mul(two[i - 1], 2);
    cout << solve() << "\n";
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<vector<ll>> c(n, vector<ll>(n));
    vector<ll> a(n), b(n);
    ll a_min = 0, b_min = 0;
    rep(i,n)rep(j,n) cin >> c[i][j];

    rep(i,n-1){
        ll d=c[i+1][0]-c[i][0];
        for(int j=1; j<n; j++){
            if(d != c[i+1][j]-c[i][j]){
                cout << "No" << endl;
                return 0;
            }
        }
        a[i+1]=a[i]+d;
        a_min = min(a_min, a[i+1]);
    }
    rep(j,n-1){
        ll d=c[0][j+1]-c[0][j];
        for(int i=1; i<n; i++){
            if(d != c[i][j+1]-c[i][j]){
                cout << "No" << endl;
                return 0;
            }
        }
        b[j+1]=b[j]+d;
        b_min = min(b_min, b[j+1]);
    }

    cout << "Yes" << endl;
    rep(i,n) cout << a[i] - a_min << " ";
    cout << endl;
    rep(i,n) cout << b[i] - b_min + (c[0][0]-(-a_min-b_min)) << " ";
    cout << endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using ll = int64_t;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
  o << "(" << v.first << "," << v.second << ")";
  return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
  for (auto e : v) {
    o << e << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1

// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b, c; cin >> a >> b >> c;
  b -= c;
  cout << (a > b ? "Takahashi" : "Aoki");
}
#endif


#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <string.h>

#define rep(i,n)    for(ll i=0;i<n;i++)
#define repu(i,k,n) for(ll i=k;i<=n;i++)
#define repd(i,k,n) for(ll i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define endl "\n"
#define INF (ll)ll_MAX

typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> pii;
typedef std::vector<ll> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, ll > > vpp;

const ll N = 3*1e5 +5 ;
const long long MOD = 1000000007;
const long long MOD2 = 998244353;
const long long inf = 1e18;

using namespace std;

set<int>m ;
bool iseq(){
	if(m.size() == 1){
		return true ;
	}
	return false ;
}
void solve()
{
	int n ;
	cin>>n ;
	int a[n] ;
	rep(i , n)cin>>a[i] ;
	rep(i , n){
		m.insert(a[i]) ;
	}
	while(!iseq()){
		int st = *m.begin() ;
		int en  = *m.rbegin() ;
		m.erase(m.find(en)) ;
		m.insert(en - st) ;
	}
	int ans  =  *m.begin() ;
	cout<<ans<<endl;
}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    //cout<<"helo";
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll t = 1;
    //cin>>t;

    while(t--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

}

#include <bits/stdc++.h>
#ifdef LILY
#include "Debug.h"
#else
#define var(...) (0)
#define dbg(...) (0)
#endif
using int32 = int;
using int64 = long long;
using namespace std;

class Solution
{
#define int int64
#define sfor(i, n) for (int i = 1; i <= (n); ++i)
#define tfor(i, n) for (int i = 0; i < (n); ++i)
#define INF 0x3f3f3f3f
#define EPS 1e-5
#define M 1000000007

    int n;
    int p;

    int pow(int base, int ex)
    {
        int ret = 1;
        while (ex)
        {
            if (ex & 1) ret = ret * base % M;
            ex >>= 1;
            base = base * base % M;
        }
        return ret;
    }

    void reals()
    {
    }

public:
    Solution()
    {
        cin >> n >> p;
        int t = pow(p - 2, n - 1);
        cout << t * (p - 1) % M << endl;
    }
#undef int
#undef tfor
#undef sfor
};

int32 main()
{
#ifdef LILY
    while (1)
#endif
        Solution();
    return 0;
}


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

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(ll x=in;x<n;x+=r)
#define ifr(x,n) for(ll x=0;x<n;x++)
#define dfr(x,n) for(ll x=n-1;x>=0;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef unordered_map<ll, ll> umap;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 200005

vector<pll> v[N]; ll a[N];
bool vis[N];

void dfs(ll u) {
	vis[u] = 1;
	ifr(i, v[u].size()) {
		if (!vis[v[u][i].ff]) {
			a[v[u][i].ff] = a[u] ^ v[u][i].ss;
			dfs(v[u][i].ff);
		}
	}
}

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

	while (t--) {
		ll n, x, y, w;
		cin >> n;
		ifr(i, n - 1) {
			cin >> x >> y >> w;
			v[x].pb(pll(y, w));
			v[y].pb(pll(x, w));
		}
		a[1] = 0;
		dfs(1);
		ll ans = 0;
		ifr(i, 60) {
			ll cnt = 0, c = 0, r = 1ll << i;
			fr(j, 1, n + 1, 1) {
				if (r & (a[j]))cnt++;
				else c++;
			}
			ans = (ans + ((r) % mod * (cnt * c) % mod) % mod ) % mod;
		}
		cout << ans << endl;
	}

	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int n; cin >> n;
  ll x; cin >> x;
  vl a(n);
  rep(i,n) cin >> a[i];

  map<ll,ll> dp1;
  dp1[-x] = 1;
  for (int i = n-1; i >= 0; --i) {
    map<ll,ll> dp2;
    for(auto val: dp1) {
      auto [d, num] = val;
      if(abs(d) % a[i] != 0) {
	ll x1 = abs(d) / a[i];
	ll x2 = x1 + 1;
	ll c = - abs(d) / d;
	if(i != n - 1) {
	  if(x1 < a[i+1] / a[i]) dp2[d + c * x1 * a[i]] += num;
	  if(x2 < a[i+1] / a[i]) dp2[d + c * x2 * a[i]] += num;
	}
	else {
	  dp2[d + c * x1 * a[i]] += num;
	  dp2[d + c * x2 * a[i]] += num;
	}
      }
      else {
	dp2[0] += num;
      }
    }
    swap(dp1, dp2);
  }
  cout << dp1[0] << "\n";

  return 0;
}


#include <iostream>
#include <stdint.h>
using namespace std;

int main()
{
	long long minn = 1e18+1;
	long long n;
	cin>>n;
	for(uint64_t b = 0;(uint64_t)(1ULL<<b) <= n;b++)
	{
		// cout<<b<<" ";
		uint64_t second = (1ULL<<b);
		long long a = n / second;
		long long c = n % (a*second);
		if(a+b+c<minn) minn = a + b + c;
	}
	cout<<minn<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
    cout << head << ' ';
    OUTX2(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

int main()
{
    ll N;
    INX(N);

    vll cnt(200, 0);
    vll A(N);
    for (ll i = 0; i < N; i++)
    {
        INX(A[i]);
        A[i] %= 200;
        cnt[A[i]]++;
    }

    ll result = 0;
    for (ll i = 0; i < 200; i++)
    {
        if(cnt[i] <= 1) continue;
        result += cnt[i] * (cnt[i] - 1) / 2;
    }
    OUTX(result);

    return 0;
}


/**

▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
 In the name of Allah

       _           _
      / /         \ \
     / / _   _   _ \ \
    < < (_) (_) (_) > >
     \ \           / /
      \_\         /_/

  Nerede Gitsen Çukur Orda

**/

#include<bits/stdc++.h>
#include<fstream>
///#include<conio.h>
///#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define Qodirov_Kamoliddin ios_base::sync_with_stdio(0) ; cin.tie(NULL) ; cout.tie(NULL) ;
#define p_b pop_back
#define p_f pop_front
#define quluq return 0;
#define NO cout << "NO" << endl ;
#define no cout << "no" << endl ;
#define YES cout << "YES" << endl ;
#define yes cout << "yes" << endl ;

using namespace std ;

    const ll N = 1e19 + 0 ;

string g ;

void vkoshp()
{
    cin >> g ;
    for (ll i = 0 ; i < g.size() ; i += 2)
    {
        if (g[i] >= 'A' and g[i] <= 'Z')
        {
            cout << "No" << endl ;
            return ;
        }
    }
    for (ll i = 1 ; i < g.size() ; i += 2)
    {
        if (g[i] >= 'a' and g[i] <= 'z')
        {
            cout << "No" << endl ;
            return ;
        }
    }
    cout << "Yes" << endl ;
}

int main ()
{
    //freopen("input.txt", "r", stdin );
    //freopen("output.txt", "w", stdout );
    Qodirov_Kamoliddin
    ///Author of the Greatest code : Murtazoev Alijon
    ///4294967295
    ll Qu_l_uQ = 1 ;
    // cin >> Qu_l_uQ ;
    while ( Qu_l_uQ -- )
        vkoshp() ;
}
///MaaN studios
///Eco students

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int n = s.length();
	string ans = "Yes";
	for(int i=0; i<n; i++){
		if(i%2==0 && s[i]>=(char)'A' && s[i]<=(char)'Z'){
			ans = "No";
			break;
		}
		if(i%2==1 && s[i]>=(char)'a' && s[i]<=(char)'z'){
			ans = "No";
			break;
		}
	}
	cout<<ans;

}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define f(i,a,b) for(ll  i = a; i < (ll) b ; i++ )
#define af(i,a,b) for(ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll  i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll) a.size()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller   ios::sync_with_stdio(false);cin.tie(0)

// policy-based

using namespace std;

typedef long long ll; // ll or ll
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

const ll MAX = 3e5 + 20;
const ll mod = 1e9 + 7;
const ll inf = 2e9;

int main(){
	fastio;
	ll ans = inf,n,a,p,x;
	cin >> n;
	f(i,0,n){
		cin >> a >> p >> x;
		if(x > a) ans = min(ans,p);
	}
	if(ans == inf) ans = -1;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

//型短縮
#define ll long long

//マクロ定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, M, T;
  cin >> N >> M >> T;
  int originN = N;
  int A = 0, B = 0;
  bool flag = true;
  rep(i, M) {
    int newA;
    int newB;
    cin >> newA >> newB;

    N -= int((newA - B) + 0.5);
    if (N <= 0) {
      flag = false;
      break;
    }

    N += int((newB - newA) + 0.5);
    if (N > originN) N = originN;

    A = newA;
    B = newB;
  }

  N -= int((T - B) + 0.5);
  if (N <= 0) flag = false;

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=65,INF=1<<30;
ll comb[MAX][MAX];

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    comb[0][0]=1;
    for(int i=0;i<60;i++){
        for(int j=0;j<=i;j++){
            comb[i+1][j]+=comb[i][j];
            comb[i+1][j+1]+=comb[i][j];
        }
    }

    int A,B;cin>>A>>B;
    ll K;cin>>K;

    string ans;
    while(A||B){
        if(A){
            ll p=comb[A-1+B][B];
            if(p>=K){
                ans+='a';
                A--;
                continue;
            }

            K-=p;
        }
        ans+='b';
        B--;
    }

    cout<<ans<<endl;
}

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

// template {{{  0
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll A,B,K;
    Scll3(A,B,K);

    ll comb[61][61] = {};
    comb[0][0] = 1;

    Rep(i,60) Rep(j,60) {
        comb[i+1][j] += comb[i][j];
        comb[i+1][j+1] += comb[i][j];
    }

    deque<int> ans;
    Rep(ni,B) {
        ll tmp = 0;
        int ti = 0;
        Rep(ai,A+1) {
            int r = B - ni;
            int n = ai + r - 1;
            if (comb[n][r] >= K) {
                break;
            } else {
                tmp = comb[n][r];
                ti = ai;
            }
        }
        K -= tmp;
        ans.push_back(A-ti);
    }

    Rep(i,A+1) {
        while ( !ans.empty() && ans.front() == i ) {
            printf("b");
            ans.pop_front();
        }
        printf ("%c", i!=A?'a':'\n');
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <time.h>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vd vector<double>
#define vvd vector<vd>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdi pair<double, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
constexpr int n = 20;
int m;
vector<string> s;
vector<deque<string>> ss(n + 1);
vvi board(n, vi(n));
void tekitou_sort(){
	rep(i, n){
		int nokori = n;
		while(true){
			bool found = false;
			for(int j = nokori; j >= 0; j--) if(!ss[j].empty()){
				found = true;
				rep(k, j) board[i][n-nokori+k] = ss[j][0][k] - 'A';
				nokori -= j;
				ss[j].pop_front();
				break;
			}
			if(!found) break;
		}
	}
}
void inputs(){
	cin >> m >> m;
	s.resize(m);
	rep(i, m) cin >> s[i];
}
int main(){
	srand(time(NULL));
	inputs();
	rep(i, m) ss[s[i].size()].push_back(s[i]);

	rep(i, n) rep(j, n) board[i][j] = rand() % 8;
	tekitou_sort();

	rep(i, n){
		rep(j, s[i].size()) board[i][j] = s[i][j] - 'A';
	}
	rep(i, n){
		rep(j, n) printf("%c", board[i][j] + 'A');
		printf("\n");
	}
}

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

#define FasterIO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define ll long long
#define ff first
#define ss second
#define pi pair<int, int>

const int MX=1e3+10;
const ll mod=1e9+7;

int d[MX][MX], vis[MX][MX], ad[MX][MX];
vector<int>g[MX][26];

void bfs(int n)
{
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++) d[i][j]=1e9;
    }

    queue<pi>q; q.push({1, n}), d[1][n]=0, vis[1][n]++;

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

        vis[x][y]--;

        for(int i=0; i<26; i++)
        {
            for(auto u:g[x][i])
            {
                for(auto v:g[y][i])
                {
                    if(d[u][v]>d[x][y]+1)
                    {
                        d[u][v]=d[x][y]+1;
                        if(vis[u][v]==0) q.push({u, v}), vis[u][v]++;
                    }
                }
            }
        }
    }
}

int main()
{
    FasterIO;

//    int tc; cin>>tc;
//    while(tc--)
    {
        int n, m; cin>>n>>m;
        for(int i=1; i<=m; i++)
        {
            int x, y; char c; cin>>x>>y>>c; ad[x][y]=ad[y][x]=1;
            g[x][c-'a'].push_back(y), g[y][c-'a'].push_back(x);
        }

        bfs(n);

        int mx=1e9;
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                if(i==j) mx=min(mx, 2*d[i][j]);
                else
                {
                    if(ad[i][j]) mx=min(mx, 2*d[i][j]+1);
                }
            }
        }

        if(mx<1e9) cout<<mx<<endl;
        else       cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  ll A, B;
  cin >> A >> B;
  ll N = 2 * A + 100 - B;
  if(N < 0) {
    N = 0;
  }
  cout << N;
}

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

int main()
{
    int A,B;
    cin>>A>>B;

    int follow = 2 * A + 100;

    cout<<follow - B<<endl;
    return 0;
}


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

//ordered_set
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
//define it as oset<int> s; or oset<pair<int,int>> s;

//bunch of pragmas
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,tune=native")

//#pragma Gcc target("avx2,fma,avx")
//(Uncomment when needed and be sure it not give TLE bcoz it requires time)
//#pragma GCC optimize "trapv"//to check integer overflow and gives RE.

//macros
#define ull unsigned long long int
#define ll long long
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define vl vector<ll>
#define mii map<int,int>
#define uii unordered_map<int,int>
#define all(x) x.begin(),x.end()
#define ff first
#define fr(i,a,b) for(int i= a ;i<=b ;i++)
#define ss second
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define INF 1e18
#define lcm(a,b) a*b/__gcd(a,b)
#define print(x) cout<<x<<"\n";
#define scanv(v,n) for(int i  = 0 ; i<n ;i++ ) cin>>v[i];
#define printv(v) for(auto it : v) cout<<it<<" ";
#define rall(v) v.rbegin(),v.rend()
#define GOOGLE(i) cout<<"Case"<<" #"<<i<<": ";
#define Time cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();

//boost for big int
//#include<boost/multiprecision/cpp_int.hpp>
//uncoment for large int requirement
//using boost::multiprecision::cpp_int;

//forced_functions
void file_io(){
fast_io
    #ifndef ONLINE_JUDGE
    freopen("inputa.txt","r",stdin);
    freopen("outputa.txt","w",stdout);
    freopen("log.txt","w",stderr);
    #endif
}

//safe_hash
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};
//use it with unordered_map<T,T,custom_hash> safe_map

//const
const long long int MOD = 1e9+7;
const long long int MOD2 = (119<<23)+1;//(119<<23)+1==998244353
//random
ll stoii(string s){
    ll ans = 0;
    for(auto it: s){
        ll cur = it-'0';
        ans = ans*10+cur;
    }
    return ans;
}

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

bool test = false;
bool file = true;
void solve(){
    ll n;
    cin>>n;
    cout<<n-1<<endl;

}
int main(){
    if(file)
      file_io();
    int t ;
    t = 1 ;
    if(test)
    cin>>t;
    while(t--){
            solve();

    }
    Time
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;

#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 repr(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

constexpr ll mod = 998244353;

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

ll inv(ll x){
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while(k){
        if(k&1)res = (res*y)%mod;
        y = (y*y) % mod;
        k /= 2;
    }
    return res;
}

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

    int t;
    cin >> t;
    while(t--){
        ll l, r;
        cin >> l >> r;
        if (2*l > r) {
            cout << 0 << endl;
        } else {
            ll mx = r - 2*l + 1;
            ll ret = 0;
            if (mx % 2 == 0) {
                ret += mx * (mx / 2 + 1);
            } else {
                ret += (mx + 1) * ((mx + 1) / 2);
            }
            ret -= (r - 2*l) / 2 + 1;
            cout << ret << endl;
        }
    }
}


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

#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define MAXN        200001

typedef tree<int, null_type,
     less_equal<int>, rb_tree_tag,
          tree_order_statistics_node_update>
    Ordered_set;
// s.find_by_order(idx) find using index..!
// s.order_of_key(val) Gives iterator to the key..!

/* First solve then try Writing Code.. And be cool ^_^ and calm. */

int n, x, a[MAXN];
void solve(){

    cin>>n>>x;
    vector<int> ans;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] != x)
            ans.pb(a[i]);
    }

    for(auto x: ans)
        cout<<x<<' ';
    cout<<endl;
}

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

    return 0;
}

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

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


#include<bits/stdc++.h>
#define int long long
using namespace std;
using ld=long double;
signed main(){
  int N; cin>>N;
  if(N==1)return puts("Yes"),0;
  vector<int> A(N),B(N),C(N),D(N);
  for(int i=0;i<N;i++)cin>>A[i]>>B[i];
  for(int i=0;i<N;i++)cin>>C[i]>>D[i];
  for(int i=0;i<N;i++){
    vector<pair<ld,ld>> v1,v2;
    for(int j=0;j<N;j++){
      if(j!=0)v1.push_back({atan2(A[0]-A[j],B[0]-B[j]),sqrt((A[0]-A[j])*(A[0]-A[j])+(B[0]-B[j])*(B[0]-B[j]))});
      if(j!=i)v2.push_back({atan2(C[i]-C[j],D[i]-D[j]),sqrt((C[i]-C[j])*(C[i]-C[j])+(D[i]-D[j])*(D[i]-D[j]))});
    }
    for(int j=0;j<N-1;j++){
      vector<pair<ld,ld>> v3,v4;
      for(int k=0;k<N-1;k++){
        ld a=v1[k].first-v1[0].first;
        if(a<0)a+=3.1415926535*2;
        v3.push_back({a,v1[k].second});
        a=v2[k].first-v2[j].first;
        if(a<0)a+=3.1415926535*2;
        v4.push_back({a,v2[k].second});
      }
      sort(v3.begin(),v3.end());sort(v4.begin(),v4.end());
      for(int k=0;k<N-1;k++){
        if(abs(v3[k].first-v4[k].first)>1e-3 || abs(v3[k].second-v4[k].second)>1e-3){
          goto home;
        }
      }
      return puts("Yes"),0;
      home:;
    }
  }
  puts("No");
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

typedef long long ll;
typedef std::pair<ll, ll> pll;
const ll INF = (1LL << 60);

struct segtree {
  int i, j;
  ll val;
  segtree *l, *r;
  segtree(std::vector<pll> &ar, int _i, int _j) : i(_i), j(_j) {
    if (i == j) {
      val = ar[i].second;
      l = r = NULL;
    } else {
      int k = (i+j) >> 1;
      l = new segtree(ar, i, k);
      r = new segtree(ar, k+1, j);
      val = std::max(l->val, r->val);
    }
  }
  ll query(int _i, int _j) {
    if (_i <= i and j <= _j) {
      return val;
    } else if (_j < i or j < _i) {
      return 0;
    } else {
      return std::max(l->query(_i, _j), r->query(_i, _j));
    }
  }
};

struct graph {
  int n;
  ll **mat;
  ll *dp;
  graph (int n) : n(n) {
    mat = new ll*[n];
    for (int u = 0; u < n; ++u)
      mat[u] = new ll[n];
    dp = new ll[n];
  }
  void change_edge(int u, int v, ll w) {
    mat[u][v] = w;
  }
  ll dfs(int u) {
    if (u == n-1) return 0;
    if (dp[u] != -1)  return dp[u];
    dp[u] = 0;
    for (int v = u+1; v < n; ++v)
      dp[u] = std::max(dp[u], dfs(v) + mat[u][v]);
    return dp[u];
  }
};

int N, M;
std::vector<ll> W;
std::vector<pll> P;

int main() {
  std::cin >> N >> M;
  ll maxw = 0;
  for (int i = 0; i < N; ++i) {
    ll w; std::cin >> w;
    W.push_back(w);
    maxw = std::max(maxw, w);
  }
  std::sort(W.begin(), W.end());

  bool unavoid_collapse = false;

  for (int i = 0; i < M; ++i) {
    ll l, v;  std::cin >> l >> v;
    P.push_back({v, l});
    if (maxw > v)
      unavoid_collapse = true;
  }
  std::sort(P.begin(), P.end());
  segtree *root = new segtree(P, 0, M-1);

  if (unavoid_collapse) {
    std::cout << "-1\n";
    return 0;
  }

  graph g(N);
  ll ans = (1LL << 60);
  do {
    /*for (int w : W)
      std::cout << w << " ";
    std::cout << "\n";*/
    for (int i = 0; i < N; ++i) {
      ll s = W[i];
      for (int j = i+1; j < N; ++j) {
        s += W[j];
        int k = -1;
        for (int jump = M; jump >= 1; jump >>= 1)
          while (k + jump < M and P[k + jump].first < s)
            k += jump;
        //std::cout << i << " " << j << " " << k << "\n";
        g.change_edge(i, j, root->query(0, k));
      }
    }
    for (int u = 0; u < N; ++u) g.dp[u] = -1;
    ll dist = g.dfs(0);
    ans = std::min(ans, dist);
    //std::cout << dist << "\n";
    //std::cout << "-----\n";
  } while (std::next_permutation(W.begin(), W.end()));
  std::cout << ans << "\n";

  return 0;
}


// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

#define double unsigned ll

enum{N=104};

struct P{
	double x,y;
	bool operator==(const P&e)const{ return x==e.x&&y==e.y; }
	bool operator<(const P&e)const{ if( x!=e.x ) return x<e.x; return y<e.y; }
};
il P operator+(const P&a,const P&b){ return (P){a.x+b.x,a.y+b.y}; }
il P operator-(const P&a,const P&b){ return (P){a.x-b.x,a.y-b.y}; }
il P operator*(const P&a,const double b){ return (P){a.x*b,a.y*b}; }
il double dot(const P&a,const P&b){ return a.x*b.x+a.y*b.y; }
il double cross(const P&a,const P&b){ return a.x*b.y-a.y*b.x; }
il double dist(const P&a,const P&b){ return sqrt(dot(a-b,a-b)); }

P d0[N],d1[N];

int main(){
	int n = ci();
	if( n==1 ){ cout<<"Yes"<<endl; return 0; }
	rep(i,1,n) d0[i] = (P){(double)((ll)ci()),(double)((ll)ci())};
	rep(i,1,n) d1[i] = (P){(double)((ll)ci()),(double)((ll)ci())};
	P a0 = d0[2]-d0[1];
	P a1 = (P){a0.y,-a0.x};
	double x1 = 0, x2 = 0, x3 = 0;
	rep(i,1,n){
		double x = dot(d0[i]-d0[1],a0)*(double)(1e9+7)+dot(d0[i]-d0[1],a1);
		x1 += x;
		x2 += x*x*x*x;
		x3 += x*x*x;
	}
//	printf("x123 %llu %llu %llu\n",x1,x2,x3);
	rep(i,1,n){
		rep(j,1,n) if( i!=j ){
			a0 = d1[j]-d1[i];
			a1 = (P){a0.y,-a0.x};
			double y1 = 0, y2 = 0, y3 = 0;
			rep(k,1,n){
				double x = dot(d1[k]-d1[i],a0)*(double)(1e9+7)+dot(d1[k]-d1[i],a1);
				y1 += x;
				y2 += x*x*x*x;
				y3 += x*x*x;
			}
//			printf("%d %d : \n",i,j);
//			printf("y123 %llu %llu %llu\n",y1,y2,y3);
			if( x1==y1 && x2==y2 && x3==y3 ){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 0.0000001;
struct point{
  double x, y;
  point(){
  }
  point(double x, double y): x(x), y(y){
  }
  point operator +(point P){
    return point(x + P.x, y + P.y);
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
  point operator /(double k){
    return point(x / k, y / k);
  }
};
double abs(point P){
  return sqrt(P.x * P.x + P.y * P.y);
}
double dist(point P, point Q){
  return abs(Q - P);
}
double arg(point P){
  return atan2(P.y, P.x);
}
point rotate(point P, double t){
  return point(P.x * cos(t) - P.y * sin(t), P.x * sin(t) + P.y * cos(t));
}
int main(){
  int N;
  cin >> N;
  vector<point> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i].x >> P[i].y;
  }
  vector<point> Q(N);
  for (int i = 0; i < N; i++){
    cin >> Q[i].x >> Q[i].y;
  }
  point GP(0, 0), GQ(0, 0);
  for (int i = 0; i < N; i++){
    GP = GP + P[i];
    GQ = GQ + Q[i];
  }
  GP = GP / N;
  GQ = GQ / N;
  for (int i = 0; i < N; i++){
    P[i] = P[i] - GP;
    Q[i] = Q[i] - GQ;
  }
  int cntp = 0, cntq = 0;
  for (int i = 0; i < N; i++){
    if (abs(P[i]) < EPS){
      cntp++;
    }
    if (abs(Q[i]) < EPS){
      cntq++;
    }
  }
  if (cntp != cntq){
    cout << "No" << endl;
    return 0;
  }
  vector<point> P2, Q2;
  for (int i = 0; i < N; i++){
    if (abs(P[i]) > EPS){
      P2.push_back(P[i]);
    }
    if (abs(Q[i]) > EPS){
      Q2.push_back(Q[i]);
    }
  }
  N = P2.size();
  P = P2;
  Q = Q2;
  if (N == 0){
    cout << "Yes" << endl;
    return 0;
  }
  bool ok = false;
  for (int i = 0; i < N; i++){
    if (abs(abs(P[0]) - abs(Q[i])) < EPS){
      double ad = arg(Q[i]) - arg(P[0]);
      bool ok2 = true;
      for (int j = 0; j < N; j++){
        point P2 = rotate(P[j], ad);
        bool ok3 = false;
        for (int k = 0; k < N; k++){
          if (dist(P2, Q[k]) < EPS){
            ok3 = true;
          }
        }
        if (!ok3){
          ok2 = false;
        }
      }
      if (ok2){
        ok = true;
      }
    }
  }
  if (ok){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fore(b,c) for(int val0=b;val0<c;val0++)
#define forr(k,c,s) for(int k=c;k<s;k++)
#define pb push_back
#define mmp make_pair
#define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long double ld;
typedef vector<vii> al;
typedef vector<ll> vl;
const int INF = 1e9;
const ll INFL = 1LL<<61;
const int LOG = 18;
const int MN = 200200;
vvi g;
int kv[MN],dist[MN],nod[MN];
void ds(int u, int p, int di) {
	nod[u] = -1;
	dist[u] = MN;
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(v == p) {continue;}
		ds(v,u,di);
		kv[u] += kv[v];
		dist[u] = min(dist[u],dist[v]+1);
		if(nod[v] >= 0) {
			nod[u] = max(nod[u],nod[v]+1);
		}
	}
	if(dist[u]+nod[u] <= di) {
		nod[u] = -1;
	}
	if(dist[u] > di) {nod[u] = max(nod[u],0);}
	if(nod[u] == di) {
		kv[u]++;
		dist[u] = 0;
		nod[u] = -1;
	}
}
int main() {
	ios::sync_with_stdio(0);cout.precision(20);cout.tie(0);cin.tie(0);
	ll n,k;
	cin >> n >> k;
	g.assign(n,vi());
	for(int i=0;i<n-1;i++) {
		ll a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int st = 1,ed = n;
	int ls = ed;
	while(st <= ed) {
		memset(kv,0,sizeof(kv));
		int m = (st+ed)/2;
		ds(0,0,m);
		int val = kv[0];
		if(nod[0] >= 0) {
			val++;
		}
		/*
		cout << "SOUP " << m << '\n';
		for(int i=0;i<n;i++) {
			cout << kv[i] << " " << dist[i] << " " << nod[i] << '\n';
		}
		*/
		if(val <= k) {
			ls = m;
			ed = m-1;
		} else {
			st = m+1;
		}
	}
	cout << ls << '\n';
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "asd"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second

using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, siz, tong, a[N], b[N], d[N], c[N], h[N], P[N][20];
string s[N];
vector<ll> adj[N];
vector<pll> kq;

ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void dfs(ll u, ll p)
{
    for(int i = 1; i <= 18; i ++)P[u][i] = P[P[u][i-1]][i-1];
    for(ll v : adj[u])
    {
        if(v == p)continue;
        h[v] = h[u] + 1;
        P[v][0] = u;
        dfs(v, u);
    }
}
ll par(ll u, ll dist)
{
    if(h[u] < dist)return 1;
    for(int i = 18; i >= 0; i --)
    {
        if((dist >> i) & 1)
        {
            u = P[u][i];
        }
    }
    return u;
}
void bfs(ll u, ll len)
{
    queue<ll> q;
    d[u] = 0;
    q.push(u);
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        if(d[u] == len)continue;
        for(ll v : adj[u])
        {
            if(d[v] > d[u] + 1)
            {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
}

bool check(ll len)
{
    ll cnt = 0;
    fill_n(d, n+2, mod);
    for(pll x : kq)
    {
        if(d[x.se] <= len)continue;
        ll root = par(x.se, len);
        bfs(root, len);
        ++cnt;
        //cout << root <<" "<<x.se<<'\n';
        if(cnt > k)return false;
    }
    return true;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i < n; i ++)
    {
        ll x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1, 0);
    for(int i = 1; i <= n; i ++)kq.pb({h[i], i});
    sort(kq.rbegin(), kq.rend());
    ll lf = 0, rt = n, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(check(mid))rt = mid - 1;
        else lf = mid + 1;
    }
    cout << lf;
}
int main()
{
    if(fopen(task".INP", "r"))
    {
       freopen(task".INP", "r", stdin);
       freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
1 2
2 3
3 4
4 5

https://codeforces.com/contest/791/problem/E

*/


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll ans = 1e17;
	vector <pair<ll, ll>> v(n);
	for (auto &i : v)
		cin >> i.ff >> i.ss;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n; j++) {
			if (i == j)
				ans = min(ans, v[i].ff + v[i].ss);
			else
				ans = min(ans, max(v[i].ff, v[j].ss));
		}
	}
	cout << ans;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>

using namespace std;

// typdef
typedef long long ll;
typedef unsigned long long ull;

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

#define IN_VEC(v)                                                              \
  for (auto &&e : v)                                                           \
  cin >> e
#define MOD 1000000007

#define MP make_pair
#define PB push_back

template <typename T> void print_vector(vector<T> v, string sep = " ") {
  REP(i, v.size()) {
    if (i != 0) {
      cout << sep;
    }
    cout << v[i];
  }
  cout << "\n";
}

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

  // Enter code here
  unsigned long long N;
  std::cin >> N;
  std::set<ull> nums;

  for (ull a = 2; a <= sqrt(N); a++) {
    for (ull i = 2; N >= pow(a, i); i++) {
      nums.insert(pow(a, i));
    }
  }

  cout << N - nums.size() << "\n";
  return 0;
}


/*
Author:Atul Pandey
*/
#include <bits/stdc++.h>
typedef long long int ll;
#define pll pair <ll, ll>
#define pii pair <int, int>
#define f first
#define s second
#define pb push_back
#define vll vector <ll>
#define mll map <ll ,ll>
#define prtq priority_queue <long long>
#define all(c) c.begin(), c.end()
#define rep(a,b) for(i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define inf 1e18
using namespace std;
#define Mod 4
#define endl "\n"
////////////////////////////////////////////////////////////////////

void fio() // file input output
{
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#else
#endif
}

void tim()
{
#ifndef ONLINE_JUDGE
  cerr << "Time elapsed: " << clock() / 1000 << " ms" << endl;
#endif
}
ll power(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp&1) res=(res*base)%Mod;
       base=(base*base)%Mod;
       exp=exp>>1;
    }
    return res%Mod;
}

int main()
{
  fio();
  IOS;
  int t = 1;
  // cin >> t;
  while (t--)
  {
    string s;
    cin>>s;
    int n=s.size();
    string temp=s;
    ll ans=0;
    map<char,ll>mp;

    for(int i=n-1;i>=0;i--)
    {  ll temp=0;
      if(i<=n-3&&s[i]==s[i+1])
      {
        for(auto &u:mp)
        {
          if(u.f!=s[i])
           { temp+=u.s,u.s=0;}

        }
        // cout<<temp<<endl;
        ans+=temp;
        mp[s[i]]+=temp;
        mp[s[i]]++;
        // cout<<mp['c']<<endl;
      }
      else mp[s[i]]++;
    }

    cout<<ans;

  }
  tim();
  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

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

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    ll n;
    cin >> n;

    ll ans = 0;
    for (ll i = 1; i * i <= 2 * n; ++i) {
        if (2 * n % i == 0) {
            ll len = i;
            auto l = (n - (len * (len - 1)) / 2);
            if (l % len == 0) ans++;
            if ((2 * n) / i != i) {
                ll len = i;
                auto l = (n - (len * (len - 1)) / 2);
                if (l % len == 0) ans++;
            }
        }
    }
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting, graph is not a tree/connected
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


#include<bits/stdc++.h>
#define ll unsigned long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
using namespace std;
const int N=2e5+10;
const double eps=1e-8;
bool ban[N];
double k[N],b[N];
int main()
{
    int n,m,K;
    scanf("%d%d%d",&n,&m,&K);
    for(int i=1;i<=K;i++){int a;scanf("%d",&a),ban[a]=1;}
    double km=0,bm=0;
    for(int i=n-1;~i;i--)
    {
        if(ban[i])k[i]=1,b[i]=0;
        else k[i]=km/m,b[i]=bm/m+1;
        km+=k[i]-k[i+m],bm+=b[i]-b[i+m];
    }
    if(fabs(1-k[0])<eps)puts("-1");
    else printf("%.10lf\n",b[0]/(1-k[0]));
	return 0;
}

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define uniq(v) vsort(v);(v).erase(unique(all(v)),(v).end())
#define endl "\n"
#define eb emplace_back
#define print(x) cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
constexpr ll mod=1000000007;
// constexpr ll mod=998244353;
constexpr ll inf=1LL<<60;
constexpr double eps=1e-9;
const double PI=acos(-1);
template<class T,class E> ostream& operator<<(ostream& os,const pair<T,E>& p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& os,const vector<T>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T> ostream& operator<<(ostream& os,const set<T>& v){
  os<<"{";bool f=false;
  for(auto& x:v){if(f)os<<",";os<<x;f=true;}
  os<<"}";
  return os;
}
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}
#ifdef DEBUG
void debugg(){cout<<endl;}
template<class T,class... Args>void debugg(const T& x,const Args&... args){cout<<" "<<x;debugg(args...);}
#define debug(...) cout<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debugg(__VA_ARGS__)
#else
#define debug(...) (void(0))
#endif

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

ll N,M,K;
int main(){
  startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j;
  cin>>N>>M>>K;
  vector<double> sumdpx(N+1,0),sumdpa(N+1,0);
  rep(i,K){
    cin>>j;
    sumdpx[j]=1;
  }
  //x=ax+b のa,bを求める
  brep(i,N){
    if(sumdpx[i]){
      sumdpx[i]+=sumdpx[i+1];
      sumdpa[i]+=sumdpa[i+1];
      continue;
    }
    sumdpx[i]=(sumdpx[i+1]-sumdpx[min(i+M+1,N)])/M+sumdpx[i+1];
    sumdpa[i]=(sumdpa[i+1]-sumdpa[min(i+M+1,N)])/M+1+sumdpa[i+1];
  }
  sumdpx[0]-=sumdpx[1];
  sumdpa[0]-=sumdpa[1];
  double ans=sumdpa[0]/abs(1-sumdpx[0]);
  if(ans>1e18){print(-1);return 0;}
  print(ans);
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#include <unordered_map>

using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
using VV = vector<V>;
using SV = vector<string>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rep3(i, m, n) for(ll i=m;i<=(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1000000000000000000

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

void solve_abc_d() {
	ll n, m;
	ll c, d;
	ll k;
	ll q;

	cin >> n >> m >> q;
	vector<P> wv(n);
	ll w, v;
	rep(i, n) {
		cin >> w >> v;
		wv[i] = make_pair(v, w);
	}
	sort(RALL(wv));
	V x(m);
	rep(i, m) {
		cin >> x[i];
	}

	ll l, r;
	deque<ll> nx;
	V ans(q, 0);
	rep(i, q) {
		cin >> l >> r;
		nx.clear();
		rep(j, l - 1) {
			nx.push_back(x[j]);
		}
		rep(j, m - r) {
			nx.push_back(x[r + j]);
		}
		sort(ALL(nx));
		rep(j, wv.size()) {
			auto itr = lower_bound(ALL(nx), wv[j].second);
			if (itr != nx.end()) {
				ans[i] += wv[j].first;
				nx.erase(itr);
			}
		}
	}

	rep(i, q) {
		cout << ans[i] << "\n";
	}
}

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

	solve_abc_d();

	return 0;
}

#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";}
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
#define TT cauto TTT=read();rep(_,TTT)
const ll MOD=1e9+7; //998244353;

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read();
	read();
	cauto ss=readV<string>(n);
	ll cnt=0;
	for(cauto &s:ss)if(count(all(s),'1')%2) ++cnt;
	cout<<cnt*(n-cnt) NL;
  return 0;
}


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

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-48;
		s=getchar();
	}
	return f*x;
}

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

int main()
{
	int n=read();
	int ans=read();
	for(int i=2;i<=n;i++)
	{
		int a=read();
		ans=gcd(ans,a);
	}
	printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
ll l=-LINF,r=LINF,m=0;
ll f(ll x){
    if(x<=l){
        return l+m;
    }else if(x>=r){
        return r+m;
    }else{
        return x+m;
    }
}

int main(){
    int n;
    cin>>n;
    vi a(n),b(n);
    REP(i,n){
        cin>>a[i]>>b[i];
        if(b[i]==1){
            m+=a[i];
        }else if(b[i]==2){
            chmax(l,a[i]-m);
            chmax(r,l);
        }else{
            chmin(r,a[i]-m);
            chmin(l,r);
        }
    }
    int q;
    cin>>q;
    REP(i,q){
        ll x;
        cin>>x;
        cout<<f(x)<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int oo = 1e9 +100;
const int maxn = 1e5+10;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1), best(n+1, -oo);
    vector<vector<int>> p(n+1);

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

    for (int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        p[y].push_back(x);
    }

    int ans = -oo;

    for (int i=n; i>=1; i--){
        for (auto pai: p[i]) best[pai] = max(best[pai], max(best[i], a[i]));
    }

    for (int i=1; i<=n; i++) {
        if (best[i] != -oo) ans = max(ans, best[i] - a[i]);
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const ll inf = 1e16;

const int MOD = 1e9 + 7;
typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const long long& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; }
    friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
    mi operator-() const { return mi(-val); }
    mi& operator+=(const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, long long p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
};

ll trade[200005];
vl graph[200005];

ll mx[200005];
ll vis[200005];

ll rec(ll v) {
    if (vis[v]) {
        return max(trade[v], mx[v]);
    }

    vis[v] = 1;

    ll m = -inf;

    for (ll u: graph[v]) {
        m = max(m, rec(u));
    }

    //cout << v << " " << m << " " << trade[v] << endl;
    mx[v] = m;

    return max(mx[v], trade[v]);
}

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

    ll n, m; cin >> n >> m;

    f0r(i, n) {
        cin >> trade[i];
    }

    f0r(i, m) {
        ll x, y; cin >> x >> y;
        x--; y--;
        graph[x].pb(y);
    }

    f0r(i, n) {
        sort(graph[i].begin(), graph[i].end());
        reverse(graph[i].begin(), graph[i].end());

    }

    ms(vis, 0);

    f0r(i, n) {
        if (!vis[i]) {
            rec(i);
        }
    }

    ll ret = -inf;

    f0r(i, n) {
        ret = max(ret, mx[i] - trade[i]);

    }

    cout << ret << endl;

}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
inline int read()
{
    int w = 0, f = 1;
    char ch = getchar();
    while (ch < '0' or ch > '9')
    {
        if (ch == '-')
            f = -f;
        ch = getchar();
    }
    while (ch >= '0' and ch <= '9')
        w = w * 10 + ch - '0', ch = getchar();
    return w * f;
}
int L[maxn], R[maxn], A[maxn], N, M, K;
bool check(int limit)
{
    for (int i = 1; i <= K; i++)
        L[i] = ((A[i] * M - limit + N - 1) / N), R[i] = ((A[i] * M + limit) / N);
    for (int i = 1; i <= K; i++)
        L[i] = max(L[i], 0ll);
    for (int i = 1; i <= K; i++)
        if (L[i] > R[i])
            return 0;
    int lsum = 0, rsum = 0;
    for (int i = 1; i <= K; i++)
        lsum += L[i], rsum += R[i];
    if (lsum <= M and rsum >= M)
        return 1;
    return 0;
}
signed main()
{
    scanf("%lld%lld%lld", &K, &N, &M);
    for (int i = 1; i <= K; i++)
        scanf("%lld", &A[i]);
    int l = 0, r = M * N;
    while (l <= r)
    {
        int mid = (l + r) >> 1;
        if (check(mid))
            r = mid - 1;
        else
            l = mid + 1;
    }
    check(l);
    int lsum = 0;
    for (int i = 1; i <= K; i++)
        lsum += L[i];
    int res = M - lsum;
    for (int i = 1; i <= K; i++)
    {
        printf("%lld ", min(L[i] + res, R[i]));
        res -= min(L[i] + res, R[i]) - L[i];
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 2020, mod = 1e9 + 7;
int n, m, a[N];
int qpow (int x, int y) {
    int t = 1;
    while (y) {
        if (y & 1) t = t * x % mod;
        x = x * x % mod, y >>= 1;
    } return t;
}
int C (int x, int y) {
    int s = 1, p = 1; if (x < y) return 0;
    for (int i = 1; i <= y; ++i)
        s = s * (x - i + 1) % mod;
    for (int i = 1; i <= y; ++i)
        p = p * i % mod;
    return s * qpow (p, mod - 2) % mod;
}
signed main() {
    read (n), read (m); int s = 0;
    for (int i = 1; i <= n; ++i) read (a[i]);
    for (int i = 1; i <= n; ++i) s += a[i];
    printf ("%lld\n", C (m + n, n + s));
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, x, y;
	cin >> a >> b >> x >> y;
	if (a<=b){
		cout << min(x+(b-a)*y, (b-a)*2*x+x) << endl;
		return 0;
	}
	else{
		cout << min(x+(a-b-1)*y, (a-b-1)*2*x+x) << endl;
		return 0;
	}
}

#include <bits/stdc++.h>
#define PB push_back
#define MP std::make_pair
#define FI first
#define SE second
typedef long long ll;
typedef long double ld;
typedef std::pair <int, int> pii;
const int mod = 998244353;
int n, K;
ll ans;
int read() {
	char c = getchar(); int ans = 0;
	while (c < '0' || c > '9') c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return ans;
}
void Write(ll x) {
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
}
int max(int x, int y) {return x > y ? x : y;}
int min(int x, int y) {return x < y ? x : y;}
ll calc(int m) {
	return min(n, m - 1) - max(1, m - n) + 1;
}
int main() {
	n = read(), K = read();
	for (int i = 2; i <= n * 2; i++)
		if (i - K >= 1 && i - K <= n * 2) ans += calc(i) * calc(i - K);
	return Write(ans), 0;
}


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

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

    int n;
    cin >> n;
    string s, ans;
    int x[n];
    map<string, int> mp;
    for(int i = 0; i < n; i++){
        cin >> s;
        cin >> x[i];
        mp[s] = x[i];
    }
    sort(x, x+n);
    reverse(x, x+n);
    for(auto it : mp){
        if(it.second == x[1])
            ans = it.first;
    }
    cout << ans << endl;

    return  0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);

  for(int i=0; i<n; i++){
    cin >> a.at(i);
    b.at(i) = i+1;
  }

  sort(a.begin(), a.end());

  int x = 1;

  for(int i=0; i<n; i++){
    if(a.at(i) != b.at(i)){
      x = 0;
    }
  }

  if(x == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


#include <bits/stdc++.h>

using namespace std;

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

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

ll dp[65][2], n;

string a[65];

ll solve(int curr, bool prevSign)
{
	if (curr == n)
	{
		return prevSign;
	}

	if (dp[curr][prevSign] != -1)
		return dp[curr][prevSign];

	ll ans = 0;

	if (a[curr] == "AND")
		ans = solve(curr + 1, prevSign & true) + solve(curr + 1, prevSign & false);
	else
		ans = solve(curr + 1, prevSign | true) + solve(curr + 1, prevSign | false);
	return dp[curr][prevSign] = ans;
}

int main()
{
	faster;
	mem(dp, -1);

	cin >> n;

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

	cout << solve(0, 0) + solve(0, 1) << endl;

	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
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;
}
struct edge {
  ll to, cost;
};

int main() {
  ll T; cin >> T;
  REP(i, T) {
    ll N; cin >> N;
    if(N % 4 == 0) cout << "Even" << endl;
    else if(N % 2 == 0) cout << "Same" << endl;
    else cout << "Odd" << endl;
  }
}


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

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

string P="RBW";

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

  int N;
  cin>>N;
  string S;
  cin>>S;

  vector<ll> two(N+1,0);
  two[0]=1;
  rep(i,N) two[i+1]=two[i]*2%MOD;

  vector<vector<ll>> above(N+1,vector<ll> (3,0));
  vector<vector<ll>> below(N+1,vector<ll> (3,0));
  above[0][1]=1;
  below[0][1]=1;
  for(int k=1;k<=N-1;k++){
      rep(j,3){
          above[k][j]=above[k-1][j];
          below[k][j]=below[k-1][j];
      }
      {
          int num=N-k;
          int cnt=0;
          while(num%3==0){
              num/=3;
              cnt++;
          }
          above[k][0]+=cnt;
          above[k][num%3]++;
      }
      {
          int num=k;
          int cnt=0;
          while(num%3==0){
              num/=3;
              cnt++;
          }
          below[k][0]+=cnt;
          below[k][num%3]++;
      }
  }

  ll ans=0;
  for(int i=0;i<N;i++){
      ll res=1;
      if(S[i]=='R') res=0;
      else if(S[i]=='B') res=1;
      else res=2;

      if(above[i][0]!=below[i][0]) res=0;
      else{
          if((above[i][2]+below[i][2])%2) mul(res,2);
      }

      mul(res,two[N-1]);
      add(ans,res);
  }

  cout<<P[ans]<<endl;

  return 0;
}

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

const int N = 20 + 5;
typedef long long LL;

struct Edge
{
	int to, nxt;
}line[N * N * 2];
int fist[N], idx;
int n, m;
LL ans = 1;
bool vis[N];
int col[N];
vector<int> v;

void add(int x, int y)
{
	line[idx] = {y, fist[x]};
	fist[x] = idx ++;
}

void dfs(int u)
{
	vis[u] = 1; v.push_back(u);
	for(int i = fist[u]; ~i; i = line[i].nxt)
	{
		int v = line[i].to;
		if(!vis[v]) dfs(v);
	}
}

bool check(int u)
{
	for(int i = fist[u]; ~i; i = line[i].nxt)
	{
		int v = line[i].to;
		if(col[v] == col[u]) return 0;
	}
	return 1;
}

void dfs(int t, LL &res)
{
	if(t == v.size())
	{
		res ++;
		return;
	}
	for(int i = 1; i <= 3; ++ i)
	{
		col[v[t]] = i;
		if(!check(v[t])) { col[v[t]] = 0; continue;}
		dfs(t + 1, res);
		col[v[t]] = 0;
	}
}

int main()
{
	IOS; cin >> n >> m;
	memset(fist, -1, sizeof fist);
	for(int i = 1; i <= m; ++ i)
	{
		int a, b; cin >> a >> b;
		add(a, b), add(b, a);
	}
	for(int i = 1; i <= n; ++ i)
		if(!vis[i])
		{
			LL res = 0;
			v.clear();
			dfs(i);
			dfs(0, res); ans *= res;
		}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)      //iをaからn
#define per(i, n, a) for (int i = a - 1; i >= n; i--) //iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
int main()
{

    cout<<(6469693230*9*8*5+1)<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N;
    cin>>N;
    if(N%2==1)cout<<"Black"<<endl;
    else cout<<"White"<<endl;
}


#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
char s[maxn];
LL ksm(LL a, LL b, const LL mod) {
    LL res = 1;
    while(b){
        if(b&1){
            res = res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

int main(){
    LL a, b, c;
    read(a); read(b); read(c);
//    if (c == 1) printf("%lld\n", ksm(a, b, 10));
//    else if(b == 1) printf("%lld\n", a % 10);
//    else if(b == 2 && c == 2) printf("%lld\n", ksm(a, 4, 10));
//    else
        printf("%lld\n", ksm(a, ksm(b, c, 4) + 4, 10));
    Please AC;
}

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

const ll sizeofS = 30000000000;

int main() {
    int n;
    cin >> n;
    string t;
    cin >> t;

    ll ans;
    if (t == "1") {
        ans = sizeofS * 2 / 3;
    } else if (t == "11") {
        ans = sizeofS / 3;
    } else {
        map<char, int> mp;
        rep(i, 3) mp[t[i]]++;
        if (mp['0'] != 1) {
            cout << 0 << endl;
            return 0;
        }

        ll pos0 = -1;
        vector<int> v(3, -1);
        rep(i, n) {
            if (v[i % 3] == -1) {
                v[i % 3] = t[i] - '0';
            } else {
                if (v[i % 3] != t[i] - '0') {
                    cout << 0 << endl;
                    return 0;
                }
            }
            if (pos0 == -1 && t[i] == '0') pos0 = i;
        }
        ans = 1 + (sizeofS - n - (2 - pos0)) / 3;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
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;}

string S1, S2, S3;
vector<char> chars;
char used[10];

bool check() {
    map<char, char> mapping;
    rep(i, 10) if (used[i] != 0) mapping[used[i]] = char('0' + i);

    string T1, T2, T3;
    for (auto c : S1) T1 += mapping[c];
    for (auto c : S2) T2 += mapping[c];
    for (auto c : S3) T3 += mapping[c];

    if (stoll(T1) + stoll(T2) != stoll(T3)) return false;
    if (T1[0] == '0') return false;
    if (T2[0] == '0') return false;
    if (T3[0] == '0') return false;

    cout << T1 << endl << T2 << endl << T3 << endl;
    return true;
}

bool dfs(int cu) {
    if (cu == chars.size()) return check();

    rep(i, 10) {
        if (used[i] != 0) continue;

        used[i] = chars[cu];
        if (dfs(cu + 1)) return true;
        used[i] = 0;
    }

    return false;
}

int main() {
    cin >> S1 >> S2 >> S3;

    for (auto c : S1) chars.push_back(c);
    for (auto c : S2) chars.push_back(c);
    for (auto c : S3) chars.push_back(c);
    sort(all(chars));
    chars.erase(unique(all(chars)), chars.end());

    if (chars.size() > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }

    bool res = dfs(0);
    if (res == false) cout << "UNSOLVABLE" << endl;
}

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

using ll=long long;
ll mod=1000000007;

int main(){
    vector<string> S(3);
    for(int i=0;i<3;i++){
        cin >> S[i];
    }
    map<char,ll> P;
    for(int i=0;i<3;i++){
        ll X=1;
        if(i==2){
            X=-1;
        }
        for(int j=S[i].size()-1;j>-1;j--){
            P[S[i][j]]+=X;
            X*=10;
        }
    }
    if(P.size()>10){
        cout << "UNSOLVABLE" << endl;
        return 0;
    }
    vector<int> Q(10);
    iota(Q.begin(),Q.end(),0);
    do{
        ll sum=0;
        int i=0;
        map<char,int> R;
        for(auto it=P.begin();it!=P.end();it++){
            sum+=Q[i]*(*it).second;
            R[(*it).first]=Q[i];
            i++;
        }
        if(sum==0){
            bool a=false;
            for(int i=0;i<3;i++){
                if(R[S[i][0]]==0){
                    a=true;
                    break;
                }
            }
            if(a){
                continue;
            }
            for(int i=0;i<3;i++){
                ll res=0;
                ll X=1;
                for(int j=S[i].size()-1;j>-1;j--){
                    res+=X*R[S[i][j]];
                    X*=10;
                }
                cout << res << endl;
            }
            return 0;
        }
    }while(next_permutation(Q.begin(),Q.end()));
    cout << "UNSOLVABLE" << endl;
}


#include <bits/stdc++.h>

using namespace std;

long long divceil(long long a, long long b) {
	if(a % b == 0) return a / b;
	return a / b + 1;
}

int main(void) {
	long long N, M;
	cin >> N >> M;
	if(M == 0) {
		cout << "1\n";
		return 0;
	}
	vector<long long> A;
	for(int i = 0; i < M; ++i) {
		long long a;
		cin >> a;
		--a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	vector<long long> diffs;
	for(int i = 0; i <= M; ++i) {
		if(i == 0) {
			if(A[0] > 0) diffs.push_back(A[0]);
		} else if(i == M) {
			if(N - 1 > A[M - 1]) diffs.push_back(N - 1 - A[M - 1]);
		} else {
			if(A[i] - A[i - 1] > 1) diffs.push_back(A[i] - A[i - 1] - 1);
		}
	}
	long long m = LLONG_MAX;
	for(auto d : diffs) {
		m = min(m, d);
	}
	long long ans = 0;
	for(auto d : diffs) {
		ans += divceil(d, m);
	}
	cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin>>n>>m;
  if(m==0) print(1);
  else {
    lvector A(m+2),B(m+1,0);A[0]=0;A[m+1]=n+1;
    ll k=1e9,ans=0;
    rep(i,m) cin>>A[i+1];
    sort(ALL(A));
    rep(i,m+1) {
      B[i]=max(0ll,A[i+1]-A[i]-1);
      if(B[i]>0) k=min(k,B[i]);
    }
    for(ll b:B) ans+=(b+k-1)/k;
    print(ans);
  }
  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <climits>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;

int main() {
    vector<int> a(4);
    rep(i, 4) cin >> a[i];
    int ans = 1e9;
    rep(i, 4) chmin(ans, a[i]);
    cout << ans << endl;
}

// CPP code for Longest Palindromic substring
// using Palindromic Tree data structure
#include <bits/stdc++.h>
using namespace std;

#define fl(n)             for(long long int i=0;i<n;i++)
#define sz(a)             int((a).size())
#define tr(c,i)           for(auto i = (c).begin(); i != (c).end(); i++)
#define trr(c,i)          for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define present(c,x)      ((c).find(x) != (c).end())
#define cpresent(c,x)     (find(all(c),x) != (c).end())
#define vi                vector <int>
#define vvi               vector < vi >
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define ll                long long
#define fr                first
#define sc                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define M                 ((long long)(1e9+7))

int par[200006];
int find_parent(int ind)
{
   if(par[ind]==ind)
      return ind;
   return par[ind]=find_parent(par[ind]);
}

void un(int p1, int p2)
{
   p1=find_parent(p1);
   p2=find_parent(p2);
   if(p1!=p2)
   {
      par[p1]=p2;
   }
}

int solve()
{
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<200006;i++)
      par[i]=i;
   std::map<int, int> mp;
   for(int i=0;i<n;i++)
   {
      cin>>a[i];
   }
   int ans=0;
   for(int i=0;i<=(n-1)/2;i++)
   {
      int t1=find_parent(a[i]), t2=find_parent(a[n-i-1]);
      if(t1==t2)
         continue;
      un(t1, t2);
      ans++;
   }
   cout<<ans<<endl;

   return 0;
}
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;
   // cin>>t;

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

   return 0;
}