#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define big 998244353
#define ff first
#define se second
#define pb push_back
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define mp make_pair
#define pi 3.141592653589
int power(int x,int y){
    int r=1,z=x;
    while(y){
        if(y & 1)r*=z;
        z*=z;y=y>>1;}
    return r;}
int powerm(int x,int y,int p){
    int r=1;
    while(y){
        if(y & 1)r=(r*x)%p;
        y=y>>1;
        x=(x*x)%p;}
    return r%p;}
int modinv(int x,int m){
    return powerm(x,m-2,m);}
int logarithm(int a,int b){
    int x=0;
    while(a>1){
        x++;
        a/=b;}
    return x;}
vector<int> ad[200005];
int vis[200005];
vector<int> gr;
void dfs(int x){
	vis[x]=1;
	gr.pb(x);
	for(auto p:ad[x])
		if(!vis[p])
			dfs(p);
}
int32_t main(){
    fast;
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++)
    	cin>>a[i];
    for(int i=0;i<n;i++)
    	cin>>b[i];
    for(int i=1;i<=m;i++){
    	int u,v;
    	cin>>u>>v;
    	ad[u].pb(v);
    	ad[v].pb(u);
    }
    for(int i=1;i<=n;i++){
    	gr.clear();
    	if(!vis[i])
    		dfs(i);
    	int sum1,sum2;
    	sum1=sum2=0;
    	for(auto p:gr){
    		sum2+=b[p-1];
    		sum1+=a[p-1];
    	}
    	if(sum1!=sum2){
    		cout<<"No";
    		return 0;
    	}
    }
    cout<<"Yes";
    return 0;
}

///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           node(a,b,c)                 mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int a[M],b[M],par[M],asum[M],bsum[M],sz[M],ok[M];
int fnd(int x)
{
    if(par[x]==x)return x;
    return par[x]=fnd(par[x]);
}
void tie(int x,int y)
{
    int fx=fnd(x);
    int fy=fnd(y);
    if(fx==fy)return ;
    par[fx]=fy;
}
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    f(i,1,n)cin>>a[i],par[i]=i;
    f(i,1,n)cin>>b[i];
    f(i,1,m)
    {
        int u,v;
        cin>>u>>v;
        tie(u,v);
    }
    f(i,1,n)
    {
        int p=fnd(i);
        asum[p]+=a[i];
        bsum[p]+=b[i];
    }
    f(i,1,n)
    {
        if(asum[i]!=bsum[i])
        {
            cout<<"No\n";return 0;
        }
    }
    cout<<"Yes\n";
    return 0;

}


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

const int MAX_N = 200000;
typedef long long ll;
const ll MOD = 998244353;

int n, k;
ll A[MAX_N];
ll S[301];
ll inv[301];

ll func(ll t) {
    ll ans = 1;
    ll pow = MOD - 2;
    while (pow > 0) {
        if (pow&1)
            ans = ans * t % MOD;
        t = t * t % MOD;
        pow >>= 1;
    }
    return ans;
}

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

    for (int j = 0; j <= k; j++) {
        S[j] = 0;
        if (j > 0)
            inv[j] = func(j);
    }

    for (int i = 0; i < n; i++) {
        cin >> A[i];
        ll tmp = 1ll;
        S[0] += tmp;
        for (int j = 1; j <= k; j++) {
            tmp = tmp * A[i] % MOD;
            S[j] += tmp;
            if (S[j] >= MOD)
                S[j] -= MOD;
        }
    }

    for (int x = 1; x <= k; x++) {
        ll ans = 0;

        ll comb = 1ll;
        for (int i = 0; i * 2 + 1 <= x; i++) {
            if (i > 0)
                comb = comb * (x - i + 1) % MOD * inv[i] % MOD;
            ll tmp = S[i] * S[x - i] % MOD + MOD - S[x];
            if (tmp >= MOD)
                tmp -= MOD;
            ans = ans + (comb * tmp % MOD);
            if (ans >= MOD)
                ans -= MOD;
        }

        if (x % 2 == 0) {
            comb = comb * (x / 2 + 1) % MOD * inv[x / 2] % MOD;
            ll tmp = (S[x / 2] * S[x / 2] % MOD + MOD - S[x]) * inv[2] % MOD;
            ans = ans + (comb * tmp % MOD);
            if (ans >= MOD)
                ans -= MOD;
        }
        cout << ans << "\n";
    }
}

#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 200005, mod = 998244353;
const ll inv2 = (mod + 1) / 2;
int n, k;
ll res[MX], s[MX], comb[705][705], a[MX];

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

	forn (i, 705) {
		comb[i][0] = 1;
		for (int j = 1; j <= i; j++)
			comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;
	}

	cin >> n >> k;
	forn (i, n) cin >> a[i];

	forn (i, n) {
		ll x = 1;
		forn (j, k + 1) {
			(s[j] += x) %= mod;
			(x *= a[i]) %= mod;
		}
	}

	forn (i, k + 1) forn (j, k + 1) {
		(res[i + j] += comb[i + j][i] * s[i] % mod * s[j] % mod) %= mod;
		(res[i + j] -= comb[i + j][i] * s[i + j]) %= mod;
	}

	for (int i = 1; i <= k; i++) {
		(res[i] *= inv2) %= mod;
		cout << MOD(res[i], mod) << endl;
	}

	return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Thursday 27 May 2021 10:33:10 AM
*/

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

const int Mod = 998244353;
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a){ s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a){ s >> a.x; return s; }
};

using mint = ModInt<Mod>;

// ...
// ...
// ...
// ...

int32_t main(){

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

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

    vector < string > s(n);
    for(auto &x: s) cin >> x;

    mint ans = 1;

    for(int i=0; i<n+m-1; ++i){
        int a=0, b=0, cnt=0;
        int nx = 0;
        for(int j=i; j>=0; --j){
            int ny = j;
            if(nx>=0 and ny>=0 and nx<n and ny<m){
                if(s[nx][ny] == 'R')++a;
                if(s[nx][ny]=='B')++b;
                if(s[nx][ny]=='.')++cnt;
            }
            ++nx;
        }
        //cerr <<  a << " " << b << "\n";
        if(a>0 and b>0){
            cout << 0 << "\n";
            return 0;
        }else if(a == 0 and b == 0){
            ans *= 2;
        }
    }

    cout << ans << "\n";

    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int h,w; cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    vector<bool> flag_R(h+w-1);
    vector<bool> flag_B(h+w-1);

    rep(i,h)rep(j,w){
        if(s[i][j] == 'R') flag_R[i+j] = true;
        if(s[i][j] == 'B') flag_B[i+j] = true;
    }

    ll ans = 1;
    rep(i,h+w-1){
        if(flag_R[i] && flag_B[i]){
            ans = 0;
        }
        if(!flag_R[i] && !flag_B[i]){
            ans *= 2; ans %= 998244353;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#include <iostream>
#include <fstream>

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

inline int inint(istream& in) {int x; in >> x; return x;}
inline ll inll(istream& in) {ll x; in >> x; return x;}
inline string instr(istream& in) {string x; in >> x; return x;}

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

class ARockPaperScissors {
public:
void solve(std::istream& in, std::ostream& out) {

    int x = inint(in);
    int y = inint(in);

    if(x == y){
        out << x << endl;
        return;
    }

    if(x + y == 1){
        out << 2 << endl;
        return;
    }

    if(x + y == 2){
        out << 1 << endl;
        return;
    }

    if(x + y == 3){
        out << 0 << endl;
        return;
    }

}
};

int main() {
	ARockPaperScissors solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define deb(k) cerr << #k << ": " << k << "\n";
#define size(a) (int)a.size()
#define fastcin cin.tie(0)->sync_with_stdio(0);
#define st first
#define nd second
#define pb push_back
#define mk make_pair
#define int long long
typedef long double ldbl;
typedef double dbl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef vector<int> vint;
#define MAX 300100
#define MAXLG 20
const int inf = 0x3f3f3f3f;
const ll mod = 998244353;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const int N = 300100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//knapstack
ll fat[MAX+100];
ll ifat[MAX+100];

ll power(ll x, ll y, ll p){
  ll res = 1;
  x = x % p;
  while (y > 0){
    if (y & 1) res = (res*x) % p;
    y = y>>1;
    x = (x*x) % p;
  }
  return res;
}

void init(){
	fat[0] = 1;
	for(ll i=1;i<=MAX;i++){
	  fat[i] = (fat[i-1]*i)%mod;
	}
	ifat[MAX] = power(fat[MAX], mod-2, mod);
	for(ll i=MAX-1;i>=0;i--) ifat[i] = (ifat[i+1]*(i+1))%mod;
}

ll choose(int x, int y){
	if(y < 0 || y > x || x < 0) return 0;
	return fat[x]*(ifat[y]*ifat[x-y]%mod)%mod;
}

int n, m;
int dp[5010][20];
int vis[5010][20];

int sol(int x, int y){
	if(y == 17){
		if(x) return 0;
		return 1;
	}
	if(vis[x][y]) return dp[x][y];
	vis[x][y] = 1;
	int &c = dp[x][y];
	for(int i=0;i<=n;i+=2){
		if( (1<<y)*i > x) break;
		c = (c + sol(x - (1<<y)*i, y+1)*choose(n, i)%mod)%mod;
	}
	return c;
}

void solve(){
	init();
	cin>>n>>m;
	cout<<sol(m, 0)<<"\n";

	// Have you read the problem again?
	// Maybe you understood the wrong problem
}

int32_t main(){
	fastcin;
	int t_ = 1;
	//cin>>t_;
	while(t_--)
		solve();
	return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const LL INF = 1e18;

int main(){
	int N, M;
	cin >> N >> M;
	vector<LL> H(N), W(M);
	rep(i,N) cin >> H[i];
	rep(i,M) cin >> W[i];
	sort(H.begin(),H.end());
	vector<int> sum_left((N+1)/2), sum_right((N+1)/2);
	rep(i,(N-1)/2){
		sum_left[i+1] = sum_left[i] + (H[2*i+1] - H[2*i]);
		sum_right[i+1] = sum_right[i] + (H[2*i+2] - H[2*i+1]);
	}
	LL ans = INF;
	rep(i,M){
		int num = lower_bound(H.begin(),H.end(),W[i])-H.begin();
		LL right = sum_right[(N-1)/2] - sum_right[num/2];
		LL res = sum_left[num/2] + right;
		if(num % 2 == 0) res += H[num] - W[i];
		else res += W[i] - H[num-1];
		ans = min(ans, res);
	}
	cout << ans << endl;

	return 0;
}

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

#include<bits/stdc++.h>
#define itn int
#define ll long long
#define pir pair<ll,ll>
#define yes {puts("Yes");}
#define no {puts("No");}
using namespace std;

ll read(){
	ll a=0,b=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return a*b;
}

int n,m;
struct edge{
	int v,nx;
	ll c,d;
}e[200005];
int cnt,hd[100005];

ll dis[100005];
bool vis[100005];

struct node{
	int i;
	ll w;
};
bool operator<(node a,node b){
	return a.w>b.w;
}

ll clac(ll t,ll c,ll d){
	if(!d)return c;
	ll sq=sqrt(d+2),ans=c+d/(t+1);
	for(ll st=t;st<=t+3;st++){
		ans=min(ans,d/(st+1)+st-t+c);
	}
	if(t+1<sq){
		for(ll st=t;st<=t+30;st++){
			ans=min(ans,d/(st+1)+st-t+c);
		}
		for(ll st=max(t,sq-30);st<=sq+5;st++){
			ans=min(ans,d/(st+1)+st-t+c);
		}
	}
	return ans;
}

void dij(){
	memset(dis,0x3f,sizeof dis);
	dis[1]=0;
	priority_queue<node>q;
	q.push(node{1,0});
	while(!q.empty()){
		node t=q.top();q.pop();
		if(vis[t.i])continue;
		vis[t.i]=1;
		for(int i=hd[t.i];i;i=e[i].nx){
			int v=e[i].v;
			ll w=clac(dis[t.i],e[i].c,e[i].d);
			if(dis[v]>dis[t.i]+w){
				dis[v]=dis[t.i]+w;
				q.push(node{v,dis[v]});
			}
		}
	}
}

int main(){
	n=read(),m=read();
	while(m--){
		int a=read(),b=read(),c=read(),d=read();
		e[++cnt]=edge{b,hd[a],c,d},hd[a]=cnt;
		e[++cnt]=edge{a,hd[b],c,d},hd[b]=cnt;
	}
	dij();
	if(dis[n]>1e18)cout<<-1;
	else cout<<dis[n]<<'\n';
	return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
    int n, w; cin >> n >> w;
    cout << n/w << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}

/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#ifdef ill
#define int long long
#endif
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef AATIF_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
//#define int long long
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
const double eps=1e-9;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;
//struct point_i{int x,y;};
struct point_i{int x,y;
point_i(){ x=0; y=0;}
point_i(int x_,int y_){x=(x_);y=(y_) ;}
};

struct point
{
	float x,y;
	point (){x=y=0.0;}
	point (float x_,float y_){x=(x_); y=(y_);}
	bool operator < (point other) const{
	  if(fabs(x-other.x)>eps)return x<other.x;
	  return y<other.y;

		}
	bool operator == (point other) const {
		return fabs(other.x-x)<=eps&& fabs(other.y-y)<=eps;
		}

} ;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;

}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{

	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
signed main()
{
	IOS
	int n,m; cin>>n>>m;
	vi a(n),b(m);
	fr(i,0,n) cin>>a[i];
	fr(i,0,m) cin>>b[i];
	int dp[n+1][m+1];
	fr(i,0,n+1)fr(j,0,m+1)dp[i][j]=inf;
	dp[0][0]=0;
	fr(i,0,n+1)
	{
		fr(j,0,m+1)
		{
			if(dp[i][j]==inf) continue;
			if(mp(i,j)==mp(n,m))continue;
			if(i!=n)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
			if(j!=m)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
			if(i!=n&&j!=m)dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+2),
			dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(a[i]!=b[j]));
		}
	}
	cout<<dp[n][m]<<endl;

}


// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cmath>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;

    constexpr int mx = 200001;
    vector<vector<int>> g(mx);
    rep(i, n) {
        if (a[i] != a[n - 1 - i]) {
            g[a[i]].push_back(a[n - 1 - i]);
        }
    }

    int ans = 0;
    vector<int> checked(mx, 0);
    rep(i, mx) {
        if (g[i].empty()) continue;
        if (checked[i]) continue;
        queue<int> q;
        q.push(i);
        int sz = 0;
        checked[i] = 1;
        ++sz;
        while (!q.empty()) {
            int j = q.front();
            q.pop();
            for (int k : g[j]) {
                if (!checked[k]) {
                    checked[k] = 1;
                    ++sz;
                    q.push(k);
                }
            }
        }
        ans += sz - 1;
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
#define ll long long
#define pb push_back
using namespace std;

const int N = 200005;
int n;
int a[N], f[N];

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

int main() {
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < N; ++i) f[i] = i;
    for(int i = 0; i < n / 2; ++i) {
        int u = find(a[i]), v = find(a[n - 1 - i]);
        if (u != v) {
            f[u] = v;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

ll inf = -1e12;

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

	int n; string str;
	cin >> n >> str;

	if(str[0] != str[n-1]){
		cout << 1;
		return 0;
	}

	for(int i=1; i<=n-3; i++){
		if(str[i] != str[0] && str[i+1] != str[0]){
			cout << 2;
			return 0;
		}
	}
	cout << -1;

	return 0;
}

#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( int i = (t); i >= (s); -- i )
#define mp make_pair
#define pi pair<int, int>
#define pb push_back
#define vi vector<int>
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e5 + 5 ;
int n ;
char s[N] ;
signed main() {
	n = gi() ;
	cin >> s + 1 ;
	n = strlen(s + 1) ;
	if(s[1] != s[n]) {
		puts("1") ; exit(0) ;
	}
	for(int i = 2; i < n; ++ i) {
		if(s[i] != s[1] && s[i + 1] != s[1]) {
			puts("2") ; exit(0) ;
		}
	}
	puts("-1") ;
	return 0 ;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;++i)
#define fep(i,j,n) for(int i=j;i<n;++i)
#define ll long long
#define ay array
#define vtc vector
#define MN 200001

vtc<int> dag;
vtc<int> v[MN];
int val[MN];
int dp[MN];
bool done[MN];

void dfs(int i){
    if(done[i])return;
    done[i]=1;
    for(int j:v[i])
        dfs(j);
    dag.push_back(i);
}

int main(){
    int n,m;
    cin >>n>>m;
    rep(i,n)
        cin >>val[i];

    rep(i,m){
        int a,b;
        cin >>a>>b;
        a--;b--;
        v[a].push_back(b);
    }

    rep(i,n){
        dfs(i);
        dp[i]=INT_MAX;
    }

    reverse(dag.begin(),dag.end());
    int sol=INT_MIN;

    for(int c:dag){
        dp[c]=min(dp[c],val[c]);
        for(int t:v[c]){
            dp[t]=min(dp[t],dp[c]);
            sol=max(sol,val[t]-dp[t]);
        }
    }
    cout <<sol<<endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <climits>
#include <set>
#include <cstring>
#include <unordered_map>
#include <cstdlib>
#include <cmath>
#include <string>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <stdlib.h>
#include <chrono>

///////////////////////////////////////////////////////////////////////////////////////////////////
#define fio  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll  long long int
#define ull unsigned long long int
#define cinll(x) ll x;cin >> x;
#define cini(x) int x;cin >> x;
#define cins(x) string x;cin >> x;
#define vect(x) vector<ll> x
#define vect1(x) vector<ll> x;x.push_back(0);
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////////////////////////////////////////////////////////
#define MAX 1e17
#define MIN -9223372036854775800
#define MOD 1000000007
#define f first
#define s second
///////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
using u64 = uint64_t;
//Safe_hashing for minimising collisions
//https://codeforces.com/blog/entry/62393
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

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

bool compare(pair<string,ll> a,pair<string,ll> b) {
    return a.s > b.s;
}

void findAns(map<ll,char> & mapit,ll currPin,ll & ans,vector<ll> &pin) {
    if(currPin == 5) {
        bool ok = true;
        for(ll i = 0;i <= 9;i++) {
            if(mapit[i] == 'o') {
                bool search = false;
                for(ll j = 1;j <= 4;j++) {
                    if(pin[j] == i) search = true;
                }
                if(search == false) {
                    ok = search;
                    break;
                }
            }
        }
        if(ok) {
            ans++;
        }
        return;
    }
    for(ll i = 0;i <= 9;i++) {
        if(mapit[i] == 'o' || mapit[i] == '?') {
            pin[currPin] = i;
            findAns(mapit,currPin+1,ans,pin);
            pin[currPin] = 0;
        }
    }
}

void solve() {
    map<ll,char> mapit;
    for(ll i=0;i<10;i++) {
        char ch;
        cin>>ch;
        mapit[i] = ch;
    }
    ll ans = 0;
    vector<ll> pin(5,0);
    findAns(mapit,1,ans,pin);
    cout<<ans;
    return;
}

int main(){
    // fio;
    // cinll(t);
///////////////////////////////////////////
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r", stdin);
    freopen("output.txt", "w" , stdout);
    #endif
///////////////////////////////////////////
    // cinll(t);
    // for(ll i=1;i<=t;i++) {
        solve();
    // }
  return 0;
}


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

int main() {
  string N;
  cin >> N;
  string n;
  reverse_copy(N.begin(), N.end(), back_inserter(n));

  int count = 0;
  for (int i = 0; i < N.size(); i++) {
    if (N.at(i) == '0') {
      count++;
    }
  }
  int f = 0;
  for(int i = 0; i < count + 1; i++){
    if(N == n){
      f = 1;
      break;
    }
    N = "0" + N;
    n = n + "0";
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define index(i, n) for(ll i = 0; i < n; i++)
#define loop(i, a, b) for(ll i = a;i<b;i++)
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool is_pelin(int n) {
    vector<int>arr;
    while(n){
        arr.push_back(n%10);
        n /= 10;
    }
    n = arr.size();
    for(int i = 0;i<n/2;i++){
        if(arr[i] != arr[n - 1 - i])return false;
    }
    return true;
}
int count_zero(int n){
    int temp = 0;
    int cnt = 0;
    while(n){
        temp = n&10;
        if(temp != 0)break;
        n/=10;
        cnt++;

    }
    return cnt;
}
bool is_rem(int n){
    vector<int>arr;
    while(n){
        arr.push_back(n%10);
        n /= 10;
    }
    int check = 0;
    index(i, arr.size()) {
        if(arr[i] != 0){
            check = i;
            break;
        }
    }
    int ans = 0;
    int j = 0;
    loop(i, check, arr.size()){
        ans += binpow(10, j) * arr[i];
        j++;
    }
    if(is_pelin(ans))return true;
    return false;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    # endif
    int n;
    cin >> n;
    if(is_pelin(n)){
        cout << "Yes";
    }
    else{
        if(is_rem(n)){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll t;cin>>t;
    rep(tt,t){
        ll n;cin>>n;
        vi v(n);
        rep(i,n)cin>>v[i];
        if(n%2)out("Second");
        else{
            sort(all(v));
            ll a=0,b=0;
            rep(i,n){
                if(i%2)a+=v[i];
                else b+=v[i];
            }
            if(a==b)out("Second");
            else out("First");
        }
    }
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    vector<int> es;

    UnionFind(int n = 1) { init(n); }

    void init(int n = 1) {
        par.resize(n);
        sz.resize(n);
        es.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            sz[i] = 1;
        }
    }

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

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        es[x]++;
        if (x == y) return;
        if (sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        es[y] += es[x];
        return;
    }

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

    int esize(int x) { return es[root(x)]; }
};

const int MAXA = 200005;
int main() {
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    UnionFind uf(MAXA);
    for (int l = 0, r = N - 1; l < r; l++, r--) {
        if (A.at(l) == A.at(r)) continue;
        uf.unite(A.at(l), A.at(r));
    }
    long long ans = 0;
    for (int i = 0; i < MAXA; i++) {
        if (i != uf.root(i)) continue;
        const int sz = uf.size(i);
        ans += sz - 1;
    }
    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 200005
#define ll long long
#define mod 998244353
int n, k;
int A[N], S[305];
int C[305][305];
int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0; i <= k; i++)
	{
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	}
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &A[i]);
		int now = 1;
		for (int x = 0; x <= k; x++)
		{
			S[x] = (S[x] + now) % mod;
			now = (ll)now * A[i] % mod;
		}
	}
	int now = 1;
	for (int i = 1; i <= k; i++)
	{
		now = (now << 1) % mod;
		int ans = 0;
		for (int j = 0; j <= i; j++)
			ans = (ans + (ll)C[i][j] * S[j] % mod * S[i - j]) % mod;
		//printf("%d\n", ans);
		ans = (ans - (ll)now * S[i] % mod + mod) % mod;
		ans = ans * 499122177ll % mod;
		if (ans < 0)
			ans += mod;
		printf("%d\n", ans);
	}
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, X; cin >> N >> X;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];

  map<ll, ll> mp;
  auto func = [&](auto rF, ll x, ll i) -> ll {
    while (i < N && x % A[i] == 0) i++;
    if (i == N) return 1;
    ll& ret = mp[x];
    if (ret == 0) {
      ll y = x % A[i];
      ret = rF(rF, x - y, i + 1) + rF(rF, x + (A[i] - y), i + 1);
    }
    return ret;
  };
  cout << func(func, X, 1) << endl;

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define mod 1000000007

// templates
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x, y) fixed << setprecision(y) << x
#define ss(s) scanf(" %[^\n]%*c", s)
#define sc(n) scanf("%d", &n)
#define sl(n) scanf("%lld", &n)
#define ps(s) printf("%s\n", s)
#define pr(n) printf("%d\n", n)
#define pl(n) printf("%lld\n", n)
#define prs(n) printf("%d ", n)
#define pls(n) printf("%lld ", n)
using namespace std;

const ll inf = (ll)1e15 + 10;
const int N = (int)1e6 + 10;

void solve() {
  int n;
  cin >> n;
  vector<pair<int, string>> a;
  for (int i = 0; i < n; i++) {
    int d;
    string s;
    cin >> s >> d;
    a.push_back({d, s});
  }
  sort(all(a));
  cout << a[n - 2].S << endl;
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("input.txt", "r", stdin);
  // 	freopen("output.txt", "w", stdout);
  // #endif
  int t = 1;
  // sc(t);
  while (t--) {
    solve();
  }
  //	cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
  return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,L,R;
signed main(){
	cin>>T;
	while(T--){
		cin>>L>>R;
		if(R>=2*L)printf("%lld\n",(R-2*L+2)*(R-2*L+1)/2);
		else printf("0\n");
	}
	return 0;
}
/*

*/


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

long long mod=1e9+7;
struct mint{
    long long x;
    mint(long long 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(long long t)const{
        if(!t)return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1)a*=*this;
        return a;
    }
    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;}

int main() {
    ll n,m;
    cin>>n>>m;
    mod=m*m;
    cout<<(mint(10).pow(n).x/m+m)%m<<endl;
}

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

const long long MOD = 5;
long long ksm(long long a,long long n,long long mod)
{
    if(n==1)return a%mod;
    if(n==0)return 1;
    long long ans=ksm(a,n>>1,mod);
    ans=ans*ans%mod;
    if(n&1)ans=ans*a%mod;
    return ans;
}
void solve(long long N, long long M){
    printf("%lld\n",ksm(10,N,M*M)/M);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}

template <typename T>
class Seg_Tree{
public: // 0-index
	vector<T> dat;
	T initial,M;
	int n;
	T unite(T a,T b){//
		return max(a,b);
	}
	Seg_Tree(int n0_=1,T initial_=1,T M_=1){
		initsize(n0_,initial_,M_);
	}
	void initsize(int n0,T initial_,T M_){
		M = M_;
		initial = initial_;
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initial;
				break;
			}
			k*=2;
		}
	}

	//i banme wo x nisuru
	void update(int i,T x){
		i += n-1;
		dat[i] = x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = unite(dat[i*2+1],dat[i*2+2]);
		}
	}

	//[a,b)
	T query0(int a,int b,int k,int l,int r){
		if(r<=a || b<=l)return initial;
		if(a<=l && r<=b)return dat[k];
		else{
			T vl = query0(a,b,k*2+1,l,(l+r)/2);
			T vr = query0(a,b,k*2+2,(l+r)/2,r);
			return unite(vl,vr);
		}
	}

	//return [a,b)
	T query(int a,int b){
		return query0(a,b,0,0,n);
	}
};

int main() {

	ll ans = 0 , N;
	cin >> N;
	vector<ll> A(N),B(N);
	FOR(i,0,N){
		cin >> A[i];
	}
	B[0] = A[0];
	FOR(i,1,N) {
		B[i] = B[i-1] + A[i];
	}

	Seg_Tree<ll> sg(N,0,MOD);
	FOR(i,0,N){
		sg.update(i,B[i]);
	}

	ll x = 0;
	FOR(i,0,N){
		ans = max(ans,x+sg.query(0,i+1));
		x += B[i];
	}
	cout << ans << endl;

}

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

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

  vector<long> vec(N);
  long max_distance = 0,now=0;
  long diff = 0,max_idx = 0;

  for(int i = 0;i<N;i++){
    cin >> vec.at(i);
    diff += vec.at(i);
    now += diff;
    if(now >= max_distance){
      max_distance = now;
      max_idx = i;
    }
  }

  long true_max = max_distance;

  if(max_idx != N-1){
    for(int i = 0;i<max_idx+1;i++){
      max_distance += vec.at(i);
      true_max = max(true_max,max_distance);
    }
  }
  else{
    max_distance -= diff;
    for(int i = 0;i<max_idx;i++){
      max_distance += vec.at(i);
      true_max = max(true_max,max_distance);
    }
  }
  cout << true_max << endl;;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <iomanip>
#include <random>
#include <climits>
#include <set>
#include <map>

using namespace std;

/*

*/

int main() {

	int n;
	cin >> n;

	int i = 1;
	int sum = 0;

	while (1) {

		sum += i;

		if (sum >= n) {
			cout << i << endl;
			break;
		}

		i++;

	}

	return 0;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vii;
ll n;
int main()
{
	cin>>n;
	n*=2LL;
	int ans=0;
	for(ll i=1LL;i*i<=n;i++)
	{
		if(n%i==0LL)
		{
			ll j=n/i;
			if((i%2LL)==(j%2LL)) continue;
			ans+=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator,class Pair=typename iterator_traits<RandomAccessIterator>::value_type>inline void sort_pairs_by_second(RandomAccessIterator first,RandomAccessIterator last){sort(first,last,[](const Pair&p1,const Pair&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    ll n=in();
    map<ll,ll>cnt;
    for(ll i=0;i<n;++i){
        ++cnt[in()];
    }
    while(cnt.size()!=1){
        cnt[cnt.rbegin()->first-cnt.begin()->first]+=cnt.rbegin()->second;
        //cnt.erase(cnt.rbegin());
        cnt.erase(prev(cnt.end()));
    }
    cout<<cnt.begin()->first<<endl;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)

#define DENOM 1000000007

using namespace std;
using ll = long long;

int main(){
  string s ;
  cin >> s ;
  size_t n = s.size() ;
  size_t j ;
  for (j=0;j<n;++j) {
    if (s[j] == '.')
      break ;
  }
  cout << s.substr(0, j) << endl ;
  return 0 ;
}


#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
#include<string>
#include<deque>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll mod = 1000000007;
ll mod2 = 998244353;

ll a[300005];

int main() {
	ll n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		mp[a[i]]--;
		ll cnt = n;
		cnt -= (i + 1);
		ans += (cnt - mp[a[i]]);
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
#define int long long
#define pb push_back

#define vi vector<int>

#define all(a) a.begin(), a.end()
using namespace std;

void solve()
{
    int n; cin>>n;
    vi a(n);
    int ans=(n*(n-1))/2;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(all(a));
    int cnt=1,val;
    for(int i=1;i<n;i++){
        if(a[i]==a[i-1]){
            cnt++;
        }
        else{
            val=(cnt*(cnt-1))/2;
            ans=ans-val;
            cnt=1;
        }
    }
    if(cnt){
        val=(cnt*(cnt-1))/2;
        ans=ans-val;
    }
    cout<<ans;
}

int32_t main()
{

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


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  string S; cin>>S;
  int ans=0;
  for(int i=0;i+3<S.size();i++)ans+=S.substr(i,4)=="ZONe";
  cout<<ans<<endl;
}

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

#define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--)
#define all(v) v.begin(), v.end()

typedef long long ll;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;

/* 提出時これをコメントアウトする */
#define LOCAL true

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    constexpr char endl = '\n';

    string s;
    cin >> s;
    int ans = 0;
    rep(i,0,s.size() - 3) {
        if (s.substr(i,4) == "ZONe") ans++;
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
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;
}
int main()
{
    int a,b,c;
    cin >> a >> b >>c;
    if(c== 0){
        cout << "=" << endl;
        return 0;
    }

    int R,L;
    if(c %2 == 0){
        L = a;
        R = b;
        if(L<0)L = -L;
        if(R<0)R = -R;
    }
    else{
        L = a;
        R = b;
    }

    if(L > R){
        cout << ">" << endl;
        return 0;
    }
    if(L ==R){
        cout << "=" << endl;
        return 0;
    }
    if(L < R){
        cout << "<" << endl;
        return 0;
    }

    return 0;
}

//        ** Sumonta Saha Mridul **                                    SWE - SUST
/*

 *        ######    ##     ##  ##     ##   #######   ##    ##   ########      ###
 !       ##    ##   ##     ##  ###   ###  ##     ##  ###   ##      ##        ## ##
 ?       ##         ##     ##  #### ####  ##     ##  ####  ##      ##       ##   ##
 *        ######    ##     ##  ## ### ##  ##     ##  ## ## ##      ##      ##     ##
 !             ##   ##     ##  ##     ##  ##     ##  ##  ####      ##      #########
 ?       ##    ##   ##     ##  ##     ##  ##     ##  ##   ###      ##      ##     ##
 *        ######     #######   ##     ##   #######   ##    ##      ##      ##     ##

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<long, long>
#define mp(a, b) make_pair(a, b)
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define Mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define f first
#define se second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define endl '\n'
#define Y cout << "YES\n"
#define No cout << "NO\n"

#define F(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rem(i, a, b) for (int i = a; i > b; i--)
#define P(str) cout << str << endl

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

#define mod 1000000007
#define INF numeric_limits<ll>::max();
#define NINF numeric_limits<ll>::min();
const int N = int(1e5 + 3);

ll power(ll base, ll powr)
{
    ll res = 1;
    while (powr)
    {
        if (powr % 2 == 0)
            base *= base, powr /= 2;
        else
            res *= base, powr--;
    }
    return res;
}

int main()
{
    fast;

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

    if (c % 2 == 0)
        a = abs(a), b = abs(b);

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


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

// Macros
//#define int long long int
#define lli long long int
#define ulli unsigned long long int
#define mods 1000000007
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forLoop(i, a, b) for(int i=a; i<b; i++)
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define mem0(a) memset(a,0,sizeof(a))

// Pre defined Variables as a constant
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;

// Functions
int www(int x, int y) {
    if (x == 0) return 0;
    return ((x % y == 0) ? x / y : x / y + 1);
}

void for_cop() {
    lli s;
    cin >> s;
    lli tmp = 1;
    lli ans = 0;
    while (1) {
        lli tmp2 = stoll(to_string(tmp) + to_string(tmp));
        tmp++;
        if (tmp2 > s)  break;
        ans++;
    }
    cout << ans << endl;
}

// Main Code
int32_t main()
{
    fio;
    int t = 1;
    //cin >> t;
    while (t--) for_cop();
    return 0;
}
// Ends Here

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

const int N = 105;

int n;
char s[N][N];

vector<int> edges[N];

int cnt[N];
void bfs(int u) {
  queue<int> q;
  vector<bool> vis(n);
  q.push(u);
  vis[u] = true;

  while (q.size()) {
    int u = q.front();
    q.pop();

    for (int v: edges[u]) {
      if (vis[v]) continue;
      vis[v] = true;
      q.push(v);
    }
  }

  for (int u = 0; u < n; ++u) {
    if (vis[u]) ++cnt[u];
  }
}

int solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
    for (int j = 0; j < n; ++j) {
      if (s[i][j] == '1') edges[i].push_back(j);
    }
  }

  for (int i = 0; i < n; ++i) bfs(i);

  double ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += 1.0 / cnt[i];
  }

  printf("%.15lf\n", ans);
  return 0;
}

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


#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
int dp[101][100001]={};
signed main(){
	int n,t[100];
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>t[i];
		sum+=t[i];
	}
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=sum;j++){
			dp[i+1][j]=dp[i][j];
			if(j>=t[i])
				dp[i+1][j]|=dp[i][j-t[i]];
		}
	}
	int ans=sum;
	for(int i=0;i<=sum;i++)
		if(dp[n][i])
			ans=min(ans,max(i,sum-i));
	cout<<ans<<endl;
}

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

#include <bits/stdc++.h>

using namespace std;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; }
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

//#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

const int INF = (1<<30)-1;
const long long LINF = 1LL<<60;
const double EPS = 1e-9;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int dx[8] = {-1,0,1,0,1,-1,1,-1};
const int dy[8] = {0,1,0,-1,1,-1,-1,1};

//-------------------------- Libraries --------------------------//

//--------------------------- Solver ----------------------------//

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    set<int> se;
    se.insert(a[0]);
    se.insert(-a[0]);
    for (int i = 1; i < N; i++) {
        set<int> tmp;
        for (auto &&e : se) {
            tmp.insert(e+a[i]);
            tmp.insert(e-a[i]);
        }
        se = tmp;
    }

    int d = INF;
    for (auto &&e : se) chmin(d, abs(e));

    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += a[i];
    }

    int ans = (sum+d)/2;

    cout << ans << '\n';
}

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

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

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55e4;
int n,K,mo,i,j,ff[N*2],*f=ff+N,S;
inline void red(int&x){x+=x>>31&mo;}
inline void ins(int x){
	if(x>0)for(j=-S;j<=S;++j)red(f[j]+=f[j-x]-mo);
		else for(j=S;j>=-S;--j)red(f[j]+=f[j-x]-mo);
	if(x>0)for(j=S;j>=-S;--j)red(f[j]-=f[j-x*(K+1)]);
		else for(j=-S;j<=S;++j)red(f[j]-=f[j-x*(K+1)]);
}
inline void del(int x){
	for(j=S;j>=-S;--j)red(f[j]-=f[j-x]);
	for(j=-S;j<=S;++j)red(f[j]+=f[j-x*(K+1)]-mo);
}
int main(){
	scanf("%d%d%d",&n,&K,&mo);
	for(i=1;i<=n;++i)S+=i*K;*f=1;
	for(i=2;i<=n;++i)ins(i-1);
	for(i=1;i<=n;++i){
		if(i>1)ins(1-i);
		j=(1ll**f*(K+1)+mo-1)%mo;printf("%d\n",j);
		if(i<n)del(n-i);
	}
}


#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fd(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 5e3 + 5;
int n, m, k;
ll a[maxn][maxn], dp[maxn][maxn];
ll power(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b & 1)ans = (ans * a) % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
int main() {
	IOS;
	cin >> n >> m >> k;
	fo(i, 1, k) {
		int x, y; char z;
		cin >> x >> y >> z;
		a[x][y] = z;
	}
	dp[1][1] = 1;
	fo(i, 1, n* m - k)dp[1][1] = 3ll * dp[1][1] % mod;
	ll inv3 = power(3, mod - 2);
	fo(i, 1, n)fo(j, 1, m) {
		dp[i][j] %= mod;
		if (a[i][j] == 'X') {
			dp[i + 1][j] += dp[i][j];
			dp[i][j + 1] += dp[i][j];
		}
		else if (a[i][j] == 'R') {
			dp[i][j + 1] += dp[i][j];
		}
		else if (a[i][j] == 'D') {
			dp[i + 1][j] += dp[i][j];
		}
		else {
			dp[i + 1][j] += 2ll * inv3 * dp[i][j];
			dp[i][j + 1] += 2ll * inv3 * dp[i][j];
		}
	}
	cout << dp[n][m] << endl;

	return 0;
}
/*

*/

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 2e5 + 50;
int n,x1[maxn],x2[maxn];
long long f[2][2];
struct node{
	int x,c;
	bool operator < (node p){
		return c < p.c;
	}
}a[maxn];
int read(){
	int x = 0,f = 1;
	char c = getchar();
	while(c < '0' || c > '9'){
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar();
	return x * f;
}
inline long long dis(int x,int a,int b){
	return 0ll + abs(x - a) + abs(a - b);
}
int main(){
	n = read();
	for(int i = 1; i <= n; i ++) a[i].x = read(),a[i].c = read();
	sort(a + 1,a + n + 1);
	int cnt = 0,p = 1;
	while(p <= n){
		cnt ++,x1[cnt] = x2[cnt] = a[p].x;
		while(p < n && a[p].c == a[p + 1].c) p ++,x1[cnt] = min(x1[cnt],a[p].x),x2[cnt] = max(x2[cnt],a[p].x);
		p ++;
	}
	cnt ++,x1[cnt] = x2[cnt] = 0;
	// for(int i = 1; i <= cnt; i ++) cout << i << ' ' << x1[i] << ' ' << x2[i] << endl;
	int cur = 0;
	for(int i = 1; i <= cnt; i ++){
		cur ^= 1;
		f[cur][0] = min(f[cur ^ 1][0] + dis(x1[i - 1],x2[i],x1[i]),f[cur ^ 1][1] + dis(x2[i - 1],x2[i],x1[i]));
		f[cur][1] = min(f[cur ^ 1][0] + dis(x1[i - 1],x1[i],x2[i]),f[cur ^ 1][1] + dis(x2[i - 1],x1[i],x2[i]));
		// cout << i << ' ' << f[cur][0] << ' ' << f[cur][1] << endl;
	}
	printf("%lld\n",min(f[cur][0],f[cur][1]));
	return 0;
}


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

int main()
{
    char X[110][110]={};
    int ans =0,H,W;

    cin>>H>>W;

    for(int i=0;i<H;i++){
        string S;
        cin>>S;
        for(int j=0;j<W;j++){
            X[i][j]=S[j];
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(X[i][j]=='#')continue;

            if(X[i+1][j]=='.')ans++;
            if(X[i][j+1]=='.')ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

int main(){
    int n=in;
    if (n%100==0) outl(n/100);
    else outl(n/100+1);
}

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

void solve() {
    int n;
    cin>>n;
    cout<<(n+99)/100<<endl;
    return;
}

int main() {
#ifdef bipinpathak
    (void)!freopen("input.txt", "r", stdin);
    (void)!freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    auto start=clock();
    int t = 1;
    for(int i=0; i<t; i++) {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    double used= (double) (clock()-start);
    used=(used*1000)/CLOCKS_PER_SEC;
    cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl;
    return 0;
}


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

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

const int mod = 1e9 + 7;
int dp[3][100][100];
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M, K;
	cin >> N >> M >> K;
	int A[100];
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N) dp[0][i][i] = 1;
	rep(i, N) dp[1][i][i] = 1;
	int are = modpow(2 * M, mod - 2);

	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		(dp[0][x][x] += mod - are) %= mod;
		(dp[0][x][y] += are) %= mod;
		(dp[0][y][x] += are) %= mod;
		(dp[0][y][y] += mod - are) %= mod;
	}

	auto mae = dp[1], ato = dp[2];
	rep(i, 30) {
		rep(x, N) rep(y, N) {
			unsigned long long tmp = 0;
			rep(z, N) {
				tmp += mae[x][z] * (ll)mae[z][y];
				if (!(z & 15)) tmp %= mod;
			}
			ato[x][y] = tmp % mod;
		}
		swap(mae, ato);

		if (K >> 29 - i & 1) {
			rep(x, N) rep(y, N) {
				unsigned long long tmp = 0;
				rep(z, N) {
					tmp += mae[x][z] * (ll)dp[0][z][y];
					if (!(z & 15)) tmp %= mod;
				}
				ato[x][y] = tmp % mod;
			}
			swap(mae, ato);
		}
	}

	rep(i, N) {
		ll kotae = 0;
		rep(j, N) kotae += (ll)mae[i][j] * A[j] % mod;
		co(kotae % mod);
	}

	Would you please return 0;
}

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

typedef vector<vector<ll>> mat;

mat mul(mat &A, mat&B){
    mat C(A.size(),vector<ll>(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int k=0;k<B.size();k++){
            for(int j=0;j<B[0].size();j++){
                C[i][j]=(C[i][j]+A[i][k]*B[k][j])%mod;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(),vector<ll>(A.size()));
    for(int i=0;i<A.size();i++){
        B[i][i]=1;
    }

    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n/=2;
    }
    return B;
}

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

int main(){

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

    int N,M,K;cin>>N>>M>>K;

    mat B(N,vector<ll>(1));
    for(int i=0;i<N;i++){
        cin>>B[i][0];
    }

    mat A(N,vector<ll>(N));
    for(int i=0;i<N;i++) A[i][i]=1;

    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        if(a==b) continue;

        A[a][a]-=rui(M*2,mod-2);
        A[b][b]-=rui(M*2,mod-2);

        A[a][b]+=rui(M*2,mod-2);
        A[b][a]+=rui(M*2,mod-2);

        if(A[a][a]<0) A[a][a]+=mod;
        if(A[b][b]<0) A[b][b]+=mod;

        A[a][b]%=mod;
        A[b][a]%=mod;
    }

    A=pow(A,K);
    A=mul(A,B);

    for(int i=0;i<N;i++) cout<<A[i][0]<<endl;
}


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

 typedef vector<int> vi;
 typedef vector<ll> vl;
 typedef vector<vi> vvi;
 typedef set<int> si;
 typedef set<ll> sl;
 typedef queue<int> qi;
 typedef queue<ll> ql;
 typedef stack<int> sti;
 typedef deque<int> dqi;
 typedef priority_queue<int> pqi;
 typedef priority_queue<ll> pql;
 typedef deque<ll> dql;
 typedef vector<vl> vvl;
 typedef pair<int,int> pii;
 typedef pair<double, double> pdd;
 typedef pair<ll, ll> pll;
 typedef vector<pii> vii;
 typedef vector<pll> vll;
 typedef double dl;

 #define PB push_back

 #define F first
 #define S second
 #define MP make_pair
 #define el  '\n'
 #define sl(x) (int)x.length()
 #define all(a) (a).begin(),(a).end()
 #define sz(x) (int)x.size()
 #define mid(l,r) ((r+l)/2)
 #define left(node) (node*2)
 #define right(node) (node*2+1)
 #define mx_int_prime 999999937
#define loop(i,n)        for(int i=0;i<n;i++)

 const double PI = acos(-1);
 const double eps = 1e-9;
 const int inf = 2000000000;
 const ll infLL = 9000000000000000000;
 #define MOD 1000000007
 #define in(n)  ll n;cin>>n;
 #define mem(a,b) memset(a, b, sizeof(a) )
 #define gcd(a,b) __gcd(a,b)
 #define sqr(a) ((a) * (a))
 #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 #define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield);
 typedef vector<int>::iterator vit;
 typedef set<int>::iterator sit;
 int dx[] = {0, 0, +1, -1};
 int dy[] = {+1, -1, 0, 0};

 void solve(){

    }
  int main(){
    in(n);
    int ans=MOD;
    bool pk=0;
    while(n--){
        in(a);
        in(b);
        in(c);
        int ok=0;
        if(a<c){
          pk=1;
          ok=b;
        ans=min(ok,ans);
        }
    }
    if(pk==0)cout<<"-1"<<el;
    else
    cout<<ans<<el;

    }

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long llp;
#define mod 1000000007
#define deb(x) cerr << '\t' << "[" << #x << ": "<< x << "]\n";
#define f first
#define s second
#define pb push_back
/*
numeric_limits<llp>::max();
*/
void solution(/*ll tc = 0*/);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    llp tc = 1;
    //cin >> tc;
    for (llp t = 0; t < tc; ++t) solution(/*t*/);
    return 0;
}

struct ps{
	ll a, p, x;
};
bool fx(struct ps a, struct ps b) {
	return (a.p < b.p);
}
void solution(/*ll tc = 0*/) {
	int n;
	cin >> n;
	vector<ps> arr(n);
	for(int i = 0; i < n; ++i) {
		cin >> arr[i].a >> arr[i].p >> arr[i].x;
	}
	sort(arr.begin(), arr.end(), fx);
	//ll ans = (ll)1e9;
	bool canwe = 0;
	for(int i = 0; i < n; ++i) {
		if(arr[i].x > arr[i].a) {
			cout << arr[i].p << '\n';
			canwe = 1;
			break;
			//ans = min(ans, arr[i].p);
		}
	}
	if(!canwe) cout << "-1\n";
//	cout << ans << '\n';
}


// Problem : D - Multiset Mean
// Contest : AtCoder - AtCoder Regular Contest 104
// URL : https://atcoder.jp/contests/arc104/tasks/arc104_d
// Memory Limit : 1024 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, K;
long long MOD;
const long long CUTOFF = 501000;

void add(long long &a, long long b){
	a += b;
	a -= (a >= MOD ? MOD : 0);
}

void sub(long long &a, long long b){
	a -= b;
	a += (a < 0 ? MOD : 0);
}

long long dp[2001005];
long long tmp[2001005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> K >> MOD;
	dp[CUTOFF] = K+1;
	for(int n = 1; n<N; n++){
		for(int r = 0; r<n; r++){
			long long tot = 0;
			for(int i = r+CUTOFF; i<=2*CUTOFF; i += n){
				if(i - n * (K+1) >= 0){
					sub(tot, tmp[i - n * (K+1)]);
				}
				tmp[i] = dp[i];
				add(tot, dp[i]);
				dp[i] = tot;
			}
		}
	}
	for(int n = 1; n<=N; n++){
		cout << (dp[CUTOFF] + MOD - 1)%MOD << "\n";
		/*
		for(int i = 0; i<=2*CUTOFF; i++){
			cout << "idx: " << (i-CUTOFF) << " " << dp[i] << "\n";
		}
		cout << "\n";
		*/
		for(int r = 0; r<N-n; r++){
			long long tot = 0;
			for(int i = r; i <= 2*CUTOFF; i += N - n){
				if(i - (N - n) * (K+1) >= 0){
					sub(tot, dp[i-(N-n)*(K+1)]);
				}
				sub(dp[i], tot);
				add(tot, dp[i]);
			}
		}
		/*
		for(int i = 0; i<=2*CUTOFF; i++){
			cout << "idx: " << (i-CUTOFF) << " " << dp[i] << "\n";
		}
		cout << "\n";
		*/
		for(int r = 0; r<n; r++){
			long long tot = 0;
			for(int i = 2*CUTOFF/n*n+r; i>=0; i -= n){
				if(i + n * (K+1) <= 2 * CUTOFF){
					sub(tot, tmp[i + n * (K+1)]);
				}
				tmp[i] = dp[i];
				add(tot, dp[i]);
				dp[i] = tot;
			}
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-30
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rrep(i,r,l) for(int i=r-1;i>=l;i--)
#define vi vector<int>
#define vvi vector<vector<int> >
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
typedef long long ll;
const int maxn=2e5+5;
char s[maxn];
int n,k,a[maxn];
ll d[maxn][17][2][2];
ll dfs(int cur,int st,int cnt,int up,int lead)
{
	if(cnt>k) return 0;
	if(cur>n) return cnt==k&&!lead;
	ll& ret=d[cur][cnt][up][lead];
	if(ret>=0) return ret;
	ret=0;
	int r=up?a[cur]:15;
	rep(i,0,r+1){
		ret=(ret+dfs(cur+1,(!i&&lead)?0:st|(1<<i),(!i&&lead)?cnt:cnt+!(1&(st>>i)),up&&(i==r),lead&&(!i)))%mod;
	}
	return ret;
}
int main()
{
	scanf("%s %d",s+1,&k);
	n=strlen(s+1);
	rep(i,1,n+1){
		if(s[i]>='A') a[i]=s[i]-'A'+10;
		else a[i]=s[i]-'0';
	}
	memset(d,-1,sizeof(d));
	printf("%lld\n",dfs(1,0,0,1,1));
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ln "\n"
using namespace std;
//#define dbg(x) cout<<#x<<" = "<<x<<" "
#define rep(i,s,n) for(ll i = (s);i<(n);++i)
#define pc(x) __builtin_popcount(x)
void DBG() {
	cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    //cerr << '[' << endl;
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) cerr << "[ ]" << endl
#endif

#define pi  pair<int,int>
//const int mod=998244353;

void solve(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(n==1)
    {
        cout<<1<<ln;
        return;
    }
    ll ans=-1;
    if(s[0]!=s[n-1]) cout<<1<<ln;
    else
    {
        char s1=s[0];
        for(int i=1;i<n;i++)
        {
            if(s[i]!=s1 && s[i+1]!=s1)
            {
                ans=2;
                break;
            }
        }
        cout<<ans<<ln;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //sieve();
    int test=1;
   // cin>>test;
    while(test--)
        solve();
    return 0;
}

#include<bits/stdc++.h>
#define mxn 100005
#define inf 1e9
using namespace std;
int n, mem[mxn][26];
char str[mxn];
int dp(int pos, int ch)
{
    if(pos==n)return inf;
    if(pos==n-1 && (str[n-1]-'a')!=ch)return 1;
    int &ret= mem[pos][ch];
    if(ret!=-1)return ret;

    ret= dp(pos+1, ch);
    if((str[pos]-'a')!=ch)ret= min(ret, 1+dp(pos+2, str[pos+1]-'a'));
    return ret;
}
int main()
{
    scanf("%d %s", &n, str);
    memset(mem, -1, sizeof mem);
    int res= dp(1, str[0]-'a');
    if(res==inf)res= -1;
    printf("%d\n", res);

    return 0;
}


/*
Author: Zcus
Blog: https://cnblogs.com/zcus
*/

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

#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define debug(x) cout << #x << " = " << x << endl
#define For(i, x, y) for (int i = x; i <= y; i++)
#define Rep(i, x, y) for (int i = x; i >= y; i--)
#define file(FILE_NAME) freopen(FILE_NAME".in", "r", stdin), freopen(FILE_NAME".out", "w", stdout)
#define filein(FILE_NAME) freopen(FILE_NAME".in", "r", stdin);
#define fileout(FILE_NAME) freopen(FILE_NAME".out", "w", stdout);

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define I int
inline I ri() {
	I s = 0, w = 1;
	char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') w = -1; c = getchar();}
	while (c >= '0' && c <= '9') { s = (s << 1) + (s << 3) + (c ^ 48); c = getchar();}
	return s * w;
}
#undef I

#define int long long

const int maxn = 2e5 + 540;

char s[maxn];
int n;

int lascor, las = 0;

int Sum[maxn][28];
signed main() {
	//file("3");
	scanf("%s", s + 1); n = strlen(s + 1);

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 26; j++) Sum[i][j] = Sum[i - 1][j];
		Sum[i][s[i] - 'a' + 1]++;
	}
	las = n + 1;
	for (int i = n - 2; i >= 1; i--) {
		if (s[i] == s[i + 1]) {
			if (lascor != s[i]) {
				ans = ans + n - (i + 1);
				if (las && las - 1 >= i + 1) ans = ans - (Sum[las - 1][s[i] - 'a' + 1] - Sum[i + 1][s[i] - 'a' + 1]);
			}
			else if (las - 1 >= i + 1) ans = ans + max(0ll, (las - 1 - (i + 2) + 1) - (Sum[las - 1][s[i] - 'a' + 1] - Sum[i + 1][s[i] - 'a' + 1]));
			lascor = s[i]; las = i;
		}
	}

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

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sd(x) scanf("%lld",&x)
#define sdi(x) scanf("%d",&x)
#define sdc(c) scanf("%c",&c)
#define inf 1000000000000000000ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bits(x) __builtin_popcountll(x)
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second
#define all(x) x.begin(),x.end()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

clock_t time_p = clock();
void time_taken()
{
    time_p = clock() - time_p;
    cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod)%mod;
        n>>=1;
    }

    return res;
}

const int MOD = 1e9+7;

inline ll add(ll x, ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = (x+y)%MOD;
    return ans;
}

inline ll mul(ll x,ll y, ll MOD) {
    x %= MOD;
    y %= MOD;
    ll ans = ((x*y)%MOD+MOD)%MOD;
    return ans;
}

int main() {
    fastio;
    string s;
    cin>>s;

    int n = s.length();
    vector<int> v(n);

    for(int i=0;i<n;i++) {
        v[i] = s[i]-'a';
    }

    vector<int> cnt(27,0);
    ll res = 0;
    cnt[v.back()]++;
    for(int i=n-2;i>=0;i--) {
        if(v[i]==v[i+1]) {
            for(int j=0;j<26;j++) {
                if(v[i]!=j) {
                    res += cnt[j];
                    cnt[v[i]] += cnt[j];
                    cnt[j] = 0;
                }
            }
        }
        cnt[v[i]]++;
    }

    cout<<res<<endl;

    time_taken();
}


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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> T(h + w - 1, vector<int>(3));
  rep(i,h){
    rep(j,w){
      char c;
      cin >> c;
      if(c == 'R') T[i + j][0] = 1;
      if(c == 'B') T[i + j][1] = 1;
      if(c == '.') T[i + j][2] = 1;
    }
  }

  long long ans = 1;
  rep(i, h + w - 1){
    if(T[i][0] == 1 && T[i][1] == 1) ans *= 0;
    else if(T[i][0] == 1 || T[i][1] == 1) ans *= 1;
    else ans = ans * 2 % mod;
  }

  cout << ans;

}

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

typedef long long ll;

int N, MAX_N = 2000001, idx = 0, MAX_LOG_V = 20;
vector<vector<int>> edge(MAX_N), parent(MAX_LOG_V, vector<int>(MAX_N, -1));
vector<int> tp(MAX_N), l(MAX_N), r(MAX_N), par(MAX_N, -1), depth(MAX_N, 0);
vector<bool> done(MAX_N, false);

void tps(int u) {
    done[u] = true;
    l[u] = idx;
    tp[idx] = u;
    idx++;
    rep(i, edge[u].size()) {
        int v = edge[u][i];
        if (done[v]) continue;
        par[v] = u;
        depth[v] = depth[u] + 1;
        tps(v);
    }
    r[u] = idx;
}

int lca(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    rep(i, MAX_LOG_V) {
        if ((depth[v] - depth[u]) >> i & 1) {
            v = parent[i][v];
        }
    }
    if (u == v) return u;
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
        if (parent[k][u] != parent[k][v]) {
            u = parent[k][u];
            v = parent[k][v];
        }
    }
    return parent[0][u];
}

void lca_init() {
    rep(i, N) parent[0][i] = par[i];
    rep(i, MAX_LOG_V - 1) {
        rep(j, N) {
            if (parent[i][j] < 0) parent[i + 1][j] = -1;
            else parent[i + 1][j] = parent[i][parent[i][j]];
            //cout << parent[i + 1][j] << " ";
        }
        //cout << "\n";
    }
}

int main() {
    scanf("%d", &N);
    vector<ll> u(N - 1), v(N - 1), w(N - 1), dist(N, 0);
    rep(i, N - 1) scanf("%lld %lld %lld", &u[i], &v[i], &w[i]);
    map<pair<int, int>, ll> edgew;
    rep(i, N - 1) {
        edge[u[i] - 1].push_back(v[i] - 1);
        edge[v[i] - 1].push_back(u[i] - 1);
        edgew[make_pair(u[i] - 1, v[i] - 1)] = w[i];
        edgew[make_pair(v[i] - 1, u[i] - 1)] = w[i];
    }
    tps(0);
    //rep(i, N) cout << tp[i] << " "; cout << "\n";
    vector<int> g(N);
    rep(i, N) g[tp[i]] = i;
    //rep(i, N) cout << g[i] << " "; cout << "\n";
    //rep(i, N) cout << depth[i] << " "; cout << "\n";
    rep(i, N - 1) {
        int x = tp[i + 1], p = par[x];
        dist[x] = dist[p] ^ edgew[make_pair(x, p)];
    }
    //rep(i, N) cout << dist[i] << " "; cout << "(dist)\n";
    ll ans = 0, MOD = 1e9 + 7;
    rep(i, 60) {
        ll count = 0;
        rep(j, N) {
            count += (dist[j] >> i) & 1;
        }
        ans = (ans + (1LL << i) % MOD * count % MOD * (N - count)) % MOD;
        //cout << ans << endl;
    }
    printf("%lld\n", ans);
}


#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define il inline
#define Ld double
#define pc putchar
#define rg register
#define ll long long
#define lll __int128
#define pb push_back
#define mp make_pair
#define It ::iterator
#define W(p) while(p--)
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define def(N, K, b) const K N = b;
#define FOR(i, b, s) for(int i = b; i < s; ++i)
#define rep(i, b, s) for(int i = b; i <= s; ++i)
#define per(i, b, s) for(int i = b; i >= s; --i)
#define FOR_(i, b, s) for(int i = b; i > s; --i)
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

namespace IO {
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE],*oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc() {
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread() {}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls) {
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do {
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    template<class T>
	inline void QreadArr(T Begin, T End) {
		while(Begin != End) {
			qread(*Begin);
			++Begin;
		}
	}
    inline void flush() {
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x) {
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite() {}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls) {
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    template<class T>
    inline void WriteArr(T Begin, T End) {
    	const char Kg = ' ', Edl = '\n';
    	while(Begin != End) {
    		qwrite(*Begin);
    		++Begin;
    		putc_(Kg);
		}
		putc_(Edl);
	}
    struct Flusher_{ ~Flusher_() { flush(); } } io_flusher;
}

using namespace IO;
using namespace std;

template<class T1, class T2>
T1 Min(const T1 x, const T2 y) { return x > y ? y : x; }
template<class T1, class T2>
T1 Max(const T1 x, const T2 y) { return x > y ? x : y; }

template<class T1, class T2>
void To_max(T1 &x, const T2 y) { x < y ? x = y : x = x; }
template<class T1, class T2>
void To_min(T1 &x, const T2 y) { x > y ? x = y : x = x; }

il ll qpow(ll n, ll base, ll mod = 1e18) {
	ll ret = 1;
	while(n) {
		if(n & 1) ret = ret * base % mod;
		base = base * base % mod;
		n >>= 1;
	}
	return ret % mod;
}

il ll gcd(ll x, ll y) { return !y ? x : gcd(y, x % y); }
il ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//header

def(N, int, 105);

int n, m, k, mx;
int a[N], b[N], c[N], d[N];
bool has[N];

void dfs(int st) {
	if(st > k) {
		int cnt = 0;
		rep(i, 1, m) { if(has[a[i]] && has[b[i]]) ++cnt; }
		To_max(mx, cnt);
		return ;
	}
	bool k = has[c[st]];
	has[c[st]] = true;
	dfs(st + 1);
	has[c[st]] = k;
	k = has[d[st]];
	has[d[st]] = true;
	dfs(st + 1);
	has[d[st]] = k;
}

int main() {
	qread(n, m);
	rep(i, 1, m) qread(a[i], b[i]);
	qread(k);
	rep(i, 1, k) qread(c[i], d[i]);
	dfs(1);
	printf("%d\n", mx);
 	return 0;
}

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

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

    int N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }
    int K; cin >> K;
    vector<int> C(K), D(K);
    for(int i = 0; i < K; i++){
        cin >> C[i] >> D[i];
        C[i]--, D[i]--;
    }
    vector<bool> ball;
    int ans = 0;
    for(int bit = 0; bit < (1<<K); bit++){
        ball.assign(N, false);
        for(int i = 0; i < K; i++){
            if(bit & (1<<i)) ball[C[i]] = true;
            else ball[D[i]] = true;
        }
        int cnt = 0;
        for(int i = 0; i < M; i++){
            if(ball[A[i]] && ball[B[i]]) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define all(v) (v).begin(),(v).end()
#define debug(x) cout << #x << ": " << x << '\n';
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll, ll>;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct UnionFind {
  int n;
  vector<int> a;
  vector<int> sz;

  UnionFind(int _n) : n(_n), a(_n), sz(_n, 1) {
    for(int i = 0; i < _n; i++) a[i] = i;
  }

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

  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    if (sz[rx] < sz[ry]) swap(rx, ry);
    sz[rx] += sz[ry];
    a[ry] = rx;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

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

  map<int, vector<int>> groups() {
    map<int, vector<int>> group;
    rep (i, n) root(i);
    rep (i, n) group[a[i]].push_back(i);
    return group;
  }
};

int main() {
  //cin.tie(0);ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  vector<int> a(N), b(N);
  rep (i, N) cin >> a[i];
  rep (i, N) cin >> b[i];

  rep (i, M) {
    int c, d;
    cin >> c >> d;
    --c; --d;
    uf.unite(c, d);
  }

  for (auto v : uf.groups()) {
    ll x = 0, y = 0;
    for (auto vv : v.second) {
      x += a[vv];
      y += b[vv];
    }
    if (x == y) continue;

    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 205
#define MOD 998244353
#define INF 1e15
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.14159265358979323846
#define Q ll MAXTEST; cin >> MAXTEST; for(ll TEST=1;TEST<=MAXTEST;TEST++)
#define endl "\n"
#define coutyes cout << "Yes\n";
#define coutno cout << "No\n";
#define flush fflush(stdout);
#define fixedprec cout << fixed << setprecision(18);

int main(){

    fast

    ll n,m;
    cin >> n >> m;
    ll b[m+1];
    for(ll i=1;i<=m;i++){
        cin >> b[i];
    }
    if(!m){
        cout << 1 << endl;
        return 0;
    }
    sort(b+1,b+m+1);
    vector<ll> a;
    for(ll i=1;i<=m;i++){
        ll tmp;
        if(i==1){
            tmp = b[i]-1;
        }
        else{
            tmp = b[i]-b[i-1]-1;
        }
        if(tmp>0){
            a.push_back(tmp);
        }
    }
    if(n-b[m]>0){
        a.push_back(n-b[m]);
    }

    ll n1 = a.size();
    ll ans = 0;
    if(!n1){
        cout << 0 << endl;
        return 0;
    }
    sort(a.begin(),a.end());
    for(ll i=0;i<n1;i++){
        ll tmp = a[i]/a[0];
        if(a[i]%a[0]){
            tmp++;
        }
        ans+=tmp;
    }
    cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
	ll a, b;
	cin >> b >> a;
	ll m = 2*b+100;
	ll d = m-a;
	cout << d << endl;
	return 0;
}

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

/*
提出前に確認!
- 配列は+10ぐらい余分にとっておく
- setとmultisetを間違えない
*/

/*
デバッグ時にチェック!
- RE
	配列の取りうる最大値、最小値を**すべて**チェックする
*/

int	main(void)
{
	long long n, k;
	cin >> n >> k;
	long long ans = 0;
	for (int B = 2; B <= 2 * n; B++)
	{
		if (2 <= B + k && B + k <= 2 * n)
		{
			long long A = B + k;
			ans += (B / 2 * 2 - (B % 2 == 0) - 2 * max(0LL, B - n - 1)) * (A / 2 * 2 - (A % 2 == 0) - 2 * max(0LL, A - n - 1));
		}
	}
	cout << ans << endl;
	return (0);
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;

/*ここから*/
int V;//頂点の個数
vector<int> e[200010];//iから出る辺
vector<int> E[200010];
int t[200010];//親情報の記録媒体

//すでにある辺と頂点の情報から木の作成
void Tree(int s){//sは一番根元
    for(int i=1;i<=V;i++){
        t[i]=i;//初期情報
    }
    queue <int> q;
    q.push(s);
    while(!q.empty()){
        int from;
        from=q.front();
        q.pop();
        while(!e[from].empty()){
            int to;
            to=e[from].back();
            e[from].pop_back();
            if(to!=t[from]){
                t[to]=from;
                q.push(to);
            }
        }
    }
}

int a[200010];
int b[200010];
int c[200010];
int flg[200010];
void C_tree(int s){
    int S=e[s].size();
    //cout<<s<<S<<endl;
    if(S==1&&e[s][0]==t[s]){
        //cout<<'x'<<endl;
        a[s]=1;
        b[s]=1;
        c[s]=0;
        flg[s]=1;
    }
    else{
        //cout<<'y'<<endl;
        int x1=0;
        int x2=0;
        int cnt=0;
        vector<int> y;
        for(int i=0;i<S;i++){
            int x=e[s][i];
            //cout<<s<<' '<<x<<endl;
            if(x!=t[s]){
                if(flg[x]==0){C_tree(x);/*cout<<x<<' '<<a[x]<<' '<<b[x]<<' '<<c[x]<<endl;*/}
                if(a[x]==0){
                    if(b[x]>c[x]){
                        b[s]=b[s]+c[x];
                        c[s]=c[s]+c[x];
                        x1=x1+b[x]-c[x];
                    }
                    else{
                        b[s]=b[s]+b[x];
                        c[s]=c[s]+b[x];
                        x2=x2+c[x]-b[x];
                    }
                }
                else{
                    cnt++;
                    b[s]=b[s]+b[x];
                    c[s]=c[s]+b[x];
                    y.push_back(c[x]-b[x]);
                }
            }
        }
        flg[s]=1;
        b[s]=b[s]+1;
        if(cnt%2==0){a[s]=1;}
        c[s]=c[s]+x2;
        if(a[s]==0){c[s]=c[s]+x1;}
        else{b[s]=b[s]+x1;}
        sort(y.begin(),y.end());
        reverse(y.begin(),y.end());
        int SS=y.size();
        int Cnt=0;
        for(int i=0;i<SS;i++){
            if(Cnt==0){
                c[s]=c[s]+y[i];
            }
            else{
                b[s]=b[s]+y[i];
            }
            Cnt=1-Cnt;
        }
    }
}

/*ここまで*/

int main()
{
    //基本用法
    cin>>V;
    for(int i=2;i<=V;i++){
        int A;
        cin>>A;
        e[i].push_back(A);
        e[A].push_back(i);
    }
    for(int i=0;i<=V;i++){
        E[i]=e[i];
    }
    Tree(1);
    for(int i=0;i<=V;i++){
        e[i]=E[i];
    }
    /*for(int i=1;i<=V;i++){
        cout<<t[i]<<endl;
    }*/
    for(int i=0;i<=V;i++){
        a[i]=0;
        b[i]=0;
        c[i]=0;
        flg[i]=0;
    }
    C_tree(1);
    /*for(int i=1;i<=V;i++){
        cout<<a[i]<<' '<<b[i]<<' '<<c[i]<<endl;
    }*/
    cout<<b[1]<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long ll;
const int maxn=1e5;
const ll MAXLL=9223372036854775807;

vt<int> adj[maxn+10];
vt<bool> vs(maxn+10, false);
vt<int> cnt(maxn, 0), a(maxn), ans;

void dfs(int u){
    vs[u]=true;
    cnt[a[u]]++;
    if (cnt[a[u]]==1) ans.pb(u);
    for (auto v:adj[u]){
        if (vs[v]) continue;
        dfs(v);
    }
    cnt[a[u]]--;
}

void solve(){
   int n;
   cin >> n;
   rep(i, 0, n) cin >> a[i];
   rep(i, 0, n-1){
       int x, y;
       cin >> x >> y, --x, --y;
       adj[x].pb(y);
       adj[y].pb(x);
   }
   dfs(0);
   sort(all(ans));
   for (auto i:ans) cout << i+1 << endl;
}

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


#include<bits/stdc++.h>
using namespace std;
int main(){
     int n,w,c=0;
     cin>>n>>w;
     int ans=0;

     while(ans<=n){
        ans+=w;
       c++;
     }
   cout<<c-1;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  	int n, w;
  	cin >> n >> w;
  	cout << n / w;
	return 0;
}