/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

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

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

//#pragma GCC optimize(2)
const int N = 3005;
const int P = 998244353;
int n, k, f[N][N];
int dfs(int n, int k) {
	if (!k && !n) return 1;
	if (!k) return 0;
	if (k > n) return 0;
	if (f[n][k] != -1) return f[n][k];
	return f[n][k] = (dfs(n - 1, k - 1) + dfs(n, k << 1)) % P;
}

int main() {
	memset(f, -1, sizeof(f));
	read(n), read(k);
	write(dfs(n, k));
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> c(200);
    rep(i, n){
        ll a;
        cin >> a;
        c[a % 200]++;
    }
    ll ans = 0;
    for(int i = 0; i < 200; i++){
        ans += c[i] * (c[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>

using namespace std;

struct fg {
	int f;
	int g;
};

fg func(int n) {
	fg r = { 0, 0 };
	if (n == 0) return r;
	while (n % 3 == 0) {
		r.f++;
		n /= 3;
	}
	r.g = n % 3;

	return r;
}

int main()
{
	bool frag = true;
	int n;
	string c;
	cin >> n >> c;

	int bf = 0;
	fg cfg = { 0, 1 };
	fg bffgu = { 0, 0 }, bffgd = { 0, 0 };
	for (int i = 0; i < n; i++) {
		if (cfg.f == 0) {
			switch (c[i])
			{
			case 'B':
				break;
			case 'W':
				bf += cfg.g;
				break;
			case 'R':
				bf += 2 * cfg.g;
				break;
			}
		}

		bffgd = func(i + 1);
		bffgu = func(n - i - 1);

		cfg.f = cfg.f + bffgu.f - bffgd.f;
		cfg.g = (cfg.g * bffgu.g) % 3;
		if (cfg.g == bffgd.g) cfg.g = 1;
		else cfg.g = 2;

		bf = bf % 3;
	}

	if (n % 2) {
		switch (bf)
		{
		case 0 :
			cout << "B";
			break;
		case 1 :
			cout << "W";
			break;
		case 2:
			cout << "R";
			break;
		}
	}
	else {
		switch (bf)
		{
		case 0:
			cout << "B";
			break;
		case 1:
			cout << "R";
			break;
		case 2:
			cout << "W";
			break;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
   cin >> n;
   vector<pair<double,double>> m (n);
   for ( int i = 0; i  < n; i ++ ) {
    cin >> m[i].first >> m[i].second;
   }
   int cnt=0;
    for (int i = 0 ; i < n ; i++){
        for (int j = i+1; j < n; j++){
            if (((m[j].second - m[i].second) / (m[j].first - m[i].first) <=1) &&(m[j].second - m[i].second) / (m[j].first - m[i].first) >=-1)
                cnt++;
               // cout << "m[j].sec = " << m[j].second - m[i].second <<  " m[i].first = " << m[j].first - m[i].first <<  " ==== " << (m[j].second - m[i].second) / (m[j].first - m[i].first)  << " cnt = " <<cnt << endl;
        }
        //cout << endl;
    }
   cout <<cnt<<endl;

   return 0;
      }

#include <bits/stdc++.h>

#define ll long long int
using namespace std;

int main() {
    ll n, f, i, j, a, b;
    cin >> n;
    vector<pair<ll, ll> > vect;
    ll sum = 0;
    for (i = 0; i < n; i++) {
        cin >> a >> b;
        vect.push_back(make_pair(a, b));
    }
    sort(vect.begin(),vect.end());
    ll mn=vect[0].first+vect[0].second;
    for(i=1;i<n;i++)
    {
        mn=min(mn,(max(vect[0].first,vect[i].second)));
    }
    cout<<mn<<endl;
}


#include <bits/stdc++.h>

#define Mod 998244353

using namespace std;

int n, m, k, pre[200010], ans;

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

int main() {
	cin >> n >> m >> k;
	if (n == 1) return printf("%d", fpow(k, m)), 0;
	if (m == 1) return printf("%d", fpow(k, n)), 0;
	for (int i = 1; i <= k; i++) ans = (ans + 1ll * (fpow(i, n) - fpow(i - 1, n)) * fpow(k - i + 1, m)) % Mod;
	if (ans < 0) ans += Mod;
	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int arr[100005];
long long mod=998244353;
int main()
{
	long long a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	long long sum,num,ans;
	if(a%2==0)
	{
		sum=((a/2)%mod*(a+1)%mod)%mod;
	}
	else if(a%2==1)
	{
		sum=(a%mod*((a+1)/2)%mod)%mod;
	}
	if(b%2==0)
	{
		num=((b/2)%mod*(b+1)%mod)%mod;
	}
	else if(b%2==1)
	{
		num=(b%mod*((b+1)/2)%mod)%mod;
	}
	if(c%2==0)
	{
		ans=((c/2)%mod*(c+1)%mod)%mod;
	}
	else if(c%2==1)
	{
		ans=(c%mod*((c+1)/2)%mod)%mod;
	}
	//printf("%lld %lld %lld\n",sum,num,ans);
	long long aans=(num*sum)%mod;
	aans=(aans*ans)%mod;
	printf("%lld\n",aans);
}


#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

int main(void){
    ll N; cin>>N;
    vl A(2*N);
    REP(i,2*N) cin>>A[i];
    vl B=A;
    sort(B.begin(),B.end());

    ll med=B[N-1],cnt=0;
    REP(i,N){
        if(B[i]==med) cnt++;
    }

    vl code(2*N);
    REP(i,2*N){
        if(A[i]<=med){
            if(A[i]<med) code[i]=-1;
            else if(cnt>0) code[i]=-1, cnt--;
            else code[i]=1;
        }
        else code[i]=1;
    }

    ll nowc=0, sum=0;
    string S;
    REP(i,2*N){
        if(nowc==0){
            if(code[i]>0) nowc=1;
            else nowc=-1;
        }

        if(nowc>0){
            if(code[i]>0) S+='(', sum++;
            else S+=')', sum--;
        }
        else{
            if(code[i]<0) S+='(', sum++;
            else S+=')', sum--;
        }

        if(sum==0) nowc=0;
    }
    cout<<S<<endl;
    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))
#define all(x) (x).begin(),(x).end()
using namespace std;

int main(){
    ll k;
    cin>>k;
    ll ans=0;
    V dp(2e5+1,0);
    for(ll a=1;a<=2e5;a++){
        ll res=0;
        for(ll b=1;b*b<=a;b++){
            if(a%b==0){
                res++;
                if(b*b!=a)res++;
            }
        }
        dp[a]=dp[a-1]+res;
    }
    for(ll i=1;i<=k;i++){
        ll maxi=k/i;
        ans+=dp[maxi];
    }
    cout<<ans<<endl;
}


/*/^--^\
  \____/
 /      \ _____  _ __  __ ____  _     ____   ____  _____
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_| |
#include <orz/i_am_noob.h>
#include <orz/balbit.h>
#include <orz/nathanlee726.h>*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
using pdd=pair<double,double>;
#define int ll

#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (ll)(1000000007)
#define INF (1e15)
#define EPS (1e-6)

#ifdef LOCALMEOW
#define debug(...) do{\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void FASTIO(){ ios::sync_with_stdio(false); cin.tie(0); }

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	int ans=1,now=b;
	while(p){
		if(p&1) ans=ans*now%MOD;
		p/=2; now=now*now%MOD;
	}
	return ans;
}
void maxify(int &a,int b) { if(b>a) a=b; }
void minify(int &a,int b) { if(b<a) a=b; }

int gcd(int a,int b,int &x,int &y){
	if(b==0){
		x=1; y=0;
		return a;
	}
	int x1,y1;
	int g=gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-y1*(a/b);
	return g;
}

int32_t main(){
	FASTIO();
	//code...
	int N; cin>>N;
	int n,s,x;
	while(N--){
		cin>>n>>s>>x;
		int a,b;
		int g=gcd(x,n,a,b);
		a%=n; if(a<0) a+=n;
		//cout<<a<<" "<<a*x%n<<"\n";
		b=(a*(n-s)/g)%(n/g);
		if(b<0) b+=n;
		if((s+b*x)%n!=0) cout<<"-1\n";
		else cout<<b<<"\n";
	}
	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>;
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 (b<a) {a=b; return 1;} return 0;}

//ax + by = g , return {g,x,y}
tuple<ll,ll,ll> extGCD(ll a, ll b){
    if(b == 0) return {a,1,0};
    ll g,x,y;
    tie(g,x,y) = extGCD(b,a%b);
    return {g,y,x-a/b*y};
}

//s + kx = 0(mod n)
// x = -s*k-^1 (mod n)

void solve(){
  ll n,k,s,g,x,y;
  cin >> n >> s >> k;
  tie(g,x,y) = extGCD(k,n);
  if(s%g != 0){
    cout << -1 << endl;
    return;
  }
  n /= g;
  k /= g;
  s /= g;
  ll ans = (n+(-s*x)%n)%n;
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  rep(i,t){
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int main(){
    vector <int> arr;
    int n=3;
    while(n--){
        int k;
        cin>>k;
        arr.push_back(k);
    }
    sort(arr.begin(),arr.end());
    if(arr[0]+arr[2]==2*arr[1]){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;

return 0;
}

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int ll
using namespace __gnu_pbds;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
map<int,int> mp;
void solve()
{

int a,b,c;
cin>>a>>b>>c;
c*=c;
a*=a;
b*=b;
if(a+b<c)
{
    cout<<"Yes";
}
else
cout<<"No";

}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

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

    return 0;
}
///order_of_key (k) : Number of items strictly smaller than k .
///find_by_order(k) : K-th element in a set (counting from zero).


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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,x,i;
	string a;
	cin>>n>>x>>a;
	for(i=0;i<n;i++)
	{
		if(a[i]=='o')
			x++;
		if(a[i]=='x'  && x>0)
			x--;
	}
	cout<<x<<endl;
}


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

LL n,m,q;
LL a[N],b[N];
bool f=0;
LL g[2]={1,1};
LL u,v;
struct HIS{
    bool f;
    LL g[2];
    LL u,v;
}hist[N];
il void sav(int x){
    hist[x].f=f;
    hist[x].g[0]=g[0];hist[x].g[1]=g[1];
    hist[x].u=u;hist[x].v=v;
}

inline void init(){
    read(n);For(i,1,n)read(a[i],b[i]);
    u=a[1],v=b[1];read(m);g[0]=1;g[1]=1;
    sav(0);
    For(i,1,m){
        int op;read(op);
        if(op==1){
            g[0^f]*=-1;f^=1;
            swap(u,v);v*=-1;
        }else if(op==2){
            g[1^f]*=-1;f^=1;
            swap(u,v);u*=-1;
        }else if(op==3){
            LL p;read(p);
            g[0^f]*=-1;
            u=2*p-u;
        }else{
            LL p;read(p);
            g[1^f]*=-1;
            v=2*p-v;
        }
        sav(i);
    }
}
inline void solve(){
    read(q);
    while(q--){
        LL ai,bi;read(ai,bi);
        LL hu=hist[ai].u,hv=hist[ai].v;
        if(hist[ai].f)swap(hu,hv);
        LL ansx=hu+hist[ai].g[0]*(a[bi]-a[1]),ansy=hv+hist[ai].g[1]*(b[bi]-b[1]);
        if(hist[ai].f)swap(ansx,ansy);
        printf("%lld %lld\n",ansx,ansy);
    }
}
signed main(){
    init();solve();
    return 0;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

ll fibrest(ll x0, ll y0, ll n, bool isx) {
    ll iter = 0;
    vector<ll> fib = {x0, y0};
    ll x = x0;
    ll y = y0;
    ll op = 0;
    while (true) {
        if (isx) {
            x = x + y;
        } else {
            y = y + x;
        }
        if (x >= n) break;
        op++;
        isx = !isx;
    }
    return op;
}
void op(vector<ll> &ops, ll &x, ll &y, ll t) {
    if (t == 1) {
        x = x + 1;
    }
    if (t == 2) {
        y = y + 1;
    }
    if (t == 3) {
        x = x + y;
    }
    if (t == 4) {
        y = y + x;
    }
    ops.push_back(t);
}
void output(vector<ll> &ops) {
    ll k = ops.size();
    print(ops.size());
    for (auto ope : ops) {
        print(ope);
    }
}

bool solve(ll n) {
    ll x = 0;
    ll y = 0;
    vector<ll> ops;
    if (n < 10) {
        while (x < n) {
            op(ops, x, y, 1);
        }
        output(ops);
        return true;
    }

    op(ops, x, y, 1);
    bool isx = false;
    while (true) {
        if (x + y > n) {
            while (x < n) {
                op(ops, x, y, 1);
            }
            break;
        }
        ll curop = fibrest(x, y, n, isx);

        {
            ll k = 0;
            while (true) {
                ll r = fibrest(x + k + 1, y, n, isx);
                if (r != curop) break;
                //perr(curop, r);
                op(ops, x, y, 1);
                k = k + 1;
            }
        }
        if (isx) {
            op(ops, x, y, 3);
        } else {
            op(ops, x, y, 4);
        }
        isx = !isx;
        if (x >= n) break;
    }
    if (ops.size() > 130) {
        return false;
    }
    output(ops);
    return true;
}
int main() {
    ioinit();

    ll n;
    cin >> n;
    if (!solve(n)) {
        assert(false);
    }
    return 0;
    // for (ll i = 1000000000000000000; true; i--) {
    //     if (!solve(i)) {
    //         assert(false);
    //         return 0;
    //     }
    // }
}


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

int N, M;

#define pii pair<int, int>
#define fi first
#define se second

vector<pii> v;
map<int, int> pos;

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

	cin >> N >> M;

	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b;
		v.push_back({a, b});
	}

	sort(v.begin(), v.end());

	pos[N] = true;

	int prev = 0;

	vector<int> add, del;

	for(int i = 0; i < M; i++){
		if(v[i].fi != prev){
			for(auto& p : add) pos[p] = true;
			for(auto& p : del) pos[p] = false;
			prev = v[i].fi;
			add.clear(); del.clear();
		}

		int b = v[i].se;
		if(pos[b - 1] || pos[b + 1]) add.push_back(b);
		else del.push_back(b);
	}

	for(auto& p : add) pos[p] = true;
	for(auto& p : del) pos[p] = false;

	int sum = 0;

	for(auto& p : pos){
		if(p.se == 1) sum++;
	}

	cout << sum << '\n';
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

vvl G;
vl visited;
vvl S;  // S[v] : 頂点vに辿り着ける頂点集合

void dfs(ll sv, ll v) {
    // 行きの処理はこのへんに書く
    S[v].pb(sv);
    visited[v] = 1;
    for(ll u : G[v]) {
        if(!visited[u]) {
            dfs(sv, u);
        }
        // 帰りの処理はこのへんに書く
    }
}

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

    G.resize(n);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if(s[j] == '1') {
                G[i].pb(j);
            }
        }
    }

    S.resize(n);
    rep(sv, n) {
        visited.assign(n, 0);
        dfs(sv, sv);
    }

    double ans = 0.0;
    rep(v, n) {
        ans += 1.0/(double)S[v].size();
    }

    exout(ans);
    re0;
}


// Jai Shree Ram

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int N=1e9+5;
const int M=1e7;

struct node{
	int l;int r;
	int val;
	int cnt;
}t[M];
int cnt=0;

int n;

void extend(int v){
	if(t[v].l==0){
		t[v].l=++cnt;
		t[v].r=++cnt;
	}
}

void pushup(int v){
	t[v].val = t[t[v].l].val + t[t[v].r].val;
	t[v].cnt = t[t[v].l].cnt + t[t[v].r].cnt;
}

void update(int v,int l,int r,pii val,int tl=0,int tr=1e9){
	if(tl>r || l>tr)return;
	if(l<=tl && tr<=r){
		assert(tl == tr);
		t[v].val += val.x;
		t[v].cnt += val.y;
		return;
	}
	extend(v);
	int mid=(tl+tr)/2;
	update(t[v].l,l,r,val,tl,mid);
	update(t[v].r,l,r,val,mid+1,tr);
	pushup(v);
}

pii query(int v,int l,int r,int tl=0,int tr=1e9){
	if(tl>r || l>tr)return {0,0};
	if(l<=tl && tr<=r){
		return {t[v].val,t[v].cnt};
	}
	int mid=(tl+tr)/2;
	extend(v);
	pii a =query(t[v].l,l,r,tl,mid);
	pii b =query(t[v].r,l,r,mid+1,tr);
	return {a.x+b.x,a.y+b.y};
}

int solve(){
		int n,m,q; cin >> n >> m >> q;

		int ans = 0;
		int roota = ++cnt;
		int rootb = ++cnt;

		vector<int>v1(n+1),v2(m+1);
		update(roota,0,0,{0,n});
		update(rootb,0,0,{0,m});

		rep(i,0,q){
			int t; cin >> t;
			int x,y; cin >> x >> y;
			if(t == 1){
				if(y > v1[x]){
					auto s = query(rootb,0,y);
					ans += s.y*y;
					s = query(rootb,v1[x]+1,y);
					ans -= s.x;
					s = query(rootb,0,v1[x]);
					ans -= v1[x]*s.y;
				}
				else if(y < v1[x]){
					auto s = query(rootb,0,v1[x]);
					ans -= s.y*v1[x];
					s = query(rootb,0,y);
					ans += s.y*y;
					s = query(rootb,y+1,v1[x]);
					ans += s.x;
				}
				update(roota,v1[x],v1[x],{-v1[x],-1});
				update(roota,y,y,{y,1});
				v1[x] = y;
			}
			else{
				if(y > v2[x]){
					auto s = query(roota,0,y-1);
					ans += s.y*y;
					s = query(roota,0,v2[x]-1);
					ans -= s.y*v2[x];
					s = query(roota,v2[x],y-1);
					ans -= s.x;
				}
				else if(y < v2[x]){
					auto s = query(roota,0,v2[x]-1);
					ans -= s.y*v2[x];
					s = query(roota,0,y-1);
					ans += s.y*y;
					s = query(roota,y,v2[x]-1);
					ans += s.x;
				}
				update(rootb,v2[x],v2[x],{-v2[x],-1});
				update(rootb,y,y,{y,1});
				v2[x] = y;
			}
			cout << ans << endl;
		}
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define mod 1000000007
#define INF 1e17
#define test int t; cin >> t;
#define all(a) a.begin(),a.end()
#define pi 3.141592653589
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ;
int power(int x, int y) ;
int gcd(int a, int b) ;
vi ft = {1} ;
int modInv(int i) {return power(i,mod-2);}
int ncr(int n,int r) {return (n>=r?(ft[n]*modInv(ft[r]))%mod*modInv(ft[n-r])%mod:0);}

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

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T>
// using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
// (*****FOR USING ORDERED SET CHANGE INT*******)

// struct chash {
//     const int RANDOM = (long long)(make_unique<char>().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count();
//     static unsigned long long hash_f(unsigned long long x) {
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
//     int operator()(int x) const { return hash_f(x)^RANDOM; }
// };

vi v[2001] ;

int vis[2001];

void dfs(int n) {
    vis[n] = 1 ;
    for(auto i : v[n]) {
        if(!vis[i]) dfs(i) ;
    }
}

signed main() {
    quickie
    int n, m ;
    cin >> n >> m ;
    rep(i, 0, m) {
        int x, y ;
        cin >> x >> y ;
        v[x].pb(y) ;
    }
    int ans = 0 ;
    rep(i, 1, n+1) {
        memset(vis, 0, sizeof(vis)) ;
        dfs(i) ;
        rep(j, 1, n+1) if(vis[j]) ans++ ;
    }
    cout << ans << "\n" ;
}


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

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

bool isOK(int n);

int main(){
    int N; cin>>N;
    int res = 0;
    rep1(i,N)res += isOK(i)?1:0;
    cout<<res<<endl;
}

bool isOK(int n){
    //10進数で7check;
    int n1 = n, n2 = n;
    while(n1){
        if(n1%10==7)return false;
        n1/=10;
    }
    while(n2){
        if(n2%8==7)return false;
        n2/=8;
    }
    return true;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

int main() {
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  int n;
  cin >> n;
  int ans = 0;
  FOR(i, 1, n) {
    auto check = [&](int d) {
      int x = i;
      while (x) {
        if (x % d == 7) return true;
        x /= d;
      }
      return false;
    };
    if (!check(10) && !check(8)) ans++;
  }
  cout << ans;
}


//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn))
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define sp setprecision
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=1000000007;
const ll MOD=998244353;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp
{
    bool operator() (const pll &a, const pll &b)  const
    {
        ll lena = a.sec - a.fi + 1;
        ll lenb = b.sec - b.fi + 1;
        if (lena == lenb) return a.fi < b.fi;
        return lena > lenb;
    }
};
********************************/

ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}
ll binpow(ll a, ll b,ll m)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll gcdExtended(ll a, ll b, ll &x, ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, x1, y1);
    x = y1 - (b/a) * x1;
    y = x1;
    return gcd;
}
ll modInverse(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, x, y);
    ll res = (x%m + m) % m;
    return res;
}

ll modinv(ll n,ll mod)
{
    return binpow(n, mod - 2,mod);
}

/**************coding****************************************/
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;//cin>>T;
    For(i,1,T)
    {
        ll n;cin>>n;
        vll a(n),b(n);
        vll tot;ll sum=0;
        For(j,0,n-1) cin>>a[j]>>b[j],tot.pb(2*a[j]+b[j]),sum+=a[j];
        sort(all(tot),greater<ll>());
        ll cur=0;
        For(j,0,n-1)
        {
            cur+=tot[j];
            if(cur>sum)
            {
                cout<<j+1;return 0;
            }
        }
    }
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int H, W;
string S[2000];
ll dp[2000][2000][3];
const int mod = 1e9 + 7;

void cal(int i, int j, int k, ll tmp) {
	if (i < H && j < W && S[i][j] == '.') {
		dp[i][j][k] += tmp;
		dp[i][j][k] %= mod;
	}
}

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

	cin >> H >> W;

	rep(i, H) cin >> S[i];

	rep(i, H) rep(j, W) {
		if (i == 0 && j == 0) {
			cal(1, 0, 0, 1);
			cal(0, 1, 1, 1);
			cal(1, 1, 2, 1);
			continue;
		}
		ll tmp = dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
		cal(i + 1, j, 0, tmp + dp[i][j][0]);
		cal(i, j + 1, 1, tmp + dp[i][j][1]);
		cal(i + 1, j + 1, 2, tmp + dp[i][j][2]);
	}

	co((dp[H - 1][W - 1][0] + dp[H - 1][W - 1][1] + dp[H - 1][W - 1][2]) % mod);

	Would you please return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const int L=1000;

void verify(vector<int> A,vector<int> B){
  int N=A.size();
  vector<vector<int>> g(N);
  rep(i,N){
    A[i]--;B[i]--;
    g[i].push_back(A[i]);
    g[i].push_back(B[i]);
  }

  auto bfs = [&](){
    for(int i=0;i<N;i++){
      queue<int> Q;
      vector<int> dist(N,MOD);
      dist[i]=0;
      Q.push(i);
      while(!Q.empty()){
        int now=Q.front();
        Q.pop();

        if(dist[now]>10) return false;

        for(auto nex:g[now]){
          if(nex>=N){
            cout<<"INVALID"<<endl;
            return false;
          }
          if(dist[nex]==MOD){
            dist[nex]=dist[now]+1;
            Q.push(nex);
          }
        }
      }
    }
    return true;
  };

  if(bfs()) cout<<"OK"<<endl;
  else cout<<"NG"<<endl;
}

int MASK=(1<<10)-1;

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

  int N;
  cin>>N;

  vector<int> A(N,-1),B(N,-1);
  for(int i=0;i<N;i++){
    int value=i;
    int targetValue=(value<<1)&MASK;
    A[i]=(value<<1)&MASK;
    for(int d=9;d>=0;d--){
      if(A[i]<N) break;
      if(A[i]&(1<<d)) A[i]^=(1<<d);
    }
    B[i]=targetValue+1;
    for(int d=9;d>=0;d--){
      if(B[i]<N) break;
      if(B[i]&(1<<d)) B[i]^=(1<<d);
    }
  }

  //verify(A,B);

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

  return 0;
}

//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

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

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int N;
	cin >> N;

	rep(i, 0, N)
	{
		cout << ((2 * i) % N) + 1 << " " << ((2 * i + 1) % N) + 1 << endl;
	}

	return 0;
}


// #include<atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};
// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;

int main(){
    ll n;   cin >> n;
    set<ll> st;
    rep(i, n){
        ll x;   cin >> x;
        st.insert(x);
    }
    while(1<st.size()){
        ll p = *st.rbegin();
        st.erase(p);
        ll nv = p%*st.begin();
        if(nv==0) continue;
        st.insert(nv);
    }
    cout << *st.begin() << endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)

int N;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int all_counter = 0, counter = 0;

vector<bool> gone;
void dfs2(const Graph &G, int v) {

    // if(all_of(gone.begin(), gone.end(), [](int x) { return x == 1; })){
    //     cout <<  "どうでしょう" << v << endl;
    //     all_counter++;
    //     // gone.assign(N, false);
    //     return;
    // }

    if(gone[v] == 0){
        counter++;
    }
    gone[v] = true;

    for (auto next_v : G[v]) {
        gone[next_v] = true;
    }

     if(all_of(gone.begin(), gone.end(), [](int x) { return x == 1; })){
                all_counter++;
                return;
    }

    rep(i, N){
        if(gone[i] == 0){
            // cout << "さいき "  << i << endl;
            dfs2(G, i);
        }
    }

    // if(all_of(gone.begin(), gone.end(), [](int x) { return x == 1; })){
    //     return;
    // }

}

int main() {
    // 頂点数と辺数
    cin >> N;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        rep(j, N){
            if(s[j] == '1') G[i].push_back(j);
        }
    }

    Graph G2(N);

    // 頂点 0 をスタートとした探索
    seen.assign(N, false); // 全頂点を「未訪問」に初期化
    rep(i, N){
        dfs(G, i);
        rep(j, N){
            if(seen[j]) G2[i].push_back(j);
        }
        seen.assign(N, false);
    }

    double res = 0.0;
    for (int i = 0; i < N; ++i) {
        int num = 0;
        for (int j = 0; j < N; ++j){
            for(int k = 0;k < G2[j].size();k++){
                if(G2[j][k] == i){
                    num++;

                    break;
                }
                else if(j == i){
                    num++;

                    break;
                }
            }
        }
        res += 1.0 / num;
    }

    printf("%.15f\n", res);
    // gone.assign(N, false);
    // rep(i, N){
    //     dfs2(G2, i);
    //     gone.assign(N, false);
    // }

    // // cout << counter << endl;
    // // cout << all_counter << endl;

    // long double ans = (long double)counter/all_counter;

    // printf("%.15Lf\n", ans);
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e5 + 100;
int a[N], b[N], n, ev[N], od[N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    long long ans = 0;
    int odd = 0, even = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) {
        if (i & 1) od[++odd] = a[i] - b[i];
        else ev[++even] = a[i] - b[i];
        ans += b[i];
    }
    sort(ev + 1, ev + even + 1);
    reverse(ev + 1, ev + even + 1);
    sort(od + 1, od + odd + 1);
    reverse(od + 1, od + odd + 1);
    int i = 1, j = 1;
    while (i <= odd && j <= even && od[i] + ev[j] > 0) {
        ans += od[i] + ev[j];
        i++, j++;
    }
    cout << ans << endl;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define Swap(a,b) (a+=b,b=a-b,a-=b)
static inline long Max(long a,long b){return a>b?a:b;}
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline void AscRadix32(int *a,const int sz,const int minus)
{
  int x,shift=0,elem[0400],temp[sz];
  while(shift<040)
  {
    int bucket[0400]={0};
    rep(i,sz){x=(a[i]>>shift)&0377;bucket[x]++;temp[i]=a[i];}
    elem[0]=0;rep(i,0377)elem[i+1]=elem[i]+bucket[i];
    rep(i,sz){x=(temp[i]>>shift)&0377;a[elem[x]]=temp[i];elem[x]++;}
    shift+=010;
  }
  rep(i,minus>>1)Swap(a[sz-minus+i],a[sz-1-i]);
  rep(i,(sz-minus)>>1)Swap(a[i],a[sz-minus-1-i]);
  rep(i,sz>>1)Swap(a[i],a[sz-1-i]);
}
int main(void)
{
  int N=IN(),A[N],B=0,m1=0,m2=0,p1[N/2],p2[N/2];long score=0;
  rep(i,N){A[i]=IN(),score+=A[i];}
  rep(i,N){B=IN();if(i&1){p1[i/2]=B-A[i];if(B-A[i]<0)m1++;}else{p2[i/2]=B-A[i];if(B-A[i]<0)m2++;}}
  AscRadix32(p1,N/2,m1);AscRadix32(p2,N/2,m2);
  rep(i,N>>1)if(p1[(N>>1)-1-i]+p2[(N>>1)-1-i]>0)score+=p1[(N>>1)-1-i]+p2[(N>>1)-1-i];
  return OUT(score),0;
}


#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#ifdef NDEBUG
  #define assert(e) if(!(e)){stod("");}
#endif
#ifdef ONLINE_JUDGE
  #define debug(x)
  #define debug2(x,y)
  #define debug3(x,y,z)
#else
  #define debug(x) std::cerr<<#x<<": "<<x<<"\n"
  #define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
  #define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
#endif

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int h, w;
  scan(h, w);
  vvi grid(h, vi(w, -1));
  string s;
  rep (i, h) {
    scan(s);
    rep (j, w) {
      if (s[j] == '+') {
        grid[i][j] = 1;
      }
    }
  }
  debug(grid);
  vvi dp(h, vi(w, 0));
  for (int i = h - 2; i >= 0; --i) {
    dp[i][w - 1] = grid[i + 1][w - 1] - dp[i + 1][w - 1];
  }
  for (int j = w - 2; j >= 0; --j) {
    dp[h - 1][j] = grid[h - 1][j + 1] - dp[h - 1][j + 1];
  }
  for (int i = h - 2; i >= 0; --i) {
    for (int j = w - 2; j >= 0; --j) {
      int cand1 = grid[i][j + 1] - dp[i][j + 1];
      int cand2 = grid[i + 1][j] - dp[i + 1][j];
      dp[i][j] = max(cand1, cand2);
    }
  }
  if (dp[0][0] > 0) {
    print("Takahashi");
  } else if (dp[0][0] < 0) {
    print("Aoki");
  } else {
    print("Draw");
  }
}

int main() {
  solve();
  return 0;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;
// cout << fixed << setprecision(桁数);

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(2010, vector<int>(2010, 0)), dp(2010, vector<int>(2010, 0));
    rep(i, H){
        rep(j, W){
            char c;
            cin >> c;
            int tmp = 0;
            if(c == '+')
                tmp = 1;

            if ((i + j + tmp) % 2 == 0){
                A[i][j] = 1;
            } else {
                A[i][j] = -1;
            }
        }
    }

    dp[H - 1][W - 1] = 0;

    for (int i = H - 2; i >= 0; i--){
        dp[i][W - 1] = dp[i + 1][W - 1] + A[i + 1][W - 1];
    }
    for (int j = W - 2; j >= 0; j--)
    {
        dp[H - 1][j] = dp[H - 1][j + 1] + A[H - 1][j + 1];
    }

    for (int a = H + W - 4; a >= 0; a--){
        for (int i = 0; i < H - 1; i++){
            int j = a - i;
            if (0 <= j && j < W - 1)
            {
                if (a % 2 == 0){
                    dp[i][j] = max(dp[i][j + 1] + A[i][j + 1], dp[i + 1][j] + A[i + 1][j]);
                } else {
                    dp[i][j] = min(dp[i][j + 1] + A[i][j + 1], dp[i + 1][j] + A[i + 1][j]);
                }
            }
        }
    }

    if(dp[0][0] > 0)
        cout << "Takahashi" << endl;
    else if (dp[0][0] < 0)
        cout << "Aoki" << endl;
    else
        cout << "Draw" << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,n;
  cin >> n;
  vector<ll> a(n),s(n+1,0);
  ll ans=0;
  for(i=0;i<n;i++){
    cin >> a[i];
    ans+=a[i]*a[i]*(n-1);
  }
  for(i=0;i<n;i++){
    s[i+1]=s[i]+a[i];
  }
  ll ans1=0;
  for(i=0;i<n;i++){
    ans1+=2*a[i]*(s[n]-s[i+1]);
  }
  cout << ans-ans1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N;
  cin >> N;
  vector<int> A, B, C;
  rep(i, N)
  {
    int a;
    cin >> a;
    A.push_back(a);
  }
  rep(i, N)
  {
    int b;
    cin >> b;
    B.push_back(b);
  }
  rep(i, N)
  {
    int c;
    cin >> c;
    C.push_back(c);
  }
  long long cou = 0;
  sort(C.begin(), C.end());
  sort(A.begin(), A.end());
  rep(i, N)
  {
    if (C.at(i) > B.size())
    {
      continue;
    }
    int BCj = B.at(C.at(i) - 1);
    decltype(A)::iterator left = lower_bound(A.begin(), A.end(), BCj);
    if (left != A.end() && *left == BCj)
    {
      decltype(A)::iterator right = upper_bound(A.begin(), A.end(), BCj);
      cou += right - left;
    }
  }
  cout << cou << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;
const double EPS = 1e-7;
const double PI = acos(-1);

struct dsu {
  vector<mii> y;
  vi id, sz;

  dsu(int n) : y(n), id(n), sz(n, 1) {
    loop(n) {
      int c;
      cin >> c;
      y[i][c] = 1;
      id[i] = i;
    }
  }

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

  bool join(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return false;
    if (sz[a] > sz[b]) swap(a, b);
    id[a] = id[b];
    sz[b] += sz[a];
    for (auto& [k, v] : y[a]) {
      y[b][k] += v;
    }
    y[a].clear();
    return true;
  }
};

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

  int n, q;
  cin >> n >> q;
  dsu uf(n);
  int op, a, b;
  loop(q) {
    cin >> op >> a >> b;
    if (op == 1) uf.join(a - 1, b - 1);
    else cout << uf.y[uf.find(a - 1)][b] << endl;
  }
  return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

int n, q;
int c[200005];
map<int, int> g[200005];
int f[200005];

int find(int u) {
  if (f[u] == u) return f[u];
  else return f[u] = find(f[u]);
}

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
    g[i][c[i]] = 1;
    f[i] = i;
  }
  while (q--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1) {
      x--, y--;
      int fx = find(f[x]);
      int fy = find(f[y]);
      if (fx == fy) continue;
      if (g[fx].size() < g[fy].size()) {
        swap(x, y);
        swap(fx, fy);
      }
      for (auto iter : g[fy]) {
        g[fx][iter.first] += iter.second;
      }
      g[fy].clear();
      f[fy] = fx;
    } else {
      x--;
      int fx = find(x);
      int ans = 0;
      if (g[fx].find(y) != g[fx].end()) {
        ans = g[fx][y];
      }
      printf("%d\n", ans);
    }
  }

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}


#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
double R,X,Y;
vector<vector<ll>> v;
vector<vector<vector<int>>> seen;

int main() {
	cin >> R >> X >> Y;
	double d = sqrt(X * X + Y * Y);
	if (int(d)-d == 0 && int(d)%int(R) == 0) {
		cout << int(d) / int(R);
	}
	else if(int(d / R) != 0){
		cout << int(d / R) + 1;
	}
	else {
		cout << 2;
	}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int sum = 0;
   int n,k,m;
   cin>>n;
   cin>>k;
   cin>>m;
   int x;
   for(int i = 0;i<n-1;i++)
   {
        cin>>x;
        sum = sum+x;
   }
   if((m*n-sum)<=k)
   {
       if((m*n-sum)<0)
       {
           cout<<0;
       }
       else
       {
           cout<<m*n-sum;

       }
   }
   else
   {

       cout<<-1;
   }
}


#define SVR "CreatedBySmitRami"

///////////////////////Loading Payloads.......////////////////////////////
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i > b;i--)
#define ll long long
#define fl(i,a,b) for(ll i = a; i < b; i++)
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VS vector<string>
#define VL vector<long long>
#define VC vector<char>
#define VF vector<float>
#define PB push_back
#define F first
#define S second
#define fa(i,skill) for(auto i : skill)
#define fr(i,skill) for(VI :: reverse_iterator i = skill.rbegin(); i != skill.rend(); i++)
#define PI pair<int,int>
#define mi map<int,int>
#define mci map<char,int>
#define all(x) x.begin(),x.end()
#define MAX 1000000001
using namespace std;

///////////////////////Engine Check.......////////////////////////////
void edit(VI &skill,int n)
{
    f(i,0,n)
        {
            int x;
            cin >> x;
            skill.PB(x);
        }
}
void editl(VL &skill,ll n)
{
    fl(i,0,n)
        {
            ll x;
            cin >> x;
            skill.PB(x);
        }
}

void achilles()
{
    int n,m;cin >> n >> m;
    VP p(m);
    f(i,0,m)
    {
        cin >> p[i].F >> p[i].S;

    }
    int k;cin >> k;
    VP q(k);
    f(i,0,k)
    {
        cin >> q[i].F >> q[i].S;
    }
    int x = 1;
    f(i,0,k) x *= 2;
    VI ans;
    f(j,0,x)
    {
        string  u = bitset<16>(j).to_string();
        string s = "";
        fd(i,15,15-k)
        s += u[i];
        set<int> sss;
        f(i,0,k)
        {
            if(s[i]=='0')sss.insert(q[i].F);
            else sss.insert(q[i].S);
        }
        int y =0;
        f(i,0,m)
        {
            if(sss.count(p[i].F) && sss.count(p[i].S))y++;
        }
        ans.PB(y);
    }

    cout << *max_element(all(ans)) << "\n";
}

///////////////////////3....2....1...Ignition////////////////////////////

int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    //freopen("out.txt","w",stdin);
    /*int t;cin >>t ;
    while(t--)*/
    {achilles();}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
ll power(ll base, ll exp)
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll powerm(ll base,ll exp,ll mod)
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
/*{{ x | (1 << k) sets the kth bit of x to one
x & ~(1 << k) sets the kth bit of x to zero
x ^ (1 << k) inverts the kth bit of x.
x & (x-1) sets the last one bit of x to zero
x & -x sets all the one bits to zero, except for the last one bit.
x | (x-1) inverts all the bits after the last one bit.}} SOME BIT MANIPULATION*/
//__builtin_clz(x): the number of zeros at the beginning of the number
//__builtin_ctz(x): the number of zeros at the end of the number
//__builtin_popcount(x): the number of ones in the number
//__builtin_parity(x): the parity (even or odd) of the number of ones
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const
	{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
/*//DSU
int parent[200005];
int rankr[200005];
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rankr[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rankr[a] < rankr[b])
            swap(a, b);
        parent[b] = a;
        if (rankr[a] == rankr[b])
            rankr[a]++;
    }
} */
vector<vector<ll>>arr,v;
unordered_map<ll,ll>mp;
ll solve(ll idx)
{
	if(idx == arr.size())
	{
		ll res = 0;
		for(ll i = 0; i < v.size(); i++)
		{
			ll a = v[i][0]; ll b = v[i][1];
			if(mp[a] > 0 && mp[b] > 0)
			{
				res++;
			}
		}
		return res;
	}
	mp[arr[idx][0]]++;
	ll c1 = solve(idx+1);
	mp[arr[idx][0]]--;
	mp[arr[idx][1]]++;
	ll c2 = solve(idx+1);
	mp[arr[idx][1]]--;
	ll ans = max(c1,c2);
	return ans;
}
int main()
{
    fast;
   	ll n,m; cin>>n>>m;
   	for(ll i = 0; i < m; i++)
   	{
   		ll x,y; cin>>x>>y; x--; y--;
   		v.push_back({x,y});
	}
	ll res = 0; ll k; cin>>k;
	for(ll i = 0; i < k; i++)
	{
		ll x,y; cin>>x>>y; x--; y--;
		arr.push_back({x,y});
	}
	cout << solve(0) << endl;
	return 0;
}


#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

//const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

ll MOD;
ll N,K;

void Add(ll &a, ll b){
    a=(a+b)%MOD;
    return;
}

void Pro(ll &a, ll b){
    a=(a*b)%MOD;
    return;
}

const ll MAXN1=1100000;
const ll MAXN=MAXN1/2;
ll d[101][MAXN];
ll Max[101];

int main(){
    cin>>N>>K>>MOD;
    d[0][0]=1;
    REP(i,1,N+1) Max[i]=Max[i-1]+(K*i);
    REP(i,1,N+1) {
       // cout<<i<<"::"<<Max[i]<<"|";
        rep(j,min(Max[i],Max[N-i])+1) {
            ll XX=Max[i]-j;
            if(XX<j) d[i][j]=d[i][XX];
            else{
                rep(k,K+1) {
                    if(j>=k*i) Add(d[i][j],d[i-1][j-k*i]);
                    else break;
                }
            }
           // cout<<d[i][j]<<' ';
        }
       // cout<<endl;
    }
    //cout<<N<<endl;
    vec ans(N+1,0);
    REP(i,1,N+1){
        ll XX=N+1-i;
        if(ans[XX]) ans[i]=ans[XX];
        else{
            ll a=i-1, b=N-i;
            ll X=min(Max[a],Max[b])+1;
            rep(j,X) Add(ans[i],(d[a][j]*d[b][j])%MOD);
        }
    }
    REP(i,1,N+1) ans[i]=(ans[i]*(1+K)-1)%MOD;
    REP(i,1,N+1) cout<<ans[i]<<endl;

}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define endl '\n'
#define br cout<<endl
#define mem(a) memset(a,0,sizeof(a))
const double pi=3.141592653589793238;
#define d(x) cout<<x<<endl;
#define de(x) cout<<#x<<" "<<x<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define rev(a) reverse(a.begin(),a.end())
//const int inf = 100000000000000000;
#define maxn 1000005
int mod = (int)(1e9 + 7);
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(),x.end()
//#define f(i,n) for(int i=1;i<=n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i+=1)
#define fn(i,k,n) for(int i=k;i>=n;i-=1)
void pv(vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<endl;}
void pa(int a[],int n,int p){for (int i = p; i < n+p; ++i){cout<<a[i]<<" ";}cout<<endl;}
int modexp(int x,int y) {
   int res = 1;
   x = x % mod;
   while (y > 0){
       if (y & 1LL)
           res = (res*x) % mod;
       y = y>>1;
       x = (x*x) % mod;
   }
   return res;
}
int invmod(int a) {
    return modexp(a,mod-2);
}
// vector<int> edge[maxn];
// void ipgraph(int n,int m) {
//     fp(i,1,n) edge[i].clear();
//     if(m==0) return;
//    fp(i,1,m) {
//        int a,b;
//        cin>>a>>b;
//        edge[a].pb(b);
//        edge[b].pb(a);
//    }
// }
/*
void dfs(int node,int p)
{
    for(int u : edge[node])
    {
        if(u!=p)
        {
            dfs(u,node);
        }
    }
}
*/
//////////////////////////////////////////////////////////////////////////////////
void solve()
{
    int a[4];
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    fp(i,1,14)
    {
        bitset<4> bs(i);
        int t0 = 0,t1 = 0;
        fp(j,0,3)
        {
            if(bs[j]) t1+=a[j];
            else t0+=a[j];
        }
        if(t0==t1)
        {
            d("Yes")
            return ;
        }
    }
    d("No")
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    std::cout << std::setprecision(20);
   int t=1;
    //cin>>t;
   fp(i,1,t)
   {
       //cout<<"Case #"<<i<<": ";
       solve();
   }
}


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

ull large(ull b, ull c, ull mod) {
    ull ans = 1;
    for(ull i=0; i<c; i++) {
        ans = (ans*b)%mod;
    }
    return ans;
}
int main() {
    ull a,b,c;
    cin>>a>>b>>c;
    ull bc;
    if(b*c>10) {
        bc = large(b,c,4);
        if(bc==0) bc = 4;
    }
    else {
        bc = pow(b,c);
    }
    // cout<<bc<<endl;
    ull ans = large(a,bc,10);
    cout<<ans<<endl;
}

#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=200005,INF=1<<30;

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

int main(){

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

    ll A,B,C;cin>>A>>B>>C;
    if(B==1){
        cout<<rui(A,C,10)<<endl;
        return 0;

    }
    A%=10;
    vector<int> wh(10,-1);
    ll now=1;
    int s,t=0;
    for(;;t++){
        if(wh[now]!=-1){
            s=wh[now];
            break;
        }
        wh[now]=t;
        now*=A;
        now%=10;
    }

    now=1;
    for(int i=0;i<C;i++){
        now*=B;
        if(now>=s) break;
    }

    if(now<s){
        for(int i=0;i<10;i++){
            if(wh[i]==now){
                cout<<i<<endl;
                return 0;
            }
        }
    }

    B%=(t-s);

    ll X=rui(B,C,(t-s));

    for(int i=0;i<10;i++){
        if(wh[i]>=s&&wh[i]%(t-s)==X){
            cout<<i<<endl;
            return 0;
        }
    }

}


#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<climits>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<list>
#include<functional>

using namespace std;

#define MAX(A,B) ((A)>(B)?(A):(B))
#define MIN(A,B) ((A)<(B)?(A):(B))
#define LP(I,S,G) for (long long int I = S; I < G; I++)
#define IN(X) 	for (int i = 0; i < X.size(); i++)cin >> X[i]
#define OUT(X) 	for (int i = 0; i < X.size(); i++)out << X[i]
#define SORT(X) sort(X.begin(), X.end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto X = Y.begin(); X != Y.end(); X++)

template<class I1, class I2>
istream& operator>>(istream& s, pair<I1, I2>& in) {
	s >> in.first >> in.second;
	return s;
}

long long int M = pow(10, 9) + 7;

bool comp(pair<int, int>& a, pair<int, int>& b) {
	return (a.second < b.second);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main(void) {
	long long int n, p;
	cin >> n>>p;
	if (p == 2) {
		cout << (n==1);
		return 0;
	}
	long long int ans = p - 1;
	ans = (ans*modpow(p - 2, n - 1, M)) % M;
	cout << ans;
	return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
#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 9223372036854775807
#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);
    }
};

ll fastExponentiation(ll base,ll exp,ll mod){
    if(exp==0)  return 1;
    else if(exp==1) return base%mod;
    else{
        ll r = fastExponentiation(base,exp/2,mod);
        if(exp%2==0){
            return ( (r%mod) * (r%mod) )%mod;
        }else{
            return ( ( ( (r%mod)*(r%mod) )%mod ) * (base%mod)  )%mod;
        }
    }
}

void solve() {
    cinll(n);cinll(p);
    if(n==1 && p==2) {
        cout<<1;
        return;
    }
    if(p==3) {
        cout<<2;
        return;
    }
    cout<< (((p-1) % MOD) * (fastExponentiation(p-2,n-1,MOD) % MOD))%MOD;
}

int main(){
    fio;
///////////////////////////////////////////
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
///////////////////////////////////////////
    // cinll(t);
    // while(t--) {
        solve();
    // }
  return 0;
}


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <iomanip>
#include <chrono>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
#define L __int128
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
#define sz 1
ll F[sz],R[sz];
void make(){
	F[0] = 1;
	for(int i=1;i<sz;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<sz;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	if(b < 0 || a < b) return 0;
	return F[a]*R[b]%mod*R[a-b]%mod;
}
void solve(){
	unordered_set<int>ex;
	int n, m;
	cin >> n >> m;
	map<int, vc<int>>M;
	set<P>black;

	rep(i, m){
		int x,y; cin >> x >> y;
		M[x].pb(y);
		black.insert(mp(x, y));
	}
	ex.insert(n);
	for(auto at:M){
		vc<int>v = at.b;
		vc<int>zan;
		for(auto k:v){
			for(int a=k-1;a<=k+1;a++){
				if(ex.find(a) != ex.end()){
					zan.pb(a);
					ex.erase(ex.find(a));
				}
			}
		}
		for(auto a:zan){
			if(black.find(mp(at.a, a)) == black.end()) ex.insert(a);
			if(black.find(mp(at.a, a-1)) != black.end()) ex.insert(a-1);
			if(black.find(mp(at.a, a+1)) != black.end()) ex.insert(a+1);
		}
	}
	o(ex.size());
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

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

    int n, m;
    cin >> n >> m;
    vector<pii> p(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i].fi >> p[i].se;
    }
    sort(all(p), [&](pii a, pii b) {
        if (a.fi == b.fi) {
            return abs(a.se - n) >= abs(b.se - n);
        } else {
            return a.fi < b.fi;
        }
    });
    if (m == 0) {
        cout << 1 << endl;
        return 0;
    }

    // m > 0
    vector<vector<pii>> query(1);
    int last = p[0].fi;
    for (int i = 0; i < m; ++i) {
        if (p[i].fi == last) {
            query.back().push_back(p[i]);
        } else {
            vector<pii> v = {p[i]};
            query.push_back(v);
            last = p[i].fi;
        }
    }

    int size = 500000;
    int geta = 250000;
    vector<int> num(size, 0);
    num[geta] = 1;

    for (auto v : query) {
        set<int> st = {};
        for (auto q : v) {
            int c = q.se - n + geta;
            if (c - 1 < 0 || c + 2 > size) {
                continue;
            }
            if (num[c] > 0 && num[c - 1] + num[c + 1] == 0) {
                st.insert(c);
            }
        }

        set<int> st2 = {};
        for (auto q : v) {
            int c = q.se - n + geta;
            if (c - 1 < 0 || c + 2 > size) {
                continue;
            }
            if (num[c - 1] + num[c + 1] >= 1) {
                st2.insert(c);
            }
        }

        for (auto c : st2) {
            num[c] = 1;
        }

        for (auto c : st) {
            num[c] = 0;
        }
    }

    int res = 0;
    for (int i = 0; i < size; ++i) {
        if (num[i] > 0) {
            res++;
        }
    }
    cout << res << endl;
}


//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 2e5 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl;
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int32_t main() {
    boost; IO();

    int N;
    cin>>N;
    vi x(N,0),y(N,0);
    FOR(i,0,N){
    	if(i%2==0) cin>>x[i];
    	else cin>>y[i];

    	if(i) x[i]+=x[i-1],y[i]+=y[i-1];
    }

    FOR(i,0,N) x[i]=x[i]-y[i];

    unordered_map<int,int>mp;
    mp[0]=1;
    int ans=0;
    FOR(i,0,N){
    	ans+=mp[x[i]];
    	mp[x[i]]++;
    }
    cout << ans << endl;

    return 0;
}
//Change your approach

/*  Namo Buddhaya */

#include <bits/stdc++.h>

using namespace std;

#define nl "\n"
#define sp " "
#define PI 2 * acos(0)
#define mem(arr, value) memset(arr, value, sizeof(arr))
#define eps 1e-6
#define ll long long
//Predefined Function
ll gcd(ll a, ll b) { if (a % b == 0) return b; return gcd(b, a % b);}
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

//Function

//Main Function
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    //Start
    int i, j;
    int n;
    cin >> n;

    vector <int> dj(n);

    for(auto &x: dj)
    {
        cin >> x;
    }
    ll ans = 1LL << 32;
    for(i = 0; i < (1 << (n-1)); i++)
    {
        ll x = 0;
        ll o = 0;
        for(j = 0; j <= n; j++)
        {
            if(j < n) o = o | dj[j];
            if(j==n || (i >> j & 1))
            {
                x = x ^ o;
                o = 0;
            }
        }
        ans = min(ans,x);
    }

    cout << ans << nl;

    return 0;
}


#include <cassert>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <time.h>
#include <chrono>
#include <random>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#define UI unsigned int
#define LL long long
#define ll long long
#define GT(it,v) for(auto it:v)
#define FU(i,a,b) for(int i=(a);i<(b);i++)
#define FD(i,a,b) for(int i=(a);i>(b);i--)
#define LD long double
#define PI 3.1415926535897932384626
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VLL vector<long long >
#define VVLL vector<vector<long long > >
#define VPLL vector<pair<long long, long long>>
#define VVPLL vector<vector<pair<long long, long long>>>
#define VD vector<double>
#define VVD vector<vector<double> >
#define VPD vector<pair<double,double> >
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define SORT(v) std::sort(v.begin(),v.end())
#define GSORT(v,T) sort(v.begin(),v.end(),greater<T>)
#define UNIQUE(v) decltype(v.begin()) it = unique(v.begin(),v.end()); v.resize(distance(v.begin(),it))
using namespace std;
LL inp, Inp; LL i1, i2, i3, i4, i5, i6, i7, i8;
LL MOD = 998244353, MOD1 = (LL)1e9 + 7, MOD2 = (LL)1e9 + 9; long long MOD3 = (long long)1e9 + 21 /*33*/;  double eps = 1e-9;
LL TMP = (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD + MOD) % MOD;
auto STTMP = chrono::steady_clock::now();//auto ENTMP = chrono::steady_clock::now();
//ELTIME = double(chrono::duration_cast<chrono::milliseconds>(ENTMP - STTMP).count());
//time_t result = time(NULL); char SS[26]; ctime_s(SS, sizeof SS, &result);
//transform(SS, SS + 26, SS, [](char ch) {return ch == ' ' ? '_' : ch; }); printf("%s", SS);;
vector<vector<int>> G;
vector<int> vis, minD, maxN, neis;

int main() {
    ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(20);
    srand((unsigned int)TMP);
    int N, K; cin >> N >> K;
    G.resize(N, vector<int>());
    for (int i = 0; i < N - 1; i++){
        cin >> i1 >> i2; i1--, i2--;
        G.at(i1).push_back(i2);
        G.at(i2).push_back(i1);
    }

    int low = 1, up = N;
    while (low < up) {
        int mid = (low + up) / 2;
        int use = 0;
        LL vcnt = 0;
        vis.assign(N, 0);
        minD.assign(N, 1e9);
        maxN.assign(N, -1e9);
        neis.assign(N, 0);
        for (int i = 0; i < N; i++) {
            neis.at(i) = G.at(i).size();
        }
        queue<int> leafs;
        for (int i = 0; i < N; i++) {
            if (neis.at(i) <= 1) {
                leafs.push(i);
                neis.at(i)++;
                maxN.at(i) = 0;
            }
        }
        while (!leafs.empty()) {
            int leaf = leafs.front(); leafs.pop();
            neis.at(leaf)--;
            if (!vis.at(leaf) && neis.at(leaf) <= 1) { // leaf
                vis.at(leaf) = 1; vcnt++;
                if (maxN.at(leaf) + minD.at(leaf) <= mid) {
                    maxN.at(leaf) = minD.at(leaf) - mid - 1;
                }
                else if(maxN.at(leaf) >= mid || vcnt == N){
                    minD.at(leaf) = 0, maxN.at(leaf) = -mid - 1; use++;
                }
                for (auto nei : G.at(leaf)) {
                    minD.at(nei) = min(minD.at(nei), minD.at(leaf) + 1);
                    maxN.at(nei) = max(maxN.at(nei), maxN.at(leaf) + 1);
                    leafs.push(nei);
                }
            }
        }
        if (use > K) {
            low = mid + 1;
        }
        else {
            up = mid;
        }
    }
    cout << low << "\n";

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 2e18;
const ll fact_table = 1200008;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
// priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue<P, vector<P>, greater<P>> pqps;
// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout << x << endl;
#define el cout << endl;
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/
bool icpc = false;
bool multicase = false;

ll n, k;
ll dist = 0, cnt = 0;

vec G[500005];

P dfs(int v, int p) {
    // first  : 一番近い黒までの距離
    // second : 一番遠い白までの距離
    ll black = INF, white = 0;

    for (auto nv : G[v]) {
        if (nv == p) continue;
        auto [b, w] = dfs(nv, v);
        b++;
        w++;
        black = min(black, b);
        white = max(white, w);
    }

    if (white + black <= dist) {
        white = -1;
    }
    if (white == dist) {
        cnt++;
        white = -1, black = 0;
    }
    if (p == -1 && white >= 0) {
        cnt++;
    }
    return P(black, white);
}

int calc(ll mid) {
    dist = mid;
    cnt = 0;
    P res = dfs(1, -1);
    return cnt;
}

bool solve() {
    cin >> n >> k;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }

    ll ok = n, ng = -1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (calc(mid) <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    p(ok);
    return true;
}

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

    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        solve();
        testcase++;
    }

    // solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pii pair<int,int>
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,w;
    cin>>n>>w;
    ll pw[(int)2e5+20]={0};
    rep(i,0,n)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        pw[x]+=z;
        pw[y]-=z;
    }
    bool f=1;
    if(pw[0]>w) f=0;
    rep(i,1,(int)2e5+20)
    {
        pw[i]+=pw[i-1];
        if(pw[i]>w)
        {
            f=0;
            break;
        }
    }
    f?cout<<"Yes":cout<<"No";
}

/**
  *  Author: dhruv_gheewala
  *  Problem: B - Many Oranges
  *  Date:   13.03.2021
  *  Time:   18:43:19
**/

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

#ifndef DEBUG

#define fundri 108
#define debug(...) 1729
#define endl '\n'

#endif

#define int int64_t

typedef pair<int, int> pii;
typedef vector<int> vi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

template<typename T>
bool in_range(T x, T l, T r) {return l <= x && x <= r;}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.first >> a.second; return in;}

// Multi-Dimension Vector
// Usage: vec<n, data-type> dp(dimention-1, dimention-2, ..., dimention-n, default = data-type())
template<int D, typename T> struct vec : public vector<vec<D - 1, T>>
{
    static_assert(D >= 1, "Vector dimensions must be greater than zero !!");
    template<typename... Args>
    vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)){}
};

template<typename T> struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val){}};

const int inf = 1e15;
const bool testcases = false;

void preprocess();
void solve(int tc);
int32_t main(int32_t argc, char **argv)
{
    preprocess();
    int TC = 1;
    if(testcases)
        cin >> TC;

    for(int tc = 1; tc <= TC; ++tc) {
        solve(tc);
        fundri;
    }
    exit(0);
}

void preprocess()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

void solve(int tc)
{
    int a, b, w;
    cin >> a >> b >> w;
    w *= 1000;

    int mini = inf, maxi = -inf;
    for(int i = 1; i <= w; i++) {
        if(in_range(w, i * a, i * b)) {
            mini = min(mini, i);
            maxi = max(maxi, i);
        }
    }

    if(mini == inf) {
        cout << "UNSATISFIABLE" << endl;
        return;
    }

    cout << mini << ' ' << maxi << endl;
}


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

typedef long long LL;
typedef pair<int, int> P;

const int maxn = 200 + 10;
const int M_MAX = 10;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;
const double eps = 1e-6;

int n;
int arr[maxn];
vector<int> ans[300];

void out(vector<int> &t) {
    cout << t.size();
    for(auto i : t) {
        cout << " " << i;
    }
    cout << endl;
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
    int cnt = min(n, 8);
    for(int i = 0; i < 1 << cnt; i++) {
        LL sum = 0;
        vector<int> s;
        for(int j = 0; j < cnt; j++) {
            if(1 << j & i) {
                s.emplace_back(j + 1);
                sum += arr[j];
            }
        }
        sum %= 200;
        if(!ans[sum].empty()) {
            cout << "YES\n";
            out(ans[sum]);
            out(s);
            return ;
        }
        else {
            ans[sum] = s;
        }
    }
    cout << "NO\n";
}

int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ld long double
using namespace std;

const int N = 205;

int n, dp[N][N][N][2][2], a[N];
vector<int> b, c;

int add(int a, int b){
    return (a + b) % 200;
}

int solve(int idx, int m1, int m2, int t, int t2){
    if(idx == n){
        return m1 == m2 && t && t2;
    }
    if(dp[idx][m1][m2][t][t2] != -1) return dp[idx][m1][m2][t][t2];

    int op1 = solve(idx + 1, m1, m2, t, t2);
    int op2 = solve(idx + 1, add(m1, a[idx]), m2, 1, t2);
    int op3 = solve(idx + 1, m1, add(m2, a[idx]), t, 1);

    return dp[idx][m1][m2][t][t2] = (op1 | op2 | op3);
}

void build(int idx, int m1, int m2, int t, int t2){
    if(idx == n){
        return;
    }
    int op1 = solve(idx + 1, m1, m2, t, t2);
    int op2 = solve(idx + 1, add(m1, a[idx]), m2, 1, t2);
    int op3 = solve(idx + 1, m1, add(m2, a[idx]), t, 1);
    if(op1){
        build(idx + 1, m1, m2, t, t2);
    }
    else if(op2){
        b.push_back(idx + 1);
        build(idx + 1, add(m1, a[idx]), m2, 1, t2);
    }
    else {
        c.push_back(idx + 1);
        build(idx + 1, m1, add(m2, a[idx]), t, 1);
    }

}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    memset(dp, -1, sizeof dp);
    if(solve(0, 0, 0, 0, 0)){
        cout << "Yes" << '\n';
        build(0, 0, 0, 0, 0);
        cout << (int) b.size() << ' ';
        for(auto i: b){
            cout << i << ' ';
        }
        cout << '\n';
        cout << (int) c.size() << ' ';
        for(auto i: c) cout << i << ' ';
    }
    else cout << "No";

    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vecctor<ll>>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9+7;

int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll t;
    cin >> t;
    rep(i,t){
        ll n,a,b;
        cin >> n >> a >> b;
        if(a+b > n){
            cout << 0 << endl;
            continue;
        }
        ll ans = 1;
        ll x = ((n-a-b+2)%mod)*((n-a-b+1)%mod)%mod;
        ans *= x;
        ans = ans*(n-a+1)%mod;
        ans = ans *(n-b+1)%mod;
        ans = ans*2%mod;
        ans -= x*x%mod;
        ans = (ans +mod)%mod;
        cout << ans << endl;

    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define io ios::sync_with_stdio(false); cin.tie(0)

struct edge { int to; ll cost; };

struct graph{
    int V;
    vector<vector<edge>> G;
    vector<ll> path;

    graph(int n): V(n) {
        G.resize(V);
        path.resize(V);
        fill(path.begin(), path.end(), -1);
    }

    void add_edge(int s, int t, ll cost) {
        edge e;
        e.to = t; e.cost = cost;
        G[s].push_back(e);
    }

    // Compute the shortest path starting from s using Dijkstra algorithm
    int dijkstra(int s) {
        priority_queue<P, vector<P>, greater<P>> que; // min-heap of (cost, vertex)
        for (auto e : G[s]) {
            que.emplace(e.cost, e.to);
        }
        while (que.size()) {
            P p = que.top(); que.pop();
            int c = p.first, v = p.second;
            if (v == s) return c;
            if (path[v] < s) {
                path[v] = s;
                for (auto e : G[v]) {
                    que.emplace(c + e.cost, e.to);
                }
            }
        }
        return -1;
    }
};

int main()
{
    io;
    int n, m;
    cin >> n >> m;
    graph g(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a, b, c);
    }
    rep(i, n) {
        cout << g.dijkstra(i) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

class UnionFind{
    public:
        ll size;
        vll v;

        UnionFind(ll n){
            this->v = vll(n);
            rep(i, n) this->v[i] = i;
        }

        ll root(ll n){
            if(n!=v[n]) return v[n] = root(v[n]);
            return n;
        }

        void unite(ll l, ll r){
            ll lroot = root(l);
            ll rroot = root(r);
            if(lroot!=rroot) this->v[rroot] = lroot;
        }
};

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

    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    UnionFind uf(H+W);
    uf.unite(0, H-1);
    uf.unite(H-1, H);
    uf.unite(H, H+W-1);
    rep(h, H) rep(w, W){
        if(S[h][w]=='#') uf.unite(h, H+w);
    }
    unordered_set<ll> sh, sw;
    rep(i, H) sh.insert(uf.root(i));
    rep(i, W) sw.insert(uf.root(H+i));
    ll t = min(sh.size(), sw.size());
    cout << t-1 << endl;
}

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

int main() {
  int N,M,P;
  cin >> N >> M;
  P=N+M;
  vector<int> A(P);
  for (int i=0;i<P;i++) {
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  for (int i=0;i<P;i++) {
     if (i==0) {
       int a,b;
       a=A.at(0);
       b=A.at(1);
       if (a!=b) {
         cout << A.at(0) << " ";
       }
     }
    else if ((i>0)&&(i<P-1)) {
      int a,b,c;
      a=A.at(i-1);
      b=A.at(i);
      c=A.at(i+1);
      if ((a!=b)&&(b!=c)) {
        cout << A.at(i) << " ";
      }
    }
    else if (i==P-1) {
      int b,c;
      b=A.at(P-2);
      c=A.at(P-1);
      if (b!=c) {
        cout << A.at(P-1) << " ";
      }
    }
  }
}


#include <bits/stdc++.h>
using namespace std;using ll=long long;
using vl=vector<ll>;using vi=vector<int>;
using vs=vector<string>;using vc=vector<char>;
using vvl=vector<vl>;using pl=pair<ll,ll>;
using vvc=vector<vc>;using vd=vector<double>;
using vpl=vector<pl>;using vb=vector<bool>;
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<(n)<<endl
#define all(n) n.begin(),n.end()
#define sortp(d) sort(all(d)) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
/*-----------順列生成-----------------
do
{
}while(next_permutation(all(A)));
*/
//'A'65,'a'97
//cout<<fixed<<setprecision(9)<<;
ll gcd(ll a,ll b) {if(b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll modpow(ll a,ll n,ll mod) {ll res=1;while(n>0)
{if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;}
ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);}

ll p=0,q=0,r=0;
ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll inf=1000000000000; //10^12:∞
ll mod=1000000007; //10^9+7:合同式の法
struct edge{ll to,cost;};
const double pi = acos(-1);

int main()
{
  ll n;cin>>n;
  vpl a(pow(2,n));
  rep(i,pow(2,n)){ll x;cin>>x;a[i]={x,i+1};}
  p=pow(2,n-1);
  rep(i,n-1)
  {
    rep(j,p)
    {
      a[j]=max(a[2*j],a[2*j+1]);

    }
    p/=2;
  }
  if(a[0]>a[1])print(a[1].second);
  else print(a[0].second);
}

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <functional>
#include <cstdlib>
#include <list>
#include <iomanip>
#define ll long long
#define MOD 1000000007
#define MAX 1000005
using namespace std;

int main() {

	int N;
	cin >> N;
	vector<pair<int, string>> v;

	for (int i = 0; i < N; i++) {
		string name;
		int height;
		cin >> name >> height;
		v.push_back({ height,name });
	}

	sort(v.begin(), v.end());

	cout << v[v.size() - 2].second << endl;
}