#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <list>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <string.h>

using namespace std;

#define REP(i,n) for (decltype(n) i = 0; i < n; i++)

using ll = long long;
using ivec = vector<int>;
using lvec = vector<long>;
using ipair = pair<int, int>;
using llvec = vector<ll>;
using llpair = pair<ll, ll>;
#define umap unordered_map
#define uset unordered_set

#define THE_MOD 1000000007

template<typename T>
vector<T> read_args()
{
	T N;
	cin >> N;
	vector<T> v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

template<class T>
void sort(T& v)
{
	sort(v.begin(), v.end());
}

template<class T>
void rsort(T& v)
{
	sort(v.begin(), v.end(), greater<typename T::value_type>());
}

void answer(bool b)
{
	cout << (b ? "Yes" : "No") << endl;
}

ll run()
{
//	int a,b,c; cin>>a>>b>>c;
	int a,b,x,y;cin >> a>>b>>x>>y;
	if (a == b) {
		return x;
	}
	if (a < b) {
		int t1 = (b - a) * y + x;
		int t2 = (b - a) * (2 * x) + x;
		return min(t1, t2);
	}
	{
		int t1 = (a - b - 1) * y + x;
		int t2 = (a - b - 1) * (2 * x) + x;
		return min(t1, t2);
	}
}

int main()
{
	// std::setprecision(15)
	auto r = run();
	cout << r << endl;
	return 0;
}

#include <iostream>

using namespace std;
#define ll long long

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

ll t;

ll power(ll x, ll p) {
  ll ans = 1;
  while (p) {
    if (p & 1) {
      ans = (ans * x) % mod;
      p--;
    }
    x = (x * x) % mod;
    p >>= 1;
  }
  return ans;
}

ll add(ll x, ll y) { return ((x % mod) + (y % mod)) % mod; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }
ll sub(ll x, ll y) { return ((x % mod) - (y % mod) + mod) % mod; }
ll nC2(ll x) { return mul(mul(x, x - 1), power(2, mod - 2)); }

void Solve() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (a + b > n) {
    cout << 0 << endl;
    return;
  }
  ll tot = mul(mul(4, nC2(n - a - b + 2)), mul(n - a + 1, n - b + 1));
  ll overlap = mul(4, mul(nC2(n - a - b + 2), nC2(n - a - b + 2)));
  ll ans = sub(tot, overlap);
  cout << ans << endl;
}

signed main() {
  cin >> t;
  while (t--) {
    Solve();
  }
}


#include <math.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include<set>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()//配列を全部参照

using namespace std;
using ll = long long int;
//vector<vector<int>> hako(n, vector<int>(2));

int main() {
    int h,w,x,y;
    string s;
    int ans=1;
    cin >> h >> w >> x >>y;
    vector<vector<char>> hako(h, vector<char>(w));
    rep(i, h)rep(j, w) cin >> hako[i][j];
    x--;
    y--;

    for (int i = x+1; i < h; i++) {
        if (hako[i][y] == '#')break;
        ans++;
    }
    for (int i = x-1; i >= 0; i--) {
        if (hako[i][y] == '#')break;
        ans++;
    }
    for (int i = y+1; i < w; i++) {
        if (hako[x][i] == '#')break;
        ans++;
    }
    for (int i = y-1; i >= 0; i--) {
        if (hako[x][i] == '#')break;
        ans++;
    }

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

/*{{{ #include */
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <tuple>
#include <algorithm>
#include <utility>
#include <cmath>/*}}}*/
/*{{{ namespace R2357 */
namespace R2357 {
    inline void IN(void){return;}
    template<class F,class... R>inline void IN(F& f,R&... r){std::cin>>f;IN(r...);}
    template <class T>inline void OUT(T x){std::cout<<x<<'\n';}
    template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
    template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
    template<class T=int>T read(){
        T x=0; char c;
        while(((c=getchar())>'9'||c<'0')&&c!='-');
        const bool f=(c=='-')&&(c=getchar());
        while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
        return f?-x:x;
    }
    template<class T>std::istream& operator>>(std::istream& is,std::vector<T>& V){
        for(auto& v:V)is>>v; return is;
    }
    template<class T1,class T2>
    std::istream& operator>>(std::istream& is,std::pair<T1,T2>& P){
        return is>>P.first>>P.second;
    }
    template<class T>inline T ceil_div(T a,T b){
    	return (a+(b-1))/b;
    }
    namespace debug {
        using namespace std;
        void Write(void){cerr<<endl;}
        template<class F,class...R>void Write(F f,R...r){cerr<<' '<<f;Write(r...);}
        template<class T>void Write(vector<T>& V,int n=-1){
            if(n==-1) n = V.size();
            for(int i=0;i<n;i++)cerr<<' '<<V[i]; cerr<<endl;
        }
        template<class T,class U> void Write(pair<T,U>& p){cerr<<' '<<'{'<<p.first<<','<<p.second<<'}'<<endl;}
        #include <cxxabi.h>
        template<class T>string TypeName(T& x){
            return string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0));
        }
    }
}/*}}}*/
/*{{{ using */
using namespace std; using namespace R2357;
using ll=long long; using ld=long double;
using pint=pair<int,int>;/*}}}*/
/*{{{ #define */
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define each(x,v) for(auto& x:v)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define Unique(x) sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end())
#define Fill(v,n) fill(v,v+sizeof(v)/sizeof(*v),n)
#define max_element(x) *max_element(x.begin(),x.end())
#define min_element(x) *min_element(x.begin(),x.end())
#define INF 1073741824 // 2e30
#define INFL 2305843009213693952ll // 2e61
#define _FASTIO_ ios::sync_with_stdio(false),cin.tie(nullptr);
/*}}}*/

int main(){ _FASTIO_
    int v, t, s, d; IN(v, t, s, d);
    t *= v;
    s *= v;
    if(t <= d && d <= s) OUT("No");
    else OUT("Yes");
    return 0;
}


#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

struct RangeSum {
  using T = double;
  T operator()(const T &a, const T &b) { return a + b; }
  static constexpr T id() { return T(0); };
};

template <typename M>
struct SegmentTree {
  using Val = typename M::T;
  M calc;
  vector<Val> data;
  int n;
  explicit SegmentTree(int size) {
    n = 1;
    while (n < size) n <<= 1;
    data = vector<Val>(n << 1, calc.id());
  }
  explicit SegmentTree(vector<Val> &v) {
    n = 1;
    while (n < v.size()) n <<= 1;
    data = vector<Val>(n << 1);
    copy(v.begin(), v.end(), data.begin() + n);
    for (int i = n + (int)v.size(); i < 2 * n; i++) data[i] = calc.id();
    for (int i = n - 1; i > 0; --i) {
      data[i] = calc(data[i * 2], data[i * 2 + 1]);
    }
  }
  void update(int i, Val v) {
    int k = i + n;
    data[k] = v;
    for (k >>= 1; k >= 1; k >>= 1) data[k] = calc(data[k * 2], data[k * 2 + 1]);
  }
  Val query(int l, int r) {  //get[a,b)
    Val resl = calc.id(), resr = calc.id();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = calc(resl, data[l++]);
      if (r & 1) resr = calc(data[r - 1], resr);
    }
    return calc(resl, resr);
  }
};

class Solver2 {
 public:
  int n, m;
  vector<int> is_return;
  SegmentTree<RangeSum> a_0, a_x;
  Solver2(LL n, LL m) : n(n), m(m), is_return(n + 1), a_0(n + 1), a_x(n + 1){};

  void solve() {
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
      int tmp;
      cin >> tmp;
      is_return[tmp] = 1;
    }
    for (int i = 0, j = 0; i <= n; ++i) {
      if (is_return[i]) {
        j++;
        if (j == m) {
          cout << -1 << endl;
          return;
        }
      } else {
        j = 0;
      }
    }
    a_0.update(n, 0);
    a_x.update(n, 0);
    for (int i = n - 1; i > 0; --i) {
      if (is_return[i]) {
        a_0.update(i, 0);
        a_x.update(i, 1);
      } else {
        double sum_0 = a_0.query(i + 1, min(i + m, n) + 1);
        double sum_x = a_x.query(i + 1, min(i + m, n) + 1);
        a_0.update(i, sum_0 / m + 1.0);
        a_x.update(i, sum_x / m);
        if (i > 99900) DBG(i, m - (n - i), sum_0 / m + 1.0, sum_x / m)
      }
    }
    double sum_0 = a_0.query(1, min(m, n) + 1);
    double sum_x = a_x.query(1, min(m, n) + 1);
    DBG(sum_0 / m + 1.0, sum_x / m)
    double ans = (sum_0 / m + 1.0) / (1.0 - sum_x / m);
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}

#include<bits/stdc++.h>
#define Pair pair<ll,int>
#define ar array
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std ;
const ll LLMAX = 9223372036854775807;
const int INF = 1e9;

struct Exp{
    long double a, b;
};

Exp operator +(Exp x, Exp y){
    return {x.a+y.a, x.b+y.b};
}

Exp operator -(Exp x, Exp y){
    return {x.a-y.a, x.b-y.b};
}
Exp operator /(Exp x, long double d){
    return {x.a/d, x.b/d};
}

bool mark[200005];
Exp dp[200005];
Exp sum[200005];
int n, m, k;

int main(){
    cin>>n>>m>>k;
    vector<int> kk;
    for(int i=0; i<k; i++){
        int a;
        cin>>a;
        kk.pb(a);
        mark[a] = true;
    }

    sort(kk.begin(), kk.end());
    if(k>0){
        int consec = 1;
        int max_consec = 1;
        for(int i=1; i<kk.size(); i++){
            if(kk[i]-kk[i-1]!=1){
                consec = 1;
            }
            else
                consec++;
            max_consec = max(max_consec, consec);
        }
        if(max_consec>=m){
            cout<<-1<<endl;
            return 0;
        }
    }

    sum[n] = {0,0};
    for(int i=n-1; i>=0; i--){
        if(!mark[i])
            dp[i] = (sum[i+1]-sum[i+m+1])/m + (Exp){0,1};
        else
            dp[i] = {1,0};
        sum[i] = sum[i+1]+dp[i];
    }

    long double res = dp[0].b / (1-dp[0].a);
    cout<<fixed<<setprecision(4)<<res<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) v.begin(), v.end()
template<class T>bool chmax(T& a, const T& b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T& a, const T& b) { if (b<a) { a=b; return 1;} return 0;}

int main() {
    int H, W, N, M; cin >> H >> W >> N >> M;
    vector<vector<int>> board(H, vector<int>(W, 0));
    vector<vector<bool>> res(H, vector<bool>(W, false));
    rep(i, N) {
        int a, b; cin >> a >> b;
        --a, --b;
        board[a][b] = 1;
    }
    rep(i, M) {
        int c, d; cin >> c >> d;
        --c; --d;
        board[c][d] = -1;
    }

    rep(y, H) {
        bool light = false;
        rep(x, W) {
            if (board[y][x] == 1) light = true;
            if (board[y][x] == -1) light = false;
            if (light) res[y][x] = true;
        }
        light = false;
        for (int x = W-1; x >= 0; --x) {
            if (board[y][x] == 1) light = true;
            if (board[y][x] == -1) light = false;
            if (light) res[y][x] = true;
        }
    }
    rep(x, W) {
        bool light = false;
        rep(y, H) {
            if (board[y][x] == 1) light = true;
            if (board[y][x] == -1) light = false;
            if (light) res[y][x] = true;
        }
        light = false;
        for (int y = H-1; y >= 0; --y) {
            if (board[y][x] == 1) light = true;
            if (board[y][x] == -1) light = false;
            if (light) res[y][x] = true;
        }
    }

    int sum = 0;
    rep(y, H) rep(x, W) if (res[y][x]) sum++;
    cout << sum << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
//bool vis[1000];
int x[]={1,-1,0,0};
int y[]={0,0,1,-1};
//int f=0;
//int t[500000];
//int ll[500000];
//"'';

int main(){
int r,c,n,m;
cin>>r>>c>>n>>m;
int dp[r][c][4];
memset(dp,0,sizeof(dp));
vector<vector<int> > v(r,vector<int>(c,0));
queue<vector<int> > q;
int ans=0;
for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    v[a][b]=1;
    for(int j=0;j<4;j++){
        q.push({a,b,j});
        dp[a][b][j]=1;
    }
}
for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    v[a][b]=-1;
}
while(!q.empty()){
    vector<int> u=q.front();
    q.pop();
    int na=u[0]+x[u[2]];
    int nb=u[1]+y[u[2]];
    int nd=u[2];
    if(na<r&&na>=0&&nb<c&&nb>=0&&dp[na][nb][nd]==0&&v[na][nb]!=-1){
        dp[na][nb][nd]=1;
        q.push({na,nb,nd});
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
        int f=0;
        for(int k=0;k<4;k++){
            f=max(f,dp[i][j][k]);
        }
        ans+=f;
    }
}
cout<<ans<<endl;
}


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

typedef long long ll;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N), b(N, 0);
    rep(i, N) {
        cin >> a[i];
        b[a[i]]++;
    }
    b[0] = min(b[0], K);
    rep(i, N - 1) b[i + 1] = min(b[i], b[i + 1]);
    ll ans = 0;
    rep(i, N - 1) {
        ans += (b[i] - b[i + 1]) * (i + 1);
    }
    cout << ans << "\n";
}

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

//TEMPLATE
#define len(a)            (ll) a.size()
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)
#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)

#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cots(a)           cout << a << " "
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotcase(cs)       cout << "Case " << cs << ": "
#define yes               cout << "Yes\n"
#define no                cout << "No\n"
#define line              cout << "\n"

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)

#define ll                long long
#define pb                push_back
#define mp                make_pair
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second
#define pi                acos(-1.0)

#define bug(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n'
void err(istringstream *iss) {}
template<typename T, typename... Args>
void err(istringstream *iss, const T a, const Args... args) {
    string _name;
    *iss >> _name;
    if (_name.back()==',') _name.pop_back();
    cerr << _name << " = " << fixed << setprecision(5) << a << "; ", err(iss, args...);
}

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;

string s, s1, s2;
ll n, k, ans = 0;
ll a[SZ];
ll f[SZ];

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin2(n, k);
    for1(i, n) cin1(a[i]), f[a[i]]++;

    fora(i, 0, n) {
        c = max(0LL, k-f[i]);
        c = min(c, k);
        ans += (c * i);
        k -= c;
    }

    cot1(ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a),(i##i)=(b);i<=(i##i);++i)
#define Rep(i,n) for(int i=0,(i##i)=(n);i<(i##i);++i)
#define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i)
#define pln puts("")
#define il inline
#define ff first
#define ss second
using LL=long long;using u32=unsigned int;using u64=unsigned LL;using LD=long double;
template<typename T>using pii=pair<T,T>;
template<typename T>il bool read(T&x){
x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar();
if(c==EOF)return 0;if(c=='-')f=-1,c=getchar();
while(isdigit(c)){x=(x<<1)+(x<<3)+(c&15);c=getchar();}x*=f;return 1;}
template<typename T,typename...Args>
il bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;}
const int M=1000000007,INF=0x3f3f3f3f;const LL INFLL=0x3f3f3f3f3f3f3f3fLL;
const int N=10010;const double EPS=1e-6;

LL n,f[N][16];
inline void init(){
    read(n);
    For(i,1,n)read(f[i][0]);
    int t=log(n)/log(2)+1;
    For(i,1,t-1)For(j,1,(n-(1<<i)+1))f[j][i]=min(f[j][i-1],f[j+(1<<(i-1))][i-1]);
}
il LL find(int l,int r){
    int k=log(r-l+1)/log(2);
    return min(f[l][k],f[r-(1<<k)+1][k]);
}
LL ans=0;
inline void solve(){
    For(i,1,n)For(j,i,n)ans=max(ans,(j-i+1)*find(i,j));
    printf("%lld\n",ans);
}
signed main(){
    init();solve();
    return 0;
}

#include<bits/stdc++.h>
#define l long
#define ll long long
#define ld long double
#define MOD 1000000007
#define MAX_N 1000006
#define f first
#define s second
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const ll inf=1e18;
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
int main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll n,lcm=1;
    cin>>n;
    for(ll i=2;i<=n;i++){
        lcm=lcm*(i/gcd(i,lcm));
    }
    lcm++;
    cout<<lcm<<"\n";
    return 0;
}


#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	long long int r, x, y;
	cin >> r >> x >> y;
	if (x * x + y * y == r * r) {
		cout << 1 << endl;
		return 0;
	}
	for (long long int i = 2; i <= 200000; i++) {
		if (r * r * i * i >= x * x + y * y) {
			cout << i << endl;
			return 0;
		}
	}
}

//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
struct Init_io {
    Init_io() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << boolalpha << fixed << setprecision(15);
    }
} init_io;
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    LL(r, x, y);
    ll l = x * x + y * y;
    if (l < r * r) fin(2);
    r *= r;
    ll ok = inf, ng = 0;
    auto f = [&](ll x) -> bool {
        if (x * x > linf / r) return true;
        return l <= x * x * r;
    };
    while (abs(ok - ng) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid)) ok = mid;
        else ng = mid;
    }
    fin(ok);
}


#include <bits/stdc++.h>
using namespace std;
int main(){

	int n;
	string s;
	char a, b;
	cin >> n >> s;
	a = s[0];
	b = s[s.length()-1];
	bool ok = false;
	for(int i=1; i<s.length(); i++){
		if(s[i]!=a && s[i+1]!=b) ok= true;
	}
	if(a!=b) cout << "1";
	else if(ok) cout << "2";
	else cout << "-1";

    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>

#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 = 'z' - 'a' + 1;

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

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

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 n;
    is >> n;

    string s;
    is >> s;

    char t = s[0];
    bool g = 1;

    FORA(i, s)
        g &= i == t;

    if(g)
    {
        os << "-1\n";
        return;
    }

    if(s.front() != s.back())
    {
        os << "1\n";
        return;
    }

    g = 0;
    FOR(i, n - 1)
        if(t != s[i] && t != s[i + 1])
        {
            g = 1;
        }

    if(g)
        os << "2\n";
    else
        os << "-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>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; //required
using namespace std;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << #x << " is " << x << endl
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
typedef long long ll;
const int MOD = 1e9 + 7;

int main(){
    fast;
    vector<ll> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
    ll a, b;
    cin >> a >> b;
    vector<ll> dp(1048578, 0), prev(1048578, 0);
    dp[0] = 1;
    vector<int> state;
    int tmp;
    for (ll i = a; i <= b; ++i){
        tmp = 0;
        for (int j = 0; j < 20; ++j){
            if (i % prime[j] == 0){
                tmp |= (1 << j);
            }
        }
        // debug(tmp);
        state.push_back(tmp);
    }
    for (ll s: state){
        for (int i = 0; i < 1048578; ++i){
            prev[i] = dp[i];
        }
        for (int i = 0; i < 1048578; ++i){
            dp[i] = prev[i];
            if ((i & s) == s){
                dp[i] += dp[i^s];
            }

        }
    }
    ll res = 0;
    for (int i = 0; i < 1048578; ++i){
        res += dp[i];
    }
    cout << res << endl;
    return 0;
}

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

using lli = int64_t;
using ld = long double;

lli g = 10000;

lli dist(lli x1, lli y1, lli x2, lli y2)
{
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

lli bsearch(lli x, lli y, lli r, lli y1, lli l, lli h, bool fl)
{
    lli ans = LLONG_MAX;

    while (l <= h)
    {
        lli mid = l + (h - l) / 2;
        mid -= mid % g;

        if (dist(x, y, mid, y1) <= r * r)
        {
            ans = mid;

            (fl ? l : h) = mid + (fl ? g : -g);
        }
        else
            (fl ? h : l) = mid + (fl ? -g : g);
    }

    return ans;
}

lli calc(lli x, lli y, lli r, lli y1)
{
    lli rx = x;
    rx -= rx % g;

    lli mid = LLONG_MAX;

    if (dist(x, y, rx, y1) <= r * r)
        mid = rx;
    else
    if (dist(x, y, rx + g, y1) <= r * r)
        mid = rx + g;

    if (mid == LLONG_MAX) return 0;

    lli rl = x - r;
    lli rr = x + r;

    rl -= rl % g;
    rr -= rr % g;
    rr += g;

    lli l = bsearch(x, y, r, y1, rl, mid, false);
    lli h = bsearch(x, y, r, y1, mid, rr, true);

    return (h - l) / g + 1;
}

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

    ld xd, yd, rd; cin >> xd >> yd >> rd;

    lli x = llroundl(xd * ld(g));
    lli y = llroundl(yd * ld(g));
    lli r = llroundl(rd * ld(g));

    lli ans = 0;

    for (lli y1 = y - y % g; y - y1 <= r; y1 -= g)
        ans += calc(x, y, r, y1);

    for (lli y1 = y - (y % g) + g; y1 - y <= r; y1 += g)
        ans += calc(x, y, r, y1);

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


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

void solve(){
	int n;
	string a,b,c;
	cin>>n;
	cin>>a>>b>>c;
	for(int i=1;i<=n;i++) cout<<0;
	for(int i=1;i<=n;i++) cout<<1;
	cout<<0<<"\n";
}

int main(){

	int t=1;
	cin>>t;

	for(int tc=1; tc<=t; tc++){
		solve();
	}

	return 0;
}

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

ll cat(string s) {
    if (s[0]=='0' && s[s.length()-1]=='0') return 0;
    if (s[0]=='0' && s[s.length()-1]=='1') return 1;
    if (s[0]=='1' && s[s.length()-1]=='0') return 2;
    else return 3;
}

void solve() {
    ll n; string a, b, c; cin >> n >> a >> b >> c;
    if (cat(a)!=3 && cat(b)!=3 && cat(c)!=3) {
        string ans = "";
        REP(i,n) ans+='1';
        ans+='0';
        REP(i,n) ans+='1';
        cout << ans << endl;
        return;
    }
    if (cat(a)!=0 && cat(b)!=0 && cat(c)!=0) {
        string ans = "";
        REP(i,n) ans+='0';
        ans+='1';
        REP(i,n) ans+='0';
        cout << ans << endl;
        return;
    }
    else {
        string ans ="";
        REP(i,n) ans+='0';
        REP(i,n) ans+='1';
        ans+='0';
        cout << ans << endl;
        return;
    }
}
int main(){
    ll t; cin >> t;
    REP(i,t) solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

void solve()
{
    int n;
    cin >> n;
    vector<vector<ll>> ncr(205, vector<ll>(15));
    ncr[0][0] = 1;
    for (int i = 1; i <= 200; i++)
    {
        ncr[i][0] = 1;
        for (int j = 1; j <= min(12, i); j++)
        {
            ncr[i][j] = ncr[i - 1][j] + ncr[i - 1][j - 1];
        }
    }
    cout << ncr[n - 1][11];
}

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

    return 0;
}


#include<bits/stdc++.h>
#define N 505
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
bool mmp1;
int n,m,K;
namespace P100 {
	int C[N][N];
	int A[N],B[N];
	int D[N][N];
	void solve() {
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				scanf("%d",&C[i][j]);
		for(int i=1;i<=n;i++)
			B[i]=C[1][i];
		for(int i=1;i<=n;i++)
			A[i]=C[i][1]-B[1];
		int ma=A[1],mb=B[1];
		for(int i=2;i<=n;i++)ma=min(ma,A[i]);
		for(int i=2;i<=n;i++)mb=min(mb,B[i]);
		if(ma+mb<0){
			puts("No");
			return;
		}else if(ma<0)for(int i=1;i<=n;i++)A[i]-=ma,B[i]+=ma;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				// printf("D[%d][%d]=%d\n",i,j,A[i]+B[j]);
				if(C[i][j]!=A[i]+B[j]){
					puts("No");
					return;
				}
			}
		puts("Yes");
		for(int i=1;i<=n;i++)
			printf("%d ",A[i]);
		puts("");
		for(int i=1;i<=n;i++)
			printf("%d ",B[i]);
	}
}
bool mmp2;
int main() {
//	srand(time(0));
//	printf("%.6fMB\n",(&mmp2-&mmp1)/1024.0/1024);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	P100::solve();
	return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*
250000
２ぶたん？
最初のAさえ決まればあとは全部？

*/
ll C[550][550];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll low = 1e9;
  ll high = 0;
  rep(i, N) rep(j, N)cin >> C[i][j];
  rep(i, N) rep(j, N){
    chmin(low, C[i][j]);
    chmax(high, C[i][j]);
  }
  // lowより小さい数だけが候補
  // さが同じかどうか
  ll dif[550] = {};
  rep(i, N-1){
    dif[i] = C[i+1][0] - C[i][0];
    rep(j, N){
      if (C[i+1][j] - C[i][j] != dif[i]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  ll bmin=1e9;
  // Bは一番小さい数がある行
  ll B[550]={};
  rep(i, N) chmin(bmin, C[i][0]);
  rep(i, N){
    if (C[i][0] == bmin)
    {
      rep(j, N) B[j] = C[i][j];
      break;
    }
  }
  ll A[550] = {};
  rep(i, N){
    A[i] = C[i][0] - bmin;
  }
  cout << "Yes" << endl;
  rep(i, N){
    cout << A[i];
    if (i==N-1) cout << endl;
    else cout << " ";
  }
  rep(i, N){
    cout << B[i];
    if (i==N-1) cout << endl;
    else cout << " ";
  }
}


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

typedef long long ll;

ll gcd(ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int prime[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    ll ans = 1e18;
    rep(i, 1 << 15) {
        ll a = 1;
        rep(j, 15) {
            if ((i >> j) & 1) a *= prime[j];
        }
        bool f = true;
        rep(j, N) {
            if (gcd(a, X[j]) == 1) {
                f = false;
                break;
            }
        }
        if (f) ans = min(ans, a);
    }
    cout << ans << "\n";
}

#include <iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#define f first
#define s second
using namespace std;
vector<pair<int,int> > e(60);
vector<int> num;
bool cmp(pair<int,int> a,pair<int,int> b){
    if(a.first==b.first) return a.second<b.second;
    return a.first>b.first;
}
int main() {
    int n,x;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        for(int j=2;j<=x;j++){
            if(x%j==0){
                e[j].first++;
                e[j].second=j;
            }
        }
        num.push_back(x);
    }
    long long now=n,ans=1;
    while(now>0){
        sort(e.begin(),e.end(),cmp);
        long long tmp=e[0].second;
        //cout<<"tmp="<<tmp<<endl;
        for(int i=0;i<n;i++){
            if(num[i]%tmp==0){
                //cout<<"who="<<i<<endl;
                num[i]=1;
                now--;
            }
        }
        for(int i=0;i<60;i++){
            e[i].first=0;
            e[i].second=0;
        }
        ans*=tmp;
        for(int i=0;i<n;i++){
            for(int j=2;j<=num[i];j++){
                if(num[i]%j==0){
                    e[j].first++;
                    e[j].second=j;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

//#define MULTITEST

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

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

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e8);
const li INF64 = li(1e18);
const int MOD = int(1e9) + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

int n, m;

bool read () {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	return true;
}

void solve() {
	if (m == 0){
		forn(i, n) printf("%d %d\n", 2 * i + 1, 2 * i + 2);
		return;
	}

	if (m < 0 || m >= n - 1){
		puts("-1");
		return;
	}

	vector<pt> ans;
	ans.pb(mp(0, 2 * m + 2));
	forn(i, m) ans.pb(mp(2 * i + 1, 2 * i + 2));
	ans.pb(mp(2 * m + 1, 2 * m + 3));

	int lst = 2 * m + 3;
	while (sz(ans) < n){
		ans.pb(mp(lst + 1, lst + 2));
		lst += 2;
	}

	for (auto it : ans)
		printf("%d %d\n", it.x + 1, it.y + 1);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef MULTITEST
	int tc;
	scanf("%d", &tc);
	while(tc--){
		read();
#else
	while(read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

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

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<ll> L(N), R(N);
    if ( N == 1 ) {
        if ( M != 0 ) return -1;
        cout << 1 << " " << 2 << "\n";
        return 0;
    }
    if ( M > N-2 ) return -1;
    if ( M < 0 ) return -1;
    for ( int i = 1; i < N; i++ ) {
        L[i] = 4*i+1;
        R[i] = 4*i+3;
    }
    L[0] = 2;
    R[0] = 4*(M+1)+2;
    for ( int i = 0; i < N; i++ ) {
        cout << L[i] << " " << R[i] << "\n";
    }
    return 0;
}

int main() {
    auto ans = solve();
    if ( ans < 0 ) {
        cout << ans << "\n";
    }
    return 0;
}


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

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

const int N=200005;

int n,k;
vector<int> e[N];

int vis[N],q[N],hi=1,ti,mid,up[N][20];

int get_k(int u) {
	for(int i=0;i<=19;i++) if(mid&(1<<i)) u=up[u][i];
	return u;
}

void dfs(int u,int x) {
//	if(u==12) cout<<x<<endl;
//	cout<<u<<' '<<x<<endl;
	if(x==mid+1 || (vis[u]<=x+1 && vis[u]!=0)) return;
	vis[u]=x+1;
	for(int i=0;i<e[u].size();i++) {
		dfs(e[u][i],x+1);
	}
}

void get_fa(int u,int fa) {
	up[u][0]=fa;
	for(int i=1;i<=19;i++) up[u][i]=up[up[u][i-1]][i-1];
	for(int i=0;i<e[u].size();i++) {
		if(e[u][i]!=fa) get_fa(e[u][i],u);
	}
}

bool check() {
	int ans=0;
	memset(vis,0,sizeof(vis));
	for(int i=n;i>=1;i--) {
		if(vis[q[i]]) continue;
		ans++;
//		cout<<"g"<<get_k(q[i])<<endl;
//		cout<<vis[]

		dfs(get_k(q[i]),0);
//		for(int j=1;j<=n;j++) cout<<vis[]
//		exit(0);
	}
	if(ans<=k) return 1;
	else return 0;
}

signed main() {
	n=read(),k=read();
	for(int i=1,u,v;i<n;i++) {
		u=read(),v=read();
		e[u].push_back(v),e[v].push_back(u);
	}
	//求出每个点的距离
	get_fa(1,1);
	q[++ti]=1; vis[1]=1;
	while(hi<=ti) {
		int u=q[hi++];
		for(int i=0;i<e[u].size();i++) {
			if(!vis[e[u][i]]) q[++ti]=e[u][i],vis[e[u][i]]=1;
		}
	}
//	mid=1;
//	cout<<check()<<endl;
	int l=0,r=2e5;
	while(l<r) {
		mid=(l+r)>>1;
		if(check()) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;

}

#include <bits/stdc++.h>
#define lc (o<<1)
#define rc ((o<<1)|1)
#define PB push_back
#define MK make_pair
using namespace std;
#define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl

const int maxn = 2e5 + 5;
const int modu = 998244353; // 1e9 + 7
const int inf = 0x3f3f3f3f;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

void read(LL &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9')  {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}

void read(int &x) { LL y; read(y); x = (int)y; }
void read(char &ch) { char s[3]; scanf("%s", s); ch = s[0]; }
void read(char *s) { scanf("%s", s); }
template<class T, class ...U> void read(T &x, U& ... u) { read(x); read(u...); }

int n, k, m;
int mind[maxn], f[maxn], maxd[maxn];
vector<int> g[maxn];

int dfs(int x, int fa) {
    mind[x] = inf;
    maxd[x] = 0;
    f[x] = 0;
    for (int y: g[x]) if (fa != y) {
        dfs(y, x);
        maxd[x] = max(maxd[x], maxd[y]+1);
        mind[x] = min(mind[x], mind[y]+1);
        f[x] += f[y];
    }
    if (maxd[x] + mind[x] <= m) {
        maxd[x] = -1;
    }
    if (maxd[x] == m) {
        f[x]++;
        mind[x] = 0;
        maxd[x] = -1;
    }
    return f[x];
}

int cal(int _m) {
    m = _m;
    dfs(1, 0);
    if (maxd[1] >= 0) return f[1]+1;
    else return f[1];
}

int bs(int l, int r) {
    while (l < r) {
        int mid = l+r >> 1;
        if (cal(mid) <= k) r = mid;
        else l = mid+1;
    }
    return l;
}

int main() {
    // freopen("my.txt", "w", stdout);
    read(n, k);
    for (int i = 0; i < n-1; ++i) {
        int u, v;
        read(u, v);
        g[u].PB(v);
        g[v].PB(u);
    }
    printf("%d\n", bs(0, n));
	return 0;
}


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

#define fo(i, n) for (i = 0; i < n; i++)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MI map<int,int>
#define MC map<char,int>
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl "\n"
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "\n"
#define deb4(x, y, z, w) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << "\n"
#define input(arr,n) for(i=0;i<n;i++) cin>>arr[i]
#define showarr(arr,n) for( i=0; i<n; i++) cout<<arr[i]<<" "; cout<<endl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
ll a[N];
vector<vector<int>> adj;
vector<int> vis;
vector<ll> all_cp;

ll ma = -LLONG_MAX;

void dfs(ll u)
{
	for (ll v : adj[u])
	{	//deb3(u, v, a[u - 1]);
		all_cp[v] = min({all_cp[v], a[u - 1], all_cp[u]});
	}
}

void solve()
{
	int i = 0, j = 0, n, m, k, flag = 0 , ans = 0, u, v;
	cin >> n >> m;
	ll CP = LLONG_MAX;
	adj.resize(n + 1);
	vis.resize(n + 1);
	all_cp.resize(n + 1);
	input(a, n);
	fo(i, m)
	{
		cin >> u >> v;
		adj[u].pb(v);
	}
	all_cp[0] = LLONG_MAX;
	fo(i, n)
	all_cp[i + 1] = LLONG_MAX;
	// fo(i, n + 1)
	// {
	// 	cout << i << "---> ";
	// 	fo(j, adj[i].size())
	// 	cout << adj[i][j] << " ";
	// 	cout << endl;
	// }
	for (i = 1; i <= n; i++)
	{
		dfs(i);
	}
	// fo(i, n)	cout << i + 1 << " " << vis[i + 1] << "   "; cout << endl;
	// fo(i, n)	cout << i + 1 << " " << all_cp[i + 1] << "   "; cout << endl;
	for (i = 1; i <= n; i++)
	{
		ma = max(a[i - 1] - all_cp[i], ma);
	}
	if (ma == -LLONG_MAX)
		cout << 0;
	else
		cout << ma;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int t = 1;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

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

	int n, m; cin >> n >> m;
	vector<int64_t> vs(n + 1);
	vector<int64_t> dp(n + 1, INT64_MIN);
	FOR_LE(i, 1, n) {
		cin >> vs[i];
	}

	vector<vector<int>> es(n + 1);
	FOR_LT(i, 0, m) {
		int a, b; cin >> a >> b;
		es[a].push_back(b);
	}

	int64_t ans = INT64_MIN;
	FOR_LE(i, 1, n) {
		ans = max(ans, vs[i] + dp[i]);
		dp[i] = max(dp[i], -vs[i]);
		for (auto& p : es[i]) {
			dp[p] = max(dp[p], dp[i]);
		}
	}
	cout << ans << endl;

	return 0;
}


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

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

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

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (106)
ll n;
bitset<MAXN> vis;
vector<int> v[MAXN];
int main() {
	FAST
	cin>>n;
	FOR(i,1,n) FOR(j,1,n) {
		char c; cin>>c;
		if(c=='1') {
			v[i].eb(j);
		}
	}
	ld ans = 0;
	FOR(i,1,n) {
		ll co = 0;
		function<void(ll)>dfs=[&](ll x){
			if(vis[x])return;
			vis[x]=1;
			for(auto i:v[x]) dfs(i);
		};
		FOR(j,1,n) {
			vis.reset();
			dfs(j);
			co += (int)vis[i];
		}
		FOR(j,0,n-1) {
			if(j>n-co) break;
			ld p = 1;
			FOR(k,0,j-1) {
				p *= ld(n-co-k) / ld(n-k);
			}
			p *= (ld)1 / (n-j);
			ans += p;
		}
	}
	cout<<setprecision(15)<<fixed<<ans<<'\n';
}

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##z=(b);i<=i##z;i++)
#define ROF(i,a,b) for(int i=(a),i##z=(b);i>=i##z;i--)
#define temT template<typename T>
using namespace std;
typedef double ld;
const int N=int(1e2)+10;

int n; char f[N][N]; ld res;

void bbfs(int i){//back bfs
	static queue<int> que;
	static bool vis[N]; int tot=0;
	memset(vis,0,sizeof(vis));

	que.push(i),vis[i]=1,tot=1;
	while(que.size()){
		int u=que.front(); que.pop();
		FOR(v,1,n) if(f[v][u]=='1' && !vis[v])
			tot++,que.push(v),vis[v]=1;
	}

	res+=1.0/tot;
}

int main(){
	scanf("%d",&n);
	FOR(i,1,n) scanf("%s",f[i]+1);
	FOR(i,1,n) bbfs(i);
	printf("%.15lf",res);
	return 0;
}


#include <algorithm>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
  for (auto val : vec) {
    if (std::is_fundamental<T>::value)
      stream << " " << val;
    else
      stream << std::endl << val;
  }
  return stream;
}

int main() {
  int A, B;
  std::cin >> A >> B;
  long long v = A * B;
  double ans = v / 100.0;
  std::cout << std::setprecision(10);
  std::cout << ans << std::endl;
}

//ver 8.1
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : (v))
#define reps(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) ((a)<=(x)&&(x)<=(b))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
  init();
  inl(a,b);
  out(a*b/100.0);
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define PLL pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll p = 1e9+7;
// ll p = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

int main(){
  cci(h,w);
  vvi v(h+2,vi(w+2,-1));
  rep(i,1,h+1){
      rep(j,1,w+1)vij=0;
  }
  cci(n,m);

  vvi lt(n,vi(2)),bl(m,vi(2));
  rep(i,0,n){
      rep(j,0,2)ci(lt[i][j]);
  }
  rep(i,0,m){
      rep(j,0,2)ci(bl[i][j]);
      v[bl[i][0]][bl[i][1]]=-1;
  }

    vvi tt=v,yk=v;
  rep(i,0,n){
      int x=lt[i][0];
      int y=lt[i][1];

      int nx=x,ny=y;
      tt[x][y]=yk[x][y]=1;
      while(tt[nx-1][y]==0)tt[--nx][y]=1;
      while(yk[x][ny-1]==0)yk[x][--ny]=1;

      nx=x,ny=y;
      while(tt[nx+1][y]==0)tt[++nx][y]=1;
      while(yk[x][ny+1]==0)yk[x][++ny]=1;
    }
/*
  rep(i,2,h+1){
      rep(j,1,w+1){
          if(yk[i][j]==-1)continue;
          chmax(yk[i][j],yk[i-1][j]);
      }
  }

  rep(i,2,w+1){
      rep(j,1,h+1){
          if(tt[j][i]==-1)continue;
          chmax(tt[j][i],tt[j][i-1]);
      }
  }
*/
    int ans=0;
    rep(i,1,h+1){
        rep(j,1,w+1){
            if(yk[i][j]==1 or tt[i][j]==1){
                // cout<<1<<" ";
                ans++;
            }
            // else if(vij==-1)cout<<'x'<<" ";
            // else cout<<0<<" ";
        }
        // co("");
    }

    co(ans);
}

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

long memo[1001001][2];
vector<pll> colors;

// direction -> 1 = right; 0 = left;
long dp(long unsigned color, int direction){
    if (color >= colors.size()) return 0;

    if(memo[color][direction] != -1)
        return memo[color][direction];

    ll l = colors[color].first;
    ll r = colors[color].second;
    ll dist = r-l;

    ll prev_pos = direction ?
        colors[color-1].second:
        colors[color-1].first;

    memo[color][direction] = min(
        dp(color+1, 0) + abs(prev_pos - r) + dist,
        dp(color+1, 1) + abs(prev_pos - l) + dist
    );

    return memo[color][direction];
}

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

    ll INF = LONG_LONG_MAX;
    vector<ll> l(n, INF);
    vector<ll> r(n, -INF);

    ll x, c;
    rep(i, n){
        cin >> x >> c;
        --c;
        l[c] = min(l[c], x);
        r[c] = max(r[c], x);
    }

    colors.emplace_back(0,0);
    rep(i, n){
        if (l[i] != INF)
            colors.emplace_back(l[i], r[i]);
    }
    colors.emplace_back(0,0);

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


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2>*arr;
  walloc1d(&arr, N, &mem);
  for(i=(0);i<(N);i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=(0);i<(N);i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
long long K;
long long A[200000];
long long B[200000];
int main(){
  int i;
  wmem = memarr;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
      rd(B[Lj4PdHRW]);
    }
  }
  sortA_L(N,A,B);
  for(i=(0);i<(N);i++){
    if(A[i] <= K){
      K += B[i];
    }
  }
  wt_L(K);
  wt_L('\n');
  return 0;
}
// cLay version 20210529-1 [beta]

// --- original code ---
// int N; ll K, A[2d5], B[2d5];
// {
//   rd(N,K,(A,B)(N));
//   sortA(N,A,B);
//   rep(i,N) if(A[i] <= K) K += B[i];
//   wt(K);
// }

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k; cin >> n >>k;
  vector<long long> points;
  vector<int> money;
  long long temp1;
  int temp2;
  for (int i = 0; i < n; i++){
    cin >> temp1;
    points.push_back(temp1);
    cin >> temp2;
    money.push_back(temp2);
  }
  vector<size_t> indices(points.size());
  iota(indices.begin(), indices.end(), 0);

  // ソートする。
  sort(indices.begin(), indices.end(), [&points](size_t i1, size_t i2) {
        return points[i1] < points[i2];
  });

  long long p;
  p = k;
  for (int i = 0; i < n; i++){
    if (p < points[indices[i]]){
      break;
    }else{
      p = p+money[indices[i]];
    }
  }
  cout << p <<endl;
  return 0;
}


#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

const ll MOD = 1000000007;
//const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = 1;
        mint tmp = 1;
        while(t > 0) {
            if (t & 1) a *= tmp;
            tmp *= *this;
            t >>= 1;
        }

        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

typedef vector<mint> vmi;

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

    int h, w; cin >> h >> w;
    vector<string> m(h);
    REP(i, h) cin >> m[i];

    vector<vi> cnt(h, vi(w, 0));

    // left - right
    REP(i, h) {
        int j = 0;
        int s = 0;
        while(j < w) {
            if (m[i][j] == '#') {
                for (int k = j - 1; k > -1 && m[i][k] != '#'; --k) {
                    cnt[i][k] += j;
                }
                s = j + 1;
            } else {
                cnt[i][j] -= s;
            }
            ++j;
        }

        for (int k = j - 1; k > -1 && m[i][k] != '#'; --k) {
            cnt[i][k] += j;
        }
    }

    // top
    REP(j, w) {
        int i = 0;
        int s = 0;
        while(i < h) {
            if (m[i][j] == '#') {
                for (int k = i - 1; k > -1 && m[k][j] != '#'; --k) {
                    cnt[k][j] += i;
                }
                s = i + 1;
            } else {
                cnt[i][j] -= s;
            }
            ++i;
        }

        for (int k = i - 1; k > -1 && m[k][j] != '#'; --k) {
            cnt[k][j] += i;
        }
    }

    ll all = 0;
    REP(i, h) REP(j, w) all += int(m[i][j] == '.');

    mint ans = 0;
    vmi t(all + 1, 1);
    FOR(i, 1, all + 1) t[i] = t[i - 1] * 2;

    REP(i, h) REP(j, w) {
        if (m[i][j] == '#') continue;
        int c = cnt[i][j] - 1;
        ans += t[all] - t[all - c];
    }

    print(ans);
}


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

#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair

#define fo(i,n) for(i=0;i<n;i++)
#define unq(v)      unique(v.begin(), v.end())-v.begin()
#define fnd(v,a)    find(v.begin(), v.end(), a)
#define uprb(v,a)   upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a)   lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v)    v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v)      reverse(v.begin(),v.end())
#define rndshf(v)   random_shuffle(v.begin(),v.end())
#define all(v)      v.begin(),v.end()

ll po(ll a,ll b,ll m)
{
ll t=1;
while(b>0)
{
    if(b%2!=0)
    {
        t=(t*a)%m;
    }
    a=(a*a)%m;
    b=b/2;
}
return t;
}
// ll inv(ll a,ll m)
// {
//   return po(a,m-2,m);
// }
// ll vis[100002]={0},x=0;
// vl v[100002];
// ll dfs(ll s)
// {
//   ll c=1,i;
//   for(i=0;i<v[s].size();i++)
//   {
//     if(vis[v[s][i]]==0)
//     {
//       vis[v[s][i]]=1;
//       c+=dfs(v[s][i]);
//     }
//   }
//   x+=c-1;
//   //cout<<x<<endl;
//   return c;
// }

void solve()
{
  ll n,p,s=1,x,y;
  cin>>n>>p;
  if(p==2)
  {
    if(n==1)
      cout<<"1";
    else
      cout<<"0";
    return;
  }
  cout<<((p-1)*po(p-2,n-1,1000000007))%1000000007;
}
int main()
{
    tej
    ll t=1;
    //cin>>t;
    while(t--)
    solve();
return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;

const int m = 1e9+7;
ll n,p;
ll f(ll n){
  if(n==0) return 1;
  ll a = f(n>>1);
  a = a*a%m;
  if(n&1) a = a*(p-2)%m;
  return a;
}
int main() {
  cin >> n >> p;
  ll ans = f(n-1);
  ans = ans*(p-1)%m;
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int mod=998244353;
const int maxn=2e5+7;
int fa[maxn];
int Find(int x)
{
    return x==fa[x]?x:fa[x]=Find(fa[x]);
}
void Union(int x,int y)
{
    x=Find(x),y=Find(y);
    fa[y]=x;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i<n;i++) fa[i]=i;
    vi f(n);
    for(int i=0;i<n;i++)
    {
        cin>>f[i];
        f[i]--;
        Union(i,f[i]);
    }
    int cc=0;
    for(int i=0;i<n;i++)
    {
        if(fa[i]==i) cc++;
    }
    int ans=1;
    for(int i=0;i<cc;i++) ans=ans*2%mod;
    ans=(ans-1+mod)%mod;
    print(ans);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep3(i, k, n) for(int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int index_now=0; index_now < v.size(); i++) cout<<v[index_now]<<' '
#define blank cout<<endl
#define newvar(n) ll n; cin >> n
const ll MOD = 998244353;
const ll INF = MOD*MOD+1;
ll powmod(ll x, ll n, ll mod){
    ll ret=1;
    while(n>0){
        if(n&1) ret = (ret * x)%mod;
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl f(n+1);
    rep(i,n) cin >> f[i+1];
    vl seen(n+1, 0);
    ll cnt = 0;
    rep3(i, 1, n+1){
        if(seen[f[i]]==2) continue;
        //cout << i << endl;
        ll now = i;
        bool check = true; //すでに見られたことがあるかどうか
        if(seen[now] == 2) check = false; //スタート地点が既訪だったら、なにもしない
        queue<ll> que;
        que.push(now);
        while(seen[now] == 0){ //今回の道が、既訪頂点に続いているか
            seen[now] = 1; //1は、この仮シミュレーションで訪れた場所
            now = f[now]; //つぎ
            if(seen[now] == 2) check = false; //かつて訪れていたら、なにもしない
            que.push(now);
        }
        if(!check){
            while(!que.empty()){
                seen[que.front()] = 2;
                que.pop();
            }
            continue;
        }
        now = i;
        while(seen[now] != 2){
            seen[now] = 2;
            now = f[now];
        }
        seen[now] = 2;
        cnt++;
    }
    cout << powmod(2, cnt, MOD) - 1;

    return 0;
}


// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
vector<T> operator--(vector<T> &vec) {
    for (T &element : vec) --element;
    return vec;
}

// Main
int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    cin >> p;
    vector<int> cnt(200020, 0);
    int ans = 0;
    rep(i, n) {
        ++cnt[p[i]];
        while (cnt[ans]) ++ans;
        cout << ans << "\n";
    }
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;

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

int main(){
    int N;
    vector<int> p;
    cin >> N;
    unordered_set<int> us;
    for(int i=0; i < N; ++i){
        int tmp;
        cin >> tmp;

        p.push_back(tmp);
    }

    int min=0;

    for(int i=0; i < N; ++i){
        us.insert(p[i]);
        //int num=i;
        while(1){
            if(us.find(min) == us.end()){
                cout << min <<endl;
                break;
            }
            else{
                ++min;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
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; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CLZ(b) __builtin_clzll(b)
#define BITLEN(b) (64LL - CLZ(b))
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

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

    ll N, M; cin >> N >> M;
    VLL X(M),Y(M),Z(M); REP(i,M) cin >> X[i] >> Y[i] >> Z[i];

    VVLL E(N+1);
    REP(i,M) {
        E[X[i]].push_back(i);
    }

    VLL dp(1<<N, 0); dp[0] = 1;
    REP(S,1<<N) {
        ll p = PCNT(S);

        bool ok = true;
        for (ll id : E[p]) {
            ll cnt = 0;
            REP(i,N) if (BIT(S,i)) {
                if (i+1 <= Y[id]) cnt++;
            }
            if (cnt > Z[id]) ok = false;
        }
        if (!ok) continue;

        REP(u,N) if (BIT(S,u)) {
            dp[S] += dp[S ^ (1<<u)];
        }
    }
    ll ans = dp[(1<<N)-1];
    COUT(ans);

    return 0;
}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';

///////////////////////////////////////////////////

int mfind(const vi &a, int N, int i, int p)
{
    for (int j = i; j < N; j++)
    {
        if (a[j] == p) return j;
    }
    return -1;
}

bool f(const vi &P, vi &A, vi &ans, int N)
{
    int ians = 0;
    for (int i = 0; i < N; i++)
    {
        int p = P[i];
        int k = mfind(A, N, i, p);

        if (i < ians && i < k) return false;
        if (k == i) continue;

        for (int j = k-1; j >= i; j--)
        {
            ans[ians++] = j;
            swap(A[j], A[j+1]);
        }
    }
    return ians == N - 1;
}

int main()
{
    int N;
    io >> N;
    vi P(N);
    for (int i = 0; i < N; i++)
        io >> P[i];
    vi A(N);
    for (int i = 0; i < N; i++)
        A[i] = i + 1;

    vi ans(N-1);
    bool r = f(P, A, ans, N);
    if (r)
    {
        for (auto it = ans.rbegin(); it != ans.rend(); ++it)
        {
            io << (*it + 1) << BR;
        }
    }
    else
    {
        io << "-1" << BR;
    }

}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

string solve(){
  cin.tie(0), ios::sync_with_stdio(false);
  int a,b,c; cin >> a >> b >> c;
  if(1 <= abs(a-b)){
    return (a<b?"Aoki":"Takahashi");
  }else{
    return (!c?"Aoki":"Takahashi");
  }
}
int main(){
  cout << solve();
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
//useful
#define rep(i,n) for(int i = 0; i < (n); i++)
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数
int long long GetDigitSum(int long long n){
    if(n < 10){
       return n;
    }
    return GetDigitSum(n/10) + n%10;
} //十進数の桁和
unsigned int long long unsignedGetDigitSum(unsigned int long long n){
    if(n < 10){
       return n;
    }
    return unsignedGetDigitSum(n/10) + n%10;
} //十進数の桁和unsigned
int long long divisorcount(int long long n){
	int long long ans = 1;
	vector<int> x(n + 1);
	int long long num = n; // 素因数分解する変数num
	for (int long long i = 0; i <= n; i++) {
		while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			x.at(i)++; //割った個数を配列に足す
			num /= i;
		}
	}
	for (int i = 2; i <= n; i++){
		ans *= x.at(i) + 1; //それぞれを+1して掛けていく
	}
    return ans;
} //約数カウント

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A > B || (A == B && C == 1)){
        cout << "Takahashi" << endl;
    }
    else{
        cout << "Aoki" << endl;
    }
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, const U &b){ return b > a ? a = b, true : false; }

int n;
vector<ld> a;

ld f(ld x){
    ld sum = 0;
    for(int i = 0; i < n; ++i){
        sum += x + a[i] - min(a[i], 2 * x);
    }
    return sum;
}

ld ternary_search(ld l, ld r) {
    ld eps = 1e-9;              //set the error limit here
    while (r - l > eps) {
        ld m1 = l + (r - l) / 3;
        ld m2 = r - (r - l) / 3;
        ld f1 = f(m1);      //evaluates the function at m1
        ld f2 = f(m2);      //evaluates the function at m2
        if (f1 > f2)
            l = m1;
        else
            r = m2;
    }
    return f(l);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n; a.assign(n, 0);
    for(int i = 0; i < n; ++i) cin >> a[i];
    cout << setprecision(10) << fixed;
    cout << ternary_search(0, 1e9 + 7)/n;
    return 0;
}

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

    int main(){
        int n;
        cin >> n;
        vector<long long> a(n);
        rep(i,n){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        vector<long long> stacksum(n);
        for(int i=0;i < n;i++){
            stacksum[i] = i == 0 ? a[0] : a[i] + stacksum[i-1];
        }
        double ave = 0;
        rep(i,n){
            ave += a[i];
        }
        ave = ave / n;
        double lostmin = 1000000000000000.0;
        for(int i=0; i<n; i++){
            double x = (double)a[i] / 2;
            long long al = i == 0 ? 0 : stacksum[i-1];
            double lost = x + ave - ((2*x*(n-i) + al) / (double) n);
            lostmin = min(lostmin,lost);
        }

        printf("%.12lf\n",lostmin);
        return 0;
    }


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

const int mod=998244353;
int a,b,c;
int main( ) {
	cin>>a>>b>>c;
	a%=mod, b%=mod, c%=mod;
	a=1ll*a*(a+1)/2%mod;
	b=1ll*b*(b+1)/2%mod;
	c=1ll*c*(c+1)/2%mod;
	cout<<1ll*a*b%mod*c%mod;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef long double ldd;
typedef double ld;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;

    a = a * a % m;
    b >>= 1;
  }
  return res;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() {time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}
int n;
string s, str;
int arr[10000001];
void solve()
{
  long long int a, b, c;
  cin >> a >> b >> c;
  long long int ans1, ans2, ans3;
  ans1 = a * (a + 1) / 2;
  ans2 = b * (b + 1) / 2;
  ans3 = c * (c + 1) / 2;
  long long int m = 998244353;
  cout << ((((ans1 % m) * (ans2 % m)) % m) * (ans3 % m)) % m;

}
int main()
{ fast;
  int t;
  t = 1;
  while (t--)
  { solve();
  }
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122) return char(x-32);
    if( 65 <= int(x) && int(x) <= 90) return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122) return x;
    if( 65 <= int(x) && int(x) <= 90) return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57) return int(x-'0');
    if(97 <= int(x) && int(x) <= 122) return int(x-96);
    if(65 <= int(x) && int(x) <= 90) return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1%MOD;
    else if(num2==1)return num1%MOD;
    else{
        ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int a,b,w;
bool validate(){
    int take = w / a;
    int rem = w % a;
    int p = (rem / take) + !!(rem % take);
    if(a + p > b) return false;
    return true;
}
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> a >> b >> w; w *= 1000;
    if(!validate()) return cout << "UNSATISFIABLE\n", 0;

    int mx = w / a;
    int mn = w / b + !!(w % b);

    cout << mn << ' ' << mx << newl;

    return 0;
}

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

#include <bits/stdc++.h>
#define readFast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fin cin
#define ll long long
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define output(x) ((int)x && cout << "YES\n") || cout << "NO\n";
#define ld long double
using namespace std;

#ifdef LOCAL
#define read() ifstream fin("date.in.txt")
#else
#define read() readFast
#endif // LOCAL

const int N = 55;
const int MOD = 998244353;

set<char> litere;
map<char, int> toCifra;

void puneLitere(string a) {
    for (char x : a)
        litere.insert(x);
}

ll createNumber(string a) {
    ll nr = 0;
    for (int i = 0; i < sz(a); ++i) {
        nr = nr * 10 + toCifra[a[i]];
    }
    return nr;
}
string a, b, c;

int main() {
    read();

    fin >> a >> b >> c;
    puneLitere(a);
    puneLitere(b);
    puneLitere(c);

    if(sz(litere) > 10) {
        cout << "UNSOLVABLE"; // to do
        return 0;
    }

    vector<int> cifre(10);
    iota(cifre.begin(), cifre.end(), 0);

    do {
        // primul caracater cu prima cifra ...
        int p = 0;
        for (char x : litere) {
            toCifra[x] = cifre[p];
            ++p;
        }
        if(toCifra[a[0]] == 0 || toCifra[b[0]] == 0 || toCifra[c[0]] == 0)
            continue;

        ll n1 = createNumber(a);
        ll n2 = createNumber(b);
        ll n3 = createNumber(c);

        if(n1 + n2 == n3) {
            cout << n1 << '\n' << n2 << '\n' << n3;
            return 0;
        }
    } while(next_permutation(cifre.begin(), cifre.end()));

    cout << "UNSOLVABLE";
    return 0;
}  /*stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
~Benq~*/


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

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

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>

struct mydistance
{
    ll index1;
    ll index2;
    ld dist;
};

class UnionFind
{
    private:
    vll parent;

    public:
    UnionFind(ll N)
    {
        parent.resize(N);
        for (ll i = 0; i < N; i++)
        {
            parent[i] = i;
        }
    }

    ll GetParent(ll x)
    {
        if(parent[x] == x)
        {
            return x;
        }
        else
        {
            return (parent[x] = GetParent(parent[x]));
        }
    }

    void Unite(ll x, ll y)
    {
        ll rx = GetParent(x);
        ll ry = GetParent(y);
        if(rx != ry)
        {
            parent[rx] = ry;
        }
    }

    bool IsUnited(ll x, ll y)
    {
        return GetParent(x) == GetParent(y);
    }
};

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

    vector<pair<ld, ld>> kugi(N);
    for (ll i = 0; i < N; i++)
    {
        INX(kugi[i].first, kugi[i].second);
    }

    // calculate distances; i = N -> wall of y = -100, i = N + 1 -> wall of y = 100
    vector<mydistance> vd;
    for (ll i = 0; i < N + 1; i++)
    {
        for (ll j = i + 1; j <= N + 1; j++)
        {
            mydistance d = {0, 0, 0};
            d.index1 = i;
            d.index2 = j;

            if(i == N)
            {
                //if(j == N + 1) <- always true in this case
                d.dist = 200;
            }
            else if(j == N)
            {
                d.dist = kugi[i].second + 100;
            }
            else if(j == N + 1)
            {
                d.dist = 100 - kugi[i].second;
            }
            else
            {
                ld tmp1 = kugi[i].first - kugi[j].first;
                ld tmp2 = kugi[i].second - kugi[j].second;
                d.dist = sqrtl(tmp1 * tmp1 + tmp2 * tmp2);
            }

            vd.ADD(d);
        }
    }
    sort(vd.begin(), vd.end(), [](mydistance x, mydistance y){return x.dist < y.dist;});

    UnionFind uf(N + 2);
    for (ll i = 0; i < (ll)vd.size(); i++)
    {
        uf.Unite(vd[i].index1, vd[i].index2);
        if(uf.IsUnited(N, N + 1))
        {
            cout << setprecision(10) << (vd[i].dist / (ld)2.0) << endl;
            break;
        }
    }

    return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<int, double> pid;

#define UP_Y 100
#define DOWN_Y -100

const double EPS = 0.00001;

double sq(int a) {
	return (double) a*a;
}

double dist(pi a, pi b) {
	return sqrt(sq(a.first-b.first) + sq(a.second-b.second));
}

double distUp(pi a) {
	return dist(make_pair(a.first, UP_Y), a);
}

double distDown(pi a) {
	return dist(make_pair(a.first, DOWN_Y), a);
}

bool can(double r, vector<vector<pid>> &g, int n) {
	// deb(r);

	double d = r+r;
	vector<bool> vis(n+2, false);
	queue<int> q;
	q.push(n);
	vis[n] = true;

	while (!q.empty()) {
		int popped = q.front();
		q.pop();

		for (auto e: g[popped]) {
			if (vis[e.first])
				continue;

			if (e.second >= d)
				continue;

			if (e.first == n+1)
				return false;

			q.push(e.first);
			vis[e.first] = true;
			// cout << "push " << e.first << endl;
		}
	}

	return true;
}

int main() {

	IOS

	int n;
	cin >> n;
	pi p[n];

	for (int i = 0; i < n; i++)
		cin >> p[i].first >> p[i].second;

	vector<vector<pid>> g(n+2);

	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			double dsq = dist(p[i], p[j]);
			g[i].push_back({j, dsq});
			g[j].push_back({i, dsq});
		}
	}

	for (int i = 0; i < n; i++) {
		double dist_up = distUp(p[i]);
		g[n].push_back({i, dist_up});
		g[i].push_back({n, dist_up});
	}

	for (int i = 0; i < n; i++) {
		double dist_down = distDown(p[i]);
		g[n+1].push_back({i, dist_down});
		g[i].push_back({n+1, dist_down});
	}

	// for (int i = 0; i < n+2; i++) {
	// 	cout << i << ": ";
	// 	for (auto x: g[i]) {
	// 		cout << "{" << x.first << "," << x.second << "} ";
	// 	}
	// 	cout << endl;
	// }

	double l = 0.5, r = 101, mid;

	while (r-l > EPS) {
		mid = (l+r) / 2;

		if (can(mid, g, n))
			l = mid;
		else
			r = mid;
	}

	cout << l;

	return 0;
}


#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
using namespace std;
const int N = 1e5 + 7;
ll n, m;
int main() {
	scanf("%lld%lld", &n, &m);
	L(i, 1, sqrt(m + 1)) if(m % i == 0 && m / i + i == n) return puts("Yes"), 0;
	puts("No");
	return 0;
}

#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 998244353;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x,y;
  cin>>x>>y;
  cout<<(x+y)/2<<" "<<(x-y)/2<<endl;
  return 0;
}


#include <bits/stdc++.h>

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t; cin >> t; while(t--)
const long long int cons = 200005;
const long long int MOD = 1000000007;
// const long long int MOD = 998244353;
const long long int const_INT_MAX = 1000000000000000000;
const long long int const_INT_MIN = -1 * 1000000000000000000;

using namespace std;
// to sort pair vector in reverse order
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return (a.first > b.first);
}
// to sort pair vector according to the second elements
bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return (a.second < b.second);
}
// to sort pair vector according to the second elements in reverse order
bool sortbysecinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return (a.second > b.second);
}
ll lcm(ll x, ll y){
    return (ll)((x * y) / __gcd(x, y));
}
ll mod_expo(ll x, ll y, ll p){
    // reference from GFG
    ll res = 1;
    if((x + p) % p == 0){
        res = 0;
    }
    else {
        x = (x + p) % p;
        while (y > 0){
            if (y & 1){
                res = (res*x + p) % p;
            }
            y = y>>1;
            x = (x*x + p) % p;
        }
    }
    return res;
}
void usaco(string str = ""){
    fastio;
    if(str.size()){
        freopen((str + ".in").c_str(), "r", stdin);
        freopen((str + ".out").c_str(), "w", stdout);
    }
}
vector<ll> adj[cons];
ll dp[cons];
int main(){
    usaco();
    ll n, m; cin >> n >> m;
    ll a[n];
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    for(ll i=0;i<m;i++){
        ll u, v; cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
    }
    for(ll i=0;i<n;i++){
        dp[i] = const_INT_MIN;
    }
    for(ll i=n-1;i>=0;i--){
        for(auto u : adj[i]){
            dp[i] = max(dp[i], max(dp[u], a[u]));
        }
    }
    ll fin_ans = const_INT_MIN;
    for(ll i=0;i<n;i++){
        fin_ans = max(fin_ans, dp[i] - a[i]);
    }
    cout << fin_ans << "\n";
}

#include<bits/stdc++.h>
#define int long long
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
const int mod = 1e9 + 7;
const int nax = 1e6;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[nax], dp[nax], deg[nax], mn[nax];
vector<int> E[nax];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        mn[i] = 2e18;
        dp[i] = -2e18;
    }
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        E[x].pb(y);
        deg[y]++;
    }

    queue<int> Q;
    vector<int> ord;
    for(int i = 1; i <= n; i++) {
        if(!deg[i]) {
            Q.push(i);
        }
    }

    while(Q.size()) {
        int node = Q.front();
        Q.pop();
        ord.pb(node);
        for(auto it : E[node]) {
            deg[it]--;
            if(!deg[it]) {
                Q.push(it);
            }
        }
    }

    int ans = -2e18;

    for(auto x : ord) {
        mn[x] = min(mn[x], a[x]);
        for(auto it : E[x]) {
            ans = max(ans, a[it] - mn[x]);
            mn[it] = min(mn[it], mn[x]);
        }
    }
    cout << ans << '\n';

    return 0;
}

// 9