#include<bits/stdc++.h>
#ifdef BIZON
    #define rr(...) [](const auto&...x){ char c='='; cerr << boolalpha << "\e[1;38;5;68m" << #__VA_ARGS__ << " "; ((cerr<<"\e[0;38;5;61m"<<exchange(c,',')<<"\e[0m "<<x),...); cerr<<endl; }(__VA_ARGS__);
#else
    #define rr(...) 0;
    #define endl '\n'
#endif
#define ALL(c) begin(c), end(c)
#define II(...) __VA_ARGS__; [](auto&...x){(cin>>...>>x);}(__VA_ARGS__);
#define ii(...) int II(__VA_ARGS__)
inline bool umin(auto&x, const auto&y){ return y<x ? x=y, 1 : 0; }
inline bool umax(auto&x, const auto&y){ return y>x ? x=y, 1 : 0; }
using namespace std;
using ll = long long;
using ld = long double;

ll f(int t, ll n) {
    ld m = (ld(100)+t) / 100;

    ll l = 1, r = 1e16;
    while(l<r) {
        ll d = (l+r) / 2;
        ll a = (t+100) * d / 100;

        assert(a>=d);
        if(a-d < n) l = d+1; else r = d;
    }

    ll ans = (t+100) * r / 100;

    return ans - 1;
}

int main(){
    if(auto f="in.txt"; fopen(f,"r") && freopen(f,"r",stdin));
    ios::sync_with_stdio(0);cin.tie(0);

    rr(f(3,1))
    rr(f(3,2))
    rr(f(3,3))
    rr(f(3,4))
    rr(f(3,5))

    ii(t,n)
    cout<<f(t,n)<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
struct UnionFind {
private:
    vector<int> par;
    vector<int> count;
    vector<int> rank;
public:
    UnionFind(int N) {
        count.assign(N, 1);
        rank.assign(N, 0);
        par.assign(N, 0);
        rep(i, N) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            par[x] = root(par[x]);
            return par[x];
        }
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y])
            swap(x, y);
        else if (rank[x] == rank[y])
            rank[y]++;
        par[y] = x;
        count[x] += count[y];
        return;
    }

    int size(int x) {
        return count[root(x)];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }
};
using UF = struct UnionFind;

int main() {
    ll N;
    cin >> N;
    vl X(N), Y(N);
    rep(i, N) cin >> X[i] >> Y[i];

    using tp = tuple<ld, ll, ll>;
    vc<tp> P;

    rep(i, N) repe(j, i + 1, N) P.eb(hypotl(X[i] - X[j], Y[i] - Y[j]), i, j);
    rep(i, N) P.eb(100 - Y[i], i, N), P.eb(Y[i] + 100, i, N + 1);
    sort(all(P));

    UF uf(N + 2);
    for(auto[d, i, j]: P){
        uf.unite(i, j);
        if(uf.issame(N, N + 1)){
            cout << d / 2 << '\n';
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ll N;
ll par[105];
ll rank_[105];
void init_uf(ll n_){
for(ll i=0;i<n_;i++){
par[i]=i;
  rank_[i]=0;
}
  }
ll find(ll x){
if(par[x]==x)
  return x;
  return par[x]=find(par[x]);
}
void unite(ll x,ll y){
x=find(x); y=find(y);
  if(x==y)
    return ;
  if(rank_[x]<rank_[y])
    par[x]=y;
  else{
  par[y]=x;if(rank_[x]==rank_[y])rank_[x]++;
  }
}
bool same(ll x,ll y){
x=find(x); y=find(y);
  return x==y;
}
int main(){
  cin>>N;
  vector<ld>X(N);
  vector<ld>Y(N);
  for(ll i=0;i<N;i++){
  cin>>X[i];cin>>Y[i];
  }ld left=0;ld right=100;
  while(0.000001<right-left){
  ld mid=left+(right-left)/2;
    init_uf(N+2);
    for(ll i=0;i<N-1;i++)
      for(ll j=i+1;j<N;j++)
        if(pow(pow(X[i]-X[j],2)+pow(Y[i]-Y[j],2),0.5)<=2*mid)
          unite(i+1,j+1);
    for(ll i=0;i<N;i++){
      if(abs(Y[i]-100)<=2*mid)unite(i+1,0);
      if(abs(Y[i]+100)<=2*mid)unite(i+1,N+1);
    }
      if(same(0,N+1))
        right=mid;
      else
        left=mid;
  }cout<<fixed<<setprecision(7)<<left<<endl;
  return 0;
}

// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using P = pair<double, pair<int, int>>;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second
double x[111], y[111];

// https://github.com/atcoder/live_library/blob/master/uf.cpp
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
// -> 一部改変.
struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0): d(n, -1) {}
    int find(int x){
        return (d[x] < 0) ? x : (d[x] = find(d[x]));
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        return -d[find(x)];
    }
};

int main(){

    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lf %lf", &x[i], &y[i]);

    // 2. 2点間の距離, 頂点のペア を 保存.
    // -> 頂点 1 … 直線 y = -100, 頂点 N + 2 … 直線 y = 100 とする.
    priority_queue<P, vector<P>, greater<P>> pq;
    rep(i, N){
        P p0, p1;
        // 頂点 1 と 他の頂点との辺 を 追加.
        p0.a = abs(-100.0 - y[i]);
        p0.b.a = 0;
        p0.b.b = i + 1;
        pq.push(p0);

        // 頂点 N + 2 と 他の頂点との辺 を 追加.
        p1.a = abs(100.0 - y[i]);
        p1.b.a = N + 1;
        p1.b.b = i + 1;
        pq.push(p1);
    }
    rep(i, N){
        repx(j, i + 1, N){
            double d = hypot(x[i] - x[j], y[i] - y[j]);
            P p;
            p.a = d;
            p.b.a = i + 1;
            p.b.b = j + 1;
            pq.push(p);
        }
    }

    // 3. 距離の短い方から順に, 辺を追加.
    double ans = 0.0;
    UnionFind uf(N + 2);
    while(!pq.empty()){
        // 3-1. 辺を取り出す.
        P p = pq.top();
        pq.pop();

        // 3-2. 円の直径を更新.
        ans = p.a;

        // 3-3. グラフに辺を追加.
        uf.unite(p.b.a, p.b.b);

        // 3-4. 辺を追加した結果, 二直線が, 同じ連結成分に含まれてしまう場合は終了.
        if(uf.same(0, N + 1)) break;

    }

    // 4. 出力.
    printf("%.12lf\n", ans / 2.0);
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
inline void mod(ll &x){
	if(x>=MOD)x-=MOD;
}
vector<ll> fact;
vector<ll> ifact;
ll add(ll a,ll b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
ll mult(ll a,ll b)
{
	return (a*1LL*b)%MOD;
}
ll binpow(ll a, ll b)
{
	ll r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
ll choose(ll a, ll b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	ll r = mult(ifact[b],ifact[a-b]);
	r = mult(r,fact[a]);
	return r;
}
ll permute(ll a,ll b){
	ll res = mult(fact[a],ifact[a-b]);
	return res;
}
ll inv(int a){return binpow(a,MOD-2);}
void init(ll n)
{
	fact.clear(); ifact.clear();
	fact.resize(n+1);
	ifact.resize(n+1);
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=n;i++){fact[i]=mult(fact[i-1],i);}
	ifact[n] = inv(fact[n]);
	for(int i=n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
}
int main()
{
	owo
	int n;
	cin>>n;
	init(1000000);
	int sum = 0;
	vector<int>a(n);
	for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
	if(sum%2){
		cout<<0;
		return 0;
	}
	sum/=2;
	VII dp(n+1,vector<ll>(sum+1));
	dp[0][0] = 1;
	for(int i=0;i<n;i++){
		for(int j=n;j>=1;j--){
			for(int k=a[i];k<=sum;k++){
				dp[j][k]+=dp[j-1][k-a[i]];
				mod(dp[j][k]);
			}
		}
	}
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ll res = dp[i][sum]*fact[i]%MOD;
		res*=fact[n-i];
		res%=MOD;
		//cout<<res<<'\n';
		ans+=res;
		ans%=MOD;
	}
	//cout<<"TES"<<'\n';
	cout<<ans;

}

#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

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

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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    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;}

mint dp[1010];

int main(){
  dp[1]=2;
  dp[2]=3;
  rep1(i,1e3) dp[i+2]=dp[i+1]+dp[i];
  int n; cin >> n;
  char a,b,c,d; cin >> a >> b >> c >> d;
  if(n==2||n==3){
    cout << 1 << endl;
    return 0;
  }
  if(b=='B'){
    if(d=='B'){
      cout << 1 << endl;
    }
    else{
      if(c=='A'){
        cout << rui(2,n-3) << endl;
      }
      else{
        cout << dp[n-3] << endl;
      }
    }
  }
  else{
    if(a=='A'){
      cout << 1 << endl;
    }
    else{
      if(c=='B'){
        cout << rui(2,n-3) << endl;
      }
      else{
        cout << dp[n-3] << endl;
      }
    }
  }

}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int h = ri();
	int w = ri();
	int x = ri() - 1;
	int y = ri() - 1;
	std::string s[h];
	for (auto &i : s) std::cin >> i;

	int cnt = -3;
	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
	printf("%d\n", cnt);
	return 0;
}


#define skies dashabi
#include <bits/stdc++.h>
using namespace std;
const int N= 200+10;
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
inline int inc(int x,int v,int mod){x+=v;return x>=mod?x-mod:x;}
inline int dec(int x,int v,int mod){x-=v;return x<0?x+mod:x;}
inline int rd(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}
inline void write(int x){if(x==0){putchar(48);return;}int len=0,dg[20];while(x>0){dg[++len]=x%10;x/=10;}for(register int i=len;i>=1;i--)putchar(dg[i]+48);}
int a[N],n;
vector<int> b[N];
int dp[N];
bool fl;
void out(vector<int>va)
{
	cout<<va.size()<<" ";
	for(int i=0;i<va.size();i++)
	{
		printf("%d ",va[i]);
	}
	puts("");
}
void dfs(int x,vector<int>v,int sum)
{
	if(fl||x>n)return ;
	sum%=200;
	if(!b[sum].empty())
	{
		fl=1;
		puts("Yes");
		out(v);
		out(b[sum]);
		return ;
	}
	cout<<x<<" "<<sum<<endl;
	b[sum]=v;
	dfs(x+1,v,sum);
	v.push_back(x);
	dfs(x+1,v,sum+a[x]);
}
int g(int x)
{
	return ((x%200)+200)%200;
}
signed main()
{
	//freopen("未命名1.in","r",stdin);
	//freopen("未命名1.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		a[i]=rd();

	}
	for(int i=1;i<=n;i++)
	{
		a[i]%=200;
	}
	bool op=0;
	for(int i=1;i<=n;i++)
	{
		if(op)break;
		for(int j=0;j<=199;j++)
		{
			if(dp[g(j-a[i])]==1||j==a[i])
			{
				if(dp[j]==1)
				{
					puts("Yes");
					b[g(j-a[i])].push_back(i);
					out(b[g(j-a[i])]);out(b[j]);
					op=1;
					break;
				}

			 }
		}

		for(int j=199;j>=0;j--)
		{
			if(dp[g(j-a[i])]==1||j==a[i])
			{
				dp[j]=2;
				if(j!=a[i])
				b[j]=b[g(j-a[i])];
				b[j].push_back(i);
			}
		}
		for(int j=199;j>=0;j--)
		{
			if(dp[j]==2)dp[j]=1;
		}
	}
	if(!op)
	{
		puts("No");
	}

    return 0;
}

#line 1 "/workspaces/compro/lib/template.hpp"

#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

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

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

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}

#line 2 "main.cpp"

std::string solve(int N, const std::vector<std::string> &S) {
  map<string, bool> yes, no;
  REP(i, N) {
    if (S[i][0] == '!') {
      auto sub = S[i].substr(1, S[i].length() - 1);
      no[sub] = true;
    } else {
      yes[S[i]] = true;
    }
  }

  for (const auto el : yes) {
    auto [str, val] = el;
    if (no.find(str) != no.end()) {
      return str;
    }
  }
  for (const auto &el : no) {
    auto [str, val] = el;
    if (yes[str]) {
      cout << str << endl;
      return str;
    }
  }
  return "satisfiable";
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int N;
  std::cin >> N;
  std::vector<std::string> S(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> S[i];
  }
  auto ans = solve(N, S);
  std::cout << ans << std::endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

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

    rep3(i, B, 1){
        if((B/i)-(A/i) >= 2) {cout << i << '\n'; return 0;}
    }
}

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

const int N = 5005;
const int p = 998244353;
int n, m, k, t, fac[N], inv[N], f[15][5005];

inline int read()
{
	char c = getchar();
	int ans = 0;
	bool f = 1;
	while (c < 48 || c > 57)
	{
		if (c == '-') f = 0;
		c = getchar();
	}
	while (c >= 48 && c <= 57) ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
	return f ? ans : -ans;
}

inline ll fpow(ll x, int y)
{
	ll z = 1;
	while (y)
	{
		if (y & 1) z = z * x % p;
		x = x * x % p, y >>= 1;
	}
	return z;
}

inline ll C(int x, int y)
{
	return 1ll * fac[x] * inv[y] % p * inv[x - y] % p;
}

int main()
{
	n = read(), m = k = read(), fac[0] = fac[1] = 1;
	if (m & 1)
	{
		putchar(48);
		return 0;
	}
	for (Re i = 2; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
	inv[n] = fpow(fac[n], p - 2);
	for (Re i = n; i; --i) inv[i - 1] = 1ll * inv[i] * i % p;
	while (k) k >>= 1, ++t;
	f[t][0] = 1;
	for (Re i = t - 1; i; --i)
		for (Re j = 0; j <= m; j += (1 << i))
			for (Re k = 0; k * (1 << i) <= j && (k << 1) <= n; ++k) f[i][j] = (C(n, k << 1) * f[i + 1][j - k * (1 << i)] + f[i][j]) % p;
	printf("%d", f[1][m]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int gr[101][101];
  for (int i = 0; i < N; i ++) {
    for (int j = 0; j < N; j ++) {
      char c;
      cin >> c;
      gr[i][j] = (c == '1');
    }
  }
  for (int i = 0; i < N; i ++) gr[i][i] = 1;
  for (int p = 0; p < 10; p ++) {
    int gr_[101][101];
    for (int i = 0; i < N; i ++) {
      for (int j = 0; j < N; j ++) {
        int kj = 0;
        for (int k = 0; k < N; k ++) {
          kj += gr[i][k] * gr[k][j];
        }
        gr_[i][j] = (kj > 0);
      }
    }
    for (int i = 0; i < N; i ++) {
      for (int j = 0; j < N; j ++) {
        gr[i][j] = gr_[i][j];
        //cout << gr[i][j];
      }
      //cout << endl;
    }
    //cout << endl;
  }
  double ans = 0;
  for (int i = 0; i < N; i ++) {
    double kj = 0;
    for (int j = 0; j < N; j ++) {
      kj += (double)gr[j][i];
    }
    ans += 1 / kj;
  }
  cout << setprecision(15) << ans << endl;
}

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

const int maxn=100000;
int f[maxn+5],l[maxn+5];
bool d[maxn+5];
vector<int>g[maxn+5];
bool cmp(int i,int j)
{
    return (f[i]-l[i])>(f[j]-l[j]);
}
void dfs(int x)
{
    //cout<<x<<endl;
    if(g[x].size()==0)
    {
        l[x]=1;
        f[x]=0;
        d[x]=1;
        return;
    }
    vector<int>v;
    d[x]=0;
    f[x]=0;
    l[x]=1;
    int tmp1=0,tmp2=0;
    for(int i=0; i<g[x].size(); i++)
    {
        int id=g[x][i];
        dfs(id);
        d[x]^=d[id];
        if(d[id])
            v.push_back(id);
        else
        {
            if(f[id]>=l[id])
            {
                f[x]+=f[id];
                l[x]+=l[id];
            }
            else
            {
                tmp1+=f[id];
                tmp2+=l[id];
            }
        }
    }
    sort(v.begin(),v.end(),cmp);
    for(int i=0; i<v.size(); i++)
    {
        int id=v[i];
        if(i%2==0)
        {
            l[x]+=l[id];
            f[x]+=f[id];
        }
        else
        {
            f[x]+=l[id];
            l[x]+=f[id];
        }
    }
    //cout<<f[x]<<" "<<l[x]<<endl;
    if(d[x])
    {
        f[x]+=tmp2;
        l[x]+=tmp1;
    }
    else
    {
        f[x]+=tmp1;
        l[x]+=tmp2;
    }
    d[x]^=1;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=2; i<=n; i++)
    {
        int x;
        scanf("%d",&x);
        g[x].push_back(i);
    }
    dfs(1);
    //for(int i=1;i<=n;i++)
    //cout<<d[i]<<" "<<l[i]<<" "<<f[i]<<endl;
    printf("%d\n",l[1]);
}


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

vector<int> getIntArray(int num) {
  vector<int> result;
  int tmp = num;
  while(tmp > 0) {
    int digit = tmp % 10;
    result.push_back(digit);
    tmp /= 10;
  }
  return result;
}

int calc(vector<int> v) {
  sort(v.begin(), v.end());
  int greater = 0;
  int less = 0;
  for(int i = 0; i < (int)v.size(); i++) {
    int num = v.at(i);
    greater+=(num * pow(10, i));
    if(num == 0) {
      less*=10;
    } else {
      less+=(num * pow(10, (v.size() - i - 1)));
    }
  }
  return greater - less;
}

int main() {
  int N, K;
  cin >> N >> K;

  int result = N;
  for(int i = 0; i < K; i++) {
    vector<int> intArr = getIntArray(result);
    result = calc(intArr);
  }
  cout << result << endl;
  return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const int maxn = 1e6 + 5;

int g2(int x) {
    string s = to_string(x);
    sort(s.begin(),s.end());
    return stoi(s);
}

int g1(int x) {
    string s = to_string(x);
    sort(s.rbegin(),s.rend());
    return stoi(s);
}

int f(int x) {
    return g1(x)-g2(x);
}

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

    int n, k;
    cin>>n>>k;

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

    cout<<n<<endl;
    return 0;
}


#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<strings.h>
#include<sstream>
using namespace std;
int fan(int x)
{
    int maxn=0,mixn=0;
    int a[10]= {0},b[10]= {0};
    string str;
    stringstream ss;
    ss << x;
    ss >> str;
    if(x==0)
        return 0;
    else
    {
        int len = str.length();
        for(int i = 0; i < len; i ++)
        {
            a[str[i]-'0']++;
            b[str[i]-'0']++;
        }
        //最大值
        for(int i = 9; i >= 0; i--)
        {
            while(a[i]!=0)
            {
                maxn = maxn *10 + i;
                a[i]--;
            }
        }
        //最小值
        for(int i = 1; i <= 9; i ++)
        {
            while(b[i]!=0)
            {
                mixn = mixn *10 + i;
                b[i]--;
            }
        }
        return maxn - mixn;
    }
}
int main()
{
    int x,n,pre=0,now=0;
    scanf("%d%d",&x,&n);
    if(n==0)
        printf("%d\n",x);
    else
    {
        for(int i = 1; i <= n ; i ++)
        {
            pre = now;
            if(i==1)
                now = fan(x);
            else
                now = fan(now);
            if(now==pre)
                break;
        }
        printf("%d\n",now);
    }
    return 0;
}

#include<cstdio>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;
	typedef long long ll;
	const int maxn=100005;
	const int inf=0x3f3f3f3f;
	int n,m,k;
    int gfun1(int x){
        vector<int>v;
        while(x){
            v.push_back(x%10);
            x/=10;
        }
        sort(v.begin(),v.end());
        int re=0;
        for(auto i:v){
            re*=10;
            re+=i;
        }
        return re;
    }
    int gfun2(int x){
        vector<int>v;
        while(x){
            v.push_back(x%10);
            x/=10;
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        int re=0;
        for(auto i:v){
            re*=10;
            re+=i;
        }
        return re;
    }
    int fun(int x){
        return gfun2(x)-gfun1(x);
    }

	signed main(){
		IOS
		#ifndef ONLINE_JUDGE
		    freopen("D:\\_ACM_code\\IO\\in.txt","r",stdin);
		    freopen("D:\\_ACM_code\\IO\\out.txt","w",stdout);
        #endif
        cin>>n>>m;
        int ans=n;
        while(m--){
            int t=fun(ans);
            if(t==ans)
                break;
            ans=t;
        }
        cout<<ans<<endl;
	}


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

void fun()
{
    ll n,k;
    cin>>n>>k;
    // ll a[n];
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        mp[a]+=b;
    }
    ll curr=0;
    for(auto i:mp)
    {
        if(curr+k>=i.first)
        {
            curr=curr+k;
            k=i.second;
        }
        else
        {
            curr=curr+k;
            k=0;
            break;
        }
    }
    if(k>0)
    curr=curr+k;
    cout<<curr;
}

int main() {
	ll t=1;
// 	cin>>t;
	while(t--)
	fun();
	return 0;
}

/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue
#define lld long long int
#define ldo long double
#define ins insert /// used in set to insert the values
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e16
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> >
#define pll pair <lld,lld>
lld p1=1e9 + 7,p2=998244353;

void judge(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    #endif
}

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

long long int modp(lld a,lld p,lld n)
{
    // n=n%(p-1);
    if(n==0) return 1;
    if(n==1) return a%p;
    lld x=modp(a,p,n/2);
    x*=x;
    x%=p;
    return (n%2?(x*a)%p:x);
}

lld modInverse(lld n, lld p)
{
    return modp(n, p, p-2);
}

// lld fac[500005];

// void getfac(lld p)
// {
//     fac[0] = 1;
//     for (lld i=1 ; i<=500005; i++)
//         fac[i] = fac[i-1]*i%p;
// }

// long long int nCrmodp(lld n, lld r,lld p)
// {
//    // Base case
//    if (r==0)
//       return 1;

//     return (fac[n]* modInverse(fac[r], p) % p *
//             modInverse(fac[n-r], p) % p) % p;
// }

struct segtree{
    lld n,n2;
    vector<lld> v;

    void init(lld x)
    {
        lld a=1;
        while(a<=x) a*=2;
        n2=2*a;
        n=x;
        v.assign(n2,0);
    }

    void build(vector<lld> &w,lld curr,lld l,lld r)
    {
        if(l==r)
        {
            if(l<n)
            {
                v[curr]=w[l];
            }
            return;
        }
        lld mid=l+(r-l)/2;
        build(w,2*curr+1,l,mid);
        build(w,2*curr+2,mid+1,r);
        v[curr]=v[2*curr+1]+v[2*curr+2];
    }

    void build(vector<lld>&w)
    {
        build(w,0,0,n-1);
    }

    void update(lld l, lld r,lld pos,lld curr)
    {
        if(l==r)
        {
            v[curr]-=1;
            return;
        }
        lld mid=l+(r-l)/2;
        if(pos<=mid)
        {
            update(l,mid,pos,2*curr+1);
        }
        else update(mid+1,r,pos,2*curr+2);
        v[curr]=v[2*curr+1]+v[2*curr+2];
    }

    void update(lld pos)
    {
        update(0,n-1,pos,0);
    }

    pll getVal(lld l,lld r,lld curr,lld k)
    {
        if(l==r)
        {
            return {l,k};
        }
        lld mid=l+(r-l)/2;
        if(v[2*curr+1]>=k)
        {
            return getVal(l,mid,2*curr+1,k);
        }
        return getVal(mid+1,r,2*curr+2,k-v[2*curr+1]);
    }

    pll getVal(lld k)
    {
        return getVal(0,n-1,0,k);
    }
};

lld l,r,mid,ans=0;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;

bool compare(pair<pll,lld> p1,pair<pll,lld> p2)
{
    if(p1.fi.fi!=p2.fi.fi) return p1.fi.fi<p2.fi.fi;
    return p1.fi.se>p2.fi.se;
}

void solve(){
    cin>>n>>k;
    vector<pll> v;
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        v.pb({x,y});

    }
    sort(all(v));
    for(i=0;i<n;i++)
    {
        if(k>=v[i].fi)
        {
            k+=v[i].se;
        }
        else break;
    }
    cout<<k;
}

int main()
{
    // judge();
    fastio();
    lld t=1;
    // lld n;
    // cin>>t;
    // cout<<t<<" \n";
    // lld p1 = 1e9 + 7;
    // getfac(p1);
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        // cout<<" ----------------\n";
        solve();
        cout<<" \n";
    }
    // cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    // exit(0);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, M;
vector<vector<int>> G(N);
bool visited[100];
vector<pair<int,int>> E1;
set<pair<int,int>> E2;
void f(int p) {
	visited[p] = true;
	for (int x : G[p]) {
		if (visited[x]) {
			E2.insert({min(p,x),max(x,p)});
		} else {
			E1.push_back({p,x});
			f(x);
		}
	}
}
int main() {
	cin >> N >> M;
	G.resize(N);
	for (int i = 0; i < M; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ll res = 1;
	vector<int> color(N);
	for (int i = 0; i < N; ++ i) if (!visited[i]) {
		E1.clear();
		E2.clear();
		f(i);
		for (auto [u,v] : E1) E2.erase({min(u,v),max(u,v)});
		int rr = 0;
		for (int p = 0; p < (1<<E1.size()); ++ p) {
			for (unsigned i = 0; i < E1.size(); ++ i) {
				auto [u, v] = E1[i];
				int cc[2];
				for (int k = 0, j = 0; k < 3; ++ k) if (k != color[u]) cc[j++] = k;
				color[v] = cc[(p>>i)&1];
			}
			for (auto [u, v] : E2) {
				if (color[u] == color[v]) goto next;
			}
			++ rr;
			next:;
		}
		res *= rr*3;
	}
	cout << res << endl;
}

#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

bool dfs(int v, int c, vector<int>& col, const vector< vector<int> >& g){
    col[v] = c;

    bool ret = true;

    for(auto to : g[v]){
        if(col[to] == -1){
            ret &= dfs(to, c ^ 1, col, g);
        }else if(col[v] == col[to]){
            return false;
        }
    }

    return ret;
}

template<class T>
T power(T x, unsigned long long n){
    T res = T(1);
    while(n){
        if(n & 1ull){
            res *= x;
        }
        x *= x;
        n >>= 1;
    }
    return res;
}

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

    int n, m;
    cin >> n >> m;

    vector< P > es;

    rep(i, m){
        int a, b;
        cin >> a >> b;
        es.emplace_back(a - 1, b - 1);
    }

    lint ans = 0;

    rep(bit, 1 << n){
        bool flg = true;
        vector< vector<int> > g(n);

        rep(i, m){
            int a = es[i].first;
            int b = es[i].second;

            if((bit >> a & 1) && (bit >> b & 1)){
                flg = false;
                break;
            }else if(!(bit >> a & 1) && !(bit >> b & 1)){
                g[a].emplace_back(b);
                g[b].emplace_back(a);
            }
        }

        if(!flg){
            continue;
        }

        vector<int> col(n, -1);

        lint tmp = 1;

        rep(i, n){
            if((bit >> i & 1) || col[i] != -1){
                continue;
            }

            if(!dfs(i, 0, col, g)){
                tmp = 0;
                flg = false;
                break;
            }

            tmp *= 2;
        }

        ans += tmp;
    }

    cout << ans << endl;

    cout << flush;

    return 0;
}


#include <bits/stdc++.h>
#define watch(x) std::cout << (#x) << " is " << (x) << std::endl
using LL = long long;
const int M = 1e9 + 7;

int main() {
	// freopen("in", "r", stdin);
	std::cin.tie(nullptr)->sync_with_stdio(false);
	int n;
	std::cin >> n;
	std::vector<std::vector<std::pair<int, LL>>> e(n + 1);
	for (int i = 1, u, v; i < n; ++i) {
		LL w;
		std::cin >> u >> v >> w;
		e[u].emplace_back(v, w);
		e[v].emplace_back(u, w);
	}
	std::vector<LL> val(n + 1);
	std::function<void(int, int)> dfs = [&](int u, int fa) {
		for (auto &[v, w] : e[u]) if (v != fa) {
			val[v] = val[u] ^ w;
			dfs(v, u);
		}
	};
	dfs(1, 0);
	const int N = 60;
	std::vector<int> cnt(N);
	for (auto x : val) {
		for (int i = 0; x; x >>= 1, ++i) if (x & 1) ++cnt[i];
	}
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = (ans + (1LL << i) % M * cnt[i] % M * (n - cnt[i])) % M;
	}
	std::cout << ans << '\n';
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
using pii = pair<int, int>;

bool nBase(string s, ll n, ll m){
    __int128 res = 0;
    int len = s.length();
    for (int i = 0; i < len;i++){
        res = res * n + s[i] - '0';
        if(res > m)
            return false;
    }
    return true;
}

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

    string x;
    cin >> x;
    ll m;
    cin >> m;

    if(x.length()==1){
        cout << (atoi(x.c_str()) <= m ? 1 : 0);
        return 0;
    }

    int d = *max_element(x.begin(), x.end()) - '0';
    ll l = d + 1, r = 1e18;
    while(l <= r){
        ll mid = (l + r) / 2;
        if(nBase(x, mid, m)){
            l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
    cout << max(0ll, l - d - 1) << '\n';
    return 0;
}

//                        YATIN KWATRA

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

#define ll                      long long
#define ar                      array
#define sz(v)                   (int)(v.size())
#define inf                     1e18
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define pq                      priority_queue
#define uomii                   unordered_map<int,int,best_hash>
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
#define cz(x)                   63 - __builtin_clzll(x)

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

struct best_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);
	}
};

void INPUT()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

/*
----------------------------------------------------------------
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
----------------------------------------------------------------
*/

const int N = 805;
int v[N][N];
int a[N][N];
int dp[N][N];
int n, k;

bool possible(int med) {
	// so we can do like this in order to check if there is any matrix of size
	// K * K, such that median is  <= med.
	// we can convert all values greater than med into 1 and other to 0
	// so if sum of a k * k matrix is <= (k*k)/2 , so median can be <= med

	fo(i, 0, n - 1) {
		fo(j, 0, n - 1) {
			if (v[i][j] > med) a[i][j] = 1;
			else a[i][j] = 0;
		}
	}

	dp[0][0] = a[0][0];

	fo(i, 1, n - 1) {
		dp[0][i] = dp[0][i - 1] + a[0][i];
		dp[i][0] = dp[i - 1][0] + a[i][0];
	}

	fo(i, 1, n - 1) {
		int sum = a[i][0];
		fo(j, 1, n - 1) {
			dp[i][j] = dp[i - 1][j] + a[i][j] + sum;
			sum += a[i][j];
		}
	}

	fo(i, k - 1, n - 1) {
		fo(j, k - 1, n - 1) {
			int sum = dp[i][j];
			if ((j - k) >= 0) sum -= dp[i][j - k];
			if ((i - k) >= 0) sum -= dp[i - k][j];
			if ((i - k) >= 0 and (j - k) >= 0) sum += dp[i - k][j - k];
			if (sum <= ((k * k) / 2)) return 1;
		}
	}
	return 0;
}

void solve()
{
	cin >> n >> k;
	fo(i, 0, n - 1) {
		fo(j, 0, n - 1) cin >> v[i][j];
	}
	int low = 0, high = 1e9, ans = 1e9, mid;
	while (low <= high) {
		mid = (low + high) / 2;
		if (possible(mid)) {
			ans = mid;
			high = mid - 1;
		}
		else low = mid + 1;
	}
	cout << ans;
}

signed main() {

	FIO
	INPUT();

	int t;
	t = 1;
	//cin >> t;
	fo(i, 0, t - 1) {
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename T> vector<T> vin(int n) {
	vector<T> v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];
	return v;
}

vector<int> vi(int n) {
	vector<int> v(n);
	for (int i = 0; i < n; ++i) v[i] = i;
	return v;
}

void in() {
}

template<typename Head, typename... Tail>
void in(Head& h, Tail&... tails) {
	cin >> h;
	in(forward<Tail&>(tails)...);
}

void init_cin(const std::string& s) {
	cin.rdbuf((new istringstream(s))->rdbuf());
}

void out() {
	cout << endl;
}

template<typename T, typename... Args>
void out(T&& head, Args&&... args) {
	cout << head << " ";
	out(forward<Args>(args)...);
}

template<template <typename T, typename A = allocator<T>> class Cont, typename T>
ostream& operator<<(ostream& os, const Cont<T>& c) {
	for (auto it = c.begin(); it != c.end(); ++it) {
		if (it != c.begin()) os << " ";
		os << *it;
	}
	return os;
}

int main() {
	auto f = [](int n, int k, const vector<vector<int>>& tt) {
		vector<int> cities = vi(n);

		int ans = 0;
		do {
			int time = 0;
			for (size_t i = 0; i < cities.size(); ++i) {
				time += tt[cities[i]][cities[(i+1)%n]];
			}
			if (time == k) ans++;
//			out(cities, "/", time, ans);
		} while (next_permutation(cities.begin()+1, cities.end()));

		out(ans);

	};

	int N, K;
	cin >> N >> K;
	vector<vector<int>> tt(N, vector<int>(N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> tt[i][j];
		}
	}

	f(N, K, tt);

//	f(4, 330,
//			{
//				{0,     1,  10, 100},
//				{1,     0,  20, 200},
//				{10,   20,   0, 300},
//				{100, 200, 300,   0}
//			});

}

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;
typedef pair<int, int> PII;

const int N = 10;
const int M = 110;

ll h[N], ne[M], e[M], w[M], idx;
ll ans;
int n;
ll k;
bool vis[N];
bool vis1;
int cnt = 1;
void add(int a, int b, int c)
{
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx++;
}

void dfs(int x, ll dis)
{
    if(cnt == n && x == 1)
        if(dis == k)
        {
            ans++;
            return;
        }

    vis[x] = true;
    cnt++;
    for(int i = h[x]; ~i; i = ne[i])
    {
        int j = e[i];
        if(vis[j])
            continue;

        ll tmp = dis + w[i];
        if(tmp > k)
            continue;

        dfs(j, tmp);
    }

    vis[x] = false;
    cnt--;
}

int main()
{

    IOS;
    memset(h, -1, sizeof h);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            int tmp;
            cin >> tmp;
            if(j < i)
                continue;

            add(i, j, tmp);
            add(j, i, tmp);
        }

    for(int i = h[1]; ~i; i = ne[i])
    {
        int t = e[i];
        dfs(t, w[i]);
    }

    cout << ans << endl;
}


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

int main(){
    int N;
    vector<int>A;
    vector<int>B;
    int tmpa,tmpb;
    cin>>N;

    rep(i,N){
        cin>>tmpa>>tmpb;
        A.push_back(tmpa);
        B.push_back(tmpb);
    }

    int time=200009;
    rep(i,N){
        rep(j,N){
            if(i==j)continue;
            if(time>max(A[i],B[j])){
                time=max(A[i],B[j]);
            }
        }
    }
    rep(i,N){
        if(A[i]+B[i]<time){
            time=A[i]+B[i];
        }
    }
    cout<<time;
    return 0;
}

#include <bits/stdc++.h>
#define ALL(a) a.begin(), a.end()
#define ALLR(a) a.rbegin(), a.rend()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define SI(a) (int)a.size()
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll shift(ll a) { return 1LL << a; }
const int INF = shift(30);
const ll LINF = shift(60);

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  REP(i, n) { cin >> a[i] >> b[i]; }

  int ma, mb, ia, ib;
  ma = mb = INF;
  ia = ib = -1;
  REP(i, n) {
    if (chmin(ma, a[i])) {
      ia = i;
    }
    if (chmin(mb, b[i])) {
      ib = i;
    }
  }

  if (ia != ib) {
    cout << max(a[ia], b[ib]) << endl;
  } else {
    int ia2, ib2;
    ia2 = ib2 = -1;
    ma = mb = INF;
    REP(i, n) {
      if (i == ia) continue;
      if (chmin(ma, a[i])) {
        ia2 = i;
      }
      if (chmin(mb, b[i])) {
        ib2 = i;
      }
    }
    cout << min({a[ia] + b[ib], max(a[ia], b[ib2]), max(a[ia2], b[ib])})
         << endl;
  }
}


#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 1000000007

int dp[1001];
int main() {
    int N;
    char aa,ab,ba,bb;
    cin >> N >> aa >> ab >> ba >> bb;
    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }

    if (ab == 'B') {
        if (bb == 'B') {
            cout << 1 << endl;
            return 0;
        }
        else if (ba == 'A') {
            int i,p = 1;
            for (i = 0; i < N-3; i++) p *= 2,p %= MOD;
            cout << p << endl;
        }
        else {
            int i;
            dp[0] = dp[1] = 1;
            for (i = 2; i <= N; i++) {
                dp[i] = dp[i-2]+dp[i-1];
                dp[i] %= MOD;
            }
            cout << dp[N-2] << endl;
        }
    }
    else {
        if (aa == 'A') {
            cout << 1 << endl;
            return 0;
        }
        else if (ba == 'B') {
            int i,p = 1;
            for (i = 0; i < N-3; i++) p *= 2,p %= MOD;
            cout << p << endl;
        }
        else {
            int i;
            dp[0] = dp[1] = 1;
            for (i = 2; i <= N; i++) {
                dp[i] = dp[i-2]+dp[i-1];
                dp[i] %= MOD;
            }
            cout << dp[N-2] << endl;
        }
    }

    return 0;
}

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

#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)

/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/
int main()
{
  FAST();

CASE(t)
{
  ll int n; cin>>n;
  int ct=0;
  while (n%2==0)
  {
    ct++; n/=2;
  }
  if (ct==1){cout<<"Same"<<endl; }
  else if (ct==0){cout<<"Odd"<<endl; }
  else {cout<<"Even"<<endl; }
}

}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
ll a[MAX_N] = {};
int main() {
    ll n, w;
    cin >> n >> w;

    ll s[n], t[n], p[n];
    rep(i,n){
        cin >> s[i] >> t[i] >> p[i];
        a[s[i]] += p[i];
        a[t[i]] -= p[i];
    }
    int ok = 1;
    ll now = 0;
    rep(i,MAX_N){
        now += a[i];
        if(now > w) ok = 0;
    }
    if(ok) yn;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vector<vector<T>>;

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

    vec<int64_t> imos(2 * 1e5 + 1, 0);
    for (int i = 0; i < n; ++i) {
        int s, t, p; cin >> s >> t >> p;
        imos[s] += p;
        imos[t] -= p;
    }
    for (int i = 0; i < 2 * 1e5; ++i) {
        imos[i + 1] += imos[i];
    }

    for (auto e : imos) {
        if (w < e) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
//static const ll MOD=1e9+7;
static const ll MOD=998244353;
//for(i=0;i<N;i++) cin>>a[i];

class sumSegTree {
public:
  ll n, height;
  vector<ll> data;

  sumSegTree(ll _n) {
    n=1;
    height=1;
    while(n<_n) {
      n*=2;
      height++;
    }
    data=vector<ll>(2*n-1);
  }

  void add(ll i, ll x) {
    i+=n-1;
    data[i]+=x;
    while(i>0) {
      i=(i-1)/2;
      data[i]+=x;
    }
  }

  //[a, b):要求区間，[l, r):対象区間
  ll _sum(ll a, ll b, ll k, ll l, ll r) {
    if(r<=a || b<=l) return 0;
    if(a<=l && r<=b) return data[k];
    else {
      ll s=_sum(a, b, 2*k+1, l, (l+r)/2);
      ll t=_sum(a, b, 2*k+2, (l+r)/2, r);
      return s+t;
    }
  }

  ll sum(ll a, ll b) {
    return _sum(a, b, 0, 0, n);
  }

};

int main(void) {
  ll i, j, k;

  ll H,W,M;
  cin>>H>>W>>M;
  vector<vector<ll>> yoko(H,vector<ll>{W}),tate(W,vector<ll>({H}));
  for(i=0;i<M;i++){
    ll x,y;
    cin>>x>>y;x--;y--;
    yoko[x].push_back(y);
    tate[y].push_back(x);
  }
  for(i=0;i<H;i++) sort(yoko[i].begin(), yoko[i].end());
  for(j=0;j<W;j++) sort(tate[j].begin(), tate[j].end());

  ll ans=0;
  ll f=0;
  for(j=0;j<yoko[0][0];j++) ans+=tate[j][0];

  sumSegTree sst(W+1);
  for(j=yoko[0][0];j<W;j++) sst.add(j,1);
  for(i=0;i<tate[0][0];i++){
    ans+=sst.sum(0, yoko[i][0]);

    for(auto u:yoko[i]){
      if(sst.sum(u, u+1)==0)
        sst.add(u, 1);
    }

  }
  pt(ans);

}

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <functional>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <cctype>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n; i >= 0; --i)
#define int long long
const int N = 201337;

int ts=N * 4;
vector<vector<int>>d(ts);
vector<int> a;
void build(int v, int l, int r) {
    if (l == r - 1) {
        d[v].push_back(a[l]);
        return;
    }
    int m = (l+r)/2;
    build(2*v+1,l,m);
    build(2*v+2,m,r);
    merge(d[2*v+1].begin(),d[2*v+1].end(),d[2*v+2].begin(),d[2*v+2].end(),back_inserter(d[v]));
}
int get_res(int v,int l,int r, int L, int R, int k){
    if (r <= L || R <= l) {
        return 0;
    }
    if (L <= l && r <= R) {
        return d[v].end() - upper_bound(d[v].begin(),d[v].end(),k);
    }
    int m = (l+r)/2;
    int left = get_res(2*v+1,l,m,L,R,k);
    int right = get_res(2*v+2,m,r,L,R,k);
    return left+right;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w, m;
    cin >> h >> w >> m;
    // храним для row минимальный
    // храним для column min
    vector<int>row(h + 3, w + 1); // сколько для строки я могу пройти вниз
    vector<int>col(w + 3, h + 1); // сколько для столбца я могу пройти вправо
    forn(i, m){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        row[x] = min(row[x], y + 1);
        col[y] = min(col[y], x + 1);
    }
    a.assign(w, 0);
    int ans = 0;
    forn(i, row[0] - 1){ //
        //cout << "at col = " << i << "limit = " << max(0ll,col[i] - 1) << "\n";
        a[i] = max(0ll,col[i] - 1);
        ans += max(0ll,col[i] - 1);
    }
    //cout << ans << "\n";
//    forn(i, w){
//        if(col[i] == w)
//            col[i]++;
//    }
    build(0,0,w);
    forn(i, a[0]){
        int R = row[i] - 1;
        //cout << "at row = " << i + 1 << " we can take up to" << R  << "\n";
        //R--;
        int q = get_res(0,0,w,0,R,i);
        //cout << "q = " << q << "\n";
        ans += R - q;
    }
    cout << ans << "\n";
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

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

int n;
string str;
pair< ll, ll > a[ 200010 ];
int cnt[ 3 ];

ll get( int, int );
ll getAns( int, int );

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	cin >> n;
	n <<= 1;
	for( int i = 1; i <= n; ++i ) {
		cin >> a[ i ].first >> str;
		if( str[ 0 ] == 'R' )
			a[ i ].second = 0;
		else if( str[ 0 ] == 'G' )
			a[ i ].second = 1;
		else
			a[ i ].second = 2;
		++cnt[ a[ i ].second ];
	}
	if( cnt[ 0 ] % 2 == 0 && cnt[ 1 ] % 2 == 0 && cnt[ 2 ] % 2 == 0 ) {
		cout << 0;
		return 0;
	}
	sort( a + 1, a + 1 + n );
	if( cnt[ 0 ] % 2 == 0 )
		cout << getAns( 1, 2 );
	else if( cnt[ 1 ] % 2 == 0 )
		cout << getAns( 0, 2 );
	else
		cout << getAns( 0, 1 );
	return 0;
}

ll get( int x, int y ) {
	ll ans = MAX_INF_VAL_LL;
	ll lst = -MAX_INF_VAL_LL;
	for( int i = 1; i <= n; ++i ) {
		if( a[ i ].second == y )
			ans = min( ans, a[ i ].first - lst );
		else if( a[ i ].second == x )
			lst = a[ i ].first;
	}
	return ans;
}

ll getAns( int x, int y ) {
	int z = 3 ^ x ^ y;
	ll ans = min( get( x, y ), get( y, x ) );
	if( cnt[ z ] ) {
		ll t1 = min( get( x, z ), get( z, x ) );
		ll t2 = min( get( y, z ), get( z, y ) );
		ans = min( ans, t1 + t2 );
	}
	return ans;
}

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

void solve() {
    cini(x);
    x%=100;
    cout<<100-x<<endl;
}

signed main() {
    solve();
}


#include <bits/stdc++.h>

using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795
#define max1 101
#define MOD 1000000007

#define read(type) readInt<type>()

#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}

signed main(){
int n;
cin>>n;
int a[n];
FOR(i,n){
cin>>a[i];
if(a[i]<0){a[i]*=-1;}
}
int x=0;
FOR(i,n){
x+=a[i];}
out(x);
x=0;
FOR(i,n){
x+=a[i]*a[i];
}
double ans=(double)sqrt(x);
cout<<fixed<<setprecision(15)<<ans<<endl;
x=0;
FOR(i,n){
x=max(x,a[i]);}
out(x);
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i = 0; i < n; i++)
int32_t main() {
    int n, q, k; cin >> n >> q;
    vector<int> a(n);
    forn(i, n) cin >> a[i];
    vector<int> ps(n);
    ps[0] = a[0] - 1;
    forn(i, n - 1) ps[i + 1] = ps[i] + a[i + 1] - a[i] - 1;
    while (q--) {
        cin >> k;
        int x = --lower_bound(ps.begin(), ps.end(), k) - ps.begin();
        if (x == -1) cout << k;
        else cout << a[x] + k - ps[x];
        cout << "\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define drep(i,b,a) for(int i = (b)-1; i >= (a); i--)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(v) sort(v.begin(),v.end());
#define RSORT(v) sort(v.rbegin(),v.rend());
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool  odd(T x) { return x & 1; }
template<class T> inline bool even(T x) { return !(x & 1); }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill( (T*)array, (T*)(array+N), val );
}
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; }
//----------------------------------------------------------------------------------------------

struct edge {
    int to;
    int c;
    edge(int to, int c):to(to),c(c){}
};
vector<edge> G[100010];
int res[100010];

void dfs(int v, int p = -1, int ok = 1) {
    if(ok) {
        if(p != -1) {
            if(res[p] != 0) res[v] = 0;
            else res[v] = 1;
        } else {
            res[v] = 0;
        }
        for(auto e : G[v]) {
            int nv = e.to;
            int co = e.c;
            if(res[nv] != -1) continue;
            if(co == res[v]) dfs(nv, v, ok);
            else {
                res[nv] = co;
                dfs(nv, v, 1-ok);
            }
        }
    }
    else {
        for(auto e : G[v]) {
            int nv = e.to;
            int co = e.c;
            if(res[nv] != -1) continue;
            if(co == res[v]) dfs(nv, v, 1-ok);
            else {
                res[nv] = co;
                dfs(nv, v, ok);
            }
        }
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    rep(i,0,m) {
        int u,v,c;
        cin >> u >> v >> c;
        u--; v--; c--;
        G[u].emplace_back(v,c);
        G[v].emplace_back(u,c);
    }
    rep(i,0,n) res[i] = -1;
    dfs(0);
    rep(i,0,n) cout << res[i]+1 << endl;
    return 0;
}

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr int INF = 0x7f7f7f7f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	int r, x, y;
	cin >> r >> x >> y;
	ll dist = (1ll * x * x) + (1ll * y * y);
	//dist = ceil(sqrt(dist));
	if(dist < 1ll * r * r) {
		cout << 2 << endl;
		return 0;
	}
	ll k = 1;
	while(1ll * k * k * r * r < dist) k ++;
	cout << k << endl;
	return 0;
}
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline
// 最好用用"\n"代替endl


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

using namespace std;

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &i : a)
        in >> i;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto &i : a) {
        out << i << " ";
    }
    return out;
}

template<typename T, typename D>
istream &operator>>(istream &in, pair<T, D> &a) {
    in >> a.first >> a.second;
    return in;
}

template<typename T, typename D>
ostream &operator<<(ostream &out, const pair<T, D> &a) {
    out << a.first << " " << a.second;
    return out;
}

struct LogOutput {
    template<typename T>
    LogOutput &operator<<(const T &x) {
#ifdef DIVAN
        cout << x;
#endif
        return *this;
    }
} dout, fout;

typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
typedef complex<double> cd;

#define nl '\n'
#define elif else if
#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define vpi vector<pair<int, int>>
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) >= 0 ? ((x) % m) : ((((x) % m) + m) % m))
#define vi vector<int>
#define pi pair<int, int>
#define ti tuple<int, int, int>
#define minq(x, y) x = min((x), (y))
#define maxq(x, y) x = max(x, (y))
#define forn(i, n) for (int i = 0; i < (n); ++i)

const ll INFL = 9187201950435737471;
const ll nINFL = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const long double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

inline void IO() {
#ifdef DIVAN
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#else
    //    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
}

//#define int ll

const int MAXN = 2000 + 15;

vpi adj[MAXN];
int dist[MAXN];
int g[MAXN][MAXN];

void Func(int from) {
    memset(dist, 127, sizeof(dist));
    dist[from] = 0;
    set <pi> q;
    q.insert({0, from});
    while (!q.empty()) {
        auto [d, v] = *q.begin();
        q.erase(q.begin());
        for (auto &[to, cost] : adj[v])  {
            if (dist[to] > d + cost) {
                q.erase({dist[to], to});
                dist[to] = d + cost;
                q.insert({dist[to], to});
            }
        }
    }
}

void Solve() {
    memset(g, -1, sizeof(g));
    int n, m;
    cin >> n >> m;
    forn(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        if (g[a][b] == -1 || g[a][b] > c) {
            g[a][b] = c;
        }
        adj[a].eb(b, c);
    }
    for (int i = 1; i <= n; ++i) {
        Func(i);
        int now = INF;
        for (int j = 1; j <= n; ++j) {
            if (g[j][i] != -1 && dist[j] != INF) {
                minq(now, g[j][i] + dist[j]);
            }
        }
        if (now == INF) {
            cout << "-1\n";
        } else {
            cout << now << '\n';
        }
    }
}

signed main() {
    IO();
    int t = 1;
//    cin >> t;
    int startTime = clock();
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        Solve();
    }
    int endTime = clock();
    fout << '\n' << "Time: " << (endTime - startTime + 999) / 1000;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
#define lin(x) ll x; cin>>x;
#define stin(x) string x; cin>>x;
#define yn(x)  if(x) {  cout<<"Yes"<<endl;   }    else {    cout<<"No"<<endl;   }
#define YN(x)  if(x) {  cout<<"YES"<<endl;   }    else {    cout<<"NO"<<endl;   }
#define co(x) cout<<x<<endl;
#define kiri(x,y) (x+y-1)/y;
#define shisha(x,y) (x+(y/2))/y;
#define gomi(x) x.erase(unique(all(x)), x.end());
using ll=long long;
using ld=long double;
using vl=vector<ll>;
using vs=vector<string>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll mod=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
    return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
    return ((a > b) ? (a = b, true) : (false));
}
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
lin(a);
  lin(b);
  lin(c);
  co(21-a-b-c);
}


#include <bits/stdc++.h>
#define forloop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ll long long int
#define ld long double
#define pb emplace_back
#define ravi ios_base::sync_with_stdio(false);
#define parmar2002 cin.tie(NULL); cout.tie(NULL);
#define nl "\n"
#define sclock clock_t tStart = clock();
#define eclock printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define finout freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define whole(x) x.begin(), x.end()
#define wholer(x) x.rbegin(), x.rend()
#define len(s) s.size()
#define endline cout << "\n";
#define T(T) ll tt; cin >> tt; forloop(T, 1, tt + 1)
#define retf(flag, x) if(flag) {cout<<x<<nl; return;}
#define vint vector<int>
#define forv(arr) for(auto i:arr) cout<<i<<" "; endline;
#define forin(arr) for(auto &i : arr) cin>>i;
#define ret(x) {cout<<x<<nl; return;}
using namespace std;
class Solution {
public:

};
void solve();
int main()
{
	ravi parmar2002
	// finout //In case of File input output
	// sclock
	// T(T)
	solve();
	// eclock
	return 0;
}
void solve()
{
	ll n, k;
	cin>>n>>k;
	vector<pair<ll, ll>>arr(n);
	for(auto &i:arr) cin>>i.first>>i.second;
	arr.pb(make_pair(0, 0));
	sort(whole(arr));
	ll prev = 0;
	forloop(i, 1, len(arr))
	{
		if(arr[i].first - arr[i-1].first <= k)
		k -=  (arr[i].first - arr[i-1].first);
		else ret(arr[i-1].first + k);
		k += arr[i].second;
	}
	cout<<arr.back().first + k;
}

#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI
const double eps = 1e-9;

int n;
ll k;

vector<pair<ll, ll> > v;

int main()
{
	#ifdef fisier
		ifstream cin("input.in");
		ofstream cout("output.out");
	#endif

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

	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
	{
		ll a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	v.push_back({(1LL<<62), 0});

	ll current_place = 0;
	for(int i = 0; i < v.size(); ++i)
	{
		if(v[i].first - current_place > k)
		{
			current_place += k;
			break;
		}

		k -= (v[i].first - current_place);
		k += v[i].second;
		current_place = v[i].first;

	}

	cout << current_place;

	return 0;
}


/*
Alexander Rango
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl                        '\n'
#define pii pair <ll , ll>
#define F first
#define S second
const ll max_n = 1e3 + 20, inf = 1e18 + 20;
ll dist[max_n][max_n], n, m ,s, t, T, u, v, w, ans;
char c;
bitset <max_n> visited[max_n];
vector <pii> g[max_n][26];
void solve(ll x, ll y) {
    for (ll i = 1; i <= n; i++) {
    	fill(dist[i] + 1, dist[i] + n + 1, inf);
		visited[i] = 0;
	}
    dist[x][y] = 0;
    priority_queue < pair <ll , pii > > pq;
    pq.push({0, {x, y}});
    while (!pq.empty()) {
        ll x = pq.top().S.F;
		ll y = pq.top().S.S;
		pq.pop();
        if (!visited[x][y]) {
        	visited[x][y] = 1;
        	for (ll i = 0; i < 26; i++) {
        		for (pii u : g[x][i]) {
        			for (pii v : g[y][i]) {
        				if (dist[x][y] + u.S + v.S < dist[u.F][v.F]) {
        					dist[u.F][v.F] = dist[x][y] + u.S + v.S;
							pq.push({-dist[u.F][v.F], {u.F, v.F}});
						}
					}
				}
			}
		}
    }
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // cin >> T;
    T = 1;
    while (T--) {
        cin >> n >> m/* >> s >> t*/;
    	for(ll i = 1; i <= n; i++) {
    		for (ll j = 0; j < 26; j++) {
    			g[i][j].clear();
			}
		}
    	for(ll i = 0; i < m; i++) {
       	 	cin >> u >> v /*>> w*/ >> c;
       	 	g[u][int(c) - 97].push_back({v, 1});
       		g[v][int(c) - 97].push_back({u, 1});
    	}
        ans = inf;
        solve(1, n);
        for (ll i = 1; i <= n; i++) {
            ans = min(ans, dist[i][i]);
        }
        for (ll u = 1; u <= n; u++) {
            for (ll j = 0; j < 26; j++) {
                for (pii v : g[u][j]) {
                    ans = min(ans, dist[u][v.F] + v.S);
                }
            }
        }
        if(ans == inf)ans = -1;
		cout << ans << endl;
   	}
    return 0;
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

void get(ll i, ll arr[], ll n, ll xo, ll o, ll &ans)
{
    if(i == n)
    {
        ans = min(ans, xo^o);
        return;
    }

    get(i+1, arr, n, xo, o|arr[i], ans);
    get(i+1, arr, n, xo^o, arr[i], ans);
}

const ld PI = acos(-1);

ll n;
ll get(ll i, ll j)
{
    return i*n + j;
}

void dijk(vector<ll> v[], ll n, ll x, vector<ll> &dis)
{
    dis[x] = 0;
    queue<pii> q;
    q.push(mp(0,x));
    dis[x] = 0;

    while(q.size() > 0)
    {
        ll temp = q.front().second;
        q.pop();

        for(auto it = v[temp].begin();it!=v[temp].end();it++)
        {
            ll v1 = *it;
            ll wt = 1;

            if(dis[v1]>dis[temp] + wt)
            {
                dis[v1] = dis[temp] + wt;
                q.push({dis[v1],v1});
            }
        }
    }

}

int main()
{
  FAST/**/

  ll m;
  cin>>n>>m;

  vector<pii> gr[n];
  bool ter = 0;
  rep(m)
  {
      ll a,b;
      char c;
      cin>>a>>b>>c;
      a--, b--;
      if(a>b)
            swap(a,b);
      if(a == 0 && b == n-1 && ter == false)
      {
          cout<<1<<'\n';
          ter = true;
      }
      gr[a].pb({b,c});
      gr[b].pb({a,c});
  }

  if(ter)
    return 0;

  ll lim = n*n;
  vector<ll> tot[lim];
  for(ll i=0;i<n;i++)
  {
      for(ll j=0;j<n;j++)
      {
          autoit(gr[i],it)
                autoit(gr[j],it1)
                {
                    if(it1->ss == it->ss)
                        tot[get(i,j)].pb(get(it->ff, it1->ff));
                }
      }
  }
  vector<ll> dis(lim,inf);
  dijk(tot,lim,get(0,n-1),dis);

  ll ans = inf;
  rep(n)
        ans = min(ans, 2*dis[get(i,i)]);
  rep(n)
        autoit(gr[i],it)
        {
            ans = min(ans, 1 + 2*dis[get(i,it->ff)]);
        }
  if(ans == inf)
        ans = -1;
  cout<<ans<<"\n";

  return 0;
}


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

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

using namespace std;

//---------------------約数の列挙
vector<long long int> divisor(long long int N){
	vector<long long int> p;
	for(long long int q=1;q*q<=N;q++){
		if(N%q == 0){
			p.push_back(q);
			if(N/q != q){
				p.push_back(N/q);
			}
			else{}
		}
		else{}
	}
	sort(p.begin(),p.end());
	return p;
}

int main(){

ll int S,P;
cin >> S >> P;
	if(1+P==S){
		cout << "Yes";
		return 0;
	}
vector<ll int > a;

a = divisor(P);
ll int i=0;
ll int j=0;
ll int N ;
N = a.size();
while(i < sqrt(P) || j!=N){

	i=a[j];
	if(i + (P/i) == S){
		cout << "Yes";
		return 0;
	}
	else{}
	j+=1;
}

		cout << "No";

	return 0;

}

/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MAXN=2e5+233;
int k,n;
vector<int> g[MAXN];
struct inf{
	int cnt,dis,ty;
	inf(){cnt=dis=ty=0;}
	inf(int A,int B,int C){cnt=A,dis=B,ty=C;}
};
int D;
inf operator + (inf A,inf B){
	if(A.ty&&B.ty) return inf(A.cnt+B.cnt,max(A.dis,B.dis),1);
	if(!A.ty&&!B.ty) return inf(A.cnt+B.cnt,min(A.dis,B.dis),0);
	if(A.ty>B.ty) swap(A,B);
	if(A.dis+B.dis<=D) return inf(A.cnt+B.cnt,A.dis,0);
	return inf(A.cnt+B.cnt,B.dis,1);
}
inf get(int now,int fa){
	inf ret;
	if(g[now].size()==1&&fa){
		return inf(0,0,1);
	}
	bool ok=0;
	for(auto it:g[now]){
		if(it!=fa){
			auto Tmp=get(it,now);
			Tmp.dis++;
			if(!ok) ret=Tmp;
			else ret=ret+Tmp;
			ok=1;
		}
	}
	if(II(ret.dis,ret.ty)==II(D,1)){
		ret=inf(ret.cnt+1,0,0);
	}
	if(II(ret.dis,ret.ty)==II(D+1,0)){
		ret=inf(ret.cnt,0,1);
	}
//	cout<<now<<" "<<ret.cnt<<' '<<ret.dis<<' '<<ret.ty<<endl;
	return ret;
}
bool check(int d){
	D=d;
	auto it=get(1,0);
	return it.cnt+it.ty<=k;
}
int main(){
	scanf("%d%d",&n,&k);
	rb(i,1,n-1){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].PB(v);
		g[v].PB(u);
	}
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}


#include <iostream>
using namespace std;

int main(void) {
	int N, A, B;

	cin >> N >> A >> B;
	N -= A;
	if (N < 0) {
		N = 0;
	}
	N += B;

	cout << N << endl;

	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c;
    d=a-b+c;
    cout<<d;
    return 0;
}


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

const int N = 100;

char s[N][N];

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

int solve() {
  int n, m;
  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int cnt = 0;
      int orient = 0;
      for (int k = 0; k < 4; ++k) {
        int nx = i + dx[k], ny = j + dy[k];

        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (s[i][j] != s[nx][ny]) {
          orient |= 1 << (k & 1);
          ++cnt;
        }
      }

      if (cnt == 2 && orient == 3) ++ans;
      else if (cnt == 3) ans += 2;
      else if (cnt == 4) ans += 4;
    }
  }

  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    solve();
  }
  return 0;
}

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

//UnionFindテンプレ
class UnionFind {
    // まとめる 判定 サイズを知る
    public:
    // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
    vector<int> Parent;

    // 初期化
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    // Aのrootを調べる
    int root(int A) {
        if (Parent[A] < 0) return A;  // マイナスならそれはroot
        return Parent[A] = root(Parent[A]);
    }

    // rootの値をプラスに戻して返す(サイズ)
    int size(int A) {
        return -Parent[root(A)];
    }

    // くっつける関数
    bool connect(int A, int B) {
        // AとBのroot同士をくっつける
        A = root(A);  // ここのAは、"rootの場所"の意味
        B = root(B);
        if (A == B) return false;  // 既にくっついている
        if (size(A) < size(B))
        swap(A, B);            // 大きい方にくっつけるために中身交換
        Parent[A] += Parent[B];  // 中身更新
        Parent[B] = A;
        return true;
    }

    //連結か調べる関数
    bool issame(int A, int B) {
        return root(A) == root(B);
    }
};

//chmin,chmax関数(DP用)
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;
}

//aのZ/mZでの逆元
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大公約数
int64_t gcd(int64_t a, int64_t b) {
    if (a % b == 0) {
        return b;
    }
    return gcd(b, a%b);
}
int64_t lcm(int64_t a, int64_t b) {
    return a*b/gcd(a,b);
}
//エラストテレスのふるい
vector<bool> make_is_prime(int N) {
    vector<bool> prime(N + 1, true);
    if (N >= 0) prime[0] = false;
    if (N >= 1) prime[1] = false;
    for (int i = 2; i * i <= N; i++) {
        if (!prime[i]) continue;
        for (int j = i * i; j <= N; j += i) {
            prime[j] = false;
        }
    }
    return prime;
}
//累乗a^b
int64_t pow(int a, int b) {
    int64_t ans = (int64_t)1;
    for (int i = 0; i < b; i++) {
        ans *= (int64_t)a;
    }
    return ans;
}

//ここから

int main() {
    int H,W; cin>>H>>W;
    vector<vector<char>> map(H,vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin>>map.at(i).at(j);
        }
    }
    int ans = 0;
    for (int i = 0; i < H-1; i++) {
        for (int j = 0; j < W-1; j++) {
            int cnt = 0;
            if (map.at(i).at(j) == '#') cnt++;
            if (map.at(i+1).at(j) == '#') cnt++;
            if (map.at(i).at(j+1) == '#') cnt++;
            if (map.at(i+1).at(j+1) == '#') cnt++;
            if (cnt == 1 || cnt == 3) ans++;
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll m;
int A[62],n;
bool judge(ll x){
  ll ret = 0,bs = 1;
  for(int i(0);i <= n;++i){
    ll sum = bs*A[i];
    if(sum > m) return 0;
    if(ret+sum > m) return 0;
    ret += sum;
    if(i != n){
      if(m/x < bs) return 0;
      bs = bs*x;
      if(bs > m) return 0;
    }
  }
  return 1;
}
int main(){
#ifdef LZX_CAI
  freopen("test.in","r",stdin);
  freopen("test.out","w",stdout);
#endif
  string S; cin >> S;
  n = S.size()-1;
  int mx = 0;
  for(int i(0);i <= n;++i){
    A[i] = S[n-i]-'0';
    mx = max(mx,S[n-i]-'0');
  }
  cin >> m;
  if(n == 0){
    int x = A[0];
    if(m < x) return puts("0"),0;
    else return puts("1"),0;
  }
  ll R = m,Ans = mx,L = mx+1;
  while(L <= R){
    ll mid = (L+R)/2;
    if(judge(mid)) Ans = mid,L = mid+1;
    else R = mid-1;
  }
  cout << Ans-mx << endl;
  return 0;
}

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

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

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

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

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

using namespace std;

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

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

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

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

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

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

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

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	printf("%d\n", n - a + b);

	Please AC;
}


// {{{ by unolight
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i,a,b) for (int i = a; i <= (int)(b); i++)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

namespace { namespace unolight {

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template <class T, class F = less<T>>
void sort_uniq(vector<T> &v, F f = F()) {
    sort(begin(v), end(v), f);
    v.resize(unique(begin(v), end(v)) - begin(v));
}
// }}}

// {{{ ModInt
template<int _MOD>
struct ModInt {
	static const auto MOD = _MOD;
	template<class T> using integral_only = typename enable_if<is_integral<T>::value>::type;

    int x;
	constexpr ModInt() : x() {}

	template<class T, integral_only<T>* = nullptr>
    ModInt(T _x=0) {
		x = _x % MOD;
		if(x<0) x+=MOD;
	}
    ModInt operator-() const { return {x == 0? 0 : MOD-x}; }
    ModInt& operator+=(const ModInt a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt a) {
        x = (long long)x * a.x % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt a) {
        return (*this) *= a.inv();
    }

    ModInt operator+(const ModInt a) const { return ModInt(*this) += a; }
    ModInt operator-(const ModInt a) const { return ModInt(*this) -= a; }
    ModInt operator*(const ModInt a) const { return ModInt(*this) *= a; }
    ModInt operator/(const ModInt a) const { return ModInt(*this) /= a; }
    ModInt inv() const {
	    // for prime MOD
        return pow(MOD-2);
    }
	ModInt inv2() const {
		// work for non-prime MOD if gcd(x,MOD) = 1
		int a = x, b = MOD, u = 1, v = 0;
		while(b != 0) {
			int t = a / b;
			a -= t * b;
			u -= t * v;
			swap(a, b);
			swap(u, v);
		}
		return u;
	}
	template<class T, integral_only<T>* = nullptr>
    ModInt pow(T t) const {
		ModInt r = 1, p = *this;
		while(t) {
			if(t & 1) r *= p;
			p *= p;
			t >>= 1;
		}
        return r;
    }

    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    bool operator<(ModInt rhs) const { return x < rhs.x; }
    bool operator<=(ModInt rhs) const { return x <= rhs.x; }
    bool operator>(ModInt rhs) const { return x > rhs.x; }
    bool operator>=(ModInt rhs) const { return x >= rhs.x; }

    friend string to_string(ModInt i) { return to_string(i.x); }
    friend istream& operator>>(istream&i,ModInt&a) { return i>>a.x; }
    friend ostream& operator<<(ostream&o,const ModInt&a) { return o<<a.x; }
};

const int MOD=998244353;
using mint=ModInt<MOD>;
// }}}

void main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    vector<mint> s(k+1); // sum(ai^k)
    vector<vector<mint>> c(k+1, vector<mint>(k+1));
    c[0][0]=1;
    REP(i,k) {
        REP(j,i+1) {
            c[i+1][j]+=c[i][j];
            c[i+1][j+1]+=c[i][j];
        }
    }
    REP(i,n) {
        mint x=1;
        REP(j,k+1) {
            s[j]+=x;
            x*=a[i];
        }
    }
    REP1(i,1,k) {
        mint ans=0;
        REP(j,i+1) {
            ans+=c[i][j]*s[j]*s[i-j];
            ans-=c[i][j]*s[i];
        }
        cout << ans/2 << '\n';
    }
}

// {{{ main
}}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    unolight::main();
    return 0;
}
// }}}

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int K=1e5;
long long w[K+10];
priority_queue<pair<long long,int>> pq;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int k;
	long long n,m;
	cin>>k>>n>>m;
	int lft=m;
	for(int i=1;i<=k;i++)
	{
		long long a;
		cin>>a;
		w[i]=(a*m)/n;
		lft-=w[i];
		pq.push({abs(w[i]*n-a*m)-abs((w[i]+1)*n-a*m),i});
	}
	for(;lft>0;lft--)
	{
		w[pq.top().se]++;
		pq.pop();
	}
	for(int i=1;i<=k;i++)
		cout<<w[i]<<" ";
	cout<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll z = 0, mod = 1000000007;

int main(){
  ll N;
  cin >> N;

  if (N == 1){
    cout << 1 << endl;
    cout << 1 << endl;
    exit(0);
  }

  vector<ll> fib(2);
  fib[0] = 1;
  fib[1] = 1;

  ll now = 2;
  while (true){
    ll next = fib[now - 1] + fib[now - 2];
    if (next > N && now % 2 == 0) break;
    now++;
    fib.push_back(next);
  }

  vector<ll> num(fib.size(), 0);
  ll ope = (ll)(fib.size()) - 1;
  for (ll i = (ll)(fib.size()) - 1; i >= 0; i--){
    num[i] = N / fib[i];
    N -= num[i] * fib[i];
    ope += num[i];
    //cout << fib[i] << ' ' << num[i] << endl;
  }

  cout << ope << endl;
  ll chnum = (ll)(num.size()) - 1;
  for (ll i = 0; i < chnum; i++){
    for (ll k = 0; k < num[chnum - 1 - 2 * (i / 2)]; k++){
      cout << 1 << endl;
      num[chnum - 1 - 2 * (i / 2)] = 0;
    }
    for (ll k = 0; k < num[chnum - 2 * ((i + 1) / 2)]; k++){
      cout << 2 << endl;
      num[chnum - 2 * ((i + 1) / 2)] = 0;
    }
    if (i % 2 == 0){
      cout << 3 << endl;
    }
    else{
      cout << 4 << endl;
    }
  }
}

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

#include <bits/stdc++.h>

using namespace std;

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 vector<bool> vb;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

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

#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

// inputs
#define VLLIN(x, n) vll x(n); REP(i, n) cin >> x[i];
#define VIIN(x, n) vi x(n); REP(i, n) cin >> x[i];
#define VLDIN(x, n) vld x(n); REP(i, n) cin >> x[i];
#define SIN(s, n) string s; cin >> s;

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

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

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

    ll a, b, c; cin >> a >> b >> c;

    if (a == b) {
        print("=");
        return 0;
    }

    if (abs(a) == abs(b) && ~c & 1) {
        print("=");
        return 0;
    }

    if (a > 0 && b > 0) {
        if (a > b) {
            print(">");
        } else {
            print("<");
        }
    } else if (a < 0 && b < 0) {
        a = abs(a), b = abs(b);
        if (c & 1) {
            // negative
            if (a > b) {
                print("<");
            } else {
                print(">");
            }
        } else {
            // positive
            if (a > b) {
                print(">");
            } else {
                print("<");
            }
        }
    } else {
        if (~c & 1) {
            a = abs(a), b = abs(b);
        }
        if (a > b) {
            print(">");
        } else {
            print("<");
        }
    }

}


/*

    P_r_A_d_Y ☹

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

#define int     long long int
#define endl    "\n"
#define mod     1000000007
#define inf     1e18
#define pb      push_back
#define all(x)  x.begin(),x.end()
#define arr_max(x)  *max_element(x.begin(),x.end())
#define arr_min(x)  *min_element(x.begin(),x.end())
#define pii         pair<int,int>
#define ff          first
#define ss          second
#define vec         vector<int>

const int N = 300005;

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

bool cmp(vector<int>a , vector<int>b) {
    return a[0] < b[0];
}
int poww(int x, int n)
{
    if (n == 0 ) return 1 ;
    int u = poww(x, n / 2);
    u = (u * u) ;
    if (n % 2 == 1)u = (u * x) ;
    return u;
}

//(x**n)%m
int mod_pow(int x, int n, int m)
{
    if (n == 0 ) return 1 % m;
    int u = mod_pow(x, n / 2, m);
    u = (u * u) % m;
    if (n % 2 == 1)u = (u * x) % m;
    return u;
}
int query(int l, int r)
{
    int x;
    cout << "? " << l << " " << r << endl;
    cin >> x;

    return x;
}

// int xd[4] = {1, 0, -1, 0};
// int yd[4] = {0, -1, 0, 1};

int help(int n)
{
    int count_pairs = 0;

    for (int i = 1; i <= sqrt(n - 1); ++i) {
        for (int j = i; j * i < n; ++j)
            ++count_pairs;
    }

    count_pairs *= 2;

    count_pairs -= (int)(sqrt(n - 1));

    return count_pairs;
}

int32_t main()
{
    fastIO;

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

    int t;
    t = 1;
    //cin >> t;
    int ert = 1;
    while (t--)
    {
        int k; cin >> k;
        int ans = 0;
        for (int i = 1; i <= k; i++)
        {
            int r = k / i;

            if (r == 0)
                break;
            int g = help(r + 1);
            //cout << r << " " << g << endl;
            ans += g;

        }

        cout << ans << endl;

    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i, a, b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

int main() {
    string S;
    cin >> S;

    bool is_reversed = false;
    deque<char> q;

    for(auto s: S) {
        if (s == 'R') is_reversed = !is_reversed;
        else {
            if (is_reversed) {
                // 反転されているときは先頭に追加する
                q.push_front(s);
            }
            else {
                // そうでないときは末尾に追加する
                q.push_back(s);
            }
        }
    }
    if (is_reversed) {
        reverse(q.begin(), q.end());
    }

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

    cout << T << endl;

    return 0;
}