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

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;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 FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
//#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) {for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;}

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

void solve(long long M, long long H){
  if (H % M == 0) {
    cout << YES << endl;
  } else {
    cout << NO << endl;
  }
}

signed main(){
  //小数の桁数の出力指定
  cout<<fixed<<setprecision(10);
  //入力の高速化用のコード
  ios::sync_with_stdio(false); // stringの時はコメントアウト
  cin.tie(nullptr);

  long long M;
  scanf("%lld",&M);
  long long H;
  scanf("%lld",&H);
  solve(M, H);
  return 0;
}

//#####   #####   #####   #####   #####   #       #####   #   #//
//#   #   #   #   #       #       #   #   #       #   #   ## ##//
//#####   #####   #####   #       #####   #       #####   # # #//
//##      #   #       #   #       #   #   #       #   #   #   #//
//# #     #   #       #   #       #   #   #       #   #   #   #//
//#  #    #   #       #   #       #   #   #       #   #   #   #//
//#   #   #   #   #####   #####   #   #   #####   #   #   #   #//

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pbds tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define cs(n) cout<<n<<" "
#define rep(i,j,k) for(int i=j;i<k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define de2(x) cout << #x << " " << x << endl;
#define rept(it,v) for(auto it=v.begin(); it!=v.end(); it++)
#define sz(v) (int)(v.size())
#define printdec(x,y) cout<< fixed << setprecision(y) << x
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define deb(x) cout<<#x<<" : "<<x<<"\n"
#define int long long
template<typename... T>
void read(T&... args) {
	((cin >> args), ...);
}
template<typename... T>
void write(T&&... args) {
	((cout << args << " "), ...);
}
template<typename... T>
void writen(T&&... args) {
	((cout << args << "\n"), ...);
}
template<typename... T>
void cn(T&&... args) {
	((cout << args << " "), ...);
	cout << "\n";
}
ll bin(ll a, ll b, ll mod)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
		return bin((a * a) % mod , b / 2 , mod) % mod;
	return ((a % mod) * (bin((a * a) % mod , b / 2 , mod) % mod)) % mod;
}
void solve()
{
	int n;
	read(n);
	int ar[n + 5];
	rep(i, 0, n) {
		read(ar[i]);
	}
	pbds s;
	s.insert(ar[0]);
	int cnt = 0;
	rep(i, 1, n) {
		s.insert(ar[i]);
		int inv = s.order_of_key(ar[i] + 1);
		cnt += sz(s) - inv;
	}
	cout << cnt << "\n";
	rep(i, 0, n - 1) {
		cnt -= ar[i];
		cnt += (n - 1 - ar[i]);
		cout << cnt << "\n";
	}
}
signed main()
{
	fastio;
	int t;
	t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    string S; cin>>S;
    //string T="";

    int flipped = 0;

    deque<char> d;

    rep(i,S.size()){
        char s = S.at(i);
        if(S.at(i)=='R'){
            flipped += 1;
            continue;
        }else{
            if(flipped%2==0){
                if(d.size()>0){
                    if(d.back()==s){
                        d.pop_back();
                    }else{
                        d.push_back(s);
                    }
                }else{
                    d.push_back(s);
                }
            }else{
                if(d.size()>0){
                    if(d.front()==s){
                        d.pop_front();
                    }else{
                        d.push_front(s);
                    }
                }else{
                    d.push_front(s);
                }
            }
        }
    }
    if(flipped%2==0){
        while(d.size()>0){
            cout<<d.front();
            d.pop_front();
        }
    }else{
        while(d.size()>0){
            cout<<d.back();
            d.pop_back();
        }
    }
    cout<<endl;

    /*
    while(d.size()>0){

    }
    if(flipped%2==1){
        reverse(T.begin(), T.end());
    }
    */

    return 0;
}

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

int main()
{
    bool prepend = false;
    string S;
    cin >> S;
    deque<char> ans;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == 'R')
        {
            prepend = !prepend;
            continue;
        }

        if (prepend)
        {
            // if(i > 0){ //安全装置
            //     if(S[i] == ans[ans.size()-1]) {//
            //         ans.pop_back();
            //         continue;
            //     }
            // }

            ans.push_front(S[i]);
            // if(ans.size() > 1 && ans[0] == ans[1]){
            //     ans.pop_front();
            //     ans.pop_front();
            // }
        }
        else
        {
            // if(S[i] == ans[0]){
            //     ans.pop_front();
            //     continue;
            // }
            ans.push_back(S[i]);
            // if(ans.size() > 1 && ans[ans.size()] == ans[ans.size() - 1]){
            //     ans.pop_back();
            //     ans.pop_back();
            // }
        }
    }
    if (prepend)
        reverse(ans.begin(), ans.end());

    string T;
    for(char c: ans){
        if(T.size() && T.back() == c)
            T.pop_back();
        else T.push_back(c);
    }

    // for (int i = 0; i < ans.size(); i++)
    // {

    //     cout << ans[i];
    // }
    // cout << endl;
    cout << T << endl;
}


#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
using namespace std;

template <typename T>
inline void read(T&x){
    x=0; char temp=getchar(); bool f=false;
    while(!isdigit(temp)){if(temp=='-') f=true; temp=getchar();}
    while(isdigit(temp)){x=(x<<1)+(x<<3)+temp-'0'; temp=getchar();}
    if(f) x=-x;
}
template <typename T>
void print(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

typedef long long ll;
const int MAXN = 105;
const ll mod = 998244353;

inline ll Add(ll x,ll y){return x+y>=mod? x+y-mod:x+y;}

//basic
int n,w[MAXN],pre[MAXN],sum,aim;
ll fac[MAXN];

//DP
ll f[MAXN][MAXN][MAXN*MAXN];

inline ll DP(){
    f[0][0][0]=1;
    for(register int i=1;i<=n;i++)
        for(register int j=0;j<=i;j++)
            for(register int k=0;k<=pre[i];k++){
                int x=k,y=pre[i]-k,now=w[i];
                if(j>0&&x-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j-1][x-now]);
                if(y-now>=0) f[i][j][x]=Add(f[i][j][x],f[i-1][j][x]);
            }
    ll res=0;
    for(register int i=0;i<=n;i++) res=Add(res,fac[i]*fac[n-i]%mod*f[n][i][aim]%mod);
    return res;
}

int main(){
    read(n),fac[0]=1;
    for(register int i=1;i<=n;i++) read(w[i]),sum+=w[i],pre[i]=pre[i-1]+w[i],fac[i]=fac[i-1]*i%mod;
    if(sum&1) return puts("0"),0;
    aim=sum>>1;
    print(DP());
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=998244353;
int f[105][10005],sum;
int n,w[105],p[105];
void add(int &x,int y){x+=y;if (x>=M)x-=M;}
int main(){
    cin >> n; f[0][0]=1;
    p[0]=1; for (int i=1;i<=n;i++) p[i]=1ll*p[i-1]*i%M;
    for (int i=0;i<n;i++) cin >> w[i];
    for (int i=0;i<n;i++){
        for (int j=i;j>=0;j--)
            for (int k=sum;k>=0;k--)
                add(f[j+1][k+w[i]],f[j][k]);
        sum+=w[i];
    }
    if (sum%2){puts("0");return 0;}
    int ans=0;
    for (int i=1;i<n;i++) add(ans,1ll*p[i]*p[n-i]%M*f[i][sum/2]%M);
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // 頂点数と辺数
    int N,k; cin >> N>>k;
    int arr[N][N];
    fr(i,N){
        fr(l,N){
            int a;
            cin>>a;
            arr[i][l]=a;
        }
    }
    // グラフ入力受取 (ここでは無向グラフを想定)
    ll conbu[50];
    conbu[0]=1;
    Fr(i,49){
        conbu[i]=((conbu[i-1]*(i+1))%998244353);
    }
    bool arrx[N][N]={};
    bool arry[N][N]={};
    fr(i,N){
        fr(l,N){
            for(int g=i+1;g<(N);++g){
               if(arr[i][l]+arr[g][l]>k) arrx[i][g]=1;
            }
            for(int g=l+1;g<(N);++g){
               if(arr[i][l]+arr[i][g]>k) arry[l][g]=1;
            }
        }
    }
    Graph Gx(N);
    Graph Gy(N);
    fr(i,N){
        for(int l=i+1;l<(N);++l){
            if(arrx[i][l]==0){
            Gx[l].push_back(i);
            Gx[i].push_back(l);
            }
            if(arry[i][l]==0){
            Gy[l].push_back(i);
            Gy[i].push_back(l);
            }
        }
    }
    vector<int> distx(N, -1);
    queue<int> que;
    ll ans=1;
    int count=1;
    for (int v = 0; v < N; ++v) {
        if (distx[v] != -1) continue; // v が探索済みならスルー
        distx[v] = 0, que.push(v);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : Gx[v]) {
                if (distx[nv] == -1) {
                    distx[nv] = distx[v] + 1;
                    que.push(nv);
                    ++count;
                }
            }
        }
        ans=(ans*conbu[count-1])%998244353;
        count=1;
    }
    vector<int> disty(N, -1);
    for (int v = 0; v < N; ++v) {
        if (disty[v] != -1) continue; // v が探索済みならスルー
        disty[v] = 0, que.push(v);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : Gy[v]) {
                if (disty[nv] == -1) {
                    disty[nv] = disty[v] + 1;
                    que.push(nv);
                    ++count;
                }
            }
        }
        ans=(ans*conbu[count-1])%998244353;
        count=1;
    }
    cout<<ans;
}

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

struct UnionFind
{
  vector<int> par; //par[i]はiの親の番号

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

  int root(int x) //データxが属する木の根を再帰で得る root(x)={xの木の根}
  {
    if(par[x] == x) return x;
    return par[x] = root(par[x]); //親を再帰的にたぐり根を探す
  }

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

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<vector<int>> A(N, vector<int>(N));

  int64_t mod = 998244353;
  int64_t total = 1;

  bool pos = true;

  for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cin >> A.at(i).at(j);

  vector<int64_t> fact(50);
  fact.at(0) = 1;
  for(int i = 1; i <= 49; i++)
  {
    fact.at(i) = fact.at(i - 1) * i;
    fact.at(i) %= mod;
  }

  UnionFind treeX(N);
  UnionFind treeY(N);

  //行
  for(int i = 0; i < N - 1; i++)
  {
    for(int j = i + 1; j < N; j++)
    {
      for(int k = 0; k < N; k++)
      {
        if(A.at(i).at(k) + A.at(j).at(k) > K)
        {
          pos = false;
          break;
        }
      }
      if(pos) treeX.unite(i, j);
      pos = true;
    }
  }
  //列
  for(int i = 0; i < N - 1; i++)
  {
    for(int j = i + 1; j < N; j++)
    {
      for(int k = 0; k < N; k++)
      {
        if(A.at(k).at(i) + A.at(k).at(j) > K)
        {
          pos = false;
          break;
        }
      }
      if(pos) treeY.unite(i, j);
      pos = true;
    }
  }

  vector<int64_t> X(N), Y(N);
  for(int i = 0; i < N; i++)
  {
    X.at(i)++;
    if(treeX.root(i) != i) X.at(treeX.root(i))++;
    Y.at(i)++;
    if(treeY.root(i) != i) Y.at(treeY.root(i))++;
  }

  for(int i = 0; i < N; i++)
  {
    total *= fact.at(X.at(i));
    total %= mod;
  }
  for(int i = 0; i < N; i++)
  {
    total *= fact.at(Y.at(i));
    total %= mod;
  }

  cout << total << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  ll n, x;
  cin >> n >> x;
  V<ll> v(n), p(n);
  rep(i, n) cin >> v[i] >> p[i];
  x *= 100;
  ll s = 0;
  rep(i, n) {
    s += v[i] * p[i];
    if (s > x) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

#include <iostream>

using namespace std;

int main()
{
    int n,x,v,p;
    int cnt = 0;
    bool notdrk = true;
    cin>>n>>x;
    int actx = x*100;
    for(int i = 0; i<n; i++){
        cin>>v>>p;
        cnt += p * v;
        if(cnt > actx and notdrk == true){
            cout<<i+1;
            notdrk = false;
        }
    }
    if(notdrk == true){
        cout<<-1<<endl;
    }
    return 0;
}


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

int main(void){
    ll N, ans;
    vector<int> P;

    cin >> N;
    P.resize(N + 1);

    ans = 1;
    for (int i = N; i > 1; i--){
        int tmp = i;
        for (int j = 2; j * j <= i; j++){
            int cnt = 0;

            while (tmp % j == 0){
                cnt++;
                tmp /= j;
            }

            P[j] = max(P[j], cnt);
        }

        P[tmp] = max(P[tmp], 1);
    }

    ans = 1;
    for (int i = 2; i <= N; i++){
        for (int j = 0; j < P[i]; j++) ans *= i;
    }
    ans += 1;

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
#define mx                          100005
#define lli                         long long int
#define ulli                        unsigned long long int
#define mset(a,b)                   memset(a, b, sizeof(a))
#define infile                      freopen("in.txt", "r", stdin);
#define outfile                     freopen ("out.txt","w",stdout);
#define fileclose                   fclose (stdin); fclose (stdout);
#define test_case                   lli T; cin>>T;for(lli t=1;t<=T;t++)
#define scani(x)                    scanf("%d",&x);
#define printi(x)                   printf("%d\n",x);
#define scanli(x)                   scanf("%lld",&x);
#define printli(x)                  printf("%lld\n",x);
#define frep(i,from,to)             for(lli i=from;i<=to;i++)
#define frev(i,from,to)             for(lli i=from;i>=to;i--)

using namespace std;

lli n;
lli arr[50];

lli ans = 1e18;
lli prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
bool isSet(lli num, lli pos)
{
	return (num & (1 << pos));
}
void fun()
{
	frep(mask, 0, (1 << 15) - 1)
	{
		lli num = 1;
		frep(pos, 0, 15)
		{
			if (isSet(mask, pos))
			{
				num *= prime[pos];
			}
		}
		bool flag = true;
		frep(i, 1, n)
		{
			if (__gcd(num, arr[i]) == 1)
			{
				flag = false;
				break;
			}
		}
		if (flag)
			ans = min(ans, num);
	}

}
int main()
{

	cin >> n;
	frep(i, 1, n)
	{
		cin >> arr[i];
	}
	fun();
	cout << ans << "\n";

}


#include<iostream>
using namespace std;

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

  if(A+B>=15&&B>=8) cout<<1;
  else if(A+B>=10&&B>=3) cout<<2;
  else if(A+B>=3) cout<<3;
  else cout<<4;

  return 0;
}

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

int main() {
  //input
  int A, B;
  cin >> A >> B;
  //calc
  int C = A + B;
  int answer = 0;
  if ( C >= 15 && B >= 8 ) {
    answer = 1;
  }
  else if ( C >= 10 && B >= 3 ) {
    answer = 2;
  }
  else if ( C >= 3 ) {
    answer = 3;
  }
  else {
    answer = 4;
  }
  //output
  cout << answer << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--)

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

	int a, b, c, aa, flag=0;
	cin>>a>>b>>c;
	aa=a;
	int x1=0, y1=0;
	forr(i, 0, b)
	{
		int x, y;
		cin>>x>>y;
		//cout<<x<<' '<<y<<' '<<x1<<' '<<y1<<"  ";
		a-=(x-y1);
		//cout<<a<<' ';
		if(a<=0)
			flag=1;
		a+=(y-x);
		a=min(a, aa);
		//cout<<a<<'\n';
		if(a<=0)
			flag=1;
		x1=x, y1=y;
	}
	a-=(c-y1);
	if(a<=0)
		flag=1;
	cout<<(flag?"No":"Yes");

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define LL long int

#define MOD const LL 1000000007;

int ans = 0;

int main(){
    int n,m,t;
    cin >> n >> m >> t;
    vector<int> a(m);
    vector<int> b(m);
    int max = n;

    for(int i = 0; i < m; ++i){
        cin >> a[i] >> b[i];
    }

    int x = 0;

    for(int i = 0; i < m; ++i){
        n -= a[i] - x;
        if(n <= 0){cerr << i << endl;
            cout << "No" << endl;
            return 0;
        }

        n = min(n + (b[i] - a[i]),max);
        x = b[i];
    }

    n -= t - x;
    if(n <= 0){
            cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=500005;
char s[N],t[N];
int las,n,cur;
ll ans;

void go(){
	for(;cur<=n&&t[cur]!='1';cur++);
}

int main(){
	read(n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	cur=1,go();
	rep(i,1,n){
		if(s[i]!='1') continue;
		if(las){
			ans+=i-las,las=0;
			continue;
		}
		if(i<cur){
			las=i;
			continue;
		}
		ans+=i-cur;
		cur++,go();
	}
	if(las||cur<=n){
		puts("-1");
	}
	else{
		cout<<ans<<endl;
	}
	return 0;
}

//缓缓飘落的枫叶像思念，我点燃烛火温暖岁末的秋天。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e6;
ll n,a[1000][1000];
ll c[N],d[N];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];

    int flag=1;
    ll g=1e10+2;
    for(int i=1;i<=n;i++)
        g=min(a[1][i],g);
    c[1]= g;
    for(int i=1;i<=n;i++)
        d[i]=a[1][i]-c[1];
    for(int i=2;i<=n;i++)
    {
        c[i]=a[i][1]-d[1];
        if(c[i]<0){flag=0;break;}
        for(int j=1;j<=n;j++)
            if(c[i]+d[j]!=a[i][j]){flag=0;break;}
    }
    if(!flag)cout<<"No";
    else
    {
        cout<<"Yes\n";
        for(int i=1;i<=n;i++)
            cout<<c[i]<<" ";
        cout<<"\n";
        for(int i=1;i<=n;i++)
            cout<<d[i]<<" ";
    }
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define int long long
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
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 T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, t;
  cin >> n >> t;
  if(n == 1) {
    int a;
    cin >> a;
    if(a > t) cout << 0 << endl;
    else cout << a << endl;
    return 0;
  }
  vi a(n);
  rep(i, n) cin >> a[i];
  int m = n/2;
  vi z(1<<m);
  rep(i, 1<<m) {
    rep(j, m) if(i>>j&1) {
      z[i] += a[j];
    }
  }
  sort(all(z));
  int _m = n-m;
  int ans = 0;
  rep(i, 1<<_m) {
    int now = 0;
    rep(j, _m) if(i>>j&1) {
      now += a[j+m];
    }
    now = t-now;
    if(now < 0) continue;
    auto itr = upper_bound(all(z), now);
    chmax(ans, t-now+*prev(itr));
  }
  cout << ans << endl;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	c *= 1000;
	bool z = false;
	int l, r;
	for (int i = 1; i <= c; i++) {
		l = i*a;
		r = i*b;

		if (l <= c && c <= r) {
			z = true;
			break;
		}
	}

	if (z) {
		int x = (c / b) + (c % b > 0);
		int y = c / a;
		cout << x << " " << y;
	}
	else {
		cout << "UNSATISFIABLE";
	}
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

const int mod=998244353;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
void ckadd(int&a,int b){a=add(a,b);}
int sub(int a,int b){a-=b;return a<0?a+mod:a;}
void cksub(int&a,int b){a=sub(a,b);}
int mul(int a,int b){return (ll)a*b%mod;}
void ckmul(int&a,int b){a=mul(a,b);}
int powmod(int x,int k){int ans=1;for(;k;k>>=1,ckmul(x,x))if(k&1)ckmul(ans,x);return ans;}
int inv(int x){return powmod(x,mod-2);}

const int N=5050;
int a[N][N],dp[N][N];
int main(){
	int h,w,k;
	rd(h,w,k);
	for(int i=1;i<=k;i++){
		int x,y;char c;
		scanf("%i %i %c",&x,&y,&c);
		if(c=='R')a[x][y]=1;
		if(c=='D')a[x][y]=2;
		if(c=='X')a[x][y]=3;
	}
	int i3_2=mul(2,inv(3));
	dp[1][1]=powmod(3,h*w-k);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i!=h){
				if(a[i][j]&2)ckadd(dp[i+1][j],dp[i][j]);
				if(a[i][j]==0)ckadd(dp[i+1][j],mul(dp[i][j],i3_2));
			}
			if(j!=w){
				if(a[i][j]&1)ckadd(dp[i][j+1],dp[i][j]);
				if(a[i][j]==0)ckadd(dp[i][j+1],mul(dp[i][j],i3_2));
			}
		}
	}
	printf("%i\n",dp[h][w]);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;
using VII = vector<VI>;
using VLL = vector<VL>;
using VDD = vector<VD>;
using P = pair<int, int>;
using PL = pair<ll, ll>;

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

void solve(long long N, string S, std::string X) {
  VII dp(N + 1, VI(7, 0));
  dp[N][0] = 1;
  FORR(i, N, 1) {
    FOR(j, 0, 6) {
      int num = S[i - 1] - '0';
      if(X[i - 1] == 'T') {
        if(dp[i][10 * j % 7] || dp[i][(10 * j + num) % 7]) {
          dp[i - 1][j] = 1;
        }
      }
      if(X[i - 1] == 'A') {
        if(dp[i][10 * j % 7] && dp[i][(10 * j + num) % 7]) {
          dp[i - 1][j] = 1;
        }
      }
    }
  }
  if(dp[0][0]) {
    cout << "Takahashi" << endl;
  } else {
    cout << "Aoki" << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  string S;
  cin >> S;
  std::string X;
  std::cin >> X;
  solve(N, S, X);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    string s; cin >> s;
	char c; cin >> c;
	if(s == "Y")cout << char(c - 32) << endl;
	else cout << c << endl;

	return 0;
}

/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>
#include <chrono>

//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)
#define printLdb(a) printf("%.50Lf\n", a)
#define printdbd(a) printf("%.16lf\n", a)
#define prints(s) printf("%s\n", s.c_str())
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d))

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

//cpp_int
#if __has_include(<boost/multiprecision/cpp_int.hpp>)
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace boost::multiprecision;
#else
using cpp_int = ll;
#endif

//atcoder library
#if __has_include(<atcoder/all>)
#include <atcoder/all>
//using namespace atcoder;
#endif

/*
	random_device seed_gen;
	mt19937 engine(seed_gen());
	uniform_int_distribution dist(1, 100);
*/

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

int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	double l = 0, r = 1e9;
	while (abs(l - r) > 0.0000001) {
		double lm = (l * 2 + r) / 3.0, rm = (l + r * 2) / 3.0, ml = 0, mr = 0;
		rep(i, n) {
			ml += lm + a[i] - min<double>(a[i], 2 * lm);
			mr += rm + a[i] - min<double>(a[i], 2 * rm);
		}
		if (ml < mr)r = rm;
		else l = lm;
	}
	double p = 0;
	rep(i, n) {
		p += l + a[i] - min<double>(a[i], 2 * l);
	}
	printdb(p / n);

	Please AC;
}


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

constexpr char LF = '\n';

template <typename T = int>
constexpr T INF()
{
    return numeric_limits<T>::max();
}

template <typename OutputIterator>
void read(OutputIterator first, OutputIterator last)
{
    for (auto p = first; p != last; p = next(p)) cin >> *p;
}

template <typename InputIterator>
void print(InputIterator first, InputIterator last)
{
    if (first != last) {
        cout << *first;
        for (auto p = next(first); p != last; p = next(p)) {
            cout << ' ' << *p;
        }
    }
    cout << LF;
}

void trace() { cout << LF; }

template <typename Head, typename... Tail>
void trace(Head head, Tail... tail)
{
    cout << head << ' ';
    trace(tail...);
}

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

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

class Problem {
public:
    void solve()
    {
        int64_t N;
        cin >> N;
        vector<int64_t> A(N);
        for (auto &&Ai : A) cin >> Ai;
        vector<int64_t> sum_A(N + 1), sum_AA(N + 1);
        for (int64_t i = 0; i < N; ++i) {
            sum_A.at(i + 1) = sum_A.at(i) + A.at(i);
            sum_AA.at(i + 1) = sum_AA.at(i) + A.at(i) * A.at(i);
        }
        int64_t ans = 0;
        for (int64_t i = 1; i < N; ++i) {
            ans += i * A.at(i) * A.at(i);
            ans -= 2LL * A.at(i) * sum_A.at(i);
            ans += sum_AA.at(i);
        }
        cout << ans << LF;
    }
};

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

    Problem problem;
    problem.solve();
}

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

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

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

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

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

    return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

ll int N;
string S;

cin >> N >> S;

vector<int> AT(N+1);
vector<int> AT2(N+1);
vector<int> CG(N+1);
vector<int> CG2(N+1);

AT[0]=0;
CG[0]=0;

rep(i,N){
 if(S[i] == 'A'){
	 AT[i+1] = AT[i] + 1;
	 AT2[i+1] = AT2[i] ;
	 CG[i+1] = CG[i] ;
	 CG2[i+1] = CG2[i] ;
 }
 else if(S[i] == 'T'){
	 AT[i+1] = AT[i] ;
	 AT2[i+1] = AT2[i] + 1;
	 CG[i+1] = CG[i] ;
	 CG2[i+1] = CG2[i] ;
 }
 else if(S[i] == 'C'){
	 AT[i+1] = AT[i] ;
	 AT2[i+1] = AT2[i] ;
	 CG[i+1] = CG[i] + 1;
	 CG2[i+1] = CG2[i] ;
 }
 else{
	 AT[i+1] = AT[i] ;
	 AT2[i+1] = AT2[i] ;
	 CG[i+1] = CG[i] ;
	 CG2[i+1] = CG2[i] + 1;
 }

//cout << AT[i+1]<<" " <<CG[i+1]<< endl;
}

ll int counter =0;
ll int at = 0;
ll int cg = 0;

for(ll int i=N;i>1;i--){
	for(ll int j=0;j<i-1;j++){

		if( AT[i] - AT[j] == AT2[i] - AT2[j] && CG[i] - CG[j] == CG2[i] - CG2[j] ){
			counter += 1;
//cout << j <<" " << i << endl;
		}
		else{}
	}
}

cout << counter;

	return 0;

}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define endl '\n'
#define br cout<<endl
#define mem(a) memset(a,0,sizeof(a))
const double pi=3.141592653589793238;
#define d(x) cout<<x<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define rev(a) reverse(a.begin(),a.end())
const int inf = 100000000000000000;
#define maxn 1000005
#define mod 998244353
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(),x.end()
#define f(i,n) for(int i=1;i<=n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i+=1)
#define fn(i,k,n) for(int i=k;i>=n;i-=1)
void pv(vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<endl;}
void pa(int a[],int n,int p){for (int i = p; i < n+p; ++i){cout<<a[i]<<" ";}cout<<endl;}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
int modexp(int x,int y) {
   int res = 1;
   x = x % mod;
   while (y > 0){
       if (y & 1LL)
           res = (res*x) % mod;
       y = y>>1;
       x = (x*x) % mod;
   }
   return res;
}
int invmod(int a) {
    return modexp(a,mod-2);
}
vector<int> edge[maxn];
void ipgraph(int n,int m) {
    fp(i,1,n) edge[i].clear();
    if(m==0) return;
   fp(i,1,m) {
       int a,b;
       cin>>a>>b;
       edge[a].pb(b);
       edge[b].pb(a);
   }
}
/*
void dfs(int node,int p)
{
    for(int u : edge[node])
    {
        if(u!=p)
        {
            dfs(u,node);
        }
    }
}
*/
///////////////////////////////////////////////////////////////////////////////////
void solve()
{
    int n;
    cin>>n;
    int pre[n+1],pre1[n+1];
    pre[0] = pre1[0] = 0;
    string s;
    cin>>s;
    s = " " + s;
    fp(i,1,n)
    {
        pre[i] = pre[i-1];
        pre1[i] = pre1[i-1];
        if(s[i]=='A') pre[i]++;
        else if(s[i]=='T') pre[i]--;
        else if(s[i]=='C') pre1[i]++;
        else if(s[i]=='G') pre1[i]--;
    }
    int ans = 0;
    fp(i,1,n)
    {
        fp(j,i,n)
        {
            if(pre[j]==pre[i-1] && pre1[j]==pre1[i-1]) ans++;
        }
    }
    d(ans)
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   int t=1;
    //cin>>t;
   fp(i,1,t)
   {
       //cout<<"Case #"<<i<<": ";
       solve();
   }
   #ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
typedef long long  ll;
int main() {
  ll N,W;
  cin>>N>>W;
  vector<ll> A(2*100000+1);
  rep(i,2*100000+1)A[i]=0;
  rep(i,N){
  ll S,T,P;
  cin>>S>>T>>P;
  A[S]+=P;
    A[T]-=P;
  }
  bool check=true;
  ll temp=0;
  rep(i,2*100000+1){
  temp+=A[i];
  if(temp>W)check=false;}
  if(check)cout<<"Yes";
  else cout<<"No";
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << H; _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define eprintf(...)
#endif

int main() {
  int n,s, d; cin >> n >> s >> d;
  rep(i,n) {
    int x,y; cin >> x >> y;
    if(x<s && y>d) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

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

    int a, b, c;
    cin >> a >> b;
    c = a + b;

    if (c >= 15 && b >= 8) cout << 1 << endl;
    else if (c >= 10 && b >= 3) cout << 2 << endl;
    else if (c >= 3) cout << 3 << endl;
    else cout << 4 << endl;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    for (int i = b - a; i > 0; i--) {
        int t1 = (a - 1) / i + 1;
        int t2 = b / i;
        if (t1 < t2) {
            cout << i << endl;
            break;
        }
    }
        return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min({a, b, c, d}) << '\n';
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll len(pll i) {
    return i.y-i.x+1;
}
ll intr(pll a, pll b) {
    ll l = max(a.x,b.x);
    ll r = min(a.y,b.y);
    if(l<=r) return r-l+1;
    return 0;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    ll b,c; cin >> b >> c;
    pll x = {b-c/2, b+(c-2)/2};
    pll y = {-b-(c-1)/2, -b+(c-1)/2};
    cout << len(x)+len(y)-intr(x,y) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dbg(X) std::cerr << "[DBG]("<<__FUNCTION__<<":"<<__LINE__<<") " << #X << ": " << X << std::endl;
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) { for (T& t : p) s >> t; return s; }
template<typename T>
ostream& operator<<(ostream& s, const vec<T>& p) { for (const T& t : p) s << t << " "; return s; }

pair<ll,ll> sim(vl& i) {
    ll x=0, y=0;
    trav(v, i)
        if (v==1) x++;
        else if (v==2) y++;
        else if (v==3) x+=y;
        else y+=x;
    return {x,y};
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    vl a;
    vl fib;
    ll x=0;
    ll y=1;
    while (y < n) {
        fib.pb(y);
        y = x+y;
        x = y-x;
    }

    ll m = n;
    int i = sz(fib)-1;
    bool t=true;
    while (i >= 0) {
        if (fib[i] < m) {
            a.pb(t?1:2);
            m -= fib[i];
        }
        a.pb(t?4:3);
        t = !t;
        i--;
    }
    auto r = sim(a);
    if (r.S == n-1) {
        trav(v, a) {
            if (v==1) v=2;
            else if (v==2) v=1;
            else if (v==3) v=4;
            else if (v==4) v=3;
        }
    }
    a.pb(1);
    /* assert(sim(a).F == n); */
    cout<<sz(a)<<endl;
    trav(v,a)cout<<v<<endl;
}

/* aman6213*/
#include<bits/stdc++.h>

#define ll              long long
#define mp              make_pair
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define all(x)          x.begin(), x.end()
#define big(x)          greater<x>()

#define sp              fixed<<setprecision
#define vi              vector<int>
#define vvi             vector<vi>
#define pi              pair<int,int>

#define PI              3.14159265
#define M               (int)1000000007
#define LINF            LONG_MAX
#define NL              LONG_MIN
#define MX             INT_MAX
#define MN              INT_MIN

#define IOS()           ios_base::sync_with_stdio(0);cin.tie(0);
#define deb(x)          cerr<<#x<<" : "<<x<<"\n";
#define deball(x)       for(auto iit:x) cerr<<" "<<iit;cerr<<"\n";
#define rep(i,b,c)      for( ll i=b; i<c; ++i)
#define rrep(i,b,c)     for( ll i=b; i>=c; --i)

using namespace std;

void solve() { ll ans=0;

   cout<<ans<<"\n";
}
int main(){
    IOS()
    int t = 1;
    cin >> t;

    t=t*1.08;
    if(t<206) cout<<"Yay!";
    else if(t==206) cout<<"so-so";
    else cout<<":(";

return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
typedef long long LL;
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << 21 - a - b - c << endl;
}

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

#define MOD 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define INF (int)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define forn(n) for(ll i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fir first
#define sec second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mli map<ll,int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define sortv(v) sort(v.begin(), v.end())
#define minv(v) min_element(v.begin(), v.end())
#define maxv(v) max_element(v.begin(), v.end())
#define ubv(v,n) upper_bound(v.begin(), v.end(), n)
#define lbv(v,n) lower_bound(v.begin(), v.end(), n)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

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

}

int main()
{
fast;
ll t;
//cin>>t;
t=1;
for(ll tc=1;tc<=t;tc++)
{
ll a,b,c;
cin>>a>>b>>c;
cout<<21-a-b-c;
}
    return 0;
}
//0xAAAAAAAA=even bits set to 1 ; 0x55555555 = odd bits set to 1


#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<long> par;

void Initpar(long n){
  par = vector<long>(n);
  for(long i=0; i<n; i++) par.at(i) = i;
}

long root(long x){
  if(x == par.at(x)) return x;
  else return par.at(x) = root(par.at(x));
}

void unite(long x, long y){
  long rx = root(x);
  long ry = root(y);
  if(rx == ry) return ;
  if(rx < ry) par.at(ry) = rx;
  else par.at(rx) = ry;
}

bool same(long x, long y){
  return root(x) == root(y);
}

void update_par(){
  for(int i=0;i<par.size();i++){
    root(i);
  }
}

struct Edge
{
  double cost;
  long from;
  long to;
  bool operator<(const Edge& o) const {
    return cost < o.cost;
  }
};

// long root(long x, vector<long> &par){
//   if(x == par.at(x)) return x;
//   else par.at(x) = root(par.at(x), par);
// }

// bool unite(long x, long y, vector<long> &par){
//   long rx = root(x, par);
//   long ry = root(y, par);
//   if(rx == ry) return true;
//   else if(rx < ry) par.at(ry) = rx;
//   else par.at(rx) = ry;
//   return false;
// }

// bool same(long x, long y, vector<long> &par){
//   return root(x,par) == root(y,par);
// }

int main(){
  long n;
  cin >> n;
  vector<pair<long,long>> d(n);
  rep(i,n) cin >> d.at(i).first >> d.at(i).second;
  vector<Edge> list;
  rep(i,n){
    double x = (double)d.at(i).first;
    double y = (double)d.at(i).second;
    REP(j,i+1,n){
      double nx = (double)d.at(j).first;
      double ny = (double)d.at(j).second;
      double r = sqrt((nx-x)*(nx-x)+(ny-y)*(ny-y))/2.0;
      list.push_back(Edge{r,i,j});
    }
  }
  rep(i,n){
    double y = (double)d.at(i).second;
    list.push_back(Edge{(100-y)/2.0,i,n});
    list.push_back(Edge{(y+100)/2.0,i,n+1});
  }
  list.push_back(Edge{100, n, n+1});
  sort(list.begin(), list.end());
  Initpar(n+2);
  rep(i,n+2) par.at(i) = i;
  for(Edge ed : list){
    long s = ed.from;
    long t = ed.to;
    double r = ed.cost;
    unite(s,t);
    if(same(n,n+1)){
      cout << r << endl;
      return 0;
    }
  }
}

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

using namespace std;

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

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;
constexpr long double eps = 1e-5;

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

class union_find
{
	int  _setnum;
	vector<int> par, nume;
public:
	union_find(){
	}

	union_find(int x){
		par.resize(x);
		nume.resize(x);
		init();
	}

	~union_find(){
		//

	}

	void clear(){
		_setnum = 0;
		par.clear();
		nume.clear();
	}

	void init(){
		_setnum = par.size();
		for(int i = 0; i < par.size(); i++){
			par[i] = i;
			nume[i] = 1;
		}
	}

	void resize(int x){

		par.resize(x);
		nume.resize(x);
		init();
	}

	int find(int x){
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);

		if(x == y)return;

		_setnum--;

		if(nume[x] > nume[y]) std::swap(x,y);

		par[x] = y;
		nume[y] += nume[x];
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}

	int numel(int x){
		return nume[find(x)];
	}

	int size(){
		return par.size();
	}

	int setnum(){
		return _setnum;
	}
};

#define x first
#define y second

int N;
vector<pair<long double,long double>> p;

long double dis(int i, int j){
    return sqrt((p[i].x - p[j].x)*(p[i].x - p[j].x) + (p[i].y - p[j].y)*(p[i].y - p[j].y));
}

bool cal(long double r){
    union_find uf(N+2);

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(dis(i,j) <= r * 2) {
                uf.unite(i, j);
            }
        }
        if(100 - p[i].y <= r * 2) uf.unite(i, N);
        if(p[i].y +100 <= r * 2) uf.unite(i, N+1);
    }

    return !uf.same(N, N+1);
}

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

	cin>>N;

    p.resize(N);

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

    long double l = 0, r = 110, m;

    for(int i = 0; i < 100; i++){
        m = (l + r) / 2;

        if(cal(m)) l = m;
        else r = m;
    }

    cout<<l<<endl;

	return 0;
}


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

//DEFINE and TYPEDEF--------------------------------------------------------------
// For actual content check from line 37

#define FORZ(i,n) for(lld i=0;i<(lld)n;++i) //for - zero
#define FORG(i,a,n) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?++i:--i) //for - general
#define FORZI(i,n,inc) for(lld i=0;i<(lld)n;i+=inc) //for - zero incremental
#define FORGI(i,a,n,inc) for(lld i=(lld)a;a<n?i<(lld)n:(lld)n<i;a<n?i+=inc:i-=inc) //for - general incremental
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define MEM(a,val) memset(a,val,sizeof(a));

#define all(m) m.begin(),m.end()
#define rall(m) m.rbegin(),m.rend()
#define sz(m) (lld)m.size()
#define cin(s) cin>>ws; getline(cin,s);

#define st first
#define nd second
#define endl "\n"
#define pb push_back
#define mod 1000000007
#define DEC(x) fixed<<setprecision(x)

typedef long double ld;
typedef long long int lld;

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.st>>a.nd;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.st<<" "<<a.nd;return out;}
template<typename T, typename U> static inline void amin(T &x, U y){if(y<x) x=y;}
template<typename T, typename U> static inline void amax(T &x, U y){if(x<y) x=y;}

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

void swagWaalaFunction()
{
	lld a,b,c,mn=1e9,mx=-1;
	cin>>a>>b>>c;

	c*=1000;
	FORG(i,1,c+1)
	{
		if(i*a<=c and c<=b*i)
		{
			amin(mn,i);
			amax(mx,i);
		}
	}

	if(mx==-1)
		cout<<"UNSATISFIABLE\n";
	else
		cout<<mn<<" "<<mx<<endl;
	return;
}

int main()
{
    SPEEDUP;
 	lld tc=1;
 	//cin>>tc;

 	#ifdef PRIMES
 		sieve();
 	#endif

 	#ifdef CHOOSE
 		nCrModInit();
 	#endif

	FORZ(i,tc)
 	{
 		// cout<<"Case #"<<i+1<<": ";
 		swagWaalaFunction();
	}

 	return 0;
}

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Incase of close mle change language to c++17 or c++14
/**#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops”)**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int m, h;
    cin>>m>>h;
    if(h%m==0)
    cout<<"Yes\n";
    else
    cout<<"No\n";
}


#line 1 "Contests/AtCoder_agc054/agc054_a/main.cpp"
using namespace std;
#line 2 "library/bits/stdc++.h"

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#line 3 "Contests/AtCoder_agc054/agc054_a/main.cpp"

// add your library with double quotation #include"" here.
// #include "atcoder/all"
// using namespace atcoder;

// define your macros here.
#define REP(a,b) for(long long a = 0;a < b;++a)

#define int long long
void solve(){
    // write your solution here.
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(s[0] != s.back()){
        cout << 1 << endl;
        return;
    }
    for(int i = 1;i < s.length()-1;++i){
        if(s[i] != s[0] and s[i+1] != s.back()){
            cout << 2 << endl;
            return;
        }
    }
    cout << -1 << endl;
}
#undef int

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}

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

int main(void)
{
  long N;
  string s;
  deque<char> deq;

  cin >> N;
  cin >> s;

  for (long i = 0; i < N; i++)
  {
    deq.push_back(s.at(i));

    if (deq.size() >= 3 && deq.at(deq.size()-3) == 'f' && deq.at(deq.size()-2) == 'o' && deq.back() == 'x')
    {
      deq.pop_back();
      deq.pop_back();
      deq.pop_back();
    }
  }

  cout << deq.size() << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
inline int read_int(){
	int t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline LL read_LL(){
	LL t=0;bool sign=false;char c=getchar();
	while(!isdigit(c)){sign|=c=='-';c=getchar();}
	while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
	return sign?-t:t;
}
inline char get_char(){
	char c=getchar();
	while(c==' '||c=='\n'||c=='\r')c=getchar();
	return c;
}
inline void write(LL x){
	char c[21],len=0;
	if(!x)return putchar('0'),void();
	if(x<0)x=-x,putchar('-');
	while(x)c[++len]=x%10,x/=10;
	while(len)putchar(c[len--]+48);
}
inline void space(LL x){write(x),putchar(' ');}
inline void enter(LL x){write(x),putchar('\n');}
const int MAXN=505;
LL a[MAXN],d[MAXN],b[MAXN],c[MAXN][MAXN];
bool solve(int n){
	_for(i,1,n){
		d[i]=c[i][0]-c[0][0];
		_for(j,1,n){
			if(c[i][j]-c[0][j]!=d[i])
			return false;
		}
	}
	LL minv=0;
	_for(i,0,n)
	minv=min(minv,d[i]);
	_for(i,0,n)a[i]=d[i]-minv;
	_for(i,0,n){
		b[i]=c[0][i]-a[0];
		if(b[i]<0)
		return false;
	}
	return true;
}
int main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	int n=read_int();
	_for(i,0,n)_for(j,0,n)c[i][j]=read_int();
	if(solve(n)){
		puts("Yes");
		_for(i,0,n)space(a[i]);
		puts("");
		_for(i,0,n)space(b[i]);
	}
	else
	puts("No");
	return 0;
}

#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}

const int N = 200100;
const int M =998244353;

ll A[N],B[N];
int32_t main(){
  fastio;
  int n,m,k;
  cin >> n >> m >> k;

  for(int i=1;i<=k;i++){
    A[i] = mod(exp(i,n,M) - exp(i-1,n,M),M);

    B[i] = mod(exp(i,m,M),M);
   // db3(exp(i,n,M),A[i],B[i]);
  }
  ll res=0;
  for(int i=1;i<=k;i++){
    ll val = A[i];
    if(m==1){
      val = val;
    }else if(n==1){
      val = mod(val * (exp(k-i+1,m,M) - exp(k-i,m,M)),M);
    }else val = mod(val * B[k-i+1],M);
    res = mod(res + val,M);
  }
  cout << res << endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}


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

#define Ff(i,j,n)  for (i = j ; i < n; i++)
#define Fb(i,j,n)  for (i = n-1 ; i >= j; i--)
#define pb push_back
#define ff first
#define ss second
#define pi 3.14159265358979323846
#define all(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define sz(x) (ll)x.size()

typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<pll> vpll;
typedef long double ld;
typedef priority_queue <ll, vll, greater<ll>> mipq;

const ll mod = 1e9+7;
const ll mod2 = 998244353;

ll binpow(ll b, ll p) { ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll inv(ll x){return binpow(x, mod - 2);}
ll divide(ll x, ll y) {return ((x%mod)*(inv(y)))%mod;}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}

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

void precalc() {
    /*Uncomment precalc() in main*/
    return;
}

int main()
{
    IOS;
    // precalc();
    int x, y;
    cin >> x >> y;
    if(x == y)
        cout << x << '\n';
    else
        cout << 3 - (x + y) << '\n';
    return 0;
}

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

void solve(){
	int a, b;cin>>a>>b;
	if(a==b)	cout<<a;
	else		cout<<3-a-b;
}

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


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

bool cmp(char x,char y){
  return x>y;
}
int main()
{
    ll n,k;
    const char *c1;
    const char *c2;
    scanf("%lld%lld",&n,&k);
    ll ans=n;
    for(int i=1;i<=k;i++){
      string s=to_string(ans);
      sort(s.begin(),s.end());
      ll b;
      c1=s.c_str();
      b=atol(c1);
      sort(s.begin(),s.end(),cmp);
      ll a;
      c2=s.c_str();
      a=atol(c2);
      ans=a-b;
    }
    printf("%lld\n",ans);
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

//wierd debugging stuff
#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 << "\n" ; }
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 imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff

using ll = long long;
using ld = long double;
using vi = vector<int>;
using ii = pair<int,int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define rep(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define each(x) for(auto& a: x)
#define ar array
#define pb push_back
#define vt vector

template<class T> bool umin(T& a,const T& b){return b<a?a=b,1:0;}
template<class T> bool umax(T& a,const T& b){return b>a?a=b,1:0;}

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {cin>>x;}
void read(double& d) {string t;read(t);	d=stod(t);}
void read(long double& d) {	string t;read(t);d=stold(t);}
template<class H, class... T> void read(H& h, T&... t) {read(h);read(t...);}
template<class A> void read(vt<A>& x) {	each(x)read(a);}

// no change
const ll MOD = 1e9+7;
/*
 */
const int mxN = 2e3;
vector<int> adj[mxN];
vector<bool> vis(mxN);
int cur = 0;
int dfs(int u){
	cur++;
	vis[u] = 1;
	for(int a : adj[u]){
		if(!vis[a])
			dfs(a);
	}
	return cur;
}
void Solve(){
	int n,m;
	cin >> n >> m;
	rep(m){
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
	}
	int ans = 0;
	for(int i = 1;i<=n;i++){
		ans += dfs(i);
		vis.clear();
		vis = vector<bool>(mxN);
		cur = 0;
	}
	cout << ans << "\n";

}

int main() {
	using namespace std::chrono_literals;

    std::this_thread::sleep_for(-9999999999999ms);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int T = 1;
	//cin >> T;		//cmt if one test case
    rep(T)Solve();
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;
const ll mod = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
  ll n;
  cin >> n;
  ll ans = 1;
  for (ll i = 2; i <= n; ++i) {
    ans = lcm(ans, i);
  }
  cout << ans + 1 << endl;
  return 0;
}

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

int main(){
  long long int N;
  cin >> N;
  N *= 2;
  vector<long long int> div(0);
  for(long long int i=1;i<=sqrt(N);i++){
    if(N%i == 0){
      div.push_back(i);
      if(i*i != N) div.push_back(N/i);
    }
  }
  long long int cnt=0;
  long long int M = div.size();
  for(long long int i=0;i<M;i++){
    if(div[i]%2 == 1) cnt++;
    else if((N/div[i])%2 == 1) cnt++;
  }
  cout << cnt << endl;
}


#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define All(a) a.begin(), a.end()
#define us unordered_set
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ll long long
#define vt vector
#define mod 1000000007

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vt<vt<double>> m(n, vt<double>(2));
    rep(i, n) {
        int t;
        cin >> t >> m[i][0] >> m[i][1];
        if (t == 2) m[i][1] -= 0.1;
        if (t == 3) m[i][0] += 0.1;
        if (t == 4) {
            m[i][0] += 0.1;
            m[i][1] -= 0.1;
        }
    }
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            if (m[i][0] <= m[j][0] && m[i][1] >= m[j][0])
                ans++;
            else if (m[i][0] >= m[j][0] && m[i][0] <= m[j][1])
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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 n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

    Modint &operator+=(const Modint &p){
			if((x+=p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator-=(const Modint &p){
			if((x+=mod-p.x)>=mod)
				x -= mod;
			return *this;
		}

		Modint &operator*=(const Modint &p){
			x = (1LL * x * p.x) % mod;
			return *this;
		}

		Modint &operator/=(const Modint &p){
			*this *= p.inverse();
			return *this;
		}

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

		bool operator==(const Modint &p) const { return x == p.x; }
		bool operator!=(const Modint &p) const{return x != p.x;}

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

		friend ostream &operator<<(ostream &os,const Modint &p){
			return os << p.x;
		}
};

using modint = Modint<mod>;

void solve(){
	ll h,w;
	cin>>h>>w;
	ll sum=0;
	vector<string>s(h);
	rep(i,h)cin>>s[i];
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='.')++sum;
		}
	}
	vector<vector<ll>>l(h,vector<ll>(w)),r(h,vector<ll>(w)),u(h,vector<ll>(w)),d(h,vector<ll>(w));
	rep(i,h){
		ll val=0;
		rep(j,w){
			if(s[i][j]!='#')r[i][j]=val,val++;
			else val=0;
		}
		val=0;
		for(int j=w-1;j>=0;--j){
			if(s[i][j]!='#')l[i][j]=val,val++;
			else val=0;
		}
	}
	rep(i,w){
		ll val=0;
		rep(j,h){
			if(s[j][i]!='#')u[j][i]=val,val++;
			else val=0;
		}
		val=0;
		for(int j=h-1;j>=0;--j){
			if(s[j][i]!='#')d[j][i]=val,val++;
			else val=0;
		}
	}
	modint ans=0;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='#')continue;
			ll cnt=l[i][j]+r[i][j]+u[i][j]+d[i][j]+1;
			modint x=2;
			x=x.pow(cnt);
			x-=1;
			modint y=2;
			y=y.pow(sum-cnt);
			ans+=x*y;
		}
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main(){
  int N;cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++) cin>>P.at(i);

  int ans=0;
  set<int> X;
  for(int i=0;i<N;i++){
    if(!X.count(P.at(i))) X.insert(P.at(i));
    if(ans==P.at(i)) while(X.count(ans)) ans++;
    cout<<ans<<endl;
  }
}

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

int main(void) {
	int N;
	cin >> N;
	int A[100000];
	pair<int, int> a(0, -1), b(0, -1);
	for (int i = 0; i < pow(2, N); i++) {
		cin >> A[i];
		if (i < pow(2, N) / 2) {
			if (A[i] > a.first) {
				a.first = A[i];
				a.second = i + 1;
			}
		} else {
			if (A[i] > b.first) {
				b.first = A[i];
				b.second = i + 1;
			}
		}
		// cout << a.second << " " << b.second << endl;
	}
	if (a.first > b.first) cout << b.second << endl;
	else cout << a.second << endl;

	return 0;
}


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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << '\n'
#define OUT(x) cout << x << '\n'
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << '\n'

template<typename T_vector>
void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start; i < end; i++) {
      cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n');
    }
}

void solve() {
    ll n, k; cin >> n >> k;
    vector<pll> v;
    REP(i, n) {
        ll a, b; cin >> a >> b;
        v.pb({a, b});
    }
    SORT(v);
    ll money = k, cur = 0;
    EACH(x, v) {
        if(x.fi > money + cur) {
            cur += money;
            OUT(cur);
            return;
        } else {
            cur += money;
            money = x.se;
        }
    }
    OUT(money + cur);
}

int main() {
    FAST_INP;

//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

    // int tc; cin >> tc;
    // TC(tc) solve();
    solve();
    return 0;
}

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define tpii pair <int, pii>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int max_n = 1500;

using namespace std;
int n,m;
int dp[max_n][max_n];
bool frnd[max_n][max_n];
vector <pii> vc[max_n];

void read() {
	cin >> n >> m;
	rep(i,m) {
		int u,v;
		char ch;
		cin >> u >> v >> ch;
		u--,v--;
		frnd[u][v] = frnd[v][u] = 1;
		vc[u].pb({v,int(ch-'a')});
		vc[v].pb({u,int(ch-'a')});
	}
}

set <tpii> st;

void rm(int x , int y , int move) {
	if(dp[x][y] < move) return;
	auto ti = st.find({dp[x][y],{x,y}});
	if(ti!=st.end()) st.erase(ti);
	dp[x][y] = move;
	st.insert({move,{x,y}});
}

void solve() {

	st.insert({0,{0,n-1}});

	rep(i,n) {
		rep(j,n) {dp[i][j] = inf;}
	}

	dp[0][n-1] = dp[n-1][0] = 0;

	int ans = inf;

	while(!st.empty()) {
		auto it = st.begin();
		tpii p = *it;
		st.erase(it);
		int move = p.fi;
		pii point = p.se;

		int fv = point.fi , bv = point.se;

		if(frnd[fv][bv] == 1) {
			// cerr << fv << " " << bv << "\n";
			ans = min(ans,move*2+1);
		}

		for(auto paf : vc[fv]) {
			for(auto pab : vc[bv]) {
				if(paf.se != pab.se) continue;
				if(paf.fi == pab.fi) {ans = min(ans,(move+1)*2); cerr << paf.fi << "\n"; continue;}

				rm(paf.fi,pab.fi,move+1);
			}
		}

	}
	cout << (ans==inf?-1:ans) << '\n';
}

int main(){
fcin;
	read();
	solve();

/*
	let f(a,b) be smolest palindrome in which :

	a is connected to 0
	and b is connected to n-1

	and way[a] = way[b]
	then it's just easy to follow up
	if there is an edge connecting us both then can be also odd length .

*/

    return 0;
}


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

using namespace std;

template<class T>
using V = vector<T>;
template<class T>
using VV = V<V<T>>;

using ld = long double;
#define ll long long
using ull = unsigned ll;
using PLL = pair<ll, ll>;
using VLL = V<ll>;
using VB = V<bool>;
using VVB = VV<bool>;
using VVLL = VV<ll>;
using Gr = VVLL;
using MLL = map<ll, ll>;
#define UMLL unordered_map<ll, ll, custom_hash>

//using int128 = __int128;
//using double128 = __float128;

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

#define R &
#define CR const R

#define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i)
#define FOR(i, n) FORI(i, 0, n)
#define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i)
#define RFOR(i, n) RFORI(i, n, 0)
#define FORA(i, a) for(auto i : a)
#define FORAR(i, a) for(auto R i : a)
#define FORACR(i, a) for(auto CR i : a)
#define ALL(obj) begin(obj), end(obj)
#define Count(q) while(q--)
#define OK cerr << "OK\n";

#define mp make_pair
#define pb push_back

//#define DEBUG

template<class T>
T sqr(T x)
{
    return x * x;
}

void YES(bool g, ostream R os, bool upper = true)
{
    if(g)
        if(upper)
            os << "YES";
        else
            os << "Yes";
    else
        if(upper)
            os << "NO";
        else
            os << "No";

    os << "\n";
}

template<class T>
void show(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        os << i << " ";
    os << "\n";
}

template<class T>
void show2d(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        show(i, os);
    os << "\n";
}

constexpr ll MOD = 1e9 + 7; //998244353;
constexpr ll len = 1e7;

constexpr ll INF = 1e15, MINF = -INF;

constexpr ld PI = atanl(1.0L) * 4;
constexpr ld eps = 1e-8, EPS = 1e-7;

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

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

//arr
void init() {}

void solve(istream R is, ostream R os)
{
    ll t, n;
    is >> t >> n;

    os << n + ceil(100.0L * n / t) - 1 << "\n";
}

void tester(istream R is, ostream R os)
{
    auto seed = time(nullptr);
    //cerr << "seed: " << seed << "\n";
    srand(seed);
    fast
    init();
    ll q = 1;
    //is >> q;

    os << setprecision(999);
    Count(q)
        solve(is, os);
}

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    tester(cin, cout);
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	int n,k,i;
	cin>>n>>k;
	int t[n+1][n+1],m=0,a[n+2];
	for(i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			cin>>t[i][j];
	for(i=1; i<=n; i++)
		a[i]=i;
	a[n+1]=1;
	int	ans;
	do{
		ans=0;
		for(int i=1; i<=n; i++)	ans+=t[a[i]][a[i+1]];
		if(ans==k)	m++;
	}while(next_permutation(a+2,a+n+1));
	cout<<m;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long N,i,count  = 0,count1  = 0,temp,temp1;
    cin>>N;
    bool v[N+1] = {false};
    for(i = 1; i <= N; i++)
    {
        temp = i;
        while(temp != 0)
        {
            if(temp % 10 == 7)
            {
                if(v[i-1] == false)
                {
                    count++;
                    v[i-1] = true;

                }
                break;
            }
            temp = temp /10;
        }
    }
    for(i = 1; i <= N; i++)
    {
        temp1 = i;
        while(temp1 != 0)
        {
            if(temp1 % 8 == 7)
            {
                if(v[i-1] == false)
                {
                    count1++;
                    v[i-1] = true;

                }
                break;
            }
            temp1 = temp1 / 8;
        }
    }
    cout<<N-(count+count1)<<endl;
}

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

int main(){
    int n;
    cin>>n;
    int a=0;
    for(int i=1;i<=n;i++){
        int x=i;
		int y=i;
        bool z=1;
        while(x>0){
            if(x%10==7) z=0;
            x/=10;
        }
        while(y>0){
            if(y%8==7) z=0;
            y/=8;
        }
        if(z) a++;
    }
    cout<<a<<endl;
}


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

int main()
{
  int n;
  cin >> n;
  cout << n - 1 << endl;
  return 0;
}

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

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

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

	int N;
	cin >> N;

	co(N - 1);
	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;

// xのn乗
long long powmod(long long x, long long n) {
  if (n == 0) return 1;
  if (n == 1) return x % MOD;
  if (n % 2 == 1) return (x * powmod(x, n - 1)) % MOD;
  long long t = powmod(x, n / 2);
  return (t * t) % MOD;
}

int main() {
  long long  n, p;
  cin >> n >> p;
  long long re = p - 1;

  re *= powmod(p-2, n-1);
  re %= MOD;

  cout << re << endl;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using db = double;
using ldb = long double;

#define _for(i, l, r) for (auto i = (l); i <= (r); ++i)
#define _rfor(i, r, l) for (auto i = (r); i >= (l); --i)

const int N = 5e3 + 5;
const int MOD = 1e9 + 7;

i64 qpow(i64 a, i64 b, i64 mod = MOD) {
    i64 res = 1;
    for (; b; b >>= 1, (a *= a) %= mod)
        if (b & 1) (res *= a) %= mod;
    return res;
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t _CLOCK_ST = clock();
#endif
    //======================================
    i64 n, p;
    cin >> n >> p;
    cout << (p - 1) * qpow(p - 2, n - 1) % MOD;
    //=====================================
#ifndef ONLINE_JUDGE
    std::cerr
        << "\n---\n"
        << "Time used: " << clock() - _CLOCK_ST << std::endl;
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 998244353
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[300005];
ll I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false;
    if (n<=3) return true;
    if (n%2==0||n%3==0) return false;
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false;
    return true;
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

void swap(ll *a, ll *b)
{
	ll temp=*a;
	*a=*b;
	*b=temp;
}

ll fact(ll n) {
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

ll modInverse(ll n,ll p)
{
	return bpow(n,p-2);
}

ll fac[300001];

ll nCr(ll n,ll r)
{
    if (r == 0) return 1;
    return (fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod) % mod;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}

int main()
{
	FAST
//	freopen("d.txt","r",stdin);
//    freopen("outputd.txt","w",stdout);
	ll testcases=1;
//	cin>>testcases;
//	fac[0]=1;
//	for(ll i=1;i<300001;i++) fac[i]=(fac[i-1]*i)%mod;
	while(testcases--)
	{
		ll n;
		cin>>n;
		ll a[n];
		for(ll i=0;i<n;i++) cin>>a[i];
		sort(a,a+n);
		ll sum=0,ans=0;
		for(ll i=0;i<n;i++) sum+=a[i];
		ll dp[n+1][sum/2+1];
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(ll i=1;i<=n;i++)
		{
			for(ll j=0;j<=sum/2;j++)
			{
				if(j<a[i-1]) dp[i][j]=dp[i-1][j];
				else dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i-1][j]);
			}
		}
//		for(ll i=0;i<=n)
		for(ll i=sum/2;i>=0;i--)
		{
			if(dp[n][i]==1)
			{
				ans=sum-i;
				break;
			}
		}
		cout<<ans;
	}
}

#include<bits/stdc++.h>
#define int long long
#define ll int
#define itn int
#define ld long double
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define rep(i, n) for(int  i = 0 ; i < n ; i++ )
#define repu(i, a, b) for(int i = a; i <=b; ++i)
#define repd(i, a, b) for(int i = a; i >=b; --i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

using namespace std;

const long long MOD = 1000000007;
int findMin(vi &t, int sum){
    int n = sz(t);
    bool dp[n+1][sum+1];
    rep(i,n+1){
        dp[i][0] = true;
    }

    repu(i,1,sum){
        dp[0][i] = false;
    }

    repu(i,1,n){
        repu(j,1,sum){
            dp[i][j] = dp[i-1][j];
            if(t[i-1] <= j) dp[i][j] |= dp[i-1][j-t[i-1]];
        }
    }

    int diff = LONG_MAX;
    repd(j,sum/2,0){
        if(dp[n][j]){
            diff = sum - 2*j;
            break;
        }
    }
    return diff;
}

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

    vi t(n);
    int sum = 0;
    rep(i,n) {
        cin >> t[i];
        sum+= t[i];
    }
    int diff = findMin(t,sum);
    int x = (sum+diff)/2;
    int y = sum - x;
    cout << max(x,y) << endl;
}

signed main(){

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

    ll t = 1;
    // cin >> t;
    rep(z,t){
        solve();
    }

    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";

    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

int main(){
    int a,b;scanf("%d%d",&a,&b);
    printf("%.10f\n",100-100.0*b/a);
    return 0;
}

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

int main()
{
    long double n,m;
    cin>>n>>m;
    long double d=n-m;
    long double e=d/n;
    long double f=e*100;
    cout<<f;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define rsrtl(v) sort(v.begin(), v.end(), greater<ll>())
#define fi(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
#define srt(v) sort(v.begin(), v.end())
#define pb push_back
#define g(v, i, j) get<i>(v[j])
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
ll md = 1000000007;
#define theartofwar                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define F first
#define S second
#define sz(v) v.size()
using namespace std;
#define dbg(x) cerr << #x << " = " << x << endl;
template <typename T>
T pw(T a, T b){
    T c = 1, m = a;
    while (b){
        if (b & 1) c = (c * m);
        m = (m * m), b /= 2;
    }
    return c;
}
template <typename T>
T ceel(T a, T b){
    if (a % b == 0)
        return a / b;
    else
        return a / b + 1;
}
template <typename T>
T my_log(T n, T b){
    T i = 1, ans = 0;
    while (1){
        if (i > n){
            ans--;
            break;
        }
        if (i == n) break;
        i *= b, ans++;
    }
    return ans;
}
template <typename T>
T gcd(T a, T b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
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 inverse(ll i){
    if (i == 1)
        return 1;
    return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b){
    return (a.second < b.second);
}
int main()
{
    theartofwar;
    ll a, b, c;
    cin >> a >> b >> c;
    if (c % 2){
        if (a == b) cout << "=";
        else if (a > b) cout << ">";
        else cout << "<";
    }
    else{
        a = abs(a), b = abs(b);
        if (a == b) cout << "=";
        else if (a > b) cout << ">";
        else cout << "<";
    }
}

 //----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
typedef    long long                	 ll;
typedef    long double              	 ld;
typedef    unordered_set<ll>         	 usll;
typedef    unordered_multiset<ll>    	 umsll;
typedef    multiset<ll>              	 msll;
typedef    set<ll>                  	 sll;
typedef    vector<ll>               	 vll;
typedef    pair<ll,ll>              	 pll;
typedef    vector<pll>              	 vpll;
typedef    priority_queue<ll>       	 pqll;
typedef    vector<int>              	 vi;
typedef    set<int>                 	 si;
typedef    multiset<int>            	 msi;
typedef    unordered_multiset<int>  	 umsi;
typedef    unordered_set<int>       	 usi;
typedef    pair<int,int>               	 pi;
typedef    vector<pi>                	 vpi;
typedef    priority_queue<int>       	 pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_sll;
typedef    tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
typedef    tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_msll;
#define    in          		insert
#define    fi          		first
#define    se          		second
#define    pb   	    	push_back
#define    mp   	   		make_pair
#define    be   	   		begin
#define    en   	   		end
#define    itr  	   		iterator
#define    io  	       		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   	   		998244353
#define    inf  	   		8222372026854775807
#define    ninf   	   		-inf
#define    ima   	   		2047483647
#define    imi   	   		-ima
#define    oncnt       		__builtin_popcount
#define    zerobegin   		__builtin_clz
#define    zeroend    		__builtin_ctz
#define    parity      		__builtin_parity
#define    eps         		1e-9
#define    coutd       		cout<<setprecision(10)<<fixed
#define    mems(dp,x)  		memset(dp,x,sizeof(dp))
#define    fbo         		find_by_order
#define    ook    	   		order_of_key
#define    all(x)      		x.be(),x.en()
#define    upb    	   		upper_bound
#define    lowb  	   		lower_bound
#define    lte(v,x)    		(upb(all(v),x)-v.be())
#define    gte(v,x)    		(v.end()-lowb(all(v),x))
#define    gt(v,x)     		(v.en()-upb(all(v),x))
#define    lt(v,x)     		(lowb(all(v),x)-v.be())
const      ld PI= 			3.1415926535897932384626433832792884197169399375105820974944;
inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll minv(ll x){return mpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

ll inta(vll v)
{
	ll c=0;
	for(auto x:v)c=c*10+x;
	return c;
}

ll g1(ll n)
{
	vll v;
	while(n)
	{
		v.pb(n%10);
		n/=10;
	}
	sort(all(v));
	reverse(all(v));
	return inta(v);
}

ll g2(ll n)
{
	vll v;
	while(n)
	{
		v.pb(n%10);
		n/=10;
	}
	sort(all(v));
	//reverse(all(v));
	return inta(v);
}

ll f(ll n)
{
	return g1(n)-g2(n);
}

int main()
{              io
int testcases=1;           //        cin>>testcases;
while(testcases--)
{

ll n,k;
cin>>n>>k;

for(int i=0;i<k;i++)
	n=f(n);

cout<<n;

}return 0;}