#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
typedef pair<int, int> P;
int k, a[100000], dist[100000];
vector<int> v[100000];
vector<P> w;
bool b[100000];
void cal(int x, int y){
    dist[x] = y;
    b[x] = false;
    w.push_back(P(y, x));
    for(int i=0;i<v[x].size();i++){
        cal(v[x][i], y+1);
    }
}
int hin(int x, int y){
    if(b[x])return 0;
    b[x] = true;
    if(x == 0 || (a[x] == 0 && y == k-1))return 0;
    if(y == k-1)return 1;
    return hin(a[x], y+1);
}
int main() {
    int n, ans = 0;
    cin >> n >> k >> a[0];
    if(--a[0] != 0)ans++;
    for(int i=1;i<n;i++){
        cin >> a[i];
        v[--a[i]].push_back(i);
    }
    cal(0, 0);
    sort(w.begin(), w.end(), greater<P>());
    for(int i=0;i<w.size();i++){
        int p = w[i].second;
        if(!b[p]){
            ans += hin(p, 0);
        }
    }
    cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define N 100000
#define pb push_back

int n, k, len, a[N + 5], d[N + 5], vis[N + 5], ans;
vector<int> G[N + 5];

struct Cmp {
	bool operator () (const int &a, const int &b) const {
		return d[a] < d[b];
	}
};
priority_queue<int, vector<int>, Cmp> pq;

void dfs1(int u) {
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		d[v] = d[u] + 1;
		dfs1(v);
	}
}

void dfs2(int u) {
	len++;
	if (u == 1)
		return ;
	dfs2(a[u]);
}

void mark(int u) {
	vis[u] = 1;
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		if (vis[v])
			continue;
		mark(v);
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	dfs2(a[1]);
	for (int i = 2; i <= n; ++i)
		G[a[i]].pb(i);
	dfs1(1);
	bool flag = 1;
	for (int i = 1; i <= n; ++i)
		if (d[i] > k || (k - d[i]) % len) {
			flag = 0;
			break;
		}
	if (flag)
		ans = 0;
	else {
		if (a[1] != 1) ans = 1;
		else ans = 0;
		a[1] = 1;
		for (int i = 2; i <= n; ++i)
			pq.push(i);
		while (!pq.empty()) {
			int u = pq.top(), v; pq.pop();
			if (d[u] <= k || vis[u])
				continue;
			ans++;
			v = u;
			for (int i = 1; i <= k - 1; ++i)
				v = a[v];
			a[v] = 1;
//			printf("u:%d v:%d\n", u, v);
			mark(v);
		}
	}
	printf("%d\n", ans);
//	for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
//	printf("\n");
	return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n;
    while(cin>>n){
        if(!n) break;
        int a[n];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        int mx=-99999999;
        for(int i=0; i<n; i++){
            int sum=0;
            for(int j=i; j<n; j++){
                if(mx < sum+a[j]) mx = sum+a[j];
                sum += a[j];
            }

        }
        cout << mx << endl;
    }

    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <complex>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_PRIME = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  for (;;) {
    int n;
    vi v;

    cin >> n;
    if (!n)
      break;

    while (n--) {
      int tmp;
      cin >> tmp;
      v.pb(tmp);
    }

    vi w(v);
    for (int i = 1; i < sz(v); i++) {
      v[i] = max(v[i-1] + v[i], v[i]);
    }
    cout << *max_element(all(v)) << endl;
  }
  return 0;
}


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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

void solve(int n) {
    VS names(n);
    VI ps(n);
    VI ts1(n);
    VI ts2(n);
    VI fs(n);
    VI ss(n);
    VI ms(n);

    rep(i, n) {
        cin >> names[i] >> ps[i];
        VI as(5);
        rep(j, 5) cin >> as[j];
        ts1[i] = accumulate(ALL(as), 0);
        ts2[i] = as[3] + as[4];
        cin >> fs[i] >> ss[i] >> ms[i];
    }

    VD scores(n);
    rep(i, n) {
        scores[i] = 1. * (fs[i] * ms[i] * ss[i] - ps[i]) / (ts1[i] + (ms[i] - 1) * ts2[i]);
    }

    vector<pair<double, string>> xs(n);
    rep(i, n) xs[i] = MP(scores[i], names[i]);
    sort(ALL(xs), [](pair<double, string> a, pair<double, string> b){
            if (abs(a.fst - b.fst) > EPS) return a.fst > b.fst;
            return a.snd < b.snd;
    });

    for (auto x : xs) cout << x.snd << endl;
    cout << "#" << endl;

}

int main(void) {
    int n;
    while (cin >> n, n) solve(n);

    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n!=0){
		int p,a,b,c,d,e,f,s,m;
		string l;
		vector<pair<double,string> > vpii;
		for(int i = 0; i < n; i++){
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int time = a+b+c+d+e;
			for(int j = 1; j < m; j++)
				time+=d+e;
			int income=-p;
			for(int j = 0; j < m; j++)
				income+=s*f;
			double rate=(double)income/time;
			vpii.push_back(make_pair(-rate,l));
		}
		sort(vpii.begin(),vpii.end());
		for(int i = 0; i < vpii.size(); i++){
			cout<<vpii[i].second<<endl;
		}
		cout<<"#"<<endl;
	}

	return 0;
}


#include<cstdio>
#include<cctype>
#include<unordered_map>
#include<vector>
#include<queue>
using namespace std;
const int N=1e5,M=2e5,P=N+2*M,inf=0x3f3f3f3f;
typedef pair<int,int> pii;
int n,m,tot;
vector<pii>e[P+1];
int dis[P+1];
int read()
{
	int ret=0;
	char c=getchar();
	while(!isdigit(c)) {
		c=getchar();
	}
	while(isdigit(c)) {
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
int get_number(int p,int c)
{
	static unordered_map<long long,int>mp;
	long long has=(long long)p<<32|c;
	if(!mp[has]) {
		mp[has]=++tot;
	}
	return mp[has];
}
void dijkstra()
{
	static bool vis[P+1];
	static priority_queue<pii,vector<pii>,greater<pii>>que;
	fill(dis+1,dis+tot+1,inf);
	que.push(pii{dis[1]=0,1});
	while(!que.empty()) {
		int u=que.top().second;
		que.pop();
		if(vis[u]) {
			continue;
		}
		vis[u]=true;
		for(pii e:e[u]) {
			int v=e.first;
			if(dis[u]+e.second<dis[v]) {
				que.push(pii{dis[v]=dis[u]+e.second,v});
			}
		}
	}
	return;
}
int main()
{
	n=read(),m=read();
	tot=n;
	for(int i=1,u,v,c;i<=m;++i) {
		u=read(),v=read(),c=read();
		int uc=get_number(u,c),vc=get_number(v,c);
		e[u].push_back(pii{uc,1}),e[uc].push_back(pii{u,1});
		e[v].push_back(pii{vc,1}),e[vc].push_back(pii{v,1});
		e[uc].push_back(pii{vc,0}),e[vc].push_back(pii{uc,0});
	}
	dijkstra();
	printf("%d\n",dis[n]==inf?-1:dis[n]/2);
	return 0;
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

typedef tuple<int, int, int> triple;

int n, m;
map<pii, vector<triple>> g;
map<pii, ll> dist;

int main()
{
  cin >> n >> m;
  rep(i, m){
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;

    g[mp(p, c)].pb(mt(q, c, 0));
    g[mp(q, c)].pb(mt(p, c, 0));
    g[mp(p, c)].pb(mt(q, -1, 0));
    g[mp(q, c)].pb(mt(p, -1, 0));
    g[mp(p, -1)].pb(mt(q, c, 1));
    g[mp(q, -1)].pb(mt(p, c, 1));

    dist[mp(p, c)] = linf;
    dist[mp(q, c)] = linf;
    dist[mp(p, -1)] = linf;
    dist[mp(q, -1)] = linf;
  }

  rep(i, n) dist[mp(i, -1)] = linf;

  priority_queue<triple, vector<triple>, greater<triple>> que;
  que.push(mt(0, 0, -1));
  dist[mp(0, -1)] = 0;

  while(!que.empty()){
    int d, v, c;
    tie(d, v, c) = que.top();
    que.pop();

    if(dist[mp(v, c)] < d) continue;
    for(auto e : g[mp(v, c)]){
      int to, cc, dd;
      tie(to, cc, dd) = e;
      if(dist[mp(to, cc)] > dist[mp(v, c)] + dd){
        dist[mp(to, cc)] = dist[mp(v, c)] + dd;
        que.push(mt(dist[mp(to, cc)], to, cc));
      }
    }
  }

  ll ans = dist[mp(n-1, -1)];
  if(ans == linf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const ll MOD = 1000000007;

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

	vector <ll> A(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
	}

	ll ans = 0;
	vector <ll> digZero(61);
	vector <ll> digOne(61);
	for (int ii = 0; ii < N; ++ii){
		ll keta = 0;
		ll val = 1;
		for (int jj = 0; jj < 61; ++jj){
			ll tmp = A[ii] & 1;
			if (tmp == 0){
				ans = (ans + val * digOne[keta]) % MOD;
				digZero[keta] = (digZero[keta] + 1) % MOD;
			} else {
				ans = (ans + val * digZero[keta]) % MOD;
				digOne[keta] = (digOne[keta] + 1) % MOD;
			}
			val = (val * 2) % MOD;
			keta++;
			A[ii] /= 2;
		}
	}

	cout << ans << "\n";

	return 0;
}

#include<cstdio>
typedef long long LL;
const int N=2003;
const int O=2*N;
int n,m,ans;
int dp[3*N][5*N];

inline LL Pow(LL x,int p) {
	if(p==0) return 1;
	if(!(p&1)) return Pow(x*x%m,p>>1);
	return x*Pow(x*x%m,p>>1)%m;
}
inline void Add(int &x,int y) {
	x+=y; if(x>=m) x-=m;
}
int main() {
	scanf("%d %d",&n,&m); n*=3;
	dp[0][O]=1;
	for(int s=0;s<=n;s++) {
		for(int D=-s/2;D<=s;D++) {
			int d=D+O;
			Add(dp[s+1][d+1],dp[s][d]);
			Add(dp[s+2][d-1],dp[s][d]*(s+1ll)%m);
			Add(dp[s+3][d],dp[s][d]*(s+1ll)%m*(s+2ll)%m);
		}
	}
	for(int i=0;i<=n;i+=3)
		Add(ans,dp[n][i+O]);
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

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

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e15;
static const ll mod = 1e9+7;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

struct MaxFlowCalculator {
	int max_flow(int s, int t, const vector<vector<pair<int, int>>>& g) {
		struct edge_ { int to, cap, rev; };
		vector<bool> used(g.size(), false);
		vector<vector<edge_>> G(g.size());
		for (int i = 0; i < g.size(); i++) for (int j = 0; j < g[i].size(); j++)
		{
			int from = i, to = g[i][j].second;
			int cap = g[i][j].first;
			G[from].push_back({ to, cap, (int)G[to].size() });
			G[to].push_back({ from, 0, (int)G[from].size() - 1 });
		}
		auto dfs = [&](auto&& f, int v, int t, int fl)->int {
			if (v == t) return fl;
			used[v] = true;
			rep(i, G[v].size()) {
				edge_& e = G[v][i];
					if (!used[e.to] && e.cap > 0) {
					int d = f(f, e.to, t, min(fl, e.cap));
					if (d > 0) {
						e.cap -= d;
						G[e.to][e.rev].cap += d;
						return d;
					}
				}
			}
			return 0;
		};
		int flow = 0;
		while (1) {
			used.assign(used.size(), false);
			int f = dfs(dfs, s, t, INT_MAX);
			if (f == 0) return flow;
			flow += f;
		}
	}
};

int main() {
	ll p, r, q;
	cin >> p >> r >> q;
	ll a1 = p + r;
	ll a2 = r + q;
	ll a3 = p + q;
	cout << min(a1, min(a2, a3)) << endl;
    return 0;
}

#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int p, q, r;
    cin >> p >> q >> r;
    cout << (min(p + q, min(q + r, r + p)));
}


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

int main(){
    ll n,r,k;
    cin>>n>>r;
    if(n>=10){
        k=0;
    }else{
        k=1000-100*n;
    }
    cout<<r+k;
}

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

int main(){

    int K,T;
    cin >> K >> T;
    int A[T];
    int mx = 0;
    for(int i = 0;i < T;i++){
        cin >> A[i];
        mx = max(mx,A[i]);
    }

    cout << max(0,mx-1-(K-mx))<<endl;
}


#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
vector<int> factor(int x) {
    vector<int> ret;
    int y = x;
    for (int i = 1; i * i <= y; i++) {
        if (y % i == 0) {
            ret.push_back(i);
            if (i * i != y) ret.push_back(y / i);
        }
    }
    return ret;
}
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) cin >> a[i];

    vector<int> cnt(N+1, 0);
    vector<int> ball;
    for (int i = N; i >= 1; i--) {
        if ((cnt[i] % 2) == a[i]) continue;
        ball.push_back(i);
        vector<int> factors = factor(i);
        for (int f : factors) cnt[f]++;
    }

    reverse(ball.begin(), ball.end());
    int M = ball.size();
    cout << M << '\n';
    for (int i = 0; i < ball.size(); i++) {
        if (i) cout << ' ';
        cout << ball[i];
    }
    cout << '\n';
}

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

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
  int n;
  int ans=0;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  vector<int>ball(n);
  for(int i=n-1;i>=0;i--){
    int p=i+1;
    int count=0;
    while(p<=n){
      if(ball[p-1])count++;
      p+=i+1;
    }
    ball[i]=abs((count%2)-a[i]);
    if(ball[i]) ans++;
  }
  cout<<ans<<endl;
  rep(i,n){
    if(ball[i])cout<<i+1<<endl;
  }
}


#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int n;
        scanf("%d",&n);
        vector<int>ar(n);
        for(auto&e:ar){
                scanf("%d",&e);
        }
        for(int i=n-1;i>0;i--){
                printf("%d ",ar[i]);
        }
        printf("%d\n",ar[0]);
        return 0;
}

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int MOD = 1000000007;

int main() {
	int mini = INT_MAX, maxi = INT_MIN; ll sum = 0;
	int n; cin >> n;
	while (n--) {
		int a; cin >> a;
		mini = min(mini, a);
		maxi = max(maxi, a);
		sum += a;
	}
	cout << mini << ' ' << maxi << ' ' << sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	char s[4]={};
	cin>>s;
	if(s[0]=='S'){
		if(s[1]=='U'){
			cout<<7<<endl;
		}else{
			cout<<1<<endl;
		}
	}else if(s[0]=='M'){
		cout<<6<<endl;
	}else if(s[0]=='W'){
		cout<<4<<endl;
	}else if(s[0]=='F'){
		cout<<2<<endl;
	}else if(s[0]=='T'){
		if(s[1]=='U'){
			cout<<5<<endl;
		}else{
			cout<<3<<endl;
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
int main()
{ string s;
long long d,sum=0,num;
cin>>s;
long long n=s.size();
for(int i=0 ; i<n ; i++){
     d = s[i] - '0';
    num = num * 10 + d;
sum+=d;
}
if(num%(sum)==0) cout<< "Yes"<<  endl;
if(num%(sum)!=0) cout<< "No"<<  endl;

return 0;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M,V,P;
  cin>>N>>M>>V>>P;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  sort(A.rbegin(),A.rend());
  int ok=0,ng=N;
  while(ng-ok>1){
    int n=(ok+ng)/2,m=0;
    for(int i=0;i<N;i++){
      if(i<P-1)m+=M;
      else if(i>=n)m+=M;
      else if(A[n]+M-A[i]>=0)m+=A[n]+M-A[i];
      else{
        ng=n;
        goto home;
      }
    }
    if(m>=M*V || n<P-1)ok=n;
    else ng=n;
    home:;
  }
  cout<<ok+1<<endl;
}

#include <bits/stdc++.h>

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0;
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

template <class T>
inline void put(T x)
{
	if (x > 9)
		put(x / 10);
	putchar(x % 10 + 48);
}

template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
template <class T>
inline void CkMin(T &x, T y) {x > y ? x = y : 0;}
template <class T>
inline T Max(T x, T y) {return x > y ? x : y;}
template <class T>
inline T Min(T x, T y) {return x < y ? x : y;}

typedef long long ll;
const int N = 1e5 + 5;
int a[N], n, m, V, P, ans;
ll sum[N];

int main()
{
	read(n); read(m); read(V); read(P);
	for (int i = 1; i <= n; ++i)
		read(a[i]);
	std::sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
		sum[i] = sum[i - 1] + a[i];
	for (int i = 1; i <= n; ++i)
	{
		int l = std::upper_bound(a + 1, a + n + 1, a[i]) - a,
			r = std::upper_bound(a + 1, a + n + 1, a[i] + m) - a - 1;
		if (l - 2 + n - r >= V - 1)
		{
			if (n - r + 1 <= P)
				++ans;
		}
		else
		{
			V -= l - 1 + n - r;
			int tl = 0, tr = r - l + 1, res = -1;
			while (tl <= tr)
			{
				int mid = tl + tr >> 1;
				if (V <= mid || 1ll * (r - l + 1 - mid) * (a[i] + m) - (sum[r - mid] - sum[l - 1]) >= 1ll * (V - mid) * m)
					res = mid, tr = mid - 1;
				else
					tl = mid + 1;
			}
			if (~res)
			{
				if (n - r + 1 + res <= P)
					++ans;
			}
			V += l - 1 + n - r;
		}
	}
	put(ans), putchar('\n');

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while(n = getInt()){
    REP(i,n){
      int pm = getInt();
      int pe = getInt();
      int pj = getInt();

      int sum = pm + pe + pj;

      if((pm == 100 || pe == 100 || pj == 100) ||
	 (pm + pe >= 180) || (sum >= 240)){
	puts("A");
      }else if((sum >= 210) ||
	       (sum >= 150 && (pm >= 80 || pe >= 80))){
	puts("B");
      }else{
	puts("C");
      }
    }
  }
  return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, a, b, c;
	vector<char>l;
	while (true){
		cin >> n;
		if (n == 0){
			break;
		}
		else{
			for (int i = 0; i < n; i++){
				cin >> a >> b >> c;
				if (a == 100 || b == 100 || c == 100){
					l.push_back('A');
				}
				else if (a + b >= 180){
					l.push_back('A');
				}
				else if (a + b + c >= 240){
					l.push_back('A');
				}
				else if (a + b + c >= 210){
					l.push_back('B');
				}
				else if (a + b + c >= 150 && a >= 80){
					l.push_back('B');
				}
				else if (a + b + c >= 150 && b >= 80){
					l.push_back('B');
				}
				else l.push_back('C');
				a = 0;
				b = 0;
				c = 0;
			}
		}
	}
	for (int i = 0; i != l.size(); i++)
	{
		cout << l[i] << endl;
	}
}


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

int soredake(int point, int kazu, int bonasu, int goal) {
  int tokukazu = goal / point;
  if (goal % point > 0) {
    tokukazu++;
  }
  if (tokukazu > kazu) {
    tokukazu = kazu;
  }
  return tokukazu;
}

int search(vector<vector<int>> questions, int goal) {

  int minimum = 0;
  for (int i = 0; i < questions.size(); i++) {
    minimum += questions.at(i).at(1);
  }
  for (int i = 0; i < questions.size(); i++) {
    int point = questions.at(i).at(0);
    int kazu = questions.at(i).at(1);
    int bonasu = questions.at(i).at(2);
    int goukei = questions.at(i).at(3);

    vector<vector<int>> q = questions;
    q.erase(q.begin() + i);
    if (goukei < goal) {
      int nokori = search(q, goal - goukei) + kazu;
      if (nokori < minimum) {
        minimum = nokori;
      }
    } else {
      int nokori = soredake(point, kazu, bonasu, goal);
      if (nokori < minimum) {
        minimum = nokori;
      }
    }
  }
  return minimum;
}

int main() {
  int d, g;
  cin >> d >> g;

  vector<vector<int>> questions(d, vector<int>(4));
  for (int i = 0; i < d; i++) {
    questions.at(i).at(0) = 100 * (i + 1);
    cin >> questions.at(i).at(1);
    cin >> questions.at(i).at(2);
    questions.at(i).at(3) =
        questions.at(i).at(0) * questions.at(i).at(1) + questions.at(i).at(2);
  }

  cout << search(questions, g) << endl;
}

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

int main(){
  int d,g;cin >> d >> g;
  vector<int> p(10),c(10);
  rep(i,d) cin >> p[i] >> c[i];
  int ind = 0;
  int sum = 0;
  int ans = INF;
  int cnt = 0;
  rep(i,1<<d){
    sum = 0;
    cnt = 0;
    rep(j,d){
      if(i>>j&1) {
        sum += p[j]*(j+1)*100;
        sum += c[j];
        cnt += p[j];
      }else ind = j;
    }
    if(g-sum > (p[ind]-1)*(ind+1)*100) continue;
    cnt += max(g-sum + (ind+1)*100 -1,0)/((ind+1)*100);
    ans = min(ans,cnt);
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main(){
    int n;
    cin >> n;
    string ans = "AGC";
    if (n<1200) ans = "ABC";
    else if (n<2800) ans = "ARC";

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

/*
Author : Devil088
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define sep cout<<"\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";

inline string shift(string s){
	int n = s.length();
	string r = "";
	r+=s[n-1];
	for(int i=0;i<n-1;i++)r+=s[i];
	return r;
}

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

	if(n<1200){
		cout<<"ABC\n";
	}else if(n<2800){
		cout<<"ARC\n";
	}else cout<<"AGC\n";
}
/*
uday
adyu
7 46
45 6
*/


#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

const int MAX = 1000000001;

int main() {
    int n;
    cin >> n;
    map<ll, int> mp;
    string ans = "YES";
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        if(mp.count(tmp) == 0) {
            mp[tmp] = 1;
        } else {
            ans = "NO";
        }
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<int,int> a;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    a[p]++;
  }
  bool ok=true;
  for(auto x:a){
    if(x.second>=2)ok=false;
  }
  if(ok){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

typedef long long ll;
const int MAX=1e4+10;
const int mod=1e9+7;

void fun(int *cnt,int n){
    for(int i=2;i<=n;i++){
        while(n%i==0){
            cnt[i]++;
            n/=i;
        }
    }
}

ll solve(int n){
    int cnt[1001]={0};
    ll ans=1;
    for(int i=2;i<=n;i++){
        fun(cnt,i);
    }
    for(int i=2;i<=1000;i++){
        ans=ans*(cnt[i]+1)%mod;
    }
    return ans;
}

int main(){
    int n;
    while(cin>>n){
        cout<<solve(n)<<endl;
    }
    return 0;
}

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

int main(){
	long long n;
	long long ans = 1;
	cin >> n;

	vector<int>  fact(10000); //factor container

    for(int j = 2; j<=n;j++){

    long long num = j;

	for (int i = 2; i <= num; i++) {
		    while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			     fact.at(i)++; //割った個数を配列に足す
			    num /= i;
		    }
	}

    }

    for(int i = 0; i < 1003; i++){
            ans *= (fact.at(i) + 1);
            ans %= 1000000007;
    }

    cout << ans << endl;

}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

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

ll A, B;

int main() {
  std::cin >> A >> B;
  --A; --B;

  std::cout << (B+A-1)/A << endl;

  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
int main() {
    int A,B;
    cin >> A >> B;
    int ans;
    if( B==1){
        ans =0;
    }
    else{
        for(int i=1;i>0;i++){
            if((A-1)*(i-1)+A >= B){
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
}


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;

int main() {
	string str;
	int i;
	while(getline(cin, str)) {
		for(i = 0; i < 26; i++) {
			for(int j = 0; j < str.size(); j++) {
				if(str[j] != ' ' && str[j] != '.') {
					if(str[j] != 'a') {
						str[j] -= 1;
					} else str[j] = 'z';
				}
			}
			for(int j = 0; j < str.size() - 4; j++) {
				if(str[j] == 't' && str[j + 1] == 'h') {
					cout << str <<endl;
					i = 26;
					break;
					//if(str[j + 2] == 'e' ) {
						//cout << str <<endl;
						//i = 26;
						//break;
					//} else if(str[j + 2] == 'i' && str[j + 3] == 's'){
						//cout << str <<endl;
						//i = 26;
						//break;
					//} else if(str[j + 2] == 'a' && str[j + 3] == 't') {
						//cout << str <<endl;
						//i = 26;
						//break;
					//}
				}
			}

		}
	}

	return 0;
}

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

int main(){
	string sa;

	while(getline(cin,sa)){

		for(int j=0;j<26;j++){
			int a=sa.size();
		for(int i=0;i<a;i++){
			if(sa[i]>='a'&&sa[i]<='z'){
				sa[i]+=1;
				if(sa[i]>'z'){
					sa[i]-=26;
					}
				}
			}
			size_t z=sa.find("this");
			size_t za=sa.find("that");
			size_t zb=sa.find("the");
			if(z!=string::npos){break;}
			else if(za!=string::npos){break;}
			else if(zb!=string::npos){break;}
			}
			cout<<sa<<endl;

		}
		return 0;
	}


#include<bits/stdc++.h>
using namespace std;
int main()
{
      int n,t=0;
      cin>>n;
      int arr[2*n];
      priority_queue<int,vector<int>,greater<int>> q;
      for(int i=0;i<2*n;i++)
      {
            int k;
            cin>>k;
            q.push(k);
      }
      for(int i=0;i<n;i++)
      {
            int x=q.top();
            q.pop();
            int y=q.top();
            q.pop();
            t=t+min(x,y);
      }
      cout<<t;
}

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

int main() {

  int A;
  int B;

  cin >> A >> B;

  if (A > B) {
    exit (1);
  }

  if (A < 9999 || B > 100000) {
    exit (1);
  }

  int sum = 0;
  for (int i = A ; i <= B ; i++) {
    string k;
    k = to_string (i);

    int kl = (int)(k.length ());
    string k1 = k.substr (0, (kl - 1)/2);

    string k2 = k.substr ((kl - 1)/2 + 1, kl - 1);

    string k3;
    for (int j = (int)(k2.length ()) - 1 ; j > -1 ; j--) {
      k3 += k2[j];
    }

    // cout << k1 << " : " << k2 << " : " << k3 << endl;
    if (k1 == k3) {
       sum += 1;
    }
  }

  cout << sum << endl;

}


#include <iostream>
#include <vector>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>

using namespace std;

const int kInfinity = 0x3F3F3F3F;
const int kNil = -1;
const int kMaxV = 10010;

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
decltype(auto) Prim(vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num,
                 typename vector<Edge>::size_type root) {
  using size_type = typename vector<Edge>::size_type;
  using const_it = typename vector<Edge>::const_iterator;
  using w_type = typename Edge::w_type;

  bitset<kMaxV> bs;
  vector<vector<Edge>> adjacency(node_num, vector<Edge>());
  for (const auto & e: edges) {
    adjacency[e.u].push_back(e);
  }
  vector<w_type> key(node_num, kInfinity);
  vector<int> parent(node_num, kNil);
  key[root] = 0;

  using Pair = pair<size_type, w_type>;
  auto compare = [](const Pair & x, const Pair & y) {
    return y.second < x.second || (!(x.second < y.second) && y.first < x.first);
  };
  priority_queue<Pair, vector<Pair>, decltype(compare)> que(compare);
  que.emplace(root, 0);

  while (!que.empty()) {
    auto top_no = que.top().first;
    auto top_key = que.top().second;
    que.pop();
    bs.set(top_no);
    for (const auto & e: adjacency[top_no]) {
      if (!bs.test(e.v) && e.w < key[e.v]) {
        key[e.v] = e.w;
        parent[e.v] = e.u;
        que.emplace(e.v, e.w);
      }
    }
  }

  auto weight_sum = accumulate(key.begin(), key.end(), 0);
  return weight_sum;
}

int main(int argc, char const *argv[]) {
  vector<Edge<int>> edges;
  unsigned V, E, r;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    unsigned w;
    cin >> u >> v >> w;
    edges.emplace_back(u, v, w);
    edges.emplace_back(v, u, w);
  }
  cout << Prim(edges, V, 0) << endl;
  return 0;
}

//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 100000
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,s,n,m;
	for(;scanf("%d%d",&n,&m)>1;printf("%d\n",s)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i;
		sort(node,node+m);
		for(i=0;i<n;i++)parent[i]=i;
		for(s=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))s+=node[i].first;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}

/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  string s; cin >>s;
  int n = s.size();
  if (n == 2) cout <<s <<endl;
  else{
    reverse(all(s)); cout <<s <<endl;
  }
}


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

int main() {

    int n, l;
    cin >> n >> l;

    int r = n + l - 1;

    int eat;

    if (r <= 0) eat = r;
    else if (l >= 0) eat = l;
    else eat = 0;

    cout << (r + l) * (r- l + 1) / 2 - eat << endl;

    return 0;
}

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

int main() {
    int n, l; cin >> n >> l;
    int a[n];
    int sum0 = 0;
    rep(i, n){
        a[i] = i+l;
        sum0 += a[i];
    }
    int s = INF;
    bool minus = false;
    rep(i, n){
        if(s > abs(a[i])){
            if(a[i] < 0) minus = true;
            else minus = false;
            s = abs(a[i]);
        }
        s = min(s, abs(a[i]));
    }
    cout << (!minus? sum0-s: sum0+s) << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m, a[1000], b[1000];
vector<int> vec;
int cnt[1000010], cnt2[1000010];
int ans = 1;

signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = 1; i <= n * m; i++) {
		if (2 <= cnt[i]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 1; i <= n * m; i++) {
		cnt[i] += cnt[i - 1];
	}
	for (int j = 0; j < m; j++) {
		cin >> b[j];
		cnt2[b[j]]++;
	}
	for (int i = 1; i <= n * m; i++) {
		if (2 < cnt2[i]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 1; i <= n * m; i++) {
		cnt2[i] += cnt2[i - 1];
	}
	for (int i = n * m; i >= 1; i--) {
		if (cnt[i] - cnt[i - 1] && cnt2[i] - cnt2[i - 1])ans *= 1;
		else if (cnt[i] - cnt[i - 1]) {
			ans *= cnt2[n*m] - cnt2[i - 1];
			ans %= mod;
		}
		else if (cnt2[i] - cnt2[i - 1]) {
			ans *= cnt[n*m] - cnt[i - 1];
			ans %= mod;
		}
		else {
			ans *= (cnt[n*m] - cnt[i - 1])*(cnt2[n*m] - cnt2[i - 1]) - (n*m - i);
			ans %= mod;
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll v[55];

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> v[i];

    int m = min(n, k);

    ll ans = 0;

    rep(i, m+1){ // i個取り出す時を考える
        rep(l, i+1){
            vector<ll> tmp;
            rep(j, l) tmp.push_back(v[j]);
            int r = i - l;
            // cout << l << " " << r << endl;
            for(int j = n-1; j >= n - r; j--) tmp.push_back(v[j]);
            // rep(j, tmp.size()) cout << tmp[j] << " ";
            // cout << endl;

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

            int res = k - (l+r);
            ll s = 0;
            rep(j, tmp.size()){
                if (tmp[j] < 0 && res > 0){
                    res--;
                }
                else s += tmp[j];
            }
            ans = max(s, ans);
        }
    }

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<bitset>
#define MN 100
#define ull unsigned long long
#define F(a,b,c,d) ((a>b||c>d)?ans:f[num[a][b]][num2[c][d]])
#define N 65535
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
char st[MN+5][MN+5];
int f[5505][5505],num[MN+5][MN+5],num2[MN+5][MN+5],n,m,ans,cnt[1<<16],s[MN+5][MN+5];
inline void R(int&x,int y){y>x?x=y:0;}
/*struct Bitset
{
    ull a,b;
    Bitset(){a=b=0;}
    Bitset(ull c,ull d):a(c),b(d){}
    void Mod(int y){y>=64?(b|=1ULL<<y-64):(a|=1ULL<<y);}
    Bitset operator & (const Bitset&c){return Bitset(a&c.a,b&c.b);}
    int Count(){return cnt[a&N]+cnt[a>>16&N]+cnt[a>>32&N]+cnt[a>>48&N]
                      +cnt[b&N]+cnt[b>>16&N]+cnt[b>>32&N]+cnt[b>>48&N];}
    Bitset operator << (int y){return y>=64?Bitset(0,a<<y-64):Bitset(a<<y,b<<y|(a>>64-y));}
};*/
bitset<105> lru[MN+5][MN+5],lrd[MN+5][MN+5],udl[MN+5][MN+5],udr[MN+5][MN+5],a[MN+5],b[MN+5];
inline int C(int u,int l,int d,int r){return s[d][r]-s[u-1][r]-s[d][l-1]+s[u-1][l-1];}
int main()
{
    for(int i=1;i<=N;++i) cnt[i]=cnt[i>>1]+(i&1);
    n=read();m=read();
    for(int i=1,k=0;i<=n;++i)for(int j=i;j<=n;++j)num[i][j]=++k;
    for(int i=1,k=0;i<=m;++i)for(int j=i;j<=m;++j)num2[i][j]=++k;
    for(int i=1;i<=n;++i) scanf("%s",st[i]+1);
    for(int i=1;i<=n;++i) for(int j=1;j<=m;++j)
    {
        if(st[i][j]=='o') a[i][j]=1,b[j][i]=1;
        s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(st[i][j]=='E');
    }
    for(int i=1;i<=m;++i) for(int j=1;j<=n;++j)
        for(int k=1;k<=i;++k)
        {
            if(C(1,k,n-j+1,m-(i-k))) lru[i][j][k]=1;
            if(C(j,k,n,m-(i-k)))     lrd[i][j][k]=1;
        }
    for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)
        for(int k=1;k<=i;++k)
        {
            if(C(k,1,n-(i-k),m-j+1)) udl[i][j][k]=1;
            if(C(k,j,n-(i-k),m))     udr[i][j][k]=1;
        }
    for(int i=1;i<=n;++i) for(int j=n;j>=i;--j)
        for(int k=1;k<=m;++k) for(int l=m;l>=k;--l)
        {
            int v=F(i,j,k,l);
            R(F(i+1,j,k,l),v+(a[i]&(lru[l-k+1][j-i+1]<<k-1)).count());
            R(F(i,j-1,k,l),v+(a[j]&(lrd[l-k+1][j-i+1]<<k-1)).count());
            R(F(i,j,k+1,l),v+(b[k]&(udl[j-i+1][l-k+1]<<i-1)).count());
            R(F(i,j,k,l-1),v+(b[l]&(udr[j-i+1][l-k+1]<<i-1)).count());
        }
    printf("%d\n",ans);
    return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int getsum(const vvi& sums,int t,int b,int l,int r)
{
	if(l>=r || t>=b) return 0;
	return sums[b][r]-sums[t][r]-sums[b][l]+sums[t][l];
}

void chmax(int& a,int b)
{
	a=max(a,b);
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];

		int ci=-1,cj=-1;
		rep(i,h) rep(j,w) if(grid[i][j]=='E') ci=i,cj=j;

		vvi sums(h+1,vi(w+1));
		rep(i,h) rep(j,w)
			sums[i+1][j+1]=(grid[i][j]=='o')+sums[i+1][j]+sums[i][j+1]-sums[i][j];

		int T=h-1-ci,B=ci,L=w-1-cj,R=cj;

		int dp[T+1][B+1][L+1][R+1]={};
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1){
			if(t!=T && ci+t+1<h-b)
				chmax(dp[t+1][b][l][r],dp[t][b][l][r]+getsum(sums,ci+(t+1),ci+(t+1)+1,max(cj-r,l),min(cj+l+1,w-r)));
			if(b!=B && t<=ci-(b+1))
				chmax(dp[t][b+1][l][r],dp[t][b][l][r]+getsum(sums,ci-(b+1),ci-(b+1)+1,max(cj-r,l),min(cj+l+1,w-r)));
			if(l!=L && cj+l+1<w-r)
				chmax(dp[t][b][l+1][r],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj+(l+1),cj+(l+1)+1));
			if(r!=R && l<=cj-(r+1))
				chmax(dp[t][b][l][r+1],dp[t][b][l][r]+getsum(sums,max(ci-b,t),min(ci+t+1,h-b),cj-(r+1),cj-(r+1)+1));
		}

		int res=0;
		rep(t,T+1) rep(b,B+1) rep(l,L+1) rep(r,R+1) chmax(res,dp[t][b][l][r]);
		cout<<res<<endl;
	}
}


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

int main(){
    int a,b;
    cin>>a>>b;
    int required = 1,extended = a;
    while(extended < b){
        required++;
        extended += a-1;
    }
    if(b == 1){
        cout<<0;
    }else{
        cout<<required;
    }
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
int const N = 1e6+5;
int const mod = 1e9+7;
using namespace std;

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll counter=0;
void prime_fuct(ll x){
    for (ll i = 2; i * i <= x; i++){
        if(x%i==0){
            while (x % i == 0){
                x /= i;
            }
            counter++;
        }
    }
    if(x != 1){
            counter++;
    }
    cout<<counter+1;
}

void solve(){
	ll a,b;
    cin>>a>>b;
    prime_fuct(gcd(a,b));
}

int main()
{
  int t;
	t=1;
     while(t--)
    {

		solve();

    }
	return 0;
}


#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}

int main(){
  int A,B; cin>>A>>B;
  cout<<A-B+1;

}

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int N;
  int K;
  rd(N);
  rd(K);
  wt_L(N-K+1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// {
//   int N, K;
//   rd(N,K);
//   wt(N-K+1);
// }


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

  cin >> n;

  while(n != 0){

    int a[12][12] ={};

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

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",a[i][j]);
      }
      printf("\n");
    }

    cin >> n;
  }

  return (0);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

int n;
vector<ll> a;

const int MAX_COL = 63;
const int MAX_ROW = 100005;

struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

BitMatrix mat(100005, 61);

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

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

    // cout << bitset<61>(1008288677408720767) << endl;

    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];

    rep(i, n) rep(j, 61) {
        if (a[i] & (1LL << j)) {
            mat[i][60 - j] = 1;
        } else mat[i][60 - j] = 0;
    }

    // rep(i, n) { rep(j, 60) cout << mat[i][j] << " "; cout << endl; }

    // たてのbit数える
    ll ans = 0;
    rep(j, 61) {
        int cnt = 0;
        rep(i, n) {
            // if (mat[i][j] & (1LL << (59 - j))) cnt++; // mat[i][j]は1, 0 -> 1LL << とかやばい
            if (mat[i][j] == 1) cnt++;
        }
        // cout << j << " " << cnt << endl;
        if (cnt % 2) {
            ans += (1LL << (60 - j));
            rep(i, n) mat[i][j] = 0;
        }
    }
    // cout << "ans " << ans << endl;
    // cout << endl; rep(i, n) { rep(j, 60) cout << mat[i][j] << " "; cout << endl; }

    GaussJordan(mat);
    // cout << endl; rep(i, n) { rep(j, 60) cout << mat[i][j] << " "; cout << endl; }

    // int r = 0;
    rep(j, 61) {
        int cnt = 0;
        rep(i, n) {
            if (mat[i][j] == 1) cnt++;
            /*
            if (mat[i][j] == 1 && r == i) {
                // cout << i << " " << j << " " << ans << endl;
                ans += (2LL << (59 - j));
                r++;
            }
             */
        }
        if (cnt % 2) ans += (2LL << (60 - j));
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

int n, a[3][MAXN], c[MAXN];
bool b[MAXN], r[2], s[2];

inline void Ast(bool x)
{
	if (!x)
		puts("No"), exit(0);
}

inline void Modify(int x)
{
	for (; x <= n; x += x & -x)
		b[x] ^= 1;
}

inline bool Query(int x)
{
	bool r = 0;
	for (; x; x -= x & -x)
		r ^= b[x];
	return r;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 0; i < 3; i ++)
		for (int j = 1; j <= n; j ++)
			a[i][j] = Read();
	for (int i = 1; i <= n; i ++)
		if (a[0][i] > a[1][i])
		{
			Ast(a[2][i] % 3 == 1);
			Ast(a[1][i] == a[2][i] + 1);
			Ast(a[0][i] == a[1][i] + 1);
			c[i] = a[2][i] / 3;
			Ast((c[i] ^ i) & 1);
			c[i] ++;
			r[i & 1] ^= 1;
		}
		else
		{
			Ast(a[0][i] % 3 == 1);
			Ast(a[1][i] == a[0][i] + 1);
			Ast(a[2][i] == a[1][i] + 1);
			c[i] = a[0][i] / 3;
			Ast((c[i] ^ i) & 1);
			c[i] ++;
		}
	for (int i = n - 1 + (n & 1); i > 0; i -= 2)
		s[1] ^= Query(c[i]), Modify(c[i]);
	mset(b, 0);
	for (int i = n - (n & 1); i > 0; i -= 2)
		s[0] ^= Query(c[i]), Modify(c[i]);
	Ast(s[0] == r[1] && s[1] == r[0]);
	return puts("Yes"), 0;
}

#include<bits/stdc++.h>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;

#define xx first
#define yy second

template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)

struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT}
I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;

const int N=100007;

int n,t[N][3],s[N];

int main()
{
	in,n;
	fo0(l,3)fo1(i,n)in,t[i][l];
	fo1(i,n)
	{
		int p=(t[i][0]-1)/3;
		//out,p,'\n';
		bool f1=1,f2=1;
		fo0(j,3)f1&=t[i][j]==p*3+j+1;
		fo0(j,3)f2&=t[i][j]==p*3+3-j;
		if((!f1&&!f2)||(~(i^p)&1))return puts("No"),0;
		s[i]=f1?p+1:-p-1;
	}
	//fo1(i,n)out,s[i],' ';out,'\n';
	int a[2]={0,0},b[2]={0,0};
	fo1(i,n)a[i&1]^=s[i]<0;
	fo1(i,n)while(abs(s[i])!=i)std::swap(s[i],s[abs(s[i])]),b[i&1]^=1;
	out,a[0]==b[1]&&a[1]==b[0]?"Yes":"No",'\n';
}


#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,u,v; cin >> n >> u >> v; u--; v--;
  vector<vector<ll>> G(n);
  rep(i,n-1){
    ll a,b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
  queue<ll> q;
  q.push(u);
  vector<ll> d_u(n, 100000000);
  d_u[u] = 0;
  while(!q.empty()){
    ll now = q.front(); q.pop();
    for(ll next:G[now]){
      if(d_u[next] !=  100000000) continue;
      d_u[next] = d_u[now] + 1;
      q.push(next);
    }
  }
  q.push(v);
  vector<ll> d_v(n, 100000000);
  d_v[v] = 0;;
  while(!q.empty()){
    ll now = q.front(); q.pop();
    for(ll next:G[now]){
      if(d_v[next] !=  100000000) continue;
      d_v[next] = d_v[now] + 1;
      q.push(next);
    }
  }
  ll ans = 0;
  rep(i,n){
    if(d_u[i] < d_v[i]) ans = max(ans,d_v[i]-1);
  }
  cout << ans;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
// #define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0,  0, -1, -1,  1, 1};
vector<ll> dy = { 0, 0, 1, -1, -1,  1, -1, 1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
/*
WeightedGraph<ll> g(V);
g[a].emplace_back(b, c);
*/
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void dijkstra(WeightedGraph< T > &g, vector< T > &dist, vector< T > &prev, vector< T > &num, int s) {
	T N = g.size();
	dist.resize(N, INF);
	prev.resize(N, -1); // 初期化
	num.resize(N, 0);
	using Pi = pair< T, int >;
	priority_queue< Pi, vector< Pi >, greater< Pi > > que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while(!que.empty()) {
	T cost;
	int idx;
	tie(cost, idx) = que.top();
	que.pop();
	if(dist[idx] < cost) continue;
	for(auto &e : g[idx]) {
		auto next_cost = cost + e.cost;
		if(dist[e.to] < next_cost) continue;
		if (dist[e.to] == next_cost) {
			num[e.to] += num[idx];
			num[e.to] %= MOD;
			continue;
		}
		dist[e.to] = next_cost;
		prev[e.to] = idx; // 頂点 v を通って e.to にたどり着いた
		num[e.to] = num[idx];
		que.emplace(dist[e.to], e.to);
	}
	}
	return;
}

/* get_path(prev, t)
	入力：dijkstra で得た prev, ゴール t
	出力： t への最短路のパス
*/
template< typename T >
vector<T> get_path(const vector<T> &prev, T t) {
	vector<T> path;
	for (T cur = t; cur != -1; cur = prev[cur]) {
		path.push_back(cur);
	}
	reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
	return path;
}

int main()
{
	ll N, u, v;
	cin >> N >> u >> v;
	u--; v--;
	if (N == 2) {
		PRINT(0);
		return 0;
	}
	WeightedGraph<ll> G(N);
	REP(i, N-1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b,1);
		G[b].emplace_back(a,1);
	}
	vector<ll> dist1, prev1, num1;
	dijkstra(G,dist1,prev1,num1,u);
	vector<ll> dist2, prev2, num2;
	dijkstra(G,dist2,prev2,num2,v);
	// REP(i, N) cout << dist1[i] << " ";
	// cout << endl;
	// REP(i, N) cout << dist2[i] << " ";
	// cout << endl;
	ll ma = 0;
	REP(i, N) {
		if (dist1[i] < dist2[i]) {
			ma = max(ma, dist2[i]);
		}
	}
	PRINT(ma-1);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
char s[maxn];
int op[maxn];
int main()
{
	int n;cin>>n;
	scanf("%s",s+1);
	if(s[1]=='W'){
		puts("0");
		return 0;
	}
	op[1] = 0;
	int cur = 1;
	ll ans = 1;
	for(int i=2;i<=2*n;i++){
		if(s[i]==s[i-1])op[i] = op[i-1]^1;
		else op[i] = op[i-1];
		if(op[i]==1){
			ans = ans*cur%mod;
			cur--;
		}
		else{
			cur++;
		}
//		cout<<"!"<<i<<" "<<cur<<endl;
		if(cur<0){
			puts("0");
			return 0;
		}
	}
//	cout<<"!"<<cur<<endl;
	if(cur){
		puts("0");
		return 0;
	}
	for(int i=1;i<=n;i++)ans = ans*i%mod;
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (1000*100)
#define MOD (ll(1E9+7))
int N;
string S;

int W,B;

ll kai[MAX_N+5];

ll kaijo(int n)
{
	DOUT<<"---- kaijo("<<n<<") ----"<<endl;
	if(kai[n]!=0) {
		return kai[n];
	}
	ll i=n;
	for(;i>=1; i--) {
		if (kai[i]!=0) {
			break;
		}
	}
	ll ret = kai[i];
	for(;i<n;i++) {
		DOUT<<"(i+1)* kai[i]=="<<((i+1)* kai[i])<<endl;
		kai[i+1] = ((i+1)* kai[i])%MOD;
	}
	return (kai[n])%MOD;
}

int main(int argc, char *argv[])
{
	kai[0]=1;
	kai[1]=1;
	ios::sync_with_stdio(false);
	cin >> N;
	cin >> S;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
		DOUT << "(2*N-n)%2=="<<(2*N-n)%2<<endl;
		if((2*N-n)%2==0) {
			if(S[n]=='B') { S[n]='W'; }
			else if(S[n]=='W') { S[n]='B'; }
		}
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
	}
	W=0;
	B=0;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<endl;
		if(S[n]=='B') { B++; }
		else if(S[n]=='W') { W++; }
	}
	if(B!=W) {
		cout << 0 << endl;
		return 0;
	}

	int count = 0;
	ll ans = 1;
	count = 0;
	FOR(n,2*N) {
		DOUT << "S["<<n<<"]=="<<S[n]<<", ans="<<ans<<", count=="<<count<<endl;
		if(S[n]=='B') {
			DOUT<<"ans*count="<<(ans*count)%MOD<<endl;
			ans = ans*count%MOD;
			count--;
		}
		else {
			count++;
		}
		DOUT << "ans=="<<ans<<", count=="<<count<<endl;
	}

	cout << ans*kaijo(N)%MOD << endl;

	DOUT << kaijo(1000*100) << endl;

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

const ll MOD=1000000007;

ll N;
ll A[100000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    ll cnt0=3;
    vector<ll> cnt(N,0);
    ll ans=1;
    rep(i,N){
        if(A[i]==0){
            ans*=cnt0;
            cnt0--;
        }else{
            ans*=cnt[A[i]-1];
            cnt[A[i]-1]--;
        }
        cnt[A[i]]++;
        ans%=MOD;
    }
    ans+=MOD;
    ans%=MOD;

    cout<<ans<<endl;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = (int) 1e9 + 7;

int mul(int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = (int) 3e5 + 5;
char tmp[maxn];
int n;
string s;

bool read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  s = tmp;
  n = sz(s);
  return true;
}

const int k = 9;
const int go[k][2] = {{1, 2}, {3, 4}, {5, 6}, {1, 1}, {1, 2}, {7, 2}, {8, 8}, {5, 5}, {6, 6}};
const int good = ((1 << 2) | (1 << 8));
int dp[k], ndp[k];

void solve() {
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    memset(ndp, 0, sizeof(ndp));
    for (int v = 0; v < k; v++) {
      auto cur = dp[v];
      if (!cur) {
        continue;
      }
      for (int c = 0; c < 2; c++) {
        if (s[i] == (char) ('0' + (c ^ 1))) {
          continue;
        }
        add(ndp[go[v][c]], cur);
      }
    }
    swap(dp, ndp);
  }
  int res = 0;
  for (int v = 0; v < k; v++) {
    if (good & (1 << v)) {
      add(res, dp[v]);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n); cin >> a;
    vector<ll> b(n, 0);
    ll m = 0;
    for(ll i = n-1; i >= 0; --i){
        if((i+1)*2 > n){
            b[i] = a[i];
        }else{
            ll sum = 0;
            for(ll j = i; j < n; j += (i+1)){
                sum += b[j];
            }
            if(sum%2 == 0 && a[i] == 1) b[i] = 1;
            if(sum%2 == 1 && a[i] == 0) b[i] = 1;
        }
        m += b[i];
    }
    cout << m << endl;
    rep(i, n){
        if(m == 0) continue;
        if(i > 0 && b[i-1]) cout << " ";
        if(b[i]) cout << i+1;
    }
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	int N; cin >> N;
	vector<int> a(N + 1);
	for(int i = 1; i <= N; i++) cin >> a[i];
	set<int> b;
	for(int i = N; i > 0; i--) {
		int sum = 0;
		for(int j = i + i; j <= N; j += i) {
			if(b.count(j)) sum++;
		}
		if(sum % 2 != a[i]) b.insert(i);
	}
	int M = b.size();
	int cnt = 0;
	cout << M << endl;
	for(auto p: b) {
		cnt++;
		if(cnt == b.size()) {
			cout << p << endl;
			return 0;
		}
		cout << p << " ";
	}
}


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

int main() {

  int saidai = 0;

  int N;
  cin >> N;

  vector<string> s(N);
  for (int i = 0; i < N; i++) {

    cin >> s.at(i);

  }
  int M;
  cin >> M;

  vector<string> t(M);
  for (int i = 0; i < M; i++) {

    cin >> t.at(i);

  }

  for (int i = 0; i < N; i++) {

    string a = s.at(i);
    int c = 0;

    for(int i = 0; i < N; i++) {

      if (a == s.at(i)) {

        c++;

      }

    }
    for(int i = 0; i < M; i++) {

      if (a == t.at(i)) {

        c--;

      }

    }
    if (saidai < c) {

      saidai = c;

    }

  }

  cout << saidai << endl;

}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M) cin >> A[i];
  vector<int> num = {0,2,5,5,4,5,6,3,7,6};
  vector<string> dp(N+1, "x");
  dp[0] = "";
  FOR(i, 1, N+1) {
    REP(j, M) {
      if(i-num[A[j]] >= 0) {
        if(dp[i-num[A[j]]] == "x") continue;
        if(dp[i] == "x" || dp[i-num[A[j]]].size() >= dp[i].size()) {
          dp[i] = dp[i-num[A[j]]] + (char)(A[j] + '0');
        } else if(dp[i-num[A[j]]].size() + 1 == dp[i].size()) {
          dp[i] = max(dp[i], dp[i-num[A[j]]] + (char)(A[j] + '0'));
        }
      }
    }
    //cout << dp[i] << endl;
  }
  cout << dp[N] << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n,flag=0,result=0;
    cin>>s;
    for(long int i=s.size()-1;i>=0;i--){
        n=s[i]-'0'+flag;
        if(n<(10-n) || (n==5 && s[i-1]<'5')){
            flag=0;
            result+=n;
        }
        else{
            flag=1;
            result+=(10-n);
        }
    }
    result+=flag;
    cout<<result;
}

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

typedef long long ll;

const int INF = 1e9 + 10;
const ll INFLL = 3e18;

int main(){

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

	int ans = 1;
	int n;
	cin >> n;

	for(int i = 1 ; i*i <= n ; i ++)
		ans = i*i;

	cout << ans << "\n";

	return 0;
}


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

struct node {
    int key;
    node *left, *right, *parent;
};
node *root, *NIL;

node* minimum(node *x) {
    while( x ->left != NIL ) x = x->left;
    return x;
}

node * successor( node *x ) {
    if( x->right != NIL ) return minimum(x->right);
    node *y = x->parent;
    while( y != NIL && x == y->right ) {
        x = y;
        y = y->parent;
    }
    return y;
}

void delete_node( node* z ) {
    node *y, *x;

    if( z->left == NIL || z->right == NIL ) y = z;
    else y = successor(z);
    if( y ->left != NIL ) x = y->left;
    else x = y->right;

    if( x != NIL ) x->parent = y ->parent;

    if( y->parent == NIL ) root = x;
    else
        if(y == y->parent->left) {
            y->parent->left = x;
        } else {
            y->parent->right = x;
        }

    if( y != z ) z->key = y->key;
}

void insert(int k) {
    node *y = NIL;
    node *x = root;
    node *z;

    z = (node *)malloc(sizeof(node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while( x != NIL ) {
        y = x;
        if( z->key < x->key ) x = x->left;
        else x = x->right;
    }
    z->parent = y;
    if( y == NIL ) root = z;
    else {
        if( z->key < y->key ) y->left = z;
        else y ->right = z;
    }
}

node* find(node *x, int key) {
    while( x != NIL && key != x->key) {
        if( key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    return x;
}

void preParse(node* u) {
    if(u == NIL) return;
    printf(" %d", u->key);
    preParse(u->left);
    preParse(u->right);
}

void inParse(node* u) {
    if(u == NIL) return;
    inParse(u->left);
    printf(" %d", u->key);
    inParse(u->right);
}

signed main() {
    ll n; scanf("%lld", &n);
    string com;
    for( ll i = 0; i < n; i++ ) {
        cin >> com;
        if( com.at(0) == 'i') {
            int x;
            scanf("%d", &x);
            insert(x);
        } else if( com.at(0) == 'f' ) {
            int x;
            scanf("%d", &x);
            node* t = find(root, x);
            if( t != NIL ) printf("yes\n");
            else printf("no\n");
        } else if( com.at(0) == 'd' ) {
            int x; scanf("%d", &x);
            delete_node(find(root, x));
        } else  {
            inParse(root);
            putchar('\n');
            preParse(root);
            putchar('\n');
        }
    }

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string tmp;
    int n;
    cin>>n;
    for (int i=0; i<n; i++) {
        getline(cin,tmp);
        while (tmp=="") getline(cin,tmp);
        while (tmp.find("Hoshino")!=string::npos) {
            tmp.replace(tmp.find("Hoshino"),7,"Hoshina");
        }
        cout<<tmp<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n;
  cin >> n;
  ll a=0;
  while(3*a<=n){
    a++;
  }
  cout << a-1 << endl;

}

#include<iostream>
using namespace std;
int main(){
  int a;
  cin>>a;

  cout<<a/3;

  return 0;
}


#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

    int m = max(h, w);
    cout << (n + m - 1) / m << endl;
    return 0;
}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

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

    int n, m;
    cin >> n >> m;
    if(n > m)
        swap(n, m);
    int k;
    cin >> k;
    int ans = 0;
    while(k > 0){
        k -= m;
        ans++;
    }
    cout << ans;
}


#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second

#define END puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

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

    //O(n^3) solution

    int n;
    cin>>n;
    lli a[n];
    f1(i,n) {
        cin>>a[i];
    }

    lli count=0;
    lli p,q,r;
    f1(i,n-2) {
        for(int j=i+1;j<n-1;++j) {
            for(int k=j+1;k<n;++k) {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]) {
                    p=a[i]+a[j];
                    q=a[j]+a[k];
                    r=a[k]+a[i];
                    if(p>a[k]&&q>a[i]&&r>a[j]) {
                        ++count;
                    }
                }
            }
        }
    }

    cout<<count<<endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stack>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, q, cnt = 0;
void search(int num, int memo[10001]){
	rep(i,n){
		if(memo[i]==num){
			cnt++;
			break;
		}
	}
}

int main(void){
	int memo[10001];
	fill_n(memo, 10001, 0);
	cin >> n;
	rep(i,n)cin >> memo[i];
	cin >> q;
	rep(i,q){
		int a;
		cin >> a;
		search(a,memo);
	}
	cout << cnt << endl;
	return 0;
}

int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (int i = 0; i < s.size(); i++) {
    	char ch = s[i];
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	if (n == 0) s = '0';
	while (n != 0) {
		if (n % 2 != 0) {
			n--;
			s = '1' + s;
		}
		else s = '0' + s;
		n /= -2;
	}
	cout << s << endl;
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string s;
    cin >> s;
    vi cnt(26);
    int n = sz(s);
    rep(i, n) cnt[s[i]-'a']++;
    rep(i, 26) {
        if (cnt[i] == 0) {
            cout << (char)(i+'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


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

/*int main(int argc, char **argv)
{
	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	std::cout << std::min(a, std::min(b, c)) + std::min(d, e) - 50 << std::endl;
	return 0;
}*/
/*int main()
{
	int l, a, b, c, d;
	std::cin >> l >> a >> b >> c >> d;
	int japa, math;
	japa = a / c;
	if(a % c != 0){
		japa++;
	}
	math = b / d;
	if(b % d != 0){
		math++;
	}
	std::cout << l - std::max(japa, math) << std::endl;
}*/
/*int main()
{
	bool sub[31];
	int input;
	for(int i = 0; i < 31; i++){
		sub[i] = false;
	}
	for(int i = 0; i < 28; i++){
		std::cin >> input;
		sub[input] = true;
	}
	for(int i = 1; i < 31; i++){
		if(!sub[i]) std::cout << i << std::endl;
	}
}*/
int main()
{
	std::vector<int> w, k;
	int input;
	for(int i = 0; i < 10; i++){
		std::cin >> input;
		w.push_back(input);
	}
	for(int i = 0; i < 10; i++){
		std::cin >> input;
		k.push_back(input);
	}
	std::sort(w.begin(),w.end(),std::greater<int>());
	std::sort(k.begin(),k.end(),std::greater<int>());
	std::cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << std::endl;
}

#include <cstdio>
#include <functional>
#include <algorithm>
using namespace std;

int p[10];

int main(){
	for(int i = 0; i < 2; i++){
		int ans = 0;
		for(int j = 0; j < 10; j++) scanf("%d", &p[j]);
		sort(p,p+10,greater<int>());
		for(int j = 0; j < 3; j++) ans += p[j];
		if(i == 0) printf("%d", ans);
		else printf(" %d\n", ans);
	}
}


/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;
#define MAXN 100000
int c[MAXN+10];
bool b[MAXN+10];
void solve(long long N, vector<vector<long long>> a){
	int r[2]={0,0},f[2]={0,0};
	for(int i=0; i<N; ++i) {
		c[i]=a[1][i]/3+1;
		if (c[i]%2==i%2) throw 2;
		if (a[0][i]==c[i]*3-2 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3) {
		} else if (a[0][i]==c[i]*3 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3-2) {
			r[(i+1)&1]^=1;
		} else {
			throw 1;
		}
	}
	memset(b,true,sizeof(b));
	for(int i=1; i<=N; ++i) {
		if (b[i]) {
			int x=c[i-1];
			while(x!=i) {
				debug(x);
				b[x]=false;
				f[i&1]^=1;
				x=c[x-1];
			}
		}
	}
	debug(f[0],f[1]);
	debug(r[0],r[1]);
	if (f[0]!=r[1] || f[1]!=r[0]) throw 3;
	puts("Yes");
}

int main(){
#ifdef WAAUTOMATON
	freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<vector<long long>> a(3-1+1,vector<long long>(N-1+1));
	for(int i = 0 ; i <= 3-1 ; i++){
		for(int j = 0 ; j <= N-1 ; j++){
			scanf("%lld",&a[i][j]);
		}
	}
	try {
		solve(N, a);
	} catch(int err) {
		puts("No");
		debug(err);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;

#define TT template<typename T>
#define TTF template<typename T, typename F>
#define ET(T) typename T::value_type
TT inline T sq(T x){return x*x;}
TT inline T In(){T x;cin>>x;return x;}
TT inline void Out(T&x){cout<<x;}
TT inline void sort(T&v){sort(begin(v),end(v));}
TT inline void revs(T&v){reverse(begin(v),end(v));}
TT inline void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT inline int ubnd(T&v,ET(T)&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT inline int lbnd(T&v,ET(T)&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF inline void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF inline void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
#undef TT
#undef TTF
#undef ET

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}

const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000;

struct Edge {
  int f, t, c;
  Edge(int f, int t, int c) : f(f), t(t), c(c) {}
  bool operator<(const Edge& e) const { return c != e.c ? c > e.c : (f != e.f ? f < e.f : t < e.t); }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int dijkstra(const Graph& g, int s, int t){
  int vis[128];
  fill(begin(vis), end(vis), 0);
  priority_queue<Edge> pq;
  for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
    Edge e = pq.top();
    if (vis[e.t]++) continue;
    if (e.t == t) return e.c;
    for (const auto& ee : g[e.t]){
      pq.push(Edge(e.f, ee.t, e.c + ee.c));
    }
  }
  return -1;
}

int main()
{
  int n, k;
  while (cin >> n >> k, n || k){
  Graph g(n + 1);
  for (int i = 0; i < k; i++){
    int t = in();
    if (t){
      int a, b, c;
      cin >> a >> b >> c;
      g[a].push_back(Edge(a, b, c));
      g[b].push_back(Edge(b, a, c));
    }
    else {
      int a, b;
      cin >> a >> b;
      cout << dijkstra(g, a, b) << endl;
    }
  }
  }
  return (0);
}

// priority_queue queue deque front stringstream max_element min_element insert count make_tuple

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

    int n, k;
    while (cin >> n && n) {
        cin >> k;
        int dist[105][105];
        fill_n(*dist, 105 * 105, inf);
        rep(i, 105) dist[i][i] = 0;

        while (k--) {
            int q;
            cin >> q;
            if (q == 0) {
                int a, b;
                cin >> a >> b;
                a--; b--;
                if (dist[a][b] != inf) cout << dist[a][b] << endl;
                else cout << -1 << endl;
            } else {
                int c, d, e;
                cin >> c >> d >> e;
                c--; d--;
                chmin(dist[c][d], e);
                chmin(dist[d][c], e);
                rep(k, n) rep(i, n) rep(j, n) {
                    if (dist[i][k] + dist[k][j] < dist[i][j]) dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=300+10;
const int MOD=998244353;
int n,a[N],dp[N][N*N],sum;

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]),sum+=a[i];

	dp[0][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<=sum;j++) {
			dp[i][j]=dp[i-1][j];
			if (j>=a[i]) dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]]*2)%MOD;
		}

	int ans=0;
	for (int i=0;i<=sum/2;i++) ans=(ans+dp[n][i])%MOD;

	if (sum%2==0) {
		memset(dp,0,sizeof(dp)); dp[0][0]=1;
		for (int i=1;i<=n;i++)
			for (int j=0;j<=sum;j++) {
				dp[i][j]=dp[i-1][j];
				if (j>=a[i]) dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%MOD;
			}
		ans=((ans-dp[n][sum/2])%MOD+MOD)%MOD;
	}
	ans=(ans*3)%MOD;

	int tmp=1;
	for (int i=1;i<=n;i++) tmp=(tmp*3)%MOD;
	cout<<((tmp-ans)%MOD+MOD)%MOD<<endl;
	return 0;
}

#include <bits/stdc++.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 305, P = 998244353;

int n, a[N], S, f[N * N];

int main() {
	read(n);
	int ans = 1;
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		ans = 3ll * ans % P;
		S += a[i];
	}
	f[0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = S; j >= a[i]; --j) {
			f[j] = (2ll * f[j] + f[j - a[i]]) % P;
		}
		for (int j = a[i] - 1; ~j; --j) {
			f[j] = 2ll * f[j] % P;
		}
	}
	for (int i = (S + 1) / 2; i <= S; ++i) {
		ans = (ans + 3ll * (P - f[i])) % P;
	}
	if (!(S & 1)) {
		for (int i = 0; i <= S; ++i) {
			f[i] = 0;
		}
		f[0] = 1;
		for (int i = 1; i <= n; ++i) {
			for (int j = S; j >= a[i]; --j) {
				f[j] = (f[j] + f[j - a[i]]) % P;
			}
		}
		ans = (ans + 3ll * f[S / 2]) % P;
	}
	print(ans);
}


#include <iostream>
//#include <vector>
#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL a;
    LL b;
    string s;
    bool is_ok=true;
    cin >> a >> b;
    cin >> s;
    if(a+b+1!=s.size()){
        is_ok=false;
    }else if(s[a]!='-'){
        is_ok=false;
    }else{
        for(LL i=0; i<a; i++){
            LL tmp=s[i]-'0';
            if(tmp<0 || tmp>9){
                is_ok=false;
            }
        }
        for(LL i=a+1; i<a+b+1; i++){
            LL tmp=s[i]-'0';
            if(tmp<0 || tmp>9){
                is_ok=false;
            }
        }
    }

    if(is_ok==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

#include <iostream>
#include <string>

using namespace std;

int main(){
  int A, B;
  string S;
  cin >> A >> B >> S;

  for (int i = 0; i < S.size(); i++){
    if (i==A){
      if (S[i]!='-'){
        printf("No\n");
        return 0;
      }
    }else if (S[i]-'0' > 9 || S[i]-'0' < 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
int n, m;
int main(){
	scanf("%d%d", &n, &m);
	rep(i,m) printf("%d %d\n", i+1, n-i-(~n&1 && n<=i*4+2));
}


#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int top;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return min(a.mn, a.top + b.mn) > min(b.mn, b.top + a.mn);
 ///return a.top - a.mn > b.top - b.mn;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
    }
    if (top >= 0) {
      a.push_back({top, mn});
    } else {
      b.push_back({top, mn});
    }
    sumtop += top;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.top;
  }
  cout << "Yes\n";
  return 0;
}

#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 998244353;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n) {
        cin >> d[i];
        if(i == 0 && d[i] != 0) {
            cout << 0 << endl;
            return 0;
        }
        else if(i != 0 && d[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    map<ll,ll> mp;
    rep(i, n) {
        ++mp[d[i]];
    }
    ll ans = 1;
    repl(i, 1, n) {
        ans *= mp[d[i]-1];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

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

    ll a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}

#include<iostream>

int main(void){
    int p, q, r;
    std::cin >> p >> q >> r;
    int ans;
    ans = std::min(p+q, p+r);
    ans = std::min(ans, q+r);
    std::cout << ans << std::endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	h2 -= h1;
	m2 -= m1;
	while(h2 > 0){
		m2 += 60;
		h2--;
	}
	cout << m2-k << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll>
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	ll ans=h2*60+m2-h1*60-m1-k;
	if(ans<0)
	cout<<0;
	else
	cout<<ans;
	return 0;
}