#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    vector<pii> X;
    rep(i, n) {
        int a;
        cin >> a;
        X.push_back({a, i});
    }
    auto compare = [](pii a, pii b) {
        if (a.fi > b.fi) return true;
        else if (a.fi == b.fi) return a.se < b.se;
        else return false;
    };
    sort(all(X), compare);
    vector<int> dp(n + 1, INF);
    rep(i, (int)X.size()) {
        int idx = X[i].se;
        *lower_bound(all(dp), idx) = idx;
    }
    int ans = 0;
    chmax(ans, (int)(lower_bound(all(dp), INF) - dp.begin()));
    cout << ans << endl;
}

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


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

const int N = 2e5 + 5, mod = 1e9 + 7;

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    int n, m, c = 0, x;
    map<int, ll> mp;
    mp[0]++;
    cin >> n >> m;
    while (n--)
        cin >> x,
        c += x,
        c %= m,
        mp[c]++;
    ll ans = 0;
    for (auto it: mp)
        ans += it.second * (it.second - 1) / 2;
    cout << ans;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
//組み合わせ nCr
vector<vector<ll>> nCr_v(5010, vector<ll>());
bool nCr_maekeisan = false;
void nCr_Calculater()
{
    for (int i = 0; i < 5010; i++)
    {
        nCr_v[i][0] = 1;
        nCr_v[i][i] = 1;
    }
    for (int k = 1; k < 5010; k++)
    {
        for (int j = 1; j < k; j++)
        {
            nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]);
        }
    }
}
ll nCr(ll n, ll r)
{
    if (n > 5010 || r > 5010)
    {
        cout << "ERROR! over range" << endl;
        return 0;
    }
    if (n < 0 || r < 0)
    {
        return 0;
    }
    else
    {
        if (nCr_maekeisan == false)
        {
            for (ll i = 0; i < 5010; i++)
            {
                nCr_v[i].resize(5010);
            }
            nCr_Calculater();
            nCr_maekeisan = true;
        }
        return nCr_v[n][r];
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a[n];
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    map<ll, ll> rensou;
    ll ruiseki[n + 1];
    ruiseki[0] = a[0] % m;
    rensou[ruiseki[0]]++;
    for (ll i = 0; i < n; i++)
    {
        ruiseki[i + 1] = ruiseki[i] + a[i];
        ruiseki[i + 1] %= m;
        rensou[ruiseki[i + 1]]++;
    }
    ll ans = 0;
    for (auto f : rensou)
    {
        ans += ((f.second) * (f.second - 1)) / 2;
    }
    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#define maxn 200010
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
inline long long min(long long a, long long b) {return a < b ? a : b;}
inline long long abs(long long a) {return a > 0 ? a : -a;}
int n, k, x, y;
int q, last;
long long V[maxn << 2][3], cov[maxn << 2];
void pushdown(int rt) {
    int lc = rt << 1, rc = rt << 1 | 1;
    long long &tmp = cov[rt];
    V[lc][0] += tmp;
    V[lc][1] += tmp;
    V[lc][2] += tmp;
    cov[lc] += tmp;
    V[rc][0] += tmp;
    V[rc][1] += tmp;
    V[rc][2] += tmp;
    cov[rc] += tmp;
    tmp = 0;
}
void update(int rt) {
    int lc = rt << 1, rc = rt << 1 | 1;
    V[rt][0] = min(V[lc][0], V[rc][0]);
    V[rt][1] = min(V[lc][1], V[rc][1]);
    V[rt][2] = min(V[lc][2], V[rc][2]);
}
void add(int rt, int l, int r, int p, long long num) {
    if (l == r) {
        V[rt][0] = num;
        V[rt][1] = num + l;
        V[rt][2] = num - l;
        return ;
    }
    if (cov[rt]) pushdown(rt);
    int mid = l + r >> 1;
    if (p <= mid) add(rt << 1, l, mid, p, num);
    else add(rt << 1 | 1, mid + 1, r, p, num);
    update(rt);
}
void add(long long num, int rt = 1) {
    V[rt][0] += num;
    V[rt][1] += num;
    V[rt][2] += num;
    cov[rt] += num;
}
long long ask(int rt, int l, int r, int L, int R, int op) {
    if (L <= l && R >= r) return V[rt][op];
    pushdown(rt);
    int mid = l + r >> 1;
    long long ans = inf;
    if (L <= mid) ans = ask(rt << 1, l, mid, L, R, op);
    if (R > mid) ans = min(ans, ask(rt << 1 | 1, mid + 1, r, L, R, op));
    return ans;
}
int main() {
    scanf("%d%d%d%d", &n, &k, &x, &y);
    scanf("%d", &q);
    memset(V, 0x3f, sizeof V);
    add(1, 1, n, x, abs(y - q));
    add(1, 1, n, y, abs(x - q));
    while (--k) {
        last = q; scanf("%d", &q);
        long long t0 = ask(1, 1, n, last, last, 0) + abs(q - last);
        long long t1 = ask(1, 1, n, q, n, 1) - q;
        long long t2 = ask(1, 1, n, 1, q, 2) + q;
        long long ans = min(t0, min(t1, t2));
        add(abs(q - last));
        add(1, 1, n, last, ans);
    }
    printf("%lld\n", V[1][0]);
    return 0;
}


/**
*    author:  souzai32
*    created: 02.08.2020 15:41:51
**/

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

int main() {

    long long int x,y;
    cin >> x >> y;

    long long int count=0;
    while(1){
        if(x==y) break;

        else if(x<y){
            if(abs(x)<abs(y)) {
                if(x>=0){
                    count+=y-x;
                    x+=y-x;
                }
                else{
                    count++;
                    x*=-1;
                }
            }
            else if(abs(x)==abs(y)){
                count++;
                x*=-1;
            }
            else{
                if(y>=0){
                    count+=abs(x)-y;
                    x+=abs(x)-y;
                }
                else{
                    count+=y-x;
                    x+=y-x;
                }
            }
        }
        else if(y<x){
            if(abs(x)>abs(y) || x<0){
                count++;
                x*=-1;
            }
            else if(abs(x)==abs(y)){
                count++;
                x*=-1;
            }
            else{
                count+=abs(y)-x;
                x+=abs(y)-x;
            }
        }
        //cout << x << ' ' << y << endl;
    }
    cout << count << endl;

    return 0;
}

#include <cstdio>

const long long mod=998244353ll;

const int MSIZE=4000000;

void ad(long long &a,long long b){a+=b;a%=mod;}
void mn(long long &a,long long b){a+=mod-b;a%=mod;}
void ml(long long &a,long long b){a*=b;a%=mod;}
long long sq(long long a){return a*a%mod;}
long long pw(long long a,long long n)
{
  return n==0?1ll:sq(pw(a,n/2))*(n%2==1?a:1ll)%mod;
}
long long iv(long long a){return pw(a,mod-2);}
long long inv[MSIZE],F[MSIZE],iF[MSIZE];

void prev(int N)
{
  inv[0]=0;
  inv[1]=1;
  for(int i=2;i<N;i++){
    inv[i]=(mod-mod/i)*inv[mod%i]%mod;
  }
  F[0]=iF[0]=1;
  for(int i=1;i<N;i++){
    F[i]=F[i-1]*i%mod;
    iF[i]=iF[i-1]*inv[i]%mod;
  }
}

long long Ch(int i,int j)
{
  return i<0||j<0||i<j?0:F[i]*iF[j]%mod*iF[i-j]%mod;
}

int main()
{
  int n,m;
  scanf("%d%d",&n,&m);
  prev(n+3*m);
  long long ans=Ch(3*m+n-1,n-1);
  mn(ans,n*Ch(m-1+n-1,n-1)%mod);
  for(int i=m+1;i<=3*m&&i<=n;i++){
    if((3*m-i)%2==0){
      mn(ans,Ch(n,i)*Ch((3*m-i)/2+n-1,n-1)%mod);
    }
  }
  printf("%lld\n",ans);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll n,S;
ll a[N],p[N],tag[N];
ll ans;
int main(){
	cin>>n>>S;
	for (int i=1;i<=n;i++)
		scanf("%lld%lld",&a[i],&p[i]);
	int l=1,r=n;
	while (a[l]<=S&&S<=a[r]){
		if (p[l]>=p[r]){
			if (!tag[l])ans+=a[r]-a[l],tag[l]=1;
			p[l]+=p[r];
			r--;
		}
		else {
			if (!tag[r])ans+=a[r]-a[l],tag[r]=1;
			p[r]+=p[l];
			l++;
		}
	}
	ans+=max(abs(S-a[l]),abs(S-a[r]));
	cout<<ans<<endl;
}

//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

const int MAXN = 1003;
int vis[MAXN];
int mark[MAXN], checkID;
vector<int> adjList[MAXN];
vector<int> inProgress;
bool ret;

bool check(int x) {
//    cout << x << endl;
    ++checkID;
    mark[x] = checkID;
    inProgress.push_back(x);
    for (int i = (int)inProgress.size() - 2; inProgress[i] != x; --i)
        mark[inProgress[i]] = checkID;
    int i;
    for (i = (int)inProgress.size() - 2; inProgress[i] != x; --i) {
        int u = inProgress[i];
        for (int v : adjList[u]) {
            if (mark[v] == checkID && v != inProgress[i + 1]) {
                inProgress.pop_back();
                return false;
            }
        }
    }
    for (int v : adjList[x]) {
        if (mark[v] == checkID && v != inProgress[i + 1]) {
            inProgress.pop_back();
            return false;
        }
    }
    return true;
}

void dfs(int u) {
    vis[u] = 1;
    inProgress.push_back(u);
    for (int v : adjList[u]) {
        if (vis[v] == 1) {
//            cout << v << endl;
            ret = check(v);
            if (ret)
                return;
        } else if (vis[v] == 0) {
            dfs(v);
            if (ret)
                return;
        }
    }
    inProgress.pop_back();
    vis[u] = 2;
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        adjList[u].push_back(v);
    }

    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            dfs(i);
            if (ret) {
                vector<int> ans;
                for (int i = (int)inProgress.size() - 2; inProgress[i] != inProgress.back(); --i)
                    ans.push_back(inProgress[i]);
                ans.push_back(inProgress.back());
                cout << ans.size() << '\n';
                reverse(ans.begin(), ans.end());
                for (int x : ans)
                    cout << x << '\n';
                return 0;
            }
        }
    }

    cout << -1 << '\n';

    return 0;
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;
}

int main() {
	int n, m, x, y; cin >> n >> m >> x >> y;
	int x_max = x;
	int y_min = y;
	for(int i=0;i<n;i++){
		int a; cin >> a;
		x_max = max(x_max, a);
	}
	for(int i=0;i<m;i++){
		 int b; cin >> b;
		 y_min = min(y_min, b);
	}
	if(x_max<y_min){
		cout << "No War" << endl;
		return 0;
	}
	cout << "War" << endl;
	return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> xs(n + 1), ys(m + 1);
  cin >> xs[0] >> ys[0];
  for (int i = 1; i <= n; ++i)
    cin >> xs[i];
  for (int i = 1; i <= m; ++i)
    cin >> ys[i];
  if (*max_element(xs.begin(), xs.end()) < *min_element(ys.begin(), ys.end()))
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}


#include<iostream>

int main(){
   int x;
   std::cin >> x;
   std::cout << x*x*x << "\n";
   return 0;
}

#include<iostream>
using namespace std;

int64_t cubic(const int64_t x) {
	return x*x*x;
}

void print(const int64_t x) {
	cout << x << endl;
}

int main() {
	int64_t x;
	cin >> x;

	//print x^3
	print(cubic(x));

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

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

signed main() {
    cin >> N >> M;
    vi a(N);
    cin >> a;
    sort(a.rbegin(), a.rend());
    REP(i, M)
    ans += a[i];
    cout << ans << endl;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{

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

    int minsofar = INT_MAX;
    int count = 0;
    for(int i = 0;i<n;i++)
    {
        minsofar = min(minsofar,v[i]);
        if(v[i] <= minsofar)
        {
            count++;
        }
    }

    cout<<count;

    return 0;
}


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

int main(){
    int a,b,c,p,q,r;
	cin >> a >> b >> c;
     p = a+b;
     q = a+c;
     r = b+c;
    if(p>=q){
        if(q >= r){
            cout << r;
        }else{
            cout << q;
        }
    }else{
        if(p >= r){
            cout << r;
        }else{
            cout << p;
        }
    }
}

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

int main(){
	vector<int> v(3);
	for(int &e : v) cin >> e;

	sort(v.begin(), v.end());
	cout << v[0] + v[1];

}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const double Pi = acos(-1.);
const int N = 110;
int n;
struct D{double x, y, f;} d[N], e[N];
double ans[N];

bool cmp(D a, D b) {return a.f < b.f;}

int main() {
	int i, j, m; D key;
	scanf("%d", &n);
	rep(i, 1, n) scanf("%lf%lf", &d[i].x, &d[i].y);
	rep(i, 1, n) {
		key = d[i];

		m = 0;
		rep(j, 1, n)
			if(i != j) {e[++m] = d[j]; e[m].f = atan2(e[m].y-key.y, e[m].x-key.x);}
		sort(e+1, e+m+1, cmp);
		rep(j, 1, m-1)
			if(e[j+1].f - e[j].f > Pi) ans[i] = (e[j+1].f - e[j].f - Pi) / Pi / 2.;
		if(e[1].f + Pi + Pi - e[m].f > Pi) ans[i] = (e[1].f + Pi - e[m].f) / Pi / 2.;
		printf("%.7lf\n", ans[i]);
	}
	return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int N;
    cin>>N;
    vector<pair<int, int> > red(N), blue(N);
    int a, b;
    rep(i, N){
        cin>>a>>b;
        red[i] = mp(a, b);
    }
    rep(i, N){
        cin>>a>>b;
        blue[i] = mp(a, b);
    }
    sort(red.begin(), red.end(), greater<pair<int, int> >());
    map<int, int> amap;
    int index;
    int tmp;
    int ans = 0;
    for(int i=0;i<N;++i){
        index = -1;
        tmp = -1;
        for(int j=0;j<N;++j){
            if((red[i].fi<blue[j].fi) && (red[i].se<blue[j].se)){
                if(((index==-1) || (tmp > blue[j].se)) && (amap[j]==0)){
                    index = j;
                    tmp = blue[j].se;
                }
            }
        }
        if(index != -1){
            amap[index]++;
            ans++;
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

#ifdef LOCAL
#include "/media/brayand/7801-B00D/debugger.h"
#else
template<typename... Args>
void db(Args... args){}
#endif

const int MOD = 1e9+7;

const int BAS = 331;

string A[30];
string rA[30];
string B[30];

const int MAXN = 2e5+100;

int mp[MAXN];
int val[MAXN];

int P[MAXN];

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

    P[0] = 1;
    for(int i = 1 ; i < MAXN ; i++)P[i] = P[i-1]*BAS%MOD;

    int N;
    cin >> N;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	for(int j = 0 ; j < 30 ; j++)
    	{
    		if(n&(1<<j))A[j] += "1", rA[j] += "0";
    		else A[j] += "0", rA[j] += "1";
    	}
    }

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	for(int j = 0 ; j < 30 ; j++)
    	{
    		if(n&(1<<j))B[j] += "1";
    		else B[j] += "0";
    	}
    }

    for(int i = 0 ; i < 30 ; i++)
    {
    	A[i] = A[i]+A[i];
    	rA[i] = rA[i]+rA[i];
    }

    vector<pair<int,int>> res[30];

    for(int i = 0 ; i < 30 ; i++)
    {
    	int ha1[A[i].size()+1];
    	int ha2[rA[i].size()+1];
    	int hhh = 0;

    	ha1[0] = 1;
    	ha2[0] = 1;

    	for(int x = 0 ; x < A[i].size() ; x++)
    	{
    		ha1[x+1] = (ha1[x]*BAS+A[i][x])%MOD;
    	}

    	for(int x = 0 ; x < rA[i].size() ; x++)
    	{
    		ha2[x+1] = (ha2[x]*BAS+rA[i][x])%MOD;
    	}

    	for(int x = 0 ; x < B[i].size() ; x++)
    	{
    		hhh = (hhh*BAS+B[i][x])%MOD;
    	}

    	for(int x = 0 ; x < N ; x++)
    	{
    		if((ha1[x+N]+MOD-ha1[x]*P[N]%MOD)%MOD == hhh)
    		{
    			res[i].push_back({x,0});
    		}
    	}

    	for(int x = 0 ; x < N ; x++)
    	{
    		if((ha2[x+N]+MOD-ha2[x]*P[N]%MOD)%MOD == hhh)
    		{
    			res[i].push_back({x,1});
    		}
    	}

    }

    for(int i = 0 ; i < 30 ; i++)
    {
    	for(auto x : res[i])
    	{
    		mp[x.first]++;
    		val[x.first] += (x.second)*(1ll<<i);
    	}
    }

    for(int i = 0 ; i < N ; i++)
    {
    	if(mp[i] == 30)
    	{
    		cout << i << " " << val[i] << '\n';
    	}
    }

    return 0;
}

#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

void solve(const vector<int>& A, const vector<int>& B, vector<int>& mask, int bit) {
  int n = A.size() - 1, m = B.size();
  vector<int> f(m);
  f[0] = 0;
  int k = 0;
  for (int i = 1; i < m; ++i) {
    for (; k > 0 && B[k] != B[i]; k = f[k - 1]);
    if (B[k] == B[i]) k++;
    f[i] = k;
  }
  k = 0;
  for (int i = 0; i < n; ++i) {
    for (; k > 0 && B[k] != A[i]; k = f[k - 1]);
    if (B[k] == A[i]) k++;
    if (k == m) {
      mask[i - m + 1] |= bit;
      k = f[k - 1];
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  vector<int> A(2 * n), B(n), mask(n);
  for (int k = 0; k < 30; ++k) {
    for (int i = 0; i < n; ++i) {
      A[i + n] = A[i] = (a[i] >> k) & 1;
    }
    for (int i = 0; i < n; ++i) B[i] = (b[i] >> k) & 1;
    solve(A, B, mask, 1 << k);
    for (int i = 0; i < n * 2; ++i) A[i] = 1 - A[i];
    solve(A, B, mask, 1 << k);
  }
  for (int i = 0; i < n; ++i) {
    if (mask[i] != (1 << 30) - 1) continue;
    printf("%d %d\n", i, a[i] ^ b[0]);
  }
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	double r, g,re;
	cin >> r >> g;
	re = 2 * g - r;
	cout<<re;

}

#include <iostream>
#include<cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
	double a, b;
	cin >> a >> b;
	cout << b - a + b;
}


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

struct Value {
	int depth, cost;
	Value() { }
	Value(int depth, int cost) {
		this->depth = depth;
		this->cost = cost;
	}
};

int n, k;
int a[100000];
vector<int> et[100000];

Value dfs(int p, int v) {
	Value ret(0, 0);

	for (int i = 0; i < et[v].size(); i++) {
		int nv = et[v][i];
		if (nv == p) continue;
		Value res = dfs(v, nv);
		ret.depth = max(ret.depth, res.depth + 1);
		ret.cost += res.cost;
	}

	if (ret.depth == k - 1 && p != 0) {
		ret.depth = -1;
		ret.cost++;
	}
	return ret;
}

int main() {
	int i;

	cin >> n >> k;
	rep(i, n) {
		cin >> a[i]; a[i]--;
		if (i != 0) {
			et[a[i]].push_back(i);
		}
	}

	int ans = dfs(0, 0).cost;
	if (a[0] != 0) ans++;
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T> T gcd(const T& a,const T& b){ return b==0?a:gcd(b,a%b); }

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int g=a[0];
	rep(i,n-1) g=gcd(g,a[i+1]);

	puts(k%g==0&&k<=*max_element(a.begin(),a.end())?"POSSIBLE":"IMPOSSIBLE");

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

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

	int number_of_instruction;
	cin >> number_of_instruction;

	for (int i = 0; i < number_of_instruction; ++i)
	{
		string instruction;
		int param1, param2;
		string temp_str = "";
		string replace_str = "";
		cin >> instruction >> param1 >> param2;

		if (instruction == "print")
		{
			for (int i = param1; i <= param2 ; ++i)
			{
				temp_str += str[i];
			}
			cout << temp_str << endl;
		}

		if(instruction == "reverse")
		{
			for (int i = 0; i < param1; ++i)
			{
				temp_str += str[i];
			}
			for (int i = param2; i >= param1; --i)
			{
				temp_str += str[i];
			}
			for (int i = param2+1; i < str.size(); ++i)
			{
				temp_str += str[i];
			}
			str = temp_str;
		}

		if(instruction == "replace")
		{
			string replace_str;
			cin >> replace_str;
			str.replace(param1, param2 - param1 + 1, replace_str);
		}

	}
}

#include <bits/stdc++.h>

int main() {

  char str[1024];
  char ope[256];
  char obj[1024];
  int q;
  int a, b;
  char temp;

  scanf("%s", str);
  scanf("%d", &q);

  for(int i = 0; i < q; ++i) {
    scanf("%s", ope);
    if( strcmp("replace", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      scanf("%s", obj);
      for(int j = a; j <= b; ++j) {
	str[j] = obj[j-a];
      }
    }
    else if( strcmp("reverse", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      for(int j = a; j <= (a+b)/2; ++j) {
	temp = str[j]; str[j] = str[a+b-j]; str[a+b-j] = temp;
      }
    }
    else if( strcmp("print", ope) == 0 ) {
      scanf("%d %d", &a, &b);
      for(int j = a; j <= b; ++j) {
	printf("%c", str[j]);
      }
      printf("\n");
    }
    else {
      printf("nya------\n");
    }

  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < int(vec.size()); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < int(table.size()); i++) {
        for (int j = 0; j < int(table.at(0).size()); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
vector<long long> divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;

    /*long long N;
    cin >> N;
    vector<long long> res = divisors(N);
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
void Yes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void YES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int n,cnt=0;
  cin >> n;
  string a,b,c;
  cin >> a >> b >> c;
  rep(i,0,n){
    if(a[i]==b[i]&&b[i]==c[i]){
      continue;
    }else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
      cnt+=2;
    }else{
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main(){
    ll l,r;cin>>l>>r;
    vector<int> vec;
    int ans=2020;
    for(int i=l;i<=min(r,l+2040)-1;i++){
        for(int j=i+1;j<=min(r,l+2040);j++){
            ans=min(ans,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int n,x,t;
    read(n),read(x),read(t);
    if(n%x==0) printf("%d\n",n/x*t);
    else printf("%d\n",(n/x+1)*t);
    return 0;
}


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

set<int> guest;
int n, m;
vector<int> people[501];
int main()
{
    while((cin >> n >> m) && n && m)
    {
        int a, b;
        int t;
        for(int i=0;i<m;i++)
        {
            cin >> a >> b;
            people[a].push_back(b);
            people[b].push_back(a);
        }
        for(int i=0;i<people[1].size();i++)
        {
            t = people[1][i];
            guest.insert(t);
            for(int j=0;j<people[t].size();j++) guest.insert(people[t][j]);
        }
        guest.insert(1);
        cout << guest.size()-1 << endl;
        guest.clear();
        for(int i=0;i<n;i++) people[i].clear();
    }
}

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

int n,m;
int g[500][500];

int main(){
	while(scanf("%d%d",&n,&m),n){
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++) g[i][j]=100000;
		for(int i=0;i<m;i++){
			int a,b;
			scanf("%d%d",&a,&b);
			g[a-1][b-1]=1;g[b-1][a-1]=1;
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				for(int k=0;k<n;k++) g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
		int res=0;
		for(int i=1;i<n;i++) if(g[0][i]<=2)res++;
		printf("%d\n",res);
	}
}


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

using namespace std;

class Dice
{
public:
    int label[6], tmp;

    void in()
    {
        rep(i, 6) scanf("%d", &label[i]);
    }

    void rollS()
    {
        tmp = label[0];
        label[0] = label[4];
        label[4] = label[5];
        label[5] = label[1];
        label[1] = tmp;
    }

    void rollN()
    {
        tmp = label[0];
        label[0] = label[1];
        label[1] = label[5];
        label[5] = label[4];
        label[4] = tmp;
    }

    void rollE()
    {
        tmp = label[0];
        label[0] = label[3];
        label[3] = label[5];
        label[5] = label[2];
        label[2] = tmp;
    }

    void rollW()
    {
        tmp = label[0];
        label[0] = label[2];
        label[2] = label[5];
        label[5] = label[3];
        label[3] = tmp;
    }

    void sideturn()
    {
        tmp = label[1];
        label[1] = label[2];
        label[2] = label[4];
        label[4] = label[3];
        label[3] = tmp;
    }
};

bool check2(Dice d1, Dice d2)
{
    bool c = true;
    FOR(i, 1, 5)
    {
        c = c && d1.label[i] == d2.label[i];
    }

    return c;
}

bool check1(Dice d1, Dice d2)
{
    bool b = false;

    if (d1.label[0] == d2.label[0] && d1.label[5] == d2.label[5])
    {
        rep(i, 4)
        {
            b = b || check2(d1, d2);
            d2.sideturn();
        }
    }
    return b;
}

bool isSame(Dice d1, Dice d2)
{
    bool a = false;

    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);

    return a;
}

int main()
{
    int n;
    bool ans = false;
    scanf("%d", &n);
    Dice dice[n];
    rep(i, n) dice[i].in();

    rep(i, n)
    {
        FOR(j, i + 1, n)
        {
            ans = ans || isSame(dice[i], dice[j]);
        }
    }

    if (ans)
        printf("No\n");
    else
        printf("Yes\n");
}

#include<stdio.h>
#include<string.h>
typedef struct {
	char direction[100];
	int num1,num2,num3,num4,num5,num6;
}DICE_t;
int main(){
	int n;
	scanf("%d",&n);
	DICE_t a[n];
	for(int x=0;x<n;x++){
	    scanf("%d %d %d %d %d %d",&a[x].num1,&a[x].num2,&a[x].num3,&a[x].num4,&a[x].num5,&a[x].num6);
	}
	int x,y;
	for(x=0;x<(n-1);x++){
		for(y=(x+1);y<n;y++){
	        int dummy,turn=0;
	        while(turn<24){
		        if(turn%4==0&&turn!=0){
		    	    strcpy(a[y].direction,(turn%8==4 ?"SSEN":"ESEN"));
	    	    }
    		    else{
        			strcpy(a[y].direction,"SEN");
    	    	}
    	        for(int i=0;a[y].direction[i]!=0;i++){
    	            if(a[y].direction[i]=='N'){
		                dummy=a[y].num5;
	            	    a[y].num5=a[y].num1;
	            	    a[y].num1=a[y].num2;
	            	    a[y].num2=a[y].num6;
	        	        a[y].num6=dummy;
	                }
	                else if(a[y].direction[i]=='S'){
		                dummy=a[y].num6;
	            	    a[y].num6=a[y].num2;
	            	    a[y].num2=a[y].num1;
	            	    a[y].num1=a[y].num5;
	            	    a[y].num5=dummy;
	                }
    	    	    else if(a[y].direction[i]=='E'){
		                dummy=a[y].num4;
	        	        a[y].num4=a[y].num6;
	        	        a[y].num6=a[y].num3;
	        	        a[y].num3=a[y].num1;
	        	        a[y].num1=dummy;
	                }
	                else if(a[y].direction[i]=='W'){
	                    dummy=a[y].num1;
    	            	a[y].num1=a[y].num3;
	                	a[y].num3=a[y].num6;
	                	a[y].num6=a[y].num4;
	                	a[y].num4=dummy;
	                }
    	        }
	        	if(a[x].num1==a[y].num1&&a[x].num2==a[y].num2&&a[x].num3==a[y].num3&&a[x].num4==a[y].num4&&a[x].num5==a[y].num5&&a[x].num6==a[y].num6){
	        		printf("No\n");
	        		goto end;
	        	}
	    	    turn++;
	        }
		}
	}
	printf("Yes\n");
end:

	return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  rep(i,10){
    int cnt = 0;
    if(i==a)cnt++;
    if(i==b)cnt++;
    if(i==c)cnt++;
    if(cnt==2){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b&&a!=c&&b!=c){
		printf("Yes");
	}
	else if(a==c&&a!=b&&c!=b)
	    printf("Yes");
	else if(b==c&&b!=a&&c!=a)
	    printf("Yes");
	else if(a==b&&a==c&&b==c)
	    printf("No");
	else if(a!=b&&a!=c&&b!=c)
	    printf("No");

	return 0;
}


#include <bits/stdc++.h>

int main() {
    long long k;
    std::cin >> k;
    std::cout << 50 << std::endl;
    const auto p = k / 50 + 50, q = p - 1 - (k % 50);
    for (int i = 0; i < k % 50; i++) {
        std::cout << p << " ";
    }
    for (int i = k % 50; i < 50; i++) {
        std::cout << q << " ";
    }
    std::cout << std::endl;

    return 0;
}

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main() {
  ll K;
  cin >> K;
  int N = 50;
  vll a(N,N-1);
  repeat(i,N){
    a[i] += K/N;
  }
  repeat(i,K%N){
    a[i] += N+1;
  }
  repeat(i,N){
    a[i] -= K%N;
  }
  cout << N << endl;
  repeat(i,N){
    cout << a[i];
    cout <<(i<N-1? " ":"\n");
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int a;
int ans=1000000000;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        int k=0;
        while(a%2==0){
            a=a/2;
            k++;
        }
        ans=min(ans,k);
    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す//計算量は0(log(max(a,b))
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す//計算量は0(log(max(a,b))
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す//計算量は0(sqrt(a))
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
vector<int> Z;
void z_algorithm(string str){//計算量はO(str.size())
  Z.resize(str.size());
  Z.at(0)=str.size();
  int m=1,n=0;
  while(m<(int)str.size()){
    while(m+n<(int)str.size()&&str.at(n)==str.at(m+n)){n++;}
    Z.at(m)=n;
    if(n==0){
      m++;
      continue;
    }
    int k=1;
    while(k+Z.at(k)<n){
      Z.at(m+k)=Z.at(k);
      k++;
    }
    m+=k;
    n-=k;
  }
}
vector<vector<int>> vec;
vector<vector<int>> now;
bool dfs(int i){
    int ii=now.at(i).at(0);
    if(ii==-1){return false;}
    if(now.at(ii).at(0)==i){return true;}
    else{return false;}
}
int main(){
    int N;
    cin>>N;
    vec.resize(N,vector<int>(N-1));
    now.resize(N,vector<int>(0));
    vector<int> enemy(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            int a;
            cin>>a;
            vec.at(i).at(j)=a-1;
            if(j==0){
                now.at(i).push_back(a-1);
            }
        }
        enemy.at(i)=0;
    }
    ll count=0;
    ll day=0;
    //countはN(N-1)/2まで
    while(count<N*(N-1)/2){
        unordered_map<int,int> mp;
        int memo=count;
        day++;
        for(int i=0;i<N;i++){
            //cout<<count<<" "<<i<<endl;
            if(dfs(i) && mp[i]==0 && mp[now.at(i).at(0)]==0 && now.at(i).at(0)!=-1){
                count++;
                int a=i;
                int b=now.at(i).at(0);
                enemy.at(a)++;
                enemy.at(b)++;
                mp[a]=1;
                mp[b]=1;
                //cout<<a<<" "<<b<<"   "<<enemy.at(a)<<" "<<enemy.at(b)<<endl;
                if(enemy.at(a)<N-1){
                    //cout<<a<<" "<<b<<" "<<enemy.at(a)<<endl;
                    now.at(a).at(0)=vec.at(a).at(enemy.at(a));
                }
                else{
                    now.at(a).at(0)=-1;
                }
                if(enemy.at(b)!=N-1){
                    //cout<<" "<<a<<" "<<b<<" "<<enemy.at(b)<<endl;
                    now.at(b).at(0)=vec.at(b).at(enemy.at(b));
                }
                else{
                    now.at(b).at(0)=-1;
                }
            }
        }
        if(memo==count){
            cout<<-1<<endl;
            return 0;
        }
        mp.clear();
    }
    cout<<day<<endl;
}


#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#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; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector< vector<bool> > a(21, vector<bool>(21));
		int cnt = N;
		while (N--) {
			int x, y; cin >> x >> y;
			a[y][x] = true;
		}
		int x = 10, y = 10;
		int M; cin >> M;
		while (M--) {
			string d; int l; cin >> d >> l;
			int dx = 0, dy = 0;
			if (d == "N") dy = 1;
			if (d == "E") dx = 1;
			if (d == "S") dy = -1;
			if (d == "W") dx = -1;
			while (l--) {
				x += dx; y += dy;
				if (a[y][x]) {
					a[y][x] = false;
					cnt--;
				}
			}
		}
		cout << (cnt == 0 ? "Yes" : "No") << endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<int> a(n);
    for(int i=0;i<n;i++) a[i]=(s[i]=='o');
    for(int ti=0;ti<2;ti++){
        for(int tj=0;tj<2;tj++){
            vector<int> b(n);
            b[0]=ti,b[1]=tj;
            for(int i=0;i<n;i++){
                int j=(i+1)%n;
                b[(i+2)%n]=b[i]^b[j]^a[j];
            }
            if(b[0]==ti&&b[1]==tj){
                string ans="";
                for(int i=0;i<n;i++) ans+="WS"[b[i]];
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


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

int main(){
  int a, b, c, N;
  int flag[3][1000], judge[1000], info[301];

  while(cin >> a >> b >> c , a+b+c){
    fill_n(info,301,2);
    cin >> N;
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j < 3 ; j++) cin >> flag[j][i];
      cin >> judge[i];
      if(judge[i] == 1) for(int j = 0 ; j < 3 ; j++ ) info[flag[j][i]] = 1;
    }
    for(int i = 0 ; i < N ; i++ ){
      if(!judge[i]){
        for(int j = 0 ; j < 3 ; j++){
          if(info[flag[j][i]] == 1 && info[flag[(j+1)%3][i]] == 1){
            info[flag[(j+2)%3][i]] = 0;
          }
        }
      }
    }
    for(int i = 1 ; i <= a+b+c ; i++ ) cout << info[i] << endl;
  }
}


#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
struct SegT {
private:
	int n; vector<ll> node, lazy;
	const ll init_c = INF/16;
public:
	SegT(int sz) {
		n = 1;
		while (n < sz)n <<= 1;
		node.resize(2 * n - 1, init_c);
		lazy.resize(2 * n - 1, 0);
	}
	ll f(ll a, ll b) {
		return min(a, b);
	}
	void eval(int k, int l, int r) {
		node[k] += lazy[k];
		if (r - l > 1) {
			lazy[2 * k + 1] += lazy[k];
			lazy[2 * k + 2] += lazy[k];
		}
		lazy[k] = 0;
	}
	void add(ll x, int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l && r <= b) {
			lazy[k] += x; eval(k, l, r);
		}
		else {
			add(x, a, b, k * 2 + 1, l, (l + r) / 2);
			add(x, a, b, k * 2 + 2, (l + r) / 2, r);
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return INF;
		if (a <= l && r <= b)return node[k];
		else {
			ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
	void update(int k, ll x) {
		ll z = query(k, k + 1);
		add(x - z, k, k + 1);
		//cout << query(k, k + 1) << endl;
		//cout << "hello" << k << " " << z << endl;
	}
	ll specialquery(int m) {
		ll res = INF;
		rep(i, m) {
			res = min(res, query(i,i+1) + i);
		}
		return res;
	}
};
int n, q;
ll dp[1 << 18];
int main() {
	cin >> n >> q;
	int a, b; cin >> a >> b; a--; b--;
	fill(dp, dp + n, INF);
	int x; cin >> x; x--;
	dp[a] = abs(b - x); dp[b] = abs(a - x);
	SegT l(n), r(n);
	l.update(a, dp[a]-a); r.update(a, dp[a]+a);
	l.update(b, dp[b]-b); r.update(b, dp[b]+b);
	int memo = x;
	//cout << l.specialquery(n) << endl;
	//cout << r.query(memo, n) - memo << endl;
	rep(i, q - 1) {
		cin >> x; x--;
		ll vl = l.query(0, x) + x;
		ll vr = r.query(x, n) - x;
		//cout << memo << " " << vl << " " << vr << endl;
		dp[memo] = min(vl, vr);
		//cout << memo << " " << dp[memo] << endl;

		l.add(abs(memo - x),0,memo); r.add(abs(memo - x), 0, memo);
		l.add(abs(memo - x), memo + 1, n); r.add(abs(memo - x), memo + 1, n);
		r.update(memo, dp[memo] + memo);
		//cout << memo << " " << dp[memo] - memo << endl;
		l.update(memo, dp[memo] - memo);
		memo = x;
		//cout << l.specialquery() << endl;
	}
	/*cout << l.query(4, 5) + 4 << endl;
	l.update(4, 3);
	cout << l.query(4, 5) + 4 << endl;
    l.specialquery(n);*/
	cout << l.specialquery(n) << endl;
	//cout << memo << endl;
	//stop
		return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

	ll n, lbuf, rbuf, mi;
	cin >> n;
	P lr[n];
	ll ans = 0;
	zep(i, 0, n){
		cin >> lbuf >> rbuf;
		lr[i] = P(rbuf, lbuf);
		if(rbuf-lbuf+1 > ans){
			ans = rbuf-lbuf+1;
			mi = i;
		}
	}
	ll lm = 0;
	ll rm = 1e9;
	zep(i, 0, n){
		if(i != mi){
			lm = max(lr[i].second, lm);
			rm = min(lr[i].first, rm);
		}
	}
	ans += max(rm-lm+1, 0LL);

	sort(lr, lr+n);
	zep(i, 0, n){
		ll tmp = lr[i].first;
		lr[i].first = lr[i].second;
		lr[i].second = tmp;
	}

	ll al[n], dl[n], ar[n], dr[n];
	al[0] = lr[0].first;
	ar[0] = lr[0].second;
	zep(i, 1, n){
		al[i] = max(lr[i].first, al[i-1]);
		ar[i] = min(lr[i].second, ar[i-1]);
	}

	dl[n-1] = lr[n-1].first;
	dr[n-1] = lr[n-1].second;
	rrep(i, n-2, 0){
		dl[i] = max(lr[i].first, dl[i+1]);
		dr[i] = min(lr[i].second, dr[i+1]);
	}

	zep(i, 0, n-1){
		ans = max(ar[i]-al[i]+1+dr[i+1]-dl[i+1]+1, ans);
	}
	print(ans)
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,Q,K;
  cin>>N;
  vector<vector<pair<int,int>>> A(N);
  for(int i=1;i<N;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A[a-1].push_back({b-1,c});
    A[b-1].push_back({a-1,c});
  }
  cin>>Q>>K;
  vector<int> B(N,-1);
  queue<int> q;
  B[K-1]=0;
  q.push(K-1);
  while(!q.empty()){
    int I=q.front();
    q.pop();
    for(pair<int,int> p:A[I])
      if(B[p.first]==-1){
        B[p.first]=B[I]+p.second;
        q.push(p.first);
      }
  }
  while(Q--){
    int x,y;
    cin>>x>>y;
    cout<<B[x-1]+B[y-1]<<endl;
  }
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

//constructor: LCA(graph);
template<class T>
class LCA_weight {
private:
    int n;
    int D = 30;                        //hight
    vector<int> depth;                 //depth from root
    vector<vector<pair<int,T>>> hen;   //tree
    vector<vector<int>> par;           //doubling array
    vector<T> dista;                    //distance form root

    void dfs(int v, int p, int dep, T dep_dist) {
        par[v][0] = p;
        depth[v] = dep;
        dista[v] = dep_dist;
        for(auto i : hen[v]) {
            if(i.first == p)continue;
            dfs(i.first, v, dep + 1, dep_dist + i.second);
        }
    }

public:

    LCA_weight(const vector<vector<pair<int,T>>>& hen):hen(hen) {
        n = hen.size();
        par.resize(n, vector<int>(D + 1));
        depth.resize(n);
        dista.resize(n);

        dfs(0, -1, 0, 0);
        for(int i = 0; i < D; i++) {
            for(int j = 0; j < n; j++) {
                if(par[j][i] == -1)par[j][i + 1] = -1;
                else par[j][i + 1] = par[par[j][i]][i];
            }
        }
    }

    //go back to root
    int back(int v, int dist) {
        for(int i = 0; i < D; i++)if((1 << i) & dist) {
            if(v == -1)return v;
            v = par[v][i];
        }
        return v;
    }

    //get LCA
    int get(int u, int v) {
        int ret = 0;
        if(depth[u] > depth[v])swap(u, v);
        ret = depth[v] - depth[u];
        v = back(v, ret);
        if(u == v)return v;

        for(int i = D; i >= 0; i--) {
            if(par[u][i] != par[v][i]) {
                u = par[u][i];
                v = par[v][i];
            }
        }
        return par[u][0];
    }

    //u-v path distance
    T dist(int u, int v) {
        int lca = get(u, v);
        return (dista[u] + dista[v]) - dista[lca] * 2;
    }

    //print parents
    void print(int i) {
        cerr << "[";
        for(int j = 0; j < n; j++)cerr << par[j][i] << (j == n - 1 ? "" : ",");
        cerr << "]";
    }

};

int main()
{
    int n; cin >> n;
    vector<vector<pair<int,ll>>> hen(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        hen[a].emplace_back(b, c);
        hen[b].emplace_back(a, c);
    }
    LCA_weight<ll> lca(hen);
    int q, k; cin >> q >> k;
    k--;
    while(q--) {
        int s, t; cin >> s >> t; s--, t--;
        cout << lca.dist(s, k) + lca.dist(t, k) << endl;
    }
}


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

int main() {
  string S; cin >>S;
  ll ans = INF;
  rep(i,S.size()-2){
    ll ints = stoi(S.substr(i,3));
    ans = min(ans,abs(753 - ints));
  }

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


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

const int MAX_N = 13;
const int n = MAX_N;
const int m = 5;
int card[MAX_N];
vi x(m);

string judge(vi num)
{
  if(num[0] == 4) return "four card";
  if(num[0] == 3 && num[1] == 2) return "full house" ;
  if(num[0] == 1 && x[4] - x[0] == 4) return "straight";
  if(num[0] == 1 && x[0] == 0 && x[1] == 9 && x[4] == 12) return "straight";
  if(num[0] == 3) return "three card";
  if(num[0] == 2 && num[1] == 2) return "two pair";
  if(num[0] == 2) return "one pair";
  return "null";
}

int main()
{
  rep(i, n) card[i] = i;

  while(~scanf("%d,%d,%d,%d,%d", &x[0], &x[1], &x[2], &x[3], &x[4], &x[5])){
    vi num(MAX_N);
    rep(i, m) x[i] -= 1;
    rep(i, m) num[x[i]] += 1;
    sort(ALL(num), greater<int>());
    sort(ALL(x));
    cout << judge(num) << endl;
  }

  return 0;
}

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

int main() {
  vector<int> x(3);
  int k, y;
  for(int i=0;i<3;i++) cin >> x.at(i);
  cin >> k;
  sort(x.begin(), x.end());
  y = x.at(2);
  for(int i=0;i<k;i++) y = 2*y;
  cout << x.at(0) + x.at(1) + y << endl;
}


#include <bits/stdc++.h>

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int x, y;
    cin >> x >> y;

    auto f = [](int i) {
        if (i == 3) return 100000;
        if (i == 2) return 200000;
        if (i == 1) return 300000;
        return 0;
    };

    int ans = [&] {
        if (x == 1 && y == 1) return 1000000;
        return f(x) + f(y);
    }();
    cout << ans << endl;
}

#include<stdio.h>
#include<string.h>

int main(){
    int a,b,total=0;
	scanf("%d %d",&a,&b);

    char s[a+b+2];
    scanf("%s", &s);

    for(int i=0; i<a+b+1 ;i++){
        if(i!=a){
            if(s[i]>=48 && s[i]<=57){
                total++;
            }
        }
		else {
            if(s[i] == '-'){
                total++;
            }
        }
    }

    if (total==a+b+1){
    	printf("Yes");
	}
	else {
		printf("No");
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  int cnt;
  int sum;
  string ans="War";
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  vector<int> b(m);
  rep(i,m){
    cin>>b[i];
  }
  for(int i=x+1;i<y;i++){
    cnt=0;
    for(int j=0;j<n;j++){
      if(i>a[j]) cnt++;
    }
    sum=0;
    if(cnt==n){
      for(int j=0;j<m;j++){
        if(i<=b[j]) sum++;
      }
    }
    if(sum==m) ans="No War";
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n,m,x,y;cin>>n>>m>>x>>y;
    bool yes=true;
    vector<ll> x_vec(n),y_vec(m);
    rep(i,n) cin>>x_vec[i];
    rep(i,m) cin>>y_vec[i];

    for(ll z=-100;z<=100;z++){
        bool Yes=false;
        if(!(x<z && z<=y)) Yes=true;
        rep(i,n) if(!(x_vec[i]<z)) Yes=true;
        rep(i,m) if(!(y_vec[i]>=z)) Yes=true;

        if(!Yes){
            yes=false;
            break;
        }
    }

    if(yes) cout<<"War"<<endl;
    else cout<<"No War"<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    // blue input
    int n;
    cin >> n;
    vector<string> blue(n);
    for(int i = 0; i < n; i++) {
        cin >> blue.at(i);
    }
    // red input
    int m;
    cin >> m;
    vector<string> red(m);
    for(int i = 0; i < m; i++) {
        cin >> red.at(i);
    }

    int max = 0;

    for(int i = 0; i < n; i++) {
        string s = blue.at(i);
        int cnt = 0;
        for(int j = 0; j < n; j++) {
            if(s == blue.at(j)){
                cnt++;
            }
        }
        for(int k = 0; k < m; k++) {
            if(s == red.at(k)){
                cnt--;
            }
        }
        if(cnt >= max){
            max = cnt;
        }
    }

    cout << max << endl;

    return 0;
}

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

ll dfs(ll prev, ll now, vector<vector<ll>>& adj, vector<ll>& dp, set<ll>& st) {
	if (dp[now] > 0) return dp[now];
	if (st.find(now) != st.end()) return -1;
	st.insert(now);
	ll ret = 0;
	for (auto i : adj[now]) {
		if (i == prev) continue;
		ll x = dfs(now, i, adj, dp, st);
		if (x == -1) return -1;
		ret = max(ret, x);
	}
	st.erase(now);
	return dp[now] = ret + 1;
}

int main() {
	ll n;
	cin >> n;
	vector<vector<ll>> a(n, vector<ll>(n - 1));
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - 1; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}

	auto idx = [&] (ll i, ll j) {
		if (i > j) swap(i, j);
		ll ret = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;
		return ret + j - i - 1;
	}; // {i, j} が対戦する試合の頂点番号

	ll m = n * (n - 1) / 2;
	vector<vector<ll>> adj(m);
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < n - 2; j++) {
			ll u = idx(i, a[i][j]), v = idx(i, a[i][j + 1]);
			adj[u].push_back(v);
		}
	}

	vector<ll> dp(m, 0);
	ll ans = 0;
	for (ll i = 0; i < m; i++) {
		set<ll> st;
		ll x = dfs(-1, i, adj, dp, st);
		if (x == -1) {
			cout << -1 << endl;
			return 0;
		} else ans = max(ans, x);
	}

	cout << ans << endl;
}


#include <cmath>

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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

string s;

void input() {
  cin >> s;
}

void solve() {
  string ans = "No";

  if (s.find('7') != string::npos)
    ans = "Yes";

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

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

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

  _times = 2;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


#include <bits/stdc++.h>
 using namespace std;
  int main (){
      int k,x;
      cin >> k >> x;
      for(int i=1;i<=k*2-1;i++){
          cout << x-k+i << " ";
      }
      cout << endl;
  }


/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t dxs[] = {-1, 1, 0, 0};
const int64_t dys[] = {0, 0, -1, 1};

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

  int64_t sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  // 1********
  for (int64_t i = 0; i < (tx - sx); ++i) {
    cout << "R";
  }
  for (int64_t i = 0; i < ty - sy; ++i) {
    cout << "U";
  }
  // 2********
  for (int64_t i = 0; i < (tx - sx); ++i) {
    cout << "L";
  }
  for (int64_t i = 0; i < ty - sy; ++i) {
    cout << "D";
  }
  // 3********
  cout << "D";
  for (int64_t i = 0; i < (tx - sx) + 1; ++i) {
    cout << "R";
  }
  for (int64_t i = 0; i < ty - sy + 1; ++i) {
    cout << "U";
  }
  cout << "L";
  // 4********
  cout << "U";
  for (int64_t i = 0; i < (tx - sx) + 1; ++i) {
    cout << "L";
  }
  for (int64_t i = 0; i < ty - sy + 1; ++i) {
    cout << "D";
  }
  cout << "R";
  cout << endl;

  return 0;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getval(_T& a) {
	std::cin >> a;
}
template<class _T> static void getval(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getval(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}
template <class _T> static void tp_swap(_T& right, _T& left) {
	//	usage:  tp_swap<type name>(a, b);
	_T tmp = right;
	right = left;
	left = tmp;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int sx, sy, tx, ty;
	getval(sx, sy);
	getval(tx, ty);

	int dx = tx - sx;
	int dy = ty - sy;
	std::string ans;
	for (int i = 0; i < dx; i++) {
		ans += 'R';
	}
	for (int i = 0; i < dy; i++) {
		ans += 'U';
	}
	for (int i = 0; i < dx; i++) {
		ans += 'L';
	}
	for (int i = 0; i < dy; i++) {
		ans += 'D';
	}

	ans += 'D';
	for (int i = 0; i <= dx; i++) {
		ans += 'R';
	}
	for (int i = 0; i <= dy; i++) {
		ans += 'U';
	}
	ans += 'L';
	ans += 'U';
	for (int i = 0; i <= dx; i++) {
		ans += 'L';
	}
	for (int i = 0; i <= dy; i++) {
		ans += 'D';
	}
	ans += 'R';

	std::cout << ans << std::endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int n, a[3], cnt, ed;
int f[50][1 << 17], ans = 1;

inline int add(const int &x, const int &y) {
	return x + y < mod ? x + y : x + y - mod;
}
inline int sub(const int &x, const int &y) {
	return x - y < 0 ? x - y + mod : x - y;
}
inline int mul(const int &x, const int &y) { return (int)((ll)x * y % mod); }
int main() {
	scanf("%d%d%d%d", &n, &a[0], &a[1], &a[2]);
	for(int i = 1; i <= n; i++) ans = mul(ans, 10);
	cnt = (1 << a[0] + a[1] + a[2]) - 1;
	ed = (1 << a[0] - 1) | (1 << a[0] + a[1] - 1) | (1 << a[0] + a[1] + a[2] - 1);
	f[0][0] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= cnt; j++)
			for(int k = 1; k <= 10; k++) {
				int t = (j << k) + (1 << k - 1); t &= cnt;
				if((t & ed) != ed) f[i][t] = add(f[i - 1][j], f[i][t]);
			}
	for(int i = 0; i <= cnt; i++) ans = sub(ans, f[n][i]);
	printf("%d\n", ans);
	return 0;
}

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

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

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 55, LG = 17, MOD = 1e9+7;
const int SQ = 320;
const long double EPS = 1e-7;
int cnt = 0;
vector<string> store[11];
void bt(string s = "", int sum = 0){
  if(sum > 7)return;
  store[sum].pb(s);
  f(i,0,7){
    s.pb('0' + i);
    bt(s,sum+i+1);
    s.pop_back();
  }
}
const int M = 10;
int trie[N*N*N][M];
int go[N*N*N][M];
int mrk[N*N*N], f[N*N*N];
int ptr = 1;
void BFS(){

  queue<int> q;
	for(int i = 0; i < M; i++)
		if(trie[0][i])
			q.push(trie[0][i]), f[trie[0][i]] = 0;
	for(int i = 0; i < M; i++) go[0][i] = trie[0][i];
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i = 0; i < M; i++) {
			if(trie[x][i]) {
				int y = trie[x][i];
				f[y] = f[x];
				while(f[y] && !trie[f[y]][i])
					f[y] = f[f[y]];
				if(trie[f[y]][i]) f[y] = trie[f[y]][i];
				q.push(y);
			}
			if(trie[x][i]) go[x][i] = trie[x][i];
			else go[x][i] = go[f[x]][i];
		}
	}

}
void ins(string x){
  int cur = 0;
  for(int i = 0; i < x.size(); i++){
      if(!trie[cur][x[i]-'0'])
        trie[cur][x[i]-'0'] = ptr++;
      cur = trie[cur][x[i]-'0'];
  }
  mrk[cur] = true;
}
int dp[N][N*N*N][2];
int n, x, y, z;
int solve(int idx, int state, bool f){
  f|=mrk[state];
  if(idx == n)
    return f;
  int &ret = dp[idx][state][f];
  if(~ret)
    return ret;
  ret = 0;
  f(j,0,10){
    ret += solve(idx+1,go[state][j], f);
    if(ret>=MOD)ret-=MOD;
  }
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  bt();

  cin >> n >> x >> y >> z;

  for(auto X : store[x])
    for(auto Y : store[y])
      for(auto Z : store[z])if(X.size()+Y.size()+Z.size()<=n)
        ins(X+Y+Z);
  BFS();
  memset(dp,-1,sizeof dp);
  cout << solve(0,0,0) << '\n';

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<(1<<(n-1));i++){
    int ans=s[0]-'0';
    vector<char> enzan;
    for(int j=0;j<n-1;j++){
      if(i&(1<<j)){
        ans-=s[j+1]-'0';
        enzan.push_back('-');
      }else{
        ans+=s[j+1]-'0';
        enzan.push_back('+');
      }
    }
    if(ans==7){
      cout<<s[0]<<enzan[0]<<s[1]<<enzan[1]<<s[2]<<enzan[2]<<s[3]<<'='<<7<<endl;
      return 0;
    }
  }
  return 0;
}

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

int main(){

	int n, prime[10001], p[10001];

	fill(prime, prime+10001, 1);
	fill(p, p+10001, 0);

	prime[0] = 0;
	prime[1] = 0;
	for(int i=2; i<10001; i++){
		if(prime[i] == 1){
			if(prime[i-2] == 1) p[i] = 1;
			for(int j=2; i*j<10001; j++){
				prime[i*j] = 0;
			}
		}
	}

	while(cin >> n){
		if(n == 0) break;
		for(int i=n; i>0; i--){
			if(p[i] == 1) {
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;

}


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

int main(){
    int n;
    ll y;
    cin >> n >> y;
    int a,b,c;
    a=-1;
    b=-1;
    c=-1;
    int cnt=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if((1000*i+5000*j+10000*(n-i-j))==y){
            a=n-i-j;
            b=j;
            c=i;
            }
        }
    }

    cout << a << " " << b << " " << c << endl;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int data[100],cnt=0,n;
  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(data[j]<data[j-1]){
    swap(data[j],data[j-1]);
    cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << (i!=0?" ":"") << data[i];
  }
  cout << endl << cnt << endl;
  }


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

vector<lint> G[200050]; // MAX_V,隣接リスト
lint root;

lint parent[20][200050]; // logMAX_V,MAX_V
lint depth[200050];

void LCAdfs(lint v,lint p,lint d){
    parent[0][v]=p;
    depth[v]=d;
    rep(i,G[v].size()) if(G[v][i]!=p) LCAdfs(G[v][i],v,d+1);
}

void LCAinit(lint V){
    LCAdfs(root,-1,0);
    for(int k=0;k+1<20;k++){
        for(int v=0;v<V;v++){
            if(parent[k][v]<0) parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}

lint LCA(lint u,lint v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<20;k++){
        if((depth[v]-depth[u])>>k&1) v=parent[k][v];
    }
    if(u==v) return u;
    for(int k=20-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}

vector<int> path(int s,int t){
    int lca=LCA(s,t);
    vector<int> ps,pt;
    int now=s;
    while(true){
        if(now==lca) break;
        ps.push_back(now);
        now=parent[0][now];
    }
    now=t;
    while(true){
        pt.push_back(now);
        if(now==lca) break;
        now=parent[0][now];
    }
    reverse(pt.begin(),pt.end());
    ps.insert(ps.end(),pt.begin(),pt.end());
    return ps;
}

vector<pint> edge[MAX_N];
bool reach[MAX_N];
lint dis[MAX_N];

void dfs(int now,lint sum){
    if(reach[now]) return;
    reach[now]=true;
    dis[now]=sum;
    rep(i,edge[now].size()){
        dfs(edge[now][i].fi,sum+edge[now][i].se);
    }
}

int main(void){
    int N;
    cin >> N;
    rep(i,N-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--,v--;
        G[u].push_back(v);
        G[v].push_back(u);
        edge[u].push_back(pint(v,w));
        edge[v].push_back(pint(u,w));
    }
    LCAinit(N);
    dfs(0,0);
    int Q,K;
    cin >> Q >> K;
    K--;
    rep(i,Q){
        int x,y;
        cin >> x >> y;
        x--,y--;
        int lca=LCA(x,K);
        lint ans=dis[x]+dis[K]-2*dis[lca];
        lca=LCA(K,y);
        ans+=dis[K]+dis[y]-2*dis[lca];
        cout << ans << endl;
    }
}

    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int MAXN=1e5+5;
    int tot,head[MAXN];
    LL dist[MAXN];
    bool vis[MAXN];

    struct Edge
    {
        int from,to,nxt;
        LL cost;
    }e[MAXN*2];

    void addedge(int u,int v,int w)
    {
        e[tot].from=u;
        e[tot].to=v;
        e[tot].cost=w;
        e[tot].nxt=head[u];
        head[u]=tot++;
    }

    void dfs(int u,int fa)
    {
        for(int i=head[u];i!=-1;i=e[i].nxt)
        {
            int to=e[i].to;
            if(to==fa) continue;
            dist[to]=dist[u]+e[i].cost;
            dfs(to,u);
        }
    }

    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            tot=0;
            memset(head,-1,sizeof(head));
            memset(dist,0,sizeof(dist));
            int u,v;
            LL w;
            for(int i=1;i<=n-1;i++)
            {
                scanf("%d%d%lld",&u,&v,&w);
                addedge(u,v,w);
                addedge(v,u,w);
            }
            int q,k;
            scanf("%d%d",&q,&k);
            dfs(k,-1);
    //        for(int i=1;i<=n;i++)
    //            cout<<dist[i]<<" ";
    //        cout<<endl;
            int x,y;
            for(int i=1;i<=q;i++)
            {
                scanf("%d%d",&x,&y);
                printf("%lld\n",dist[x]+dist[y]);
            }
        }
        return 0;
    }


#include<iostream>
#include<sstream>
using namespace std;
int s2d(string buf){
  istringstream iss(buf);
  double x;iss >> x;
  return x;
}
int main(){
  string buf;
  while(cin>>buf){
    int i;
    for(i=0;i<buf.size();i++) if(buf[i]==',') buf[i]=' ';
    stringstream ss(buf);
    double d[12];
    for(i=0;i<12;i++){
      ss >> buf;
      d[i]=s2d(buf);
      //cout << i << ":" << d[i] << endl;
    }
    double p=0;
    for(i=0;i<10;i++) p+=d[i];
    p*=d[10]/(d[10]+d[11]);
    //cout << p << endl;
    int o=0,k=0;
    for(i=0;i<10;i++){
      if(p<=k+d[i]){
	o=i+1;
	break;
      }
      k+=d[i];
    }
    cout << o << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    vector<string> g(100);
    for(int i = 0; i < 100; i++) {
        string tmp = "";
        if(i < 50) {
            for(int j = 0; j < 100; j++) {
                tmp += "#";
            }
        } else {
            for(int j = 0; j < 100; j++) {
                tmp += ".";
            }
        }
        g[i] = tmp;
    }
    int h = 0, w = 1;
    while(a - 1 > 0) {
        if(w == 99) {
            h += 2;
            w = 1;
        }
        g[h][w] = '.';
        w += 2;
        a--;
    }
    h = 51, w = 1;
    while(b - 1 > 0) {
        if(w == 99) {
            h += 2;
            w = 1;
        }
        g[h][w] = '#';
        w += 2;
        b--;
    }
    cout << "100 100" << endl;
    for(int i = 0; i < 100; i++) {
        cout << g[i] << endl;
    }
}

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

int main(){

  int N,Q;
  string S;

  cin >> N;
  cin >> S;
  cin >> Q;

  vector<int> k(Q);
  for (int i = 0; i < Q ; i++){
    cin >> k.at(i);
  }

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

    long long dnum = 0,mnum = 0,dmnum = 0,ans = 0;

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

      if (j >= k.at(i)){

	if (S.at(j-k.at(i)) == 'D'){
	  dnum -= 1;
	  dmnum -= mnum;
	}else if (S.at(j-k.at(i)) == 'M'){
	  mnum -= 1;
	}
      }

      if (S.at(j) == 'D'){
	dnum += 1;
      }else if (S.at(j) == 'M'){
	mnum += 1;
	dmnum += dnum;
      }else if (S.at(j) == 'C'){
	ans += dmnum;
      }

    }

    cout << ans << endl;

  }

  return 0;
}


#include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    int n, l ;
    cin >> n >> l ;
    vector<int> vec (n) ;
    rep(i, n) vec[i] = i + 1 ;
    rep(i , n){
        vec[i] = vec[i] + l - 1 ;
    }
    int t = 200000 ;
    int num ;
    rep(i, n){
        if(t > abs(vec[i])){
            t = abs(vec[i]) ;
            num = i ;
        }
    }
    int tot = 0;
    rep(i, n){
        if(i == num){
            continue ;
        }
        else {
            tot += vec[i] ;
        }
    }
    cout << tot << endl ;
}

#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll fact[7000];
ll ifact[7000];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll comb(ll n, ll k, ll m) {
  return fact[n] * ifact[k] % m * ifact[n-k] % m;
}

ll pmod(ll x, ll i, ll m) {
  if (i == 0) return 1;
  if (i % 2 == 1) return pmod(x, i-1, m) * x % m;
  ll h = pmod(x, i/2, m);
  return h * h % m;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;
  cin>>n>>m;
  fact[0] = 1;
  REP(i,7000-1) {
    fact[i+1] = (i+1) * fact[i] % m;
  }
  ifact[6999] = inv(fact[6999], m);
  REP(i,7000-1) {
    int j = 7000-i-1;
    ifact[j-1] = j * ifact[j] % m;
  }
  ll inv3 = inv(3, m);
  ll inv2 = inv(2, m);
  ll ans = 0;
  REP(i,n+1) {
    REP(j,n+1-i) {
      ll tmp = comb(3*n, 3*i, m);
      tmp *= fact[3*i] * ifact[i] % m;
      tmp %= m;
      tmp *= pmod(inv3, i, m);
      tmp %= m;
      ll rem = 3*n - 3*i;
      tmp *= comb(rem, 2*j, m);
      tmp %= m;
      tmp *= fact[2*j] * ifact[j] % m;
      tmp %= m;
      tmp *= pmod(inv2, j, m);
      tmp %= m;
      ans += tmp;
      ans %= m;
    }
  }
  cout << ans << endl;
  return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
void read(int &x) {
	char ch; bool ok;
	for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
	for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=1e5+10;bool vis[maxn];
int n,k,dep[maxn],ans,f[maxn],cnt,pre[maxn*2],nxt[maxn*2],h[maxn];
void add(int x,int y){
	pre[++cnt]=y,nxt[cnt]=h[x],h[x]=cnt;
}
void dfs(int x){
	vis[x]=1;
	for(rg int i=h[x];i;i=nxt[i])
		if(!vis[pre[i]])dfs(pre[i]),dep[x]=max(dep[pre[i]]+1,dep[x]);
	if(dep[x]>=k-1&&f[x]!=1)dep[x]=-1,ans++;
}
int main()
{
	read(n),read(k);scanf("%d",&f[1]);
	for(rg int i=2;i<=n;i++)read(f[i]),add(f[i],i);
	if(f[1]!=1)ans++,f[1]=1;dfs(1);
	printf("%d\n",ans);
}

#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
int a[100000];
vector <int> children[100000];
int d[100000];
bool done[100000];
void set_d(int cur, int cur_d){
  d[cur] = cur_d;
  for(int i = 0; i < children[cur].size(); i++){
    set_d(children[cur][i], cur_d + 1);
  }
}

void set_done(int cur){
  if(done[cur]){
    return;
  }
  done[cur] = true;
  for(int i = 0; i < children[cur].size(); i++){
    set_done(children[cur][i]);
  }
}

int main(){
  int N;
  long long K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    a[i] --;
    if(i != 0){
      children[a[i]].push_back(i);
    }
  }

  for(int i = 0; i < N; i++){
    d[i] = INT_MAX;
  }

  set_d(0, 0);
  int ans;
  if(a[0] == 0){
    ans = 0;
  } else {
    ans = 1;
  }

  vector <pair <int, int> > tmp;
  for(int i = 0; i < N; i++){
    if(d[i] <= K){
      //done[i] = true;
    } else {
      tmp.push_back(make_pair(d[i], i));
    }
  }
  sort(tmp.begin(), tmp.end());
  reverse(tmp.begin(), tmp.end());

  for(int i = 0; i < tmp.size(); i++){
    int cur_d = tmp[i].first;
    int cur = tmp[i].second;
    if(!done[cur]){
      int teleport = cur;
      for(int i = 0; i < K - 1; i++){
        teleport = a[teleport];
      }
      ans ++;
      set_done(teleport);
    }

  }

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


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

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

int main(){
    int N,T; cin>>N>>T;
    vector<pair<int,int>> AB;
    rep(i,N){
        int a,b; cin>>a>>b;
        AB.push_back({a,b});
    }
    sort(AB.begin(),AB.end());
    vector<vector<int>> dp(N+1,vector<int> (T+1,0));
    for(int i = 0; i < N; i++){
        for(int t = 0; t < T; t++){
            int a = AB.at(i).first;
            int b = AB.at(i).second;
            if(a+t>T)dp.at(i+1).at(T) = max(dp.at(i+1).at(T),dp.at(i).at(t)+b);
            if(a>t)dp.at(i+1).at(t) = dp.at(i).at(t);
            else{
                dp.at(i+1).at(t) = max(dp.at(i).at(t),dp.at(i).at(t-a)+b);
            }
        }
    }
    int res = 0;
    rep(i,N+1)res = max({res,dp.at(i).at(T-1),dp.at(i).at(T)});
    cout<<res<<endl;
}

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

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

    priority_queue<pair<int, int>> q;
    int ai;
    for (int i = 0; i < T; i++)
    {
        cin >> ai;
        q.push(make_pair(ai, i + 1));
    }

    int res = 0;
    int prev = 0;
    for (int i = 0; i < K; i++)
    {
        pair<int, int> p0 = q.top();
        q.pop();

        if (p0.second == prev)
        {
            if (q.empty())
            {
                res += p0.first;
                break;
            }
            else
            {
                pair<int, int> p1 = q.top();
                q.pop();
                p1.first--;
                prev = p1.second;
                if (p1.first > 0)
                {
                    q.push(p1);
                }
            }
        }
        else
        {
            p0.first--;
            prev = p0.second;
        }

        if (p0.first > 0)
        {
            q.push(p0);
        }
    }
    cout << res << endl;
}


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

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

  vector<int> A(N);
  for(int i=0; i<N ;i++){
    cin >> A.at(i);
  }

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

  int x=0;

  for(int i=0; i<N-1 ; i++){
    if(A.at(i)==A.at(i+1)){
      cout << "NO" << endl;
      x=1;
      break;
    }
  }

  if(x==0){
    cout << "YES" << endl;
  }

}

#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using sl = stack<ll>;
using ql = queue<ll>;

const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vl a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N;
    bool ans = true;
    cin >> N;
    vb check(1000000002, false);
    REP(i, N){
        ll A;
        cin >> A;
        if(check[A] == false){
            check[A] = true;
        } else {
            ans = false;
            break;
        }
    }

    YES(ans);

    return 0;
}


#include<stdio.h>
int main() {

	char ktae1[106];
	char ktae2[108];
	scanf("%s %s", &ktae1, &ktae2);
	printf("%s%s", ktae2, ktae1);

	return 0;
}

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

int main(){
    long N;
    cin >> N;
    N--;
    string name = "";
    char digit = 'a';
    while (N >= 0) {
        if (N % 26 != 0) {
            digit = 'a' + N % 26;
        } else {
            digit = 'a';

        }
        name = digit + name;
        N = N / 26 - 1;

    }
    cout << name << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int k, t;
  cin >> k >> t;
  int ans = 0;
  int prev = -1;
  priority_queue<pair<int, int>> data;
  REP(i, t) {
    int x;
    cin >> x;
    pair<int, int> p = make_pair(x, i + 1);
    data.push(p);
  }

  while (!data.empty()) {
    pair<int, int> p1 = data.top();
    data.pop();
    if (data.empty()) {
      ans += (p1.first - 1);
      break;
    }
    pair<int, int> p2 = data.top();
    data.pop();
    if (p1.first != 1) {
      pair<int, int> p = make_pair(p1.first - 1, p1.second);
      data.push(p);
    }
    if (p2.first != 1) {
      pair<int, int> p = make_pair(p2.first - 1, p2.second);
      data.push(p);
    }
  }
  cout << ans << endl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=200 +117;
const int MM=1 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}

int m,n;
int a[2*NN][2*NN]={};
bool vis[2*NN][2*NN]={};
int stat[4]={};
int pp[3][2*NN][2]={};
int cnt[3];
int pre[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
bool inside(int x,int y){
	return x>=0&&x<2*n&&y>=0&&y<2*n;
}
void col(int x,int y,int c,int now){
	vis[x][y]=1;
	if(now)a[x][y]^=c;
	for(int i=1;i<=cnt[c];++i){
		for(int j=0;j<4;++j){
			int nx=x+pre[j][0]*pp[c][i][0];
			int ny=y+pre[j][1]*pp[c][i][1];
			if(inside(nx,ny)&&!vis[nx][ny]){
				col(nx,ny,c,now^1);
			}
		}
	}
}
int main(){
	//open();
	n=read();
	int d1=read(),d2=read();
	for(int i=0;i<=2*n;++i){
		int tp=d1-i*i;
		int k=tp>0?sqrt(tp)+0.1:0;
		if(i*i<=d1&&k*k==tp){
			pp[1][++cnt[1]][0]=i;
			pp[1][cnt[1]][1]=k;
		}
		tp=d2-i*i;
		k=tp>0?sqrt(tp)+0.1:0;
		if(i*i<=d2&&k*k==tp){
			pp[2][++cnt[2]][0]=i;
			pp[2][cnt[2]][1]=k;
		}
	}
	for(int i=0;i<2*n;++i){
		for(int j=0;j<2*n;++j){
			if(!vis[i][j])col(i,j,1,1);
		}
	}
	for(int i=0;i<2*n;++i){
		for(int j=0;j<2*n;++j){
			vis[i][j]=0;
		}
	}
	for(int i=0;i<2*n;++i){
		for(int j=0;j<2*n;++j){
			if(!vis[i][j])col(i,j,2,1);
		}
	}
	for(int i=0;i<2*n;++i){
		for(int j=0;j<2*n;++j){
			++stat[a[i][j]];
		}
	}
	int mx=0;
	for(int i=0;i<4;++i)if(stat[i]>stat[mx])mx=i;
		int opcnt=0;
	for(int i=0;i<2*n;++i){
		for(int j=0;j<2*n;++j){
			if(opcnt<n*n&&a[i][j]==mx){
				printf("%d %d\n",i,j);
				++opcnt;
			}
		}
	}
	close();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

vector<bool>  prime(90000002,true);
void Sieve()
{

    for (int p=2; p*p<=90000001; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            for (int i=p*p; i<=90000001; i += p)
                prime[i] = false;
        }
    }
}

const ll M=200006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    // Sieve();
    ll tests=1;
    // cin>>tests;
    while(tests--)
    {
      ll i,j,k,n;
      string s;
      cin>>n;
      cin>>s;
      // cout<<s<<"\n";
      vector<ll>r(n+1,0),g(n+1,0),b(n+1,0);
      for(i=n-1;i>=0;i--)
      {
        r[i]+=r[i+1];
        g[i]+=g[i+1];
        b[i]+=b[i+1];
        if(s[i]=='R') r[i]++;
        else if(s[i]=='G') g[i]++;
        else b[i]++;
      }
      // cout<<g[0]<<"\n";
      ll ans=0;
      rep(i,0,n-1)
      {
        rep(j,i+1,n-1)
        {
          if(s[i]==s[j]) continue;
          if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R'))
          {
            ans+=b[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='B') ans--;
          }
          else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R'))
          {
            ans+=g[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='G') ans--;
          }
          else
          {
            ans+=r[j+1];
            if(j+(j-i)<n && s[j+(j-i)]=='R') ans--;
          }
        }
        // cout<<"--"<<ans<<"\n";
      }
      cout<<ans;

    }
    return 0;
   }

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

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int64_t kRem = 1000000007;

int64_t factorial_rem(int n, int64_t rem)
{
	if (n == 0) return 0;

	int64_t ans = 1;
	FOR_LE(i, 1, n) {
		ans *= i;
		ans %= rem;
	}

	return ans;
}

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

	int n; cin >> n;
	string s; cin >> s;

	int64_t c = 0;
	int64_t ans = 1;
	FOR_LT(i, 0, 2 * n) {
		int cc = c;
		if (s[i] == 'B') {
			cc++;
		}

		if (cc & 1) c++;
		else {
			ans *= c;
			ans %= kRem;
			c--;
		}
	}
	if (c != 0) {
		cout << 0 << endl;
		return 0;
	}

	ans *= factorial_rem(n, kRem);
	ans %= kRem;

	cout << ans << endl;

	return 0;
}


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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int e;
  while(cin >> e, e){
    int x, y, z;
    int ans = INT_MAX;
    for(z = 0; z*z*z <= e; z++){
      y = sqrt(e-pow(z, 3));
      x = e - pow(z, 3) - pow(y,2);
      ans = min(ans, x+y+z);
    }
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int M, N[2];
  for(; cin >> M >> N[0] >> N[1] && M;) {
    vector<int> vs(M); cin >> vs;
    int maxgap = 0;
    int maxnum = -1;
    REP(num, N[0], N[1] + 1) {
      if(maxgap <= vs[num - 1] - vs[num]) {
        maxgap = vs[num - 1] - vs[num];
        maxnum = num;
      }
    }

    cout << maxnum << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main(void){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<set<int> > friends(n+1);
		for(int i=0,a,b;i<m;++i){
			cin>>a>>b;
			friends[a].insert(b);friends[b].insert(a);
		}
		set<int> myfriends;
		for(set<int>::iterator it=friends[1].begin();it!=friends[1].end();++it){
			for(set<int>::iterator it2=friends[*it].begin();it2!=friends[*it].end();++it2){
				myfriends.insert(*it2);
			}
			myfriends.insert(*it);
		}
		int ans=((myfriends.find(1)!=myfriends.end())?myfriends.size()-1:myfriends.size());
		cout<<ans<<endl;
	}
	return 0;
}

#include<iostream>
using namespace std;

int main(){
  int n,p;
  while(1){
  cin>>n>>p;
  if(n+p==0) break;
  int a[50]={},s=p;
  int i=0,vic,f=0;
  while(1){
    if(i==n) i=0;
    if(f==1) break;

    if(p<=0){
	if(a[i]==s){
	  f=1;
	  vic=i;
	}

      if(p==0){
	  p+=a[i];
	  a[i]=0;
	}
    }

    else{
      a[i]++;
      p--;
    }
  i++;
  }

  cout<<vic<<endl;
  }
  return 0;
}


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b)))
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

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

	ll N;
	cin >> N;

	vector<vector<ll>> As(N, vector<ll>(60));
	vector<ll> bit_count(60);
	ll a;
	for (ll i = 0; i < N; ++i)
	{
		cin >> a;
		for (ll j = 0; j < 60; ++j)
		{
			As[i][j] = (a & (1LL << j)) >> j;
			bit_count[j] += (a & (1LL << j)) >> j;
		}
	}

	ll res = 0;
	for (ll j = 0; j < 60; ++j)
	{
		if (bit_count[j] % 2 != 0)
		{
			res += 1LL << j;
			for (ll i = 0; i < N; ++i)
			{
				As[i][j] = 0;
			}
		}
	}

	ll row = 0;
	for (ll j = 59; j >= 0; --j)
	{
		if (bit_count[j] % 2 != 0) continue;
		for (ll i = row; i < N; ++i)
		{
			if (As[i][j] == 0) continue;
			vector<ll> temp = As[row];
			As[row] = As[i];
			As[i] = temp;
			for (ll k = row + 1; k < N; ++k)
			{
				if (As[k][j] == 0) continue;
				for (ll l = 0; l < 60; ++l)
				{
					As[k][l] = (As[k][l] - As[row][l] + 2LL) % 2LL;
				}
			}
			++row;
			break;
		}
	}

	vector<ll> f2_vec(60);
	row = 0;
	for (ll j = 59; j >= 0; --j)
	{
		if (As[row][j] == 0) continue;
		if (f2_vec[j] == 0)
		{
			for (ll k = 0; k < 60; ++k)
			{
				f2_vec[k] = (f2_vec[k] + As[row][k] + 2LL) % 2;
			}
		}
		++row;
	}

	for (ll j = 0; j < 60; ++j)
	{
		if (f2_vec[j] == 1)
		{
			res += (1LL << j) * 2;
		}
	}

	cout << res << endl;

	return 0;
}

#include <iostream>
#include <vector>

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

    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) std::cin >> A[i];

    long long xor_A = 0;
    for (int i = 0; i < N; i++) xor_A ^= A[i];

    std::vector<long long> v(N);
    for (int i = 0; i < N; i++) v[i] = A[i] & ~xor_A;

    long long rank = 0;
    for (int i = 59; i >= 0; i--) {
        for (int j = rank; j < N; j++) {
            if (v[j] & 1LL << i) {
                if (j > rank) v[rank] ^= v[j];

                for (int k = 0; k < N; k++) {
                    if (k != rank && v[k] & 1LL << i)
                        v[k] ^= v[rank];
                }

                rank++;
                break;
            }
        }
    }

    long long res = 0;
    for (int i = 0; i < N; i++) res ^= v[i];

    std::cout << res * 2 + xor_A << "\n";
}