#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define T third
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<int,int>> vp;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
const int C=1e9+7;
const int C1=998244353;
void yes(){
    cout<<"YES\n";
}
void no(){
    cout<<"NO\n";
}
ll binpow(ll a, ll b, ll m=C) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//Variables********************************************

//Functions********************************************

//*****************************************************
void solve(){
	ll n; cin>>n;
	ll ans=LLONG_MAX;
	for(int i=0;i<=60;i++){
		if(pow(2,i)>n) break;
		ll p=pow(2,i);
		ll r=n%p;
		ll c=(n-r)/p;
			ans=min(ans,i+c+r);
	}
	cout<<ans<<endl;
}

signed main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1; //cin>>t;
    int x{};
    while(t--){
    	//cout<<"Case #"<<x<<": "; x++;
        solve();
    }
}

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

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

ll tmp[600001], *A = tmp + 200000, *B = tmp + 400000;
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
const int CM = 400001, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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

	int N = getint();
	rep(i, N) {
		A[i] = ll(i) << 32 | getint();
		B[i] = ll(i) << 32 | getint();
	}
	pakuri_sort(N, A);
	pakuri_sort(N, B);

	const ll ma = (1ll << 32) - 1;
	rep(i, N) {
		auto tmp = (A[i] & ma) < (B[N - 1 - i] & ma);
		cn[A[i] >> 31] = tmp;
		cn[B[N - 1 - i] >> 31 | 1] = tmp;
	}

	int c = -1, pn = 0;
	rep(i, N << 1) {
		if (c != -1 && pn == cn[i]) {
			cn[c] = '(';
			cn[i] = ')';
			c = tmp[c];
			pn ^= 1;
		}
		else {
			pn = cn[i];
			tmp[i] = c;
			c = i;
		}
	}
	fwrite(cn, 1, N << 1, stdout);

	Would you please return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 998244353;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2);
}

int dp[5000][5000];
char d[5000][5000];

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

    int h, w, k;
    cin >> h >> w >> k;

    for (int l = 0; l < k; l++) {
        int i, j;
        char c;
        cin >> i >> j >> c;
        i--; j--;

        d[i][j] = c == 'R' ? 1 : c == 'D' ? 2 : 3;
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            ll t = 0;
            if (i == 0 && j == 0) {
                t = 1;
            } else {
                if (j > 0 && d[i][j - 1] != 2) {
                    int s = 1;
                    if (d[i][j - 1] == 0) s = 2;
                    t += dp[i][j - 1] * s;
                }
                if (i > 0 && d[i - 1][j] != 1) {
                    int s = 1;
                    if (d[i - 1][j] == 0) s = 2;
                    t += dp[i - 1][j] * s;
                }
            }
            if (d[i][j] != 0) t *= 3;
            dp[i][j] = t % P;
        }
    }

    ll r = dp[h - 1][w - 1];
    int t = h * w - k - (h + w - 1);
    if (d[h - 1][w - 1] == 0) r = r * 3 % P;
    if (t > 0) {
        r = r * powmod(3, t) % P;
    } else if (t < 0) {
        r = r * powmod(modinv(3), -t) % P;
    }

    cout << r << endl;

    //通らない場所の塗り方も関係するじゃん！
    //通るマスの数はH+W-1

    return 0;
}

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

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

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

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n,k,A[MAXN],C[302][302],mod=998244353,sum[MAXN],ans[302],co[MAXN];
ll qexp(ll x,ll e){
	ll sum=1;
	for(;e;e>>=1,x*=x,x%=mod)if(e&1)sum*=x,sum%=mod;
	return sum;
}
int main(){
	FAST
	cin>>n>>k;
	FOR(i,1,n)cin>>A[i];
	FOR(i,0,300) C[i][0]=1;
	FOR(i,1,300) FOR(j,1,300) C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
	FOR(i,1,n){
		ll co = 1;
		FOR(j,0,k){
			sum[j] += co, sum[j] %= mod;
			co *= A[i], co %= mod;
		}
	}
	fill(co,co+MAXN,1);
	FOR(i,1,k){
		ll ans = 0;
		FOR(j,0,i){
			ans += sum[j] * sum[i-j] % mod * C[i][j] % mod, ans %= mod;
		}
		FOR(z,1,n){
			co[z] *= A[z] * 2 % mod, co[z] %= mod;
			ans -= co[z], ans += mod, ans %= mod;
		}
		ans *= qexp(2, mod-2), ans %= mod;
		cout<<ans<<'\n';
	}
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,int y){x=upd(x+y-mod);}
inline void iadd(int &x,int y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
/*
typedef pair<int,int> P;
*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	printf("%d\n",(1<<n)-1);
	rep(i,1,(1<<n)-1){
		rep(j,0,(1<<n)-1) putchar("AB"[__builtin_parity(i&j)]);
		puts("");
	}
}
int main()
{
	for (int T=1;T--;) solve();
}

#include <cstdio>
#include <queue>
using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n*2);
	for(int& i: a)
		scanf("%d", &i);
	priority_queue<int> q;
	long long ans=0;
	for(int i = 0;i < n;i ++){
		q.push(a[i]);
		q.push(a[n*2-1-i]);
		ans+=q.top();
		q.pop();
	}
	printf("%lld\n", ans);
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
#define asort(arr, size) std::sort(arr, arr + size)
#define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; })
#define cauto const auto&
#define bit(n) (1LL << (n))

////////////////////////////////////
// ここから下に任意のコードを書く //
////////////////////////////////////

int d[200];
int h[200];

int main()
{
    int N, D, H;
    cin >> N >> D >> H;
    rep(i, N) cin >> d[i] >> h[i];
    double res = 0;
    rep(i, N) {
        double dx = D - d[i];
        double dy = H - h[i];
        double slope = dy / dx;
        // y = slope * x + n
        // H = slope * D + n
        // H - n = slope * D
        // -n = slope * D - H
        // n = -(slope * D - H)
        auto n = -(slope * D - H);
        res = max(res, n);
    }
    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N], d[N], h[N];
int n, m, H, D;
bool chck(double x){
	for(int i=0; i<n; ++i){
		double tmp = (H-x)/(double)D;
		if(tmp*d[i]+x<h[i])
			return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d%d",&n,&D,&H);
	for(int i=0; i<n; ++i){
		scanf("%d%d",&d[i],&h[i]);
	}
	double st = 0, nd = 1000, md;
	int cnt = 100;
	while(cnt--){
		md = (st+nd)/2.0;
		if(chck(md)){
			nd = md;
		}
		else{
			st = md;
		}
	}
	cout<<fixed<<setprecision(9)<<md<<endl;
}


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

#define M 1005
#define LL long long
const LL mod = 1000000007;

int n;
LL f[M];
char Caa, Cab, Cba, Cbb;

inline LL qkpow (LL x, LL y){
	LL res = 1;
	while (y){
		if (y & 1)
			res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
signed main (){
	scanf ("%d\n%c\n%c\n%c\n%c", &n, &Caa, &Cab, &Cba, &Cbb);
	if (n == 3 || n == 2){
		printf ("1\n");
		return 0;
	}
	f[1] = 2, f[2] = 3;
	for (int i = 3; i <= n; i ++)
		f[i] = (f[i - 1] + f[i - 2]) % mod;
	if (Cab == 'B'){
		if (Cbb == 'B')
			printf ("1\n");
		else{
			if (Cba == 'A'){
				printf ("%lld\n", qkpow (2, n - 3));
			}
			else{
				printf ("%lld\n", f[n - 3]);
			}
		}
	}
	else{
		if (Caa == 'A')
			printf ("1\n");
		else{
			if (Cba == 'B'){
				printf ("%lld\n", qkpow (2, n - 3));
			}
			else{
				printf ("%lld\n", f[n - 3]);
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

int main(){
    ll n,x;
    cin>>n>>x;
    vi a(n);
    rep(i,n) cin>>a[i];
    vi b;
    rep(i,n) if(a[i]!=x) b.eb(a[i]);
    outv(b);
}


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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

/*ll NcR(ll n, ll r)
{
    ll p = 1, k = 1;
    if (n - r < r)
        r = n - r;

    if (r != 0)
    {
        while (r)
        {
            p *= n;
            k *= r;
            ll m = __gcd(p, k);
            p /= m;
            k /= m;

            n--;
            r--;
        }
    }
    else
        p = 1;

    return p;
} */

int main()
{
    _fastio
    double a,b;
    cin>>a>>b;
    cout<<setprecision(6)<<fixed<<(a/100.0)*b<<en;
}


#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>
#include <algorithm>
// #include <atcoder/all>

// URL:

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n)? "YES": "NO") << endl
#define Yes(n) cout << ((n)? "Yes": "No") << endl

#define rept(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fore(x, a) for(auto& (x) : (a))

#define reptll(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)

#define ALL(a) (a).begin(), (a).end()

#define VECCIN(x) for(auto& youso_: (x)) cin >> youso_
#define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = numeric_limits<ll>::max() / 4;
const int INF = 1e9;
const int MOD = 1e9 + 7;

//数列a(a[0],a[1],…,a[n-1])についての区間和と点更新を扱う
//区間和,点更新,二分探索はO(log{n})で動作する
class BIT {
public:
  //データの長さ
  ll n;
  //データの格納先
  vector<ll> a;
  //コンストラクタ
  BIT(ll n):n(n),a(n+1,0){}

  //a[i]にxを加算する
  void add(ll i,ll x){
    i++;
    if(i==0) return;
    for(ll k=i;k<=n;k+=(k & -k)){
      a[k]+=x;
    }
  }

  //a[i]+a[i+1]+…+a[j]を求める
  ll sum(ll i,ll j){
    return sum(j)-sum(i-1);
  }

  //a[0]+a[1]+…+a[i]を求める
  ll sum(ll i){
    i++;
    ll s=0;
    if(i==0) return s;
    for(ll k=i;k>0;k-=(k & -k)){
      s+=a[k];
    }
    return s;
  }

  //a[0]+a[1]+…+a[i]>=xとなる最小のiを求める(任意のkでa[k]>=0が必要)
  ll lower_bound(ll x){
    if(x<=0){
      //xが0以下の場合は該当するものなし→0を返す
      return 0;
    }else{
      ll i=0;ll r=1;
      //最大としてありうる区間の長さを取得する
      //n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
      while(r<n) r=r<<1;
      //区間の長さは調べるごとに半分になる
      for(int len=r;len>0;len=len>>1) {
        //その区間を採用する場合
        if(i+len<n && a[i+len]<x){
          x-=a[i+len];
          i+=len;
        }
      }
      return i;
    }
  }
};

int main(){
  optimize_cin();

  int N;
  cin >> N;
  vll A(N), B(N);
  vector<pll> paa(N), pab(N);
  ll SA = 0, SB = 0;
  rep(i, N) {cin >> A[i]; A[i] += i; paa[i] = make_pair(A[i], i);}
  rep(i, N) {cin >> B[i]; B[i] += i; pab[i] = make_pair(B[i], i);}

  sort(ALL(paa));
  sort(ALL(pab));

  vll C(N);
  rep(i, N) {
    if(paa[i].first != pab[i].first) {
      cout << -1 << endl;
      return 0;
    }
    C[paa[i].second] = pab[i].second;
  }
  // rep(i, N){
  //   cout << C[i] << endl;
  // }

  BIT bit(N);
  ll ans = 0;
  rep(i, N){
    ans += i - bit.sum(C[i]);
    bit.add(C[i], 1);
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

vector<ll> edges[1100][26];
vector<vector<ll>> paths(1100000);
ll dist[1100000];

int main(){
    ll n, m; cin >> n >> m;
    REP(i,m) {
        ll a, b; char c; cin >> a >> b >> c; a--; b--; c-='a';
        edges[a][c].pb(b); edges[b][c].pb(a);
    }
    REP(i,n) REP(j,n) {
        ll from = i*n+j;
        REP(k,26) {
            for (ll ito : edges[i][k]) for (ll jto : edges[j][k]) {
                ll to = ito*n+jto;
                paths[from].pb(to);
            }
        }
    }
    REP(i,1100000) dist[i]=INF;
    queue<ll> q;
    q.push(n-1); dist[n-1]=0;
    while (!q.empty()) {
        ll nat = q.front(); q.pop();
        for (ll nex : paths[nat]) {
            if (dist[nex]!=INF) continue;
            dist[nex]=dist[nat]+1;
            q.push(nex);
        }
    }

    ll ans = INF;
    REP(i,n) {
        ans = min(ans,2*dist[i*n+i]);
        REP(j,26) for (ll to : edges[i][j]) {
            ans = min(ans,2*dist[i*n+to]+1);
        }
    }
    if (ans==INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(x, L, R) for(int x = (L), _x = (R); x <= _x; x++)
#define per(x, R, L) for(int x = (R), _x = (L); x >= _x; x--)
#define broken fprintf(stderr, "running on %s %d\n", __FUNCTION__, __LINE__)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define SZ(v) (int)(v).size()
#define ALL(x) (x).begin(), (x).end()
#define x first
#define y second
#define mp make_pair
#define pb push_back

template<typename T> inline bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef pair<int, int> par;
typedef long long LL;
typedef unsigned long long uLL;
typedef double db;
const int N = 2e5 + 10;
struct Edge {
	int to, nxt;
}e[N << 1];
int head[N], tot = 0;
int n, ans[N], idt = 1;
int pa[N], vis[N];
int mxd, id;

void adde(int u, int v) { e[++tot] = Edge{v, head[u]}, head[u] = tot; }

void Dfs(int u, int fa, int dep) {
	pa[u] = fa;
	if(dep > mxd) {
		id = u, mxd = dep;
	}
	for(int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(v == fa) continue;
		Dfs(v, u, dep + 1);
	}
	return;
}
void con(int u, int fa) {
	ans[u] = idt;
	for(int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(v == fa || vis[v]) continue;
		idt++;
		con(v, u);
		idt++;
	}
	for(int i = head[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(v == fa || !vis[v]) continue;
		idt++;
		con(v, u);
	}
	return;
}

int main() {
	cin >> n;
	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adde(u, v), adde(v, u);
	}
	mxd = id = -1;
	Dfs(1, 0, 0);
	int S = id;
	mxd = id = -1;
	Dfs(S, 0, 0);
	int T = id;
	for(int u = T; u; u = pa[u]) vis[u] = 1;
	con(S, 0);
	for(int i = 1; i <= n; i++) cout << ans[i] <<" ";
	cout << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef map<ll, ll> ml;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

ll itr1, itr2, M1 = 0, M2 = 0;
bool found = 0;
vl e, d1, d2;
vb diam;
vvl G;

void dfs1(ll v) {
  for(ll u: G[v]) {
    if(d1[u] == INF) {
      d1[u] = d1[v] + 1;
      dfs1(u);
    }
  }
  return;
}

void dfs2(ll v) {
  for(ll u: G[v]) {
    if(d2[u] == INF) {
      d2[u] = d2[v] + 1;
      dfs2(u);
    }
  }
  return;
}

void dfs3(ll v) {
  if(v == itr2) {
    found = 1;
    return;
  }
  for(ll u: G[v]) {
    if(found) break;
    if(d2[v] < d2[u]) dfs3(u);
    if(found) diam[u] = 1;
  }
  return;
}

ll dfs4(ll v, ll num) {
  e[v] = num;
  ll last = -1;
  for(ll u: G[v]) {
    if(e[u] == INF) {
      if(diam[u]) {
        last = u;
        continue;
      }
      num = dfs4(u, num+1);
    }
  }
  if(last != -1) num = dfs4(last, num+1);
  if((rand()%4 == 0) && !diam[v]) e[v] = num;
  return num+1;
}

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

  ll n, a, b;
  cin >> n;
  e = vl(n, INF);
  d1 = vl(n, INF);
  d2 = vl(n, INF);
  diam = vb(n, 0);
  G = vvl(n);
  rep(_, n-1) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  d1[0] = 0;
  dfs1(0);
  rep(i, n) if(chmax(M1, d1[i])) itr1 = i;
  d2[itr1] = 0;
  dfs2(itr1);
  rep(i, n) if(chmax(M2, d2[i])) itr2 = i;
  diam[itr1] = 1;
  dfs3(itr1);
  dfs4(itr1, 1);
  rep(i, n) cout << e[i] << ' ';
  cout << newl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  char* cstr = new char[N];

  strcpy(cstr, S.c_str());

  bool f = true;
  for(int i = 0; i < N; ++ i){
    if((i + 1) % 2 == 1){ // 奇数
      if(+cstr[i] < 91){
        f = false;
        break;
      }
    }else{ // 偶数
      if(+cstr[i] > 96){
        f = false;
        break;
      }
    }
  }

  if(f){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  bool check[202020] = {}; int n; cin >> n;
  int now = 0;
  rep(i, n){
    int x; cin >> x; check[x] = true;
    if(!check[now]){
      cout << now << endl; continue;
    }
    else{
      while(check[now]){
        now++;
      }
    }
    cout << now << endl;
  }
}


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

#include <iostream>
#include <fstream>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>

#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>

#ifndef CONTESTS_CPP_MY_ALIASES_HPP
#define CONTESTS_CPP_MY_ALIASES_HPP

#include <utility>
#include <cstdint>

#include <limits>

using pii = std::pair<int, int>;
using pll = std::pair<int64_t, int64_t>;
using pli = std::pair<int64_t, int>;
using tiii = std::tuple<int, int, int>;
using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
#if __x86_64__ && __GNUG__
using int128 = __int128;
using uint128 = unsigned __int128;
#else
using int128 = ll;
using uint128 = ull;
#endif
using vc = std::vector<char>;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;

#define fori(n) for (int i = 0; (i) < (int) (n); ++i)
#define forj(n) for (int j = 0; (j) < (int) (n); ++j)
#define rofi(n) for (int i = (int) (n); (i) >= 0; --i)
#define rofj(n) for (int j = (int) (n); (j) >= 0; --j)
#define forn(i, n) for(int i = 0; i < (int) (n); ++i)
#define fore(i, l, r) for(int i = (int) (l); i < (int) (r); ++i)
#define sqr(x) ((x)*(x))
#define pow2(x) ((ull)1 << static_cast<uint64_t>(x))
#define div2k(x, k) (static_cast<uint64_t>(x) >> static_cast<uint64_t>(k))
#define div2(x) div2k(x, 1ULL)
#define divUP(a, b) ((a)+(b)-1)/(b)
#define lowest_significant_bit(x) (static_cast<ull>(x) & -static_cast<ull>(x))
#define count_set_bits(x) __builtin_popcountll(static_cast<ull>(x))
#define sz(x) (static_cast<int>((x).size()))
#define is_odd(x) static_cast<bool>(static_cast<uint64_t>(x) & 1ULL)
#define is_even(x) (!(is_odd(x)))
#define have_diff_parity(x, y) static_cast<bool>(is_odd(x) ^ is_odd(y))
#define have_same_parity(x, y) (!(have_diff_parity(x, y)))
#define All(x) (x).begin(), (x).end()
#define ENDL "\n"
#define FOR_ALL_TEST_CASES int MyTestCaseCounter; in >> MyTestCaseCounter; while(MyTestCaseCounter--)

#endif //CONTESTS_CPP_MY_ALIASES_HPP

class AHealthMDeath {

public:

    void solve(std::istream &in, std::ostream &out) {
        int m, h;
        in >> m >> h;
        if (h % m == 0) out << "Yes" << ENDL;
        else out << "No" << ENDL;
    }

    bool _my_clever_check(std::istream &input, std::istream &juryAnswer, std::istream &myAnswer) {
        return false;
    }
};

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    AHealthMDeath solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    fflush(stdout);
    return 0;
}

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (ll i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define all(v) v.begin(),v.end()
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(all(v))
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}

#define MAX_SIZE 10005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}

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

void solve(){
    ll n;
    cin>>n;
    ll l[n];
    vll v(n+1);
    fi(i,0,n)cin>>l[i],v[l[i]]=i+1;
    vll vis(n+1,0),q,w;
    //fi(i,1,n+1)cout<<v[i]<<nl;
    fi(i,1,n){
        if(v[i]<=i){
            cout<<-1<<nl;
            return;
        }
        for(ll j=v[i]-1;j>=i;j--){
            q.pb(j);
        }
        w.pb(i);
        fi(j,i-1,v[i]-2)w.pb(l[j]);
        l[v[i]-1]=l[v[i]-2];
        i+=max(0ll,v[i]-i-1);
    }
    ll k=0;
    fi(i,0,n-1){
        if(w[i]==i+1)k++;
    }
    if(k==n-1){
        fi(i,0,n-1)cout<<q[i]<<nl;
    }
    else cout<<-1<<nl;
//fi(i,0,n-1)cout<<q[i]<<nl;
}

int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi  = vector<int64_t>;
using vvi = vector<vi>;
using vc  = vector<char>;
using vvc = vector<vc>;
using vd  = vector<long double>;
using vvd = vector<vd>;
using pii = pair<int64_t, int64_t>;
using vvp = vector<vector<pii>>;
int64_t INF = 1e18;
int64_t mod = 1e9 + 7;

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

  string ns;
  rep(j, k) {
    ns = "";
    int a;
    if (n % 2 == 0) a = n /2;
    else a = n;
    for(int i = 0; i < n * 2; i += 2) {
      if (s[i % n] == s[(i+1) % n]) ns += s[i % n];
      else if ((s[i % n] == 'R' && s[(i+1) % n] == 'S') || (s[i % n] == 'P' && s[(i+1) % n] == 'R') || (s[i % n] == 'S' && s[(i+1) % n] == 'P')) ns += s[i % n];
      else ns += s[(i+1) % n];
    }
    s = ns;
    n = s.size();
  }
  cout << ns[0] << endl;
}

# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
#define MOD 1000000007
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int A1, A2, A3, A4;

int main(){
        cin >> A1 >> A2 >> A3 >> A4;

        cout << min(min(A1, A2), min(A3, A4)) << endl;
        return 0;
}


/*And I thought my jokes were bad*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("Viva la vida");
#define CHECK(x) cout << (#x) << " is " << (x) << endl;
#define nl puts("");
#define mp make_pair
#define IN(x) scanf("%d",&x);
#define INL(x) scanf("%lld",&x);
#define OUT(x) printf("%d",x);
#define OUTL(x) printf("%lld",x);
#define MAX 200005
#define MOD 1000000009
#define INF (1 << 31)
#define CASE(x,y) printf("Case %d: %d\n",++x,y);
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define PI acos(-1.0)
#define EPS 1e-19
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int ll
/*
	When I get older
	I will be stronger
	they'll call me freedom
	just like a waving flag
*/

void solve()
{
	int j,l,r,m,a,b,c,d,x,y,z,t,p;
	unsigned int i,n,k;
	cin>>n;
	x=n+1;
	i=1;

	for(j=30;j>=0;j--)
	{
		k=i+(1LL<<j);

		if(k*(k+1)/2<=x)
			i=k;
	}
	cout<<(n-i+1)<<endl;
}
int32_t main()
{
	FASTIO
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;

int main() {
    ll n; cin >> n;
    ll ng = 2ll * (ll)1e9;
    ll ok = 0;
    while(llabs(ok - ng) > 1ll) {
        ll x = (ok+ng) / 2;
        if(x * (x+1) / 2 <= (n+1)) ok = x;
        else ng = x;
    }
    cout << (n+1) - ok << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {int N;cin>>N;
            vector<long long>A(N),B(N);
            for(int i=0;i<N;i++)
              cin>>A.at(i);
            for(int i=0;i<N;i++)
              cin>>B.at(i);
            long long c=0;
            int d=0;
            for(int i=0;i<N;i++)
              {d=max<long long>(d,A.at(i));
               c=max(c,d*B.at(i));
              cout<<c<<endl;}

}

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int64_t> A(n), B(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());
    copy_n(istream_iterator<int64_t>(cin), n, B.begin());

    int64_t ma = 1, mab = 1;
    for (int i = 0; i < n; i++){
        ma = max(ma, A[i]);
        mab = max(mab, ma * B[i]);
        cout << mab << "\n";
    }
}


#include<bits/stdc++.h>
const int mod=3,N=600005;
using namespace std;

struct nd{
	int a,b;
	nd(int k=1){b=0;if(k)while(k%mod==0)k/=mod,b++;a=k%mod;}
	nd(int A,int B){a=A,b=B;}
	nd operator*(nd c){
		nd as=(nd){a*c.a%mod,b+c.b};
		return as;
	}
	nd operator/(nd c){
		nd as=(nd){a*c.a%mod,b-c.b};
		return as;
	}
	int operator~(){return b?0:a;}
}nw;

int a[N],n,ans;
char S[N];

int main(){
	a['R']=0,a['W']=1,a['B']=2;
	scanf("%d%s",&n,S+1);
	for(int i=1;i<=n;i++){
		ans+=~nw*a[S[i]];
		nd x(n-i),y(i);
		nw=nw*x/y;
	}
	if(!(n&1))ans=ans*2;
	if(ans%3==0)printf("R");
	else if(ans%3==1)printf("W");
	else printf("B");
}

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

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

/*
    前処理: O(MAX_N*MAX_N)
    nCk(n,k): nCk の計算。O(1)
*/
const int MAX_N = 60;         // n の最大値
vector<vector<long long>> com;  // 前計算の結果を保存

// 動的計画法で前処理
void init() {
    com.assign(MAX_N, vector<long long>(MAX_N));
    com[0][0] = 1;
    for (int i = 1; i < MAX_N; ++i) {
        com[i][0] = 1;
        for (int j = 1; j < MAX_N; j++) {
            com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]);
        }
    }
}
// nCk を取得
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return com[n][k];
}

int main(){
  ll A,B;
  ll K;
  cin>>A>>B>>K;
  init();
  string ANS="";
  while(A>0LL && B>0LL){
    //cout << A << " " << B << " " << K << endl;
    if(K <= nCk(A+B-1LL,B)){
      ANS = ANS +'a';
      A--;
    }
    else{
      ANS = ANS + 'b';
      K -= nCk(A+B-1LL,B);
      B--;
    }
  }
  if(A == 0LL){
    for(int i=0;i<(int)B;i++){
      ANS = ANS + 'b';
    }
  }
  else if(B == 0LL){
    for(int i=0;i<(int)A;i++){
      ANS = ANS + 'a';
    }
  }
  cout << ANS << endl;
}


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

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, W; cin >> N >> W;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> s(N), t(N), p(N); rep(i, N) cin >> s[i] >> t[i] >> p[i];
  vector<ll> a(200200, 0);

  bool ok = true;
  ll maxt = 0;
  rep(i, N) {
    a[s[i]] += p[i];
    a[t[i]] += -p[i];
    if(t[i] > maxt) maxt = t[i];
  }
  ll ttl = 0;
  rep(i, maxt + 1) {
    ttl += a[i];
    if(ttl > W) ok = false;
  }

  cout << (ok?"Yes":"No") << endl;
}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}

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

int main() {
    int N, X;
    cin >> N >> X;
    int num = 0;
  	int cnt = 0;
    int ans = -1;

    X *= 100;
    rep(i, N) {
        int V, P;
        cin >> V >> P;
        cnt += V * P;
        num++;
        if(cnt > X) {
            ans = num;
            break;
        }
    }

    cout << ans << endl;
}


/* Ahmed Maher ( Acro_14 )*/
/*while(WA)try();*/
#include <bits/stdc++.h>
using namespace std;

#define fastIO ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

typedef long long         ll;
typedef long double   	  ld;

typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

const ll OO = 0x3f3f3f3f;
int const N = 1e5+5;
int const mod = 1e9+7;

/*string Alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet="abcdefghijklmnopqrstuvwxyz";*/

void solve(){
string s,a="atcoder";
cin>>s;
int f=-1;
for(int i=0;i<s.size();i++){
    if(s[i]!='a'){
        f=i;
        break;
    }
}
if(f==-1){
    cout<<f<<endl;
}
else{
    if(s>a) f=0;
    if(s[f]>'t') f--;
    cout<<max(f,0)<<endl;
}
}
int main(){
    /*read
    write*/
    fastIO
    ll t ;
    cin>>t;
    while(t--){
         solve();
    }
    return 0;

}

//       int anss[t+1];
//            anss[j]=ans;
//     for(int j=1;j<=t;j++) printf("Case %d: %d\n",j,anss[j]);

#include<bits/stdc++.h>
using namespace std;
int main() {
  char a, b, c;
  cin >> a >> b >> c;
  cout << (a == b && b == c ? "Won\n" : "Lost\n");
  return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
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;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int A[505][505];
int B[505][505];

const int INF = 1001001001;
int dp[505][505];
struct State {
  int r, c;
  int cost;
  bool operator < (const State& o) const {
    return cost > o.cost;
  }
  int &ref() {
    return dp[r][c];
  }
};

int main2() {
  int R = nextLong();
  int C = nextLong();
  REP(i, R) REP(j, C-1) A[i][j] = nextLong();
  REP(i, R-1) REP(j, C) B[i][j] = nextLong();

  REP(i, R) REP(j, C) dp[i][j] = INF;
  priority_queue<State> pq;

  {
    State s = {0, 0, 0};
    pq.push(s);
    s.ref() = 0;
  }
  while (!pq.empty()) {
    auto cur = pq.top(); pq.pop();
    if (cur.r == R - 1 && cur.c == C - 1){
      break;
    }
    if (cur.cost != cur.ref()) continue;

    if (cur.c + 1 < C) {
      int nr = cur.r;
      int nc = cur.c + 1;
      int n_cost = cur.cost + A[cur.r][cur.c];
      if (dp[nr][nc] > n_cost) {
        dp[nr][nc] = n_cost;
        pq.push((State){nr, nc, n_cost});
      }
    }
    if (cur.c - 1 >= 0) {
      int nr = cur.r;
      int nc = cur.c - 1;
      int n_cost = cur.cost + A[cur.r][cur.c - 1];
      if (dp[nr][nc] > n_cost) {
        dp[nr][nc] = n_cost;
        pq.push((State){nr, nc, n_cost});
      }
    }
    if (cur.r + 1 < R) {
      int nr = cur.r + 1;
      int nc = cur.c;
      int n_cost = cur.cost + B[cur.r][cur.c];
      if (dp[nr][nc] > n_cost) {
        dp[nr][nc] = n_cost;
        pq.push((State){nr, nc, n_cost});
      }
    }
    for (int i = 1; i <= cur.r; i++) {
      int nr = cur.r - i;
      int nc = cur.c;
      int n_cost = cur.cost + (1 + i);
      if (dp[nr][nc] > n_cost) {
        dp[nr][nc] = n_cost;
        pq.push((State){nr, nc, n_cost});
      }
    }

  }

  ll ans = dp[R-1][C-1];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int f(int x){
	int ans=0;
	while (x){
		ans+=x%10;
		x/=10;
	}
	return ans;
}

int main(){
	int a,b;
	cin>>a>>b;
	printf("%d\n",max(f(a),f(b)));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__)
using ll=long long;using ld=double;using pii=pair<int,int>;using vi=vector<int>;
using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>;
#define pb push_back
#define mk make_pair
#define ins insert
#define era erase
#define fi first
#define se second
#define lowbit(x) x&-x
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
int _w,_t;FILE* _f;

const int N=2e5+5;

int n,m,a[N],len,b[N],cnt,ans;

void solve(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d",&a[i]);
    }
    a[++m]=n+1;
    sort(a+1,a+m+1);
    len=INF;
    for(int i=1;i<=m;i++){
        if(a[i]-a[i-1]-1){
            b[++cnt]=a[i]-a[i-1]-1;
            len=min(len,a[i]-a[i-1]-1);
        }
    }
    for(int i=1;i<=cnt;i++){
        // printf("%d%c",b[i]," \n"[i==cnt]);
        ans+=(b[i]+len-1)/len;
    }
    printf("%d\n",ans);
}

int main(){
    #ifdef MULTI_CASES
    _w=scanf("%d",&_t);while(_t--)
    #endif
    solve();
    return 0;
}

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

int main(){
  int n,m;
  cin>>n>>m;

  vector<long long>a(m,0);
  for(int i=0;i<a.size();i++)
    cin>>a.at(i);
  a.insert(a.begin(),0);
  a.push_back(n+1);
  sort(a.begin(),a.end());

  vector<long long>len;
  long long k=1000000000;
  for(int i=0;i<a.size()-1;i++){
    long long temp=0;
    temp=a.at(i+1)-a.at(i)-1;

    if(temp){
    len.push_back(temp);
    k=k<temp?k:temp;
    }
  }

  long long ans=0;
  for(int i=0;i<len.size();i++){
    ans+=len.at(i)/k;
    if(len.at(i)%k)
      ans++;
  }

  cout<<ans<<endl;

  return 0;
}


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

int combination(int n, int k){
  vector<vector<int>> comb(n + 1, vector<int>(k + 1, 0));
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= k && j <= i; j++){
//      printf("(i, j) = (%d, %d)\n", i, j);
      if(j == 0){
        comb[i][j] = 1;
      }
      else{
        comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
      }
//      printf("comb[%d][%d] = %d\n", i, j, comb[i][j]);
    }
  }
  return comb[n][k];
}

signed main(){
  int L;
  scanf("%lld", &L);
  printf("%lld\n", combination(L - 1, 11));
  return 0;
}

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

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)
#define repl(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; i++)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define mp make_pair

#define has_key(m, k) (m.find(k) != m.end())

#define INF (1e9)
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const ll mod = (1000000007);

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

#include <unordered_set>
#include <unordered_map>
class Radix
{
private:
    unordered_map<char, ull> a;

public:
    Radix(const char *s = "0123456789")
    {
        int i;
        for (i = 0; s[i]; ++i)
            a[s[i]] = i;
    }
    ull to(const std::string &t, ull p)
    {
        ull sm = a[t[0]];
        const int l = (int)t.length();
        for (int i = 1; i < l; ++i)
            sm = sm * p + a[t[i]];
        return sm;
    }
};

int main()
{
    std::string X;
    std::cin >> X;
    ull M;
    cin >> M;

    const ull start = (*std::max_element(X.begin(), X.end())) - '0';
    ull min_n = start + 1;
    ull max_n = M;
    if(X.size() != 1)
        max_n = max(pow(M,1.0l/(X.size()-1)),start) + 1;
    Radix r;
    ull ans = 0;

    ull mid_n;

    if (X.size() == 1)
    {
        if (stoull(X) <= M)
        {
            ans = 1;
        }
    }
    else if (r.to(X, min_n) <= M)
    {
        while (max_n != min_n)
        {
            mid_n = (min_n + max_n) / 2;
            const ull val = r.to(X, mid_n);
            if (val <= M)
            {
                min_n = mid_n;
            }
            else
            {
                max_n = mid_n;
            }
            if (min_n + 1 == max_n)
            {
                if (r.to(X, max_n) > M)
                {
                    max_n = min_n;
                }
                break;
            }
        }
        ans = max_n - start;
    }

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


//Problem link :
//done by ankit reddy
#include<bits/stdc++.h>
using namespace std;
#define loop(i,l,h)         for(int i=l;i<h;i++)
#define loopr(i,l,h) 		for(int i=(h);i>=(l);i--)
#define ll                  long long
#define ld      			long double
#define inf     			1e9
#define mod                 1000000007
#define pb                  push_back
#define rloop(i,l,h)        for(int i=l;i>h;i--)
#define vi                  vector<int>
#define vll 				vector<ll>
#define vs					vector<string>
#define pll 				pair<ll,ll>
#define pii 				pair<int,int>
#define ump 				unordered_map
#define mp 					make_pair
#define pq_max  			priority_queue<int>
#define pq_min				priority_queue<int,vector<int>,greater<int>>
#define pq_max_ll  			priority_queue<ll>
#define pq_min_ll			priority_queue<ll,vector<ll>,greater<ll>>
#define all(v)				v.begin(),v.end()
#define ff                  first
#define ss                  second
#define pii                 pair<int,int>
#define endl    			"\n"
#define yes 				cout<<"YES"<<endl;
#define no 					cout<<"NO"<<endl;
#define mid(l,r)    		(l+(r-l))/2
#define bitc(x)				__builtin_popcount(x)
#define iter(c,it)			for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define log(args...)		{string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
#define logarr(arr,a,b) 	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}

void err(istream_iterator<string> it){}
template<typename T,typename... Args>
void err(istream_iterator<string> it,T a,Args... args){
	cout<<*it<<" = "<<a<<endl;
	err(++it,args...);
}

void file_i_o(){
	ios_base::sync_with_stdio(false);

	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
int main(){
	file_i_o();
	clock_t begin=clock();
	ll a,b,c;
	cin>>a>>b>>c;
	if(c%2==0){
		if(a<0)a=a*(-1);
		if(b<0)b=b*(-1);
	}
	if(a==b)cout<<"="<<endl;
	else if(a>=0&&b>=0||c%2==0){

		cout<<((a>b)?">":"<")<<endl;

	}
	else if(a>=0&&b<=0)cout<<">"<<endl;
	else if(a<=0&&b>=0)cout<<'<'<<endl;

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

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	int ac_minus=c%2==1&a<0;
	int bc_minus=c%2==1&b<0;
	if(ac_minus!=bc_minus){
		if(ac_minus)
			cout<<"<";
		else
			cout<<">";
	}
	else{
		if(abs(a)<abs(b))
			cout<<"<";
		else if(abs(a)>abs(b))
			cout<<">";
		else
			cout<<"=";
	}
	return 0;
}


// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define endl "\n"
#define mod 1000000007
#define inf (int)1e18

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

    string s; cin >> s;
    bool ok1=1,ok2=1;

    for(int i=0;i<s.length();i++){
        if((i+1)%2==1){
            ok1 &= (s[i]>='a' and s[i]<='z');
        }else{
            ok2 &= (s[i]>='A' and s[i]<='Z');
        }
    }

    if(ok1&&ok2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

// general template {{{
// region
typedef int int_;
#define int int64_t

#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define db double

#define sz(x) x.size()
#define watch(x) cout << #x << " : " << x << endl;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){
    return out << "(" << a.first << ", " << a.second << ")";
}

template<class A>ostream& operator<<(ostream& out,const vector<A>&v) {
    out << "[";
    for(int i=0;i<sz(v);i++) {
        if(i) out << ", ";
        out << v[i];
    }
    return out << "]" << endl;
}

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

const int64_t mod = 1e9 + 7;

int Mod(int x) {
    x %= mod;
    if(x<0) x += mod;
    return x;
}

int Pow(int x,int n) {
    if(n == 0) return 1;
    int t = Pow(x,n/2);
    t = Mod(t*t);
    if(n&1) t = Mod(t*x);
    return t;
}

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

int_ main() {
    fast;
    int n; cin >> n;

    vvi g(n+1);

    for(int i=0;i<n;i++) {
        g[i].pb((2*i)%n);
        g[i].pb((2*i + 1)%n);
    }

    for(int i=1;i<=n;i++) {
        // cout << i << " : ";
        for(int x:g[i-1]) cout << x+1 << " ";
        cout << endl;
    }
}


#include<cstdio>
#include<cstring>
using namespace std;
long long answer,ans=1;
long long used[20],x[101];
bool prime[101];
int n;
long long gcd(long long x,long long y)
{
	if (y==0) return x;
	return gcd(y,x%y);
}
void dfs(int k,long long sum)
{
	if (k>used[0])
	{
		bool bo=false;
		for (int i=1;i<=n;i++)
		{
			if (gcd(sum,x[i])==1)
			{
				bo=true;break;
			}
		}
		if (!bo)
			if (answer>sum) answer=sum;
		return;
	}
	dfs(k+1,sum*used[k]);
	dfs(k+1,sum);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&x[i]);
	long long ans=1;
	memset(prime,true,sizeof(prime));
	for (int i=2;i<=50;i++)
		for (int j=2;j<i;j++)
			if (i%j==0) prime[i]=false;
	ans=1;
	for (int i=1;i<=n;i++)
		if (prime[x[i]]&&x[i]*2>50) ans*=x[i];
	for (int i=1;i<=25;i++)
		if (prime[i])
			used[++used[0]]=i;
	answer=3e18;
	dfs(1,ans);
	printf("%lld\n",answer);
}

#include<bits/stdc++.h>
#define N 500005
using namespace std;
int n,zs,zt;
char s[N],t[N];
int front[N],behind[N];
void init(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>s[i];
		if(s[i]=='0')zs++;
	}
	for(int i=1;i<=n;i++){
		cin>>t[i];
		if(t[i]=='0')zt++;
	}
}
int main(){
	init();
	if(zs!=zt)printf("-1");
	else{
		int ans=zs;
		int nums=0,numt=0;
		for(int i=1;i<=n;i++){
			if(s[i]=='0')nums++;
			if(t[i]=='0')numt++;
			if(s[i]=='0'&&t[i]=='0'&&nums==numt){
				ans--;
			}
		}
		printf("%d",ans);
	}
	return 0;
}


#include<iostream>
using namespace std;
typedef long long ll;
const ll N = 2e5+10;
ll a[N],b[N],maxn[N],c[N];
ll n;
int main(){
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    maxn[1]=a[1];
    for(ll i=2;i<=n;i++){
        if(a[i]>maxn[i-1]){
            maxn[i]=a[i];
        }
        else{
            maxn[i]=maxn[i-1];
        }
    }
    b[1]=a[1];
    for(ll i=2;i<=n;i++){
        b[i]=b[i-1]+a[i];
    }
    c[1]=b[1];
    for(ll i=2;i<=n;i++){
        c[i]=c[i-1]+b[i];
    }

    for(ll i=1;i<=n;i++){
        ll ans = b[i]+c[i-1]+i*maxn[i];
        cout<<ans<<endl;
    }
}

#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll  = long long int;
using pii = pair<ll, ll>;
using vi = vector<ll>;
template <typename T> void out(const T& t) {cout << t << '\n';}
vi vin(int n) {vi res(n); for(auto&i:res)cin>>i; return res;}
ll in() {ll x; cin>>x; return x;}

const ll MOD = 998244353;
const int N = 2e5 + 5;
ll two[N];
ll twoinv = 499122177;
ll mmod(ll x, ll y) {
    if (x >= 0LL)
        return x % y;
    else
        return (y - (-x) % y) % y;
}
void solve() {
    two[0] = 1;
    for (int i = 1; i < N; ++i) two[i] = 2 * two[i-1] % MOD;
    ll n = in();
    vi a = vin(n);
    sort(all(a));
    ll f = 0;
    for (int i = n - 2; i >= 0; --i) f =(f+ a[i] * two[n - 2 - i]) % MOD;
    ll ans = (f+a[n-1]) * a[n-1]%MOD;
    for (int i = n - 2; i >= 0; --i) {
        f = mmod(f-a[i], MOD);
        f=f*twoinv%MOD;
        ans =(ans + a[i] * f) % MOD;
        ans =(ans + a[i]*a[i])%MOD;
        ans = ans % MOD;
    }
    out(ans);
}

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


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

int main()
{
  long double sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;

  long double ans = (sx * gy + sy * gx) / (sy + gy);
  cout << fixed << setprecision(10) <<ans;
}

#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;

int main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  gy *= -1;

  cout << setprecision(12) << - (double) (gx - sx) / (gy - sy) * sy + sx << endl;
  return 0;
}


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 400005;
const int INF = 1e12;

int a[2*N], b[2*N], sa[4*N], sb[4*N];

void change_a(int p, int value, int val_sum = 0) {
    for (a[p + N] += value, sa[p += N] += val_sum; p > 1; p >>= 1) a[p>>1] = a[p] + a[p^1], sa[p>>1] = sa[p] + sa[p^1];
}

void change_b(int p, int value, int val_sum = 0) {
    for (b[p + N] += value, sb[p += N] += val_sum; p > 1; p >>= 1) b[p>>1] = b[p] + b[p^1], sb[p>>1] = sb[p] + sb[p^1];
}

int query_a(int l, int r) {
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res += a[l++];
    if (r&1) res += a[--r];
  }
  return res;
}

int query_b(int l, int r) {
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res += b[l++];
    if (r&1) res += b[--r];
  }
  return res;
}

int sum_a(int l, int r) {
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res += sa[l++];
    if (r&1) res += sa[--r];
  }
  return res;
}

int sum_b(int l, int r) {
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l&1) res += sb[l++];
    if (r&1) res += sb[--r];
  }
  return res;
}

signed main()
{
    FAST
    int tc=1;
    // cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,m,q;
        cin>>n>>m>>q;
        set<int> s;
        int arr[n] = {}, brr[m] = {};
        int t[q], x[q], y[q];
        s.insert(0);
        for(int i=0;i<q;i++)
        {
            cin>>t[i]>>x[i]>>y[i];
            x[i]--;
            s.insert(y[i]);
        }
        map<int, int> mp;
        int ind = 0;
        for(int i:s) mp[i] = ind++;
        change_a(0, n);
        change_b(0, m);
        int ans = 0;
        for(int i=0;i<q;i++)
        {
            if(t[i] == 1)
            {
                ans -= sum_b(mp[arr[x[i]]]+1, N);
                ans -= (query_b(0,mp[arr[x[i]]]+1)*arr[x[i]]);
                change_a(mp[arr[x[i]]], -1, -arr[x[i]]);
                change_a(mp[y[i]], 1, y[i]);
                ans += (query_b(0,mp[y[i]]+1)*y[i]);
                ans += sum_b(mp[y[i]]+1, N);
                arr[x[i]] = y[i];
            }
            else
            {
                ans -= sum_a(mp[brr[x[i]]]+1, N);
                ans -= (query_a(0,mp[brr[x[i]]]+1)*brr[x[i]]);
                change_b(mp[brr[x[i]]], -1, -brr[x[i]]);
                change_b(mp[y[i]], 1, y[i]);
                ans += (query_a(0,mp[y[i]]+1)*y[i]);
                ans += sum_a(mp[y[i]]+1, N);
                brr[x[i]] = y[i];
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using lli = long long;
using vi = vc<int>;
using ii = pair<int,int>;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }
lli poww(lli a, lli b){
	lli res = 1;
	while(b){ if(b&1) res = res*a; a=a*a; b>>=1;}
	return res;
}

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

template<class t,class u>bool mmax(t&a,u b){if(a<b)a=b;return a<b;}
template<class t,class u>bool mmin(t&a,u b){if(b<a)a=b;return b<a;}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- しゃけ ツナマヨ ('-')7
typedef struct node *pn;
struct node{
	array<lli,2>a;
	pn l,r;
	node(){a[0]=a[1]=0; l = r = 0;}
};

lli g0(pn u){
	if(u)return u->a[0];
	return 0;
}

lli g1(pn u){
	if(u)return u->a[1];
	return 0;
}

array<lli,2> SUM(array<lli,2> a, array<lli,2> b){
	return {a[0]+b[0],a[1]+b[1]};
}

void upd(pn &u, int l, int r, int val, int side){
	if(l>r)return;
	if(l==r){
		u->a[0]+=side;
		u->a[1]=(u->a[0])*val;
		return;
	}
	int mid = (l+r)/2;
	if(val<=mid){
		if(!u->l)u->l = new node();
		upd(u->l,l,mid,val,side);
	}
	else{
		if(!u->r)u->r = new node();
		upd(u->r,mid+1,r,val,side);
	}
	u->a[0]=g0(u->l)+g0(u->r);
	u->a[1]=g1(u->l)+g1(u->r);
}

array<lli,2> find(pn &u, int l, int r, int ll, int rr){
	if(!u or l>r or l>rr or r<ll)return {0,0};
	if(ll<=l and r<=rr)return {g0(u),g1(u)};
	int mid = (l+r)/2;
	return SUM(find(u->l,l,mid,ll,rr), find(u->r,mid+1,r,ll,rr));
}

int main(){_

	auto solve=[&](){
		int L = 0, R = 1e8+5;
		int n,m,q; cin>>n>>m>>q;
		pn A = new node(), B = new node();
		upd(A,L,R,0,n);
		upd(B,L,R,0,m);
		vi aa(n,0), bb(m,0);
		lli sum = 0;
		auto g=[&](pn &a, pn &b, int &x, int y){
			auto tot = find(a,L,R,L,R);
			auto aux = find(a,L,R,L,x);
			sum-= (tot[1]-aux[1])+aux[0]*x;
			upd(b,L,R,x,-1);
			x = y;
			upd(b,L,R,x,+1);
			aux = find(a,L,R,L,x);
			sum+=(tot[1]-aux[1])+aux[0]*x;
		};
		fore(i,0,q){
			int t,x,y; cin>>t>>x>>y; x--;
			if(t==2)g(A,B,bb[x],y);
			else g(B,A,aa[x],y);
			cout<<sum<<ENDL;
		}

	};
	//int t; cin>>t; while(t--)
		solve();

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_backk
#define pp pair
int main()
{
	int tt;
	tt=1;
	while(tt--)
	{
       ll n;
       cin>>n;
       ll ans=0,spit=n+1;
       ll kk=1;
       while(spit>=kk)
       {
       	ans++;
       	spit-=kk;
       	kk+=1;
       }
       cout<<n-ans+1<<endl;
	}
	return 0;
}

#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int64 n;
  cin >> n;
  __int128 sum = (__int128)n * (n + 1) / 2;
  __int128 low = 0, high = n;
  while (low != high) {
    __int128 mid = (low + high) / 2;
    __int128 cur = (n + 1 + n + 1 - mid + 1) * mid / 2;
    if (cur < sum) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }
  cout << (int64)high << '\n';
  return 0;
}


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

const ll MOD = 1000000007;
const int INF = 1e9;
// using Graph = vector<vector<int>>;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<pair<int,int>> r(n);
  vector<int> ansa(n);
  vector<int> ansb(n);
  vector<int> ansc(n);
  vector<int> ansd(n);
  vector<int> fansa(n);
  vector<int> fansb(n);
  vector<int> fansc(n);
  vector<int> fansd(n);
  rep(i,n){
    cin >> x[i] >> y[i] >> r[i].first;
    r[i].second = i;
  }
  vector<vector<int>> distx(n, vector<int> (n));
  vector<vector<int>> disty(n, vector<int> (n));
  vector<int> midistu(n,INF);
  vector<int> midistd(n,INF);
  vector<int> midistl(n,INF);
  vector<int> midistr(n,INF);
  rep(i,n){
    rep(j,n){
      distx[i][j] = x[i]-x[j];
      disty[i][j] = y[i]-y[j];
      if(distx[i][j]>0) midistl[i] = min(midistl[i],distx[i][j]);
      else midistr[i] = min(midistr[i],(-1*distx[i][j]));
      if(disty[i][j]>0) midistd[i] = min(midistd[i],disty[i][j]);
      else midistu[i] = min(midistu[i],(-1*disty[i][j]));
    }
  }
  rep(i,n){
  int a = x[i]-midistl[i];
  int b = y[i]-midistd[i];
  int c = x[i]+midistr[i];
  int d = y[i]+midistu[i];
  a = max(0,a);
  b = max(0,b);
  c = min(10000,c);
  d = min(10000,d);
  cout << a << " " << b << " " << c << " " << d << endl;
  }
}

#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);
	auto s=read<string>();
	cauto t=read();
	rep(_,t){
		auto a=s,b=s;
		sort(rall(a));
		sort(all(b));
		s=to_string(stoi(a)-stoi(b));
		out(s,a,b,1);
	}
	cout<<s NL;
  return 0;
}


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

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

  int n;
  cin >> n;
  vector<pair<int, int>> pos(n);
  for (auto &&[x, y] : pos) {
    cin >> x >> y;
  }
  auto judge = [&](double r) -> bool {
    queue<int> q;
    for (auto i = 0; i != n; ++i) {
      if (100 - r < pos[i].second + r) {
        q.push(i);
      }
    }
    vector<bool> used(n);
    while (!q.empty()) {
      auto id = q.front();
      q.pop();
      if (used[id]) continue;
      used[id] = true;
      for (auto i = 0; i != n; ++i) {
        if (hypot(pos[i].first - pos[id].first,
                  pos[i].second - pos[id].second) < 2 * r) {
          q.push(i);
        }
      }
    }
    for (auto i = 0; i != n; ++i) {
      if (used[i]) {
        if (r - 100 > pos[i].second - r) {
          return false;
        }
      }
    }
    return true;
  };
  constexpr double eps = 1e-4;
  double ok = 0, ng = 100;
  while (ng - ok > eps) {
    auto r = (ok + ng) / 2;
    if (judge(r))
      ok = r;
    else
      ng = r;
  }
  cout << ok << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T> bool chmin(T &a, T b) {if(a>b){a=b; return 1; } return 0; }
int h, w;

#ifndef dijkstra_hpp
#define dijkstra_hpp

#include<vector>
#include<queue>
#include<utility>

struct Dijkstra {
	// Edge: 辺の情報の構造体
	private:
		const long long MAX_DIST = 1e18;
		struct Edge {int to; long long cost; };
		int n;
		std::vector<std::vector<Edge>> es;
		std::vector<long long> dist;
	public:
		Dijkstra(int _n): n(_n), es(_n), dist(_n){}
		void add_edge(int from, int to, long long cost) {
			es[from].push_back(Edge{to, cost});
		}
		void solve(int s) {
			for (int i = 0; i < n; ++i) dist[i] = MAX_DIST;
			dist[s] = 0;
			std::priority_queue<std::pair<long long,int>, std::vector<std::pair<long long,int>>, std::greater<std::pair<long long,int>>> q;
			q.push({0, s});
			while (!q.empty()) {
				auto p = q.top(); q.pop();
				int v = p.second;
				if (dist[v] < p.first) continue;
				if (v >= w) {
					for (int i = 1; i <= v/w; ++i) {
						int to = v - i*w;
						if (chmin(dist[to], dist[v] + i+1)) {
							q.push({dist[to], to});
						}
					}
				}
				for (Edge e: es[v]) {
					if (dist[e.to] > p.first + e.cost) {
						dist[e.to] = p.first + e.cost;
						q.push({dist[e.to], e.to});
					}
				}
			}
		}
		long long get_dist(int t) {
			return dist[t];
		}
};

#endif // dijkstra_hpp

int main() {
	cin >> h >> w;
	Dijkstra g(h*w);
	vector<vector<int>> a(h, vector<int>(w));
	rep(i,h) {
		rep(j,w-1) {
			cin >> a[i][j];
		}
	}
	rep(i,h) {
		rep(j,w) {
			int now = i*w+j;
			if (0 < j) g.add_edge(now, now-1, a[i][j-1]);
			if (j < w-1) g.add_edge(now, now+1, a[i][j]);
		}
	}
	int b;
	rep(i,h-1) {
		rep(j,w) {
			cin >> b;
			int now = i*w+j;
			g.add_edge(now, now+w, b);
		}
	}

	g.solve(0);

	cout << g.get_dist(h*w-1) << endl;
}


#line 1 "main_c.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;

#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n;

  std::cin>>n;

  std::vector<i64> pe(2*n,-1);

  std::vector<bool> dp(n+1,false);
  dp[0]=true;

  rep(i,0,n){
    i64 a,b;
    std::cin>>a>>b;
    if(a!=-1){
      a--;
      if(pe[a]!=-1){
        std::cout<<"No\n";
        return 0;
      }
      pe[a]=i;
    }
    if(b!=-1){
      b--;
      if(pe[b]!=-1){
        std::cout<<"No\n";
        return 0;
      }
      pe[b]=i+n;
    }
  }

  rep(i,1,n+1){
    rep(j,0,i){
      i64 len=i-j;
      bool val=dp[j];
      rep(k,2*j,2*j+len){
        if(pe[k]==-1){
          if(pe[k+len]!=-1&&pe[k+len]<n)val=false;
        }else{
          if(pe[k] >=n) val=false;
          if((pe[k+len]!=-1)&&(pe[k+len]!=pe[k]+n))val=false;
        }
      }
      if(val)dp[i]=true;
    }
  }

  debug(pe);
  debug(dp);

  if(dp[n])std::cout<<"Yes\n";
  else std::cout<<"No\n";

  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
// #define Vector vector
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define int long long int
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void solve(){
    int n;
    cin >> n;
    vll a(n);
    f(i, 0, n){
        cin >> a[i];
    }
    sort(all(a));
    int aage = n-1;
    int sum = 0;
    f(i, 0, n){
        int piche = n - aage - 1;
        sum += piche*a[i]-aage*a[i];
        aage--;
    }

    cout << sum << nl;
    return ;
}
main()
{
    IO;
    int T = 1;
    // cin >> T;
    for(int c=1; c <= T; c++){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}


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

int t[10][10],a[12];
int n,k,ans;
int main()
{
  cin>>n>>k;

  for(int i=1;i<=n;i++)
   for(int j=1;j<=n;j++)
    cin>>t[i][j];

   for(int i=1;i<=n;i++) a[i]=i;

   do{
   	 int sum=0;
   	 for(int i=2;i<=n;i++)
   	 {
   	 	sum+=t[a[i-1]][a[i]];
	 }
	 sum+=t[a[n]][1];

	 if(sum==k)
	  ans++;
   	}while(next_permutation(a+2,a+n+1));

   	cout<<ans<<endl;
   	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 a[10];

int main()
{
	int sum=0;
	for(int i=1;i<=4;i++) sum+=(a[i]=read());
	if(sum&1) puts("No");
	else
	{
		for(int i=1;i<4;i++)
			if(a[i]==sum-a[i])
			{
				puts("Yes");
				return 0;
			}
		for(int i=1;i<4;i++)
			for(int j=i+1;j<=4;j++)
				if(a[i]+a[j]==sum-a[i]-a[j])
				{
					puts("Yes");
					return 0;
				}
		puts("No");
	}
	return 0;
}


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

int n;
struct CH
{
	string s;
	int v;
}Ty[1010];

bool cmp(CH x,CH y)
{
	return x.v>y.v;
}

template<typename Tp>
void read(Tp &x)
{
	x=0;int f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}x*=f;
}

int main()
{
	read(n);
	for(int i=1;i<=n;i++)
	{
		cin>>Ty[i].s;
		read(Ty[i].v);
	}
	sort(Ty+1,Ty+n+1,cmp);
	cout<<Ty[2].s<<endl;
	return 0;
}

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

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    string n;int k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        string a = n;
        sort(a.begin(),a.end());
        int an = 0,bn = 0;
        for(int i=0;i<(int)(a.size());i++){
            an = (an*10)+(a[i]-'0');
        }
        for(int i=(int)a.size()-1;i>=0;i--){
            bn = (bn*10)+(a[i]-'0');
        }
        n = to_string((bn-an));
    }
    cout << n << '\n';
    return 0;
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100100;
const int maxn = 17;
int n, m;
int dist[maxn][maxn];
int dp[1<<maxn][maxn];

int dfs(int s, int v){

    if(dp[s][v] >= 0){
        return dp[s][v];
    }

    if(s == (1<<n)-1 && v == 0){
        return dp[s][v] = 0;
    }

    int ans = inf;
    rep(u,0,n){
        if(!(s >> u & 1)){
            ans = min(ans, dfs(s | 1 << u, u) + dist[v][u]);
        }
    }

    dp[s][v] = ans;
    return ans;

}

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

    cin >> n;

    memset(dp,-1,sizeof(dp));
    fill(dist[0],dist[0]+maxn*maxn,inf);

    vector<vector<int>> vec(n,vector<int>(3));
    for(int i=0;i<n;i++){
        cin>>vec[i][0]>>vec[i][1]>>vec[i][2];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dist[i][j]=inf;
            else{
                int tmp;
                if((0>vec[j][2]-vec[i][2]))tmp=0;
                else tmp=vec[j][2]-vec[i][2];
                dist[i][j]=abs(vec[j][0]-vec[i][0])+abs(vec[j][1]-vec[i][1])+tmp;
            }
        }
    }
    int ans = dfs(0,0);
    cout << (ans == inf ? -1 : ans) << endl;

}

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

  vl as, bs;
  for (ll i = 1; i < 1e18; i *= 3) {
    as.push_back(i);
  }
  for (ll i = 1; i < 1e18; i *= 5) {
    bs.push_back(i);
  }
  ll N; cin >> N;
  FOR(i, 1, sz(as)) {
    ll b = N - as[i];
    auto bp = lower_bound(rng(bs), b);
    if (*bp==b && bp != bs.begin()) {
      cout << i << ' ' << (bp - bs.begin()) << newl;
      return 0;
    }
  }
  cout << -1;
}
#endif


using namespace std;
#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++)
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a. end())
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<ll>> vvll;
typedef long double ld;
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;

    if(c%2==0){
        if(abs(a)==abs(b))cout << "=" << endl;
        if(abs(a)<abs(b))cout << "<" << endl;
        if(abs(a)>abs(b))cout << ">" << endl;
    }
    if(c%2==1){
        if(a==b)cout << "=" << endl;
        if(a<b)cout << "<" << endl;
        if(a>b)cout << ">" << endl;
        }
}


#include <iostream>
using namespace std;

int main() {
	int n,x;
	cin >> n >> x;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
	}
	int count=0;
	for(int i=0;i<n;i++){
		count=count+a[i]*b[i];
		if(count>100*x){
			cout << i+1 << endl;
			break;
		}
		if((i==n-1)&&(count<=100*x)){
			cout << -1 << endl;
		}

	}

}

/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*                                                                                *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                *
\*********************************************************************************/

//Now Write to Code ___________________________

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

typedef    long long             ll;
typedef    long double           ld;
typedef    unsigned long long    ull;
typedef    pair<int,int>         pii;
typedef    pair<ll,ll>           pll;
typedef    vector<int>           vi;
typedef    vector<ll>            vll;
typedef    vector<vector<int>>   vvi;

inline     int         Int(){int x; cin >> x; return x;}
inline     ll          Long(){ll x; cin >> x; return x;}
inline     float       Float(){float x; cin >> x; return x;}
inline     double      Double(){double x; cin >> x; return x;}
inline     void        Yes(){cout << "Yes" << endl;}
inline     void        No(){cout << "No" << endl;}
inline     void        YES(){cout << "YES" << endl;}
inline     void        NO(){cout << "NO" << endl;}

const      int N       =(int)2e5 + 5;
const      int maxN    =(int)1e6 + 6;
const      ll  Mod     =(ll)1e9 + 7;
const      int inf     =(int)2e9;
const      ll  Inf     =(ll)1e18;

#define    fastio      ios_base::sync_with_stdio(false),cin.tie(NULL)
#define    T           int t,q; cin >> t; for(q=1;q<=t;q++)
#define    Forn(i,n)   for(int i=0;i<n;i++)
#define    ForN(i,n)   int i;for(i=n-1;n>=0;i--)
#define    forn(i,n)   for(int i=1;i<=n;i++)
#define    forN(i,n)   int i;for(i=n;n>=1;i--)
#define    fors(i,s)   for(int i=0;i<s.size();i++)
#define    Sort(s)     sort(s.begin(),s.end())
#define    debug(x)    cerr << #x << " = " << x << '\n' ;
#define    rep(i,b,e)  for(__typeof(e) i=(b); i!=(e+1)-2*(b>e); i=i+1-2*(b>e))
#define    gcd(a,b)    __gcd(a , b)
#define    lcm(a,b)    (a*(b/__gcd(a,b)))
#define    gt          greater<int>()
#define    Int         Int()
#define    Long        Long()
#define    Float       Float()
#define    Double      Double()
#define    all(x)      x.begin() , x.end()
#define    sz(x)       (int)x.size()
#define    ff          first
#define    ss          second
#define    pb          push_back
#define    eb          emplace_back
#define    mp          make_pair
#define    mem(a)      memset(a,0,sizeof a)
#define    memn(a)     memset(a,-1,sizeof a)
#define    biday       return 0
#define    nl          endl
#define    sp(n)       fixed<<setprecision(n)
#define    pi          acos(-1)
#define    PI          3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342

int main()
{
    int n,x,i;
    double sum=0;
    cin >> n >> x;

    int v[n],p[n];
    x*=100;
    for(i=0; i<n; i++)cin >> v[i] >> p[i];
    for(i=0; i<n; i++)
    {
    	sum+=((double)v[i]*(double)p[i]);
    	if(sum>x)
    	{
    		cout << i+1 << endl;
    		break;
    	}
    }
    if(sum<=x)cout << -1 << endl;

    biday;
}

//...............BYE BYE................


#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int a,b;cin>>a>>b;if(a==b)cout<<a<<endl;else cout<<3-a-b<<endl;
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define M 1000000007
#define pb push_back
#define bg begin
#define pob pop_back
#define rep(x,y,j) for(ll j = x;j < y ;j++)
#define sz size
#define ss second
#define ff first
#define SUM accumulate
#define INF 2000000000000000000
#define SPACE " "
#define vr std::vector
#define que queue
#define dqu deque
#define stk stack
#define pqu priority_queue
#define mst multiset
#define pf push_front
#define pof pop_front
#define sqr(x) ((x)*(x))
#define cube(x) (x)*sqr(x)

void solve(){
  // std::cout << std::setprecision(9) << std::showpoint << std::fixed;
  ll x,y;
  cin >> x >> y;
  set <ll> s{0,1,2};
  if (x == y )
  {
    cout << x << endl;
    /* code */
  }
  else
  {
    s.erase(x);
    s.erase(y);
    cout << *(s.bg())<<endl;

  }

}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int tt= 1;
  // cin >> tt;
  while (tt--) {
    solve();

  }
  return 0;
}


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

using namespace std;

using ll = int64_t;
using db = double;
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) cerr << #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(x) cout<<((x)?"Yes":"No")<<newl;
#define YESNO(x) cout<<((x)?"YES":"NO")<<newl;
#define v(T) vector<T>
#define vv(T) vector<vector<T>>

template<class A, class B> using umap = unordered_map<A, B>;
template<class A> using uset = unordered_set<A>;

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

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

  int N; ll K;
  cin >> N >> K;
  using E = pair<ll, int>;
  v(E) es(N);
  F0R(i, N) {
    ll a; int b; cin >> a >> b;
    es[i] = { a,b };
  }
  sort(rng(es));
  F0R(i, N) {
    auto [a, b] = es[i];
    if (a > K) break;
    K += b;
  }
  cout << K << newl;
}
#endif

//by ciwomuli
//enter ICPC WF 2020
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define LL long long
using namespace std;
template <typename T>
inline void read(T &t)
{
    int f = 0, c = getchar();
    t = 0;
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        t = t * 10 + c - 48, c = getchar();
    if (f)
        t = -t;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}
int main()
{
    int n, x;
    read(n, x);
    x *= 100;
    double sum = 0;
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        read(a, b);
        sum += a * b;
        if (sum > x)
        {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}


#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int INF = 1e9+7;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)

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

int V;
int G[20][20];  // グラフ
int dp[200000][20];
// メモ化再帰
int rec(int S, int v) {
    if (S == 0) {
        if (v == 0) {
            return 0;
        } else {
            return INF;
        }
    }
    if ((S & (1 << v)) == 0) {  // Sに{v}が含まれていない
        return INF;
    }
    int &ret = dp[S][v];
    if (ret != 0) return ret;
    ret = INF;
    REP(u, V) { chmin(ret, rec(S ^ (1 << v), u) + G[u][v]); }
    return ret;
}

int main() {
    cin >> V;
    // グラフの初期化
    REP(i, 20) {
        REP(j, 20) { G[i][j] = INF; }
    }
    int x[20], y[20], z[20];
    for (int i = 0; i < V; i++){
    	cin >> x[i] >> y[i] >> z[i];
    }
    for (int i = 0; i < V; i++){
    	for (int j = 0; j < V; j++){
    		G[i][j] = abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0, z[j] - z[i]);
    	}
    }
    int ans = rec((1 << V) - 1, 0);
    if (ans != INF) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i,n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i--)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define mem(x,n) memset(x,n,sizeof(x))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     fast
     ll x,y,z;
     cin>>x>>y>>z;
     double a=(dd)y/x;
     dd b=a*z;
     if(floor(b)==ceil(b))
     cout<<b-1;
     else
     cout<<floor(b);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b,c;
  cin>>a>>b>>c;
  vector<long long>vec;
  vec.push_back(a);vec.push_back(c);vec.push_back(b);
  sort(vec.begin(),vec.end());
  if(vec[1]-vec[0]==vec[2]-vec[1])
     {
       cout<<"Yes"<<endl;
     }
     else
     {
       cout<<"No"<<endl;
     }
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
int main(){
  vl v(3);rep(i,3)cin >> v[i];
  sort(all(v));
  if(v[2]-v[1]==v[1]-v[0])cout << "Yes" <<endl;
  else cout << "No" <<endl;
}