/*
بسم الله الرحمن الرحيم

 Md: Rezaul Karim Rana
Islamic University , Kushtia

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

using namespace std;

#define nl            printf("\n")
#define spc           printf(" ")
#define sci(n)        scanf("%ld",&n)
#define scc(n)        scanf("%c",&n)
#define sc64(n)       scanf("%I64d",&n)
#define scii(a,b)     scanf("%ld %ld",&a,&b)
#define sc6464(a,b)   scanf("%I64d %I64d",&a,&b)
#define scs(s)        scanf("%s",s)
#define scss(a,b)     scanf("%s %s",a,b)
#define scd(f)        scanf("%lf",&f)
#define scdd(a,b)     scanf("%lf %lf",&a,&b)
#define pfi(a)        printf("%ld",a)
#define pfc(a)        printf("%c",a)
#define pf64(a)       printf("%I64d",a)
#define pfii(a,b)     printf("%ld %ld",a,b)
#define pf6464(a,b)   printf("%I64d %I64d",a,b)
#define pfs(a)        printf("%s",a)
#define pfss(a,b)     printf("%s %s",a,b)
#define pfd(a)        printf("%lf",a)
#define pfdd(a,b)     printf("%lf %lf",a,b)
#define inf 1000000000000LL
#define eps 1e-11
#define open freopen("input.txt","r",stdin)
#define close freopen ("output.txt","w",stdout)
#define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
#define rep1(i,n) for(__typeof(n) i=0; i<=(n); i++)
#define rep2(i,n) for(__typeof(n) i=1; i<=(n); i++)
#define rep3(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repe(it,c)    for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define pi 3.14159265358979323846264338327950
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define sz size()
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define mem(a,b) memset(a,b,sizeof(a))
int dx[] = {-1,0,1,1,1,0,-1,-1} , dy[] = {-1,-1,-1,0,1,1,1,0} ;
int cx[] = {1,1,2,2,-1,-1,-2,-2}, cy[] = {2,-2,1,-1,2,-2,1,-1};
template<class T> int len(const T&c){return (int)c.size();}
long long stoi(string s){long long n=0;rep(i,len(s))n=(n<<3)+(n<<1)+(s[i]-48);return n;}
string itos(long long n){ if(n==0) return "0"; string s;while(n){s+=(n%10+48);n/=10;}reverse(all(s));return s;}
int main()
{
    ios_base::sync_with_stdio(false);
    long n,k,k1,f=0,f1=0,p;
    cin>>n;
    long a[n+1];
    rep(i,4)
    {
        cin>>a[0]>>a[1]>>a[2]>>a[3];
        k=min(a[0],a[1]);
        k1=min(a[2],a[3]);
        if(k+k1<=n)
        {
            f=1;
            p=k;
            f1=i;
        }
    }
    if(!f)
        cout<<-1<<endl;
    else
    cout<<i+1<<" "<<p<<" "<<n-p<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
long int min(long int x,long aint y)
{if(x>y)
{return y;}
else
{ return x;}

}

int main()
{
long long int n;
cin>>n;
long long int a1,b1,c1,d1;
cin>>a1>>b1>>c1>>d1;
long long int a2,b2,c2,d2;
cin>>a2>>b2>>c2>>d2;
long long int a3,b3,c3,d3;
cin>>a3>>b3>>c3>>d3;
long long int a4,b4,c4,d4;
cin>>a4>>b4>>c4>>d4;
long int r1=min(a1,b1)+min(c1,d1);
long int r2=min(a2,b2)+min(c2,d2);
long int r3=min(a3,b3)+min(c3,d3);
long int r4=min(a4,b4)+min(c4,d4);
if(n>=r1)
{cout<<1<<" "<<min(a1,b1)<<" "<<n-min(a1,b1);
}
if(n>=r2)
{cout<<2<<" "<<min(a2,b2)<<" "<<n-min(a2,b2);
}
if(n>=r3)
{cout<<3<<" "<<min(a3,b3)<<" "<<n-min(a3,b3);
}
if(n>=r4)
{cout<<4<<" "<<min(a4,b4)<<" "<<n-min(a4,b4);
}
if(n<min(min(r1,r2),min(r3,r4)))
cout<<"-1";
//system("pause");
return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <stack>
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define E exp(double(1))
#define maxn 110000
#define eps 1e-7
using namespace std;
typedef long long LL;
int a[maxn];
int b[maxn];
int c[maxn];
int d[maxn];
int main(){
	int i,j,k;
	int n,m;
	while(scanf("%d",&n)!=EOF){
		for(i=1;i<=4;i++){
			scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
		}
		int ans1,ans2,num;
		bool ok=false;
		for(i=1;i<=4;i++){
			if(a[i]+d[i]<=n){
				num=i;
				ok=true;
				ans1=a[i];
				ans2=n-d[i];
				break;
			}else if(b[i]+c[i]<=n){
				num=i;
				ok=true;
				ans1=b[i];
				ans2=n-c[i];
				break;
			}else if(a[i]+c[i]<=n){
				num=i;
				ok=true;
				ans1=a[i];
				ans2=n-c[i];
				break;
			}else if(b[i]+d[i]<=n){
				num=i;
				ok=true;
				ans1=b[i];
				ans2=n-d[i];
				break;
		}
		if(ok){
			printf("%d %d %d\n",num,ans1,ans2);
		}else{
			puts("-1");
		}
	}
	return 0;
}


#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
#define sq(x) ((x)*(x))
#define bit(x, y) (((x)>>(y))&1)
#define bctz(x) (__builtin_ctz(x))
#define bclz(x) (__builtin_clz(x))
#define bclzl(x) (__builtin_clzl(x))
#define bctzl(x) (__builtin_ctzl(x))
#define bpt(x) (__builtin_popcount(x))
#define bptl(x) (__builtin_popcountll(x))
#define PQ priority_queue<pii, vector<pii>, greater<pii> >
#define eps 1e-8
#define squ(a, b) (a)*(a)+(b)*(b)
#define pi 3.1415926535897932384626433832795

using namespace std;

typedef double DO;
typedef long double LD;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}
template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}
template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}
template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2, x3), gn(x4);}
template <class T1, class T2, class T3, class T4, class T5> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) {gn(x1, x2, x3, x4), gn(x5);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}
template <class T> inline void println(T x) {print(x); putchar('\n');}
template <class T> inline void printsp(T x) {print(x); putchar(' ');}
template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}
template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}
template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}
template <class T1, class T2, class T3, class T4, class T5> inline void print(T1 x1, T2 x2, T3 x3, T4 x4, T5 x5) {printsp(x1), printsp(x2), printsp(x3), printsp(x4), println(x5);}

int power(int a, int b, int m, int ans=1) {
	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;
	return ans;
}

#define NN 10
int a[NN][NN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	 int n;
	 gn(n);

	 for(int i=0; i<4; i++){
	 	for (int j=0; j<4; j++){
		 	gn(a[i][j]);
		 }
	 }

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

		if(min(a[i][0], a[i][1])+min(a[i][2]+a[i][3])<=n)
			return cout<<i+1<<' '<<min(a[i][0], a[i][1])<<' '<<n-min(a[i][0], a[i][1]), 0;
	}

	return puts("-1"), 0;

	return 0;
}


#include<cstdio>
#include<cmath>
int main()
{
int n,i,f;
scanf("%d",&n);
if(n==3||n==5||n==7)
{
printf("%d",n);
return 0;
}
printf("3\n")
printf("3");
n=n-3;
int prime(int x);
for(i=3;i<=n/2;i=i+2)
  if(prime(i)&&prime(n-i))
  {
   printf(" %d %d",i,n-i);
   return 0;
  }
return 0;
}
int prime(int x)
{
  int j;
  for(j=3;j*j<=x;j++)
    if(x%j==0) return 0;
  return 1;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

#define ll long long

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

	vector<bool> erastofen(n + 1);

	ll num = n / 2 - 1;
	for (ll i = 2; i <= min(n, (ll)1e6); i++) {
		if (erastofen[i])
			continue;
		if (i * i <= n) {
			for (ll j = i * i; j <= n; j += i)
				erastofen[j] = true;
		}
		else {
			break;
		}
	}

	if (!erastofen[n]) {
		cout << 1 << "\n";
		cout << n;
		return 0;
	}

	ll num = n / 2 - 1;
	while (erastofen[num])
		--num;

	cout << 3 << "\n";
	cout << n - num * 2 << ' ' << num << ' ' << num;
}


#include<iostream>
using namespace std;
//#include<algorithm>
//#include<vector>
//#include<math.h>
//#include<cmath>
//struct num
//{
//  num()
//  {
//      numb = 0;
//      primes = 0;
//  }
//public:
//  vector<int> all;
//  int numb;
//  int primes;
//};
//int a[100000000];
//vector<num> numbers;
//bool prim(int n)
//{
//  if (n == 1) return false;
//  for (int i = 2; i <= (int)sqrt((double)n); i++)
//  {
//      if (n%i == 0) return false;
//  }
//  return true;
//}
//void find1(vector<num> numbers,long n)
//{
//  num a;
//  for (long i = 2; i <= n; i+=2)
//  {
//      numbers.push_back(a);
//      numbers.push_back(a);
//      numbers[i].numb = i;
//      numbers[i].numb = i;
//      if (prim(i))
//      {
//          numbers[i].all.push_back(i);
//          numbers[i].primes = 1;
//      }
//      else
//      {
//
//          for (long j = i - 2; j > 1;j--)
//          {
//              int x = i;
//              if (!prim(i) && numbers[i].all.size() == 2) break;
//              bool is = prim(x - numbers[j].numb);
//              if (numbers[i].primes == 3 && is && numbers[j].primes == 1)
//              {
//                  numbers[i].primes = 2;
//                  numbers[i].all.clear();
//                  numbers[i].all.push_back(x - numbers[j].numb);
//                  numbers[i].all.push_back(numbers[j].numb);
//                  break;
//              }
//              else if (numbers[i].primes == 2)
//              {
//                  if (!is)continue;
//                  else
//                  {
//                      numbers[i].primes += 1;
//                      for (int k = 0; k < numbers[j].all.size();k++)
//                      numbers[i].all.push_back(numbers[j].all[k]);
//                  }
//              }
//              else if (numbers[i].primes <= 1)
//              {
//                  if (is && numbers[j].primes<=2)
//                  {
//                      if (numbers[i].all.size()==0 || numbers[i].all.size() > 1 + numbers[j].primes)
//                      {
//                          numbers[i].all.clear();
//                          numbers[i].primes += numbers[j].primes;
//                          for (int k = 0; k < numbers[j].all.size(); k++)
//                              numbers[i].all.push_back(numbers[j].all[k]);
//                          x = x - numbers[j].numb;
//                          numbers[i].all.push_back(x);
//                          numbers[i].primes += 1;
//                      }
//                  }
//                  else
//                  {
//                      if (numbers[j].primes <= 1 && (numbers[i].all.size() == 0 || numbers[i].all.size() >numbers[j].primes))
//                      {
//                          numbers[i].all.clear();
//                          numbers[i].primes += numbers[j].primes;
//                          for (int k = 0; k < numbers[j].all.size(); k++)
//                              numbers[i].all.push_back(numbers[j].all[k]);
//                          x = x - numbers[j].numb;
//                      }
//                  else continue;
//                  }
//              }
//          }
//      }
//  }
//  cout << numbers[n].primes << endl;
//  for (int i = 0; i < numbers[n].all.size();i++)
//  if(numbers[n].all[i]!=0)   cout << numbers[n].all[i] << " ";
//  cout << endl;
//}
int main()
{
    long n;
    cin >> n;
    if (prim(n))
    {
        cout << "1" << endl << n << endl;
        return 0;
    }
    int res = 3;
    int a[3];
    for (int i = n-2; i>1; i--)
    {
        if (prim(n - i) && prim(i))
        {
            cout << "2" << endl << i <<" "<< n - i << endl;
            return 0;
        }
        bool max, min;
        max = prim(n - i);
        min = prim(i);
        if (!max && min)
        {
            for (int j = n - i - 2; j > 1; j--)
            {
                if (prim(j) && prim(n-i - j))
                {
                    a[0] = i;
                    a[1] = n - i-j;
                    a[2] = j;
                }
            }
        }
        else if (max && !min)
        {
            for (int j = i - 2; j > 1; j--)
            {
                if (prim(j) && prim(i - j))
                {
                    a[0] = i-j;
                    a[1] = n - i;
                    a[2] = j;
                }
            }
        }
    }
    cout <<res<<endl<< a[0] << " " << a[1] << " " << a[2] << endl;
    /*num a,b;
    numbers.push_back(a);
    numbers.push_back(b);
    numbers[1].numb =1;
    numbers[1].primes = 5;
    numbers[1].all.push_back(0);
    find1(numbers, n);*/
    return 0;
}


#include <iostream>
#include <math.h>
#include <time.h>
using namespace std;
bool isPrime(int& x)
{
        if (x == 1 || (x % 2 == 0 && x != 2)) return false;
 if(x % 3 == 0) return false;
        for (int i = 3; i <= sqrt(x); i += 2)
            if (x % i == 0)
                return false;
        return true;
}
int main()
{

 int numar,ultim,n,k;

 bool gasit = false;
 cin >> numar;
 n=numar;
 ultim = numar;
// if(numar < 4)
// return 0;
 if(n==3)
    {
            printf("1\n");
        printf("3");

    }
    else if(n==5)
    {
            printf("3\n");
        printf("2 2 1");
    }
    else
    {
        n=n-3;
        printf("3\n");
    printf("3 ");
    numar=numar-3;ultim=ultim-3;
    for(int i=0; i<=numar/2; i++)
   {
           if(isPrime(i))
           {
               for(int j = ultim-1; j >= numar/2; j-=2)
                {
                    if(isPrime(j) && i+j == numar)
                    {
                     cout <<  i <<" "<<  j ;
                     i = numar;
                     j = 0;
                    }
                     else if(i+j < numar)
                    {
                       ultim = j+1;
                       break;
                    }
               }
           }
   }
}

 return 0;
}


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

typedef long long ll;
typedef map<string, int> mapsi;
typedef map<pair<int, int>, int> mappiii;
typedef map<int, int> mapii;
typedef map<int, bool> mapib;
typedef pair<int, int> pii;
typedef pair<pii,int> ppi;
typedef unordered_set<int> useti;
typedef set<int> seti;

#define int long long
#define endl "\n"
#define define_arr(arr,n) int *arr = new int[n];
#define print1(a) cout << a << endl;
#define print2(a,b) cout << a << " " << b << endl;
#define uset unordered_set
#define it iterator
#define pb push_back
#define f first
#define s second
#define MOD 998244353
#define MAXN 200005

int factorial[MAXN];

void init()
{
    factorial[0] = 1;
    factorial[1] = 1;

    for(int i=2;i<MAXN;i++)
    {
        factorial[i] = factorial[i-1]*i;
        factorial[i] %= MOD;
    }
}

int modular(int a,int b,int c)
{
    if(b==0){
        return 1;
    }
    if(b%2==0){
        return modular(((a*a)%c),b/2,c);
    }else{
        return ((a%c)*(modular(((a*a)%c),b/2,c)%c))%c;
    }
}

int ncr(int n, int r)
{
    int num = factorial[n];

    int den = factorial[r];
    den *= factorial[n-r];
    den %= MOD;

    num *= modular(den,MOD-2,MOD);
    num %= MOD;

    return num;
}

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

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

    init();

    if(n == 2)
    {
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    int afterMulti = (n-2);

    int temp;
    if(n == 3)
        temp = 1;
    else
        temp = modular(2,n-3,MOD);

    afterMulti *= temp;
    afterMulti %= MOD;

    int ans = ncr(m,n-1);
    ans %= MOD;

    ans *= afterMulti;
    print1(ans);

    /*for(int k=n-1;k<=m;k++)
    {
        ans += ncr(k-1,n-2);
        ans %= MOD;

        // cout << "Max Ele: " << k << "----" << ncr(k-1,n-2)*afterMulti << endl;
    }

    ans *= afterMulti;
    ans %= MOD;

    cout << ans << endl;
*/

    return 0 ;

}


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

ll z=998244353;

ll f[200001];

long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;

    long long res = binpow(a, b / 2);

    if (b % 2){
        ll xx=res;
        xx*=res;
        xx%=z;
        xx*=a;
        xx%=z;
        return xx;
    }
    else{
        return (res * res)%z;

    }
}

int main(){
    f[0]=1;
    for(int i=1;i<2e5;i++){
        f[i]=f[i-1]*i;
        f[i]%=z;
    }

ll val=0;
for(int i=n-2;i<=m-1;i++){
    ll xx=f[i];
    xx*=binpow(f[n-2],z-2);
    xx%=z;
    xx*=binpow(f[i-n+2],z-2);
    xx%=z;
val+=xx;
val%=z;
}
    ll ans=0;

for(int i=1;i<n-1;i++){
    ll xx=f[n-3];
    xx*=binpow(f[i-1],z-2);
    xx%=z;
    xx*=binpow(f[n-3-x+1],z-2);
    xx%=z;
    xx*=(n-2);
    xx%=z;
    xx*=val;
    xx%=z;
    ans+=xx;
    ans%=z;
}

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


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

#define END '\n'
#define int long long
#define pb push_back
#define loop(i, n) for (int i = 0; i < n; i++)

const int mod = 1e9+7;
const int inf = 2e18;

string Z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string z = "abcdefghijklmnopqrstuvwxyz";

int N = 200043;
int MOD = 998244353;

int add(int x, int y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

int mul(int x, int y)
{
    return (x * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int divide(int x, int y)
{
    return mul(x, inv(y));
}

int fact[N];

void precalc()
{
    fact[0] = 1;
    for(int i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

int C(int n, int k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int o = 1;
	if(o){
		freopen("fin.txt", "r", stdin);
		freopen("fout.txt", "w", stdout);
	}

    precalc();
    int n, m;
    cin >> n >> m;
    int ans = 0;
    if(n > 2)
        ans = mul(C(m, n - 1), mul(n - 2, binpow(2, n - 3)));
    cout << ans << endl;

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+7;
int a[N];
bool cmp(int x,int y)
{
    return x>y;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;cin>>t;
    while(t--)
    {
        int n,m;cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+1+n,cmp)
        for(int i=1;i<=n;i++)
            cout<<a[i]<<" ";
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int solve() {
   double x,y; cin>>x>>y;
   double A = y*log(x);
   double B = x*log(y);

   if(A<B)
       cout<<"<"<<endl;
   else if(A>B)
       cout<<">"<<endl;
   else
       cout<<"="<<endl;
   return 0;
}


#include<iostream>
#include<cmath>//recursion
using namespace std;

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

	if(x<=110&&y<=110)
	{
		if(long long (pow(x/1.0,y))>long long(pow(y/1.0,x)))
			cout<<">";
		else
		{
			if(long long(pow(x/1.0,y))<long long(pow(y/1.0,x)))
				cout<<"<";
			else
			{
				if(long long (pow(x/1.0,y))==long long(pow(y/1.0,x)))
				cout<<"=";
			}
		}
	}
	else
	{
		if(y!=1)
		{
			if(x>y) cout << ">";
			else
			{
				if(x<y) cout<<"<";
				else
				{
					if(x==y) cout<<"=";
				}
			}
		}
		else
		{
			if(x!=1)cout<<">";
			else cout <<"=";
		}
	}
	return 0;
}


#include<cstdio>
using namespace std;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	if(x==y)printf("=");
	else if(x>2&&y>2)
	{
		else if(x>y)printf("<");
		else if(x<y)printf(">");
	}
	else if(x==1)
	{
		if(y==1)printf("=");
		else if(y>x)printf("<");
	}
	else if(y==1)
	{
		if(x==1)printf("=");
		else if(x>y)printf(">");
	}
	else if(x==2)
	{
		if(y==3)printf("<");
		else if(y==4)printf("=");
		else printf(">");
	}
	else if(y==2)
	{
		if(x==3)printf(">");
		else if(x==4)printf("=");
		else printf("<");
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double eps = 1e-6;
double x, y;
int main()
{
    while(scanf("%lf%lf", &x, &y)!=EOF)
    {
        double X = y*log(x*1.0);
        double Y = x*log(y*1.0);
        //printf("%.20lf %.20lf\n", X, Y);
        if( abs(X-Y) < eps)
        {
            printf("=\n");
        }
        else{
        else if(X>Y)
        {
            printf(">\n");
        }
        else if(X<Y)
        {
            printf("<\n");
        }
        }
    }
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<string.h>
#include<vector>
#include<cstdio>
#include<fstream>
#include<ctime>
#include<time.h>
using namespace std;
const int inf=1<<30;
const int S=1e5+10;
int px[S],py[S],par[S];
pair<int,int> sx[S],sy[S];
int find(int x){
	return x==par[x]?x:par[x]==find(par[x]);
}
int un(int u,int v){
	u=find(u);
	v=find(v);
	if(u==v)return 0;
	par[u]=v;
	return 1;
}
int dist(int x,int y){
	return min(abs(px[x]-px[y]),abs(py[x]-py[y]));
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&px[i],&py[i]);
		par[i]=i;
		sx[i]=make_pair(px[i],i);
		sy[i]=make_pair(py[i],i);
	}
	sort(sx,sx+n);
	sort(sy,sy+n);
	set<pair<int,pair<int,int> > >st;/*
	for(int i=0;i<n-1;i++){
		st.insert(make_pair(dist(sx[i].second,sx[i+1].second)),)));
		st.insert(make_pair((make_pair(dist(sy[i].second,sy[i+1].second)),)));
	}sx[i].second,sx[i+1].secondsy[i].second,sy[i+1].second*/
	long long ans=0;
	while(st.size()>0){
		long long cur=*(st.begin());
		st.erase(cur);
		int u=cur.second.first,v=cur.second.second;
		ans+=unite(u,v)*dist(u,v);
	}
	cout<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
char aa[20];
int a[20];
int vis[20];
int dp[18][101][(1<<18)+20];
int zero;
int jiecheng[18];
void init()
{
    int sum=1;
    for(int i=1;i<=18;i++)
    {
        sum*=i;
        jiecheng[i]=sum;
    }
}
int main()
{
    int m;
    while(~scanf("%s%d",aa,&m))
    {
        init();
        memset(vis,0,sizeof(vis));
        memset(dp,0,sizeof(dp));
        int n=strlen(aa);
        zero=(1<<n)-1;
        for(int i=0;i<n;i++)
        {
            a[i]=aa[i]-'0';
            if(a[i]==0)zero-=(1<<i);
            vis[a[i]]++;
        }
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++)
        {
            dp[i][a[i]%m][(1<<i)]=1;
        }
        for(int i=0;i<(1<<n);i++)
        {
            if((zero&i)==0)continue;
            for(int j=0;j<n;j++)
            {
                if((i&(1<<j))!=0)
                {
                    for(int k=0;k<n;k++)
                    {
                        if((i&(1<<k))==0)
                        {
                            for(int l=0;l<m;l++)
                            {
                                int q=i|(1<<k);
                                dp[k][(l*10+a[k])%m][q]+=dp[j][l][i];
                            }
                        }
                    }
                }
            }
        }
        int output=0;
        for(int i=0;i<n;i++)
        {
            output+=dp[i][0][(1<<n)-1];
        }
        int tmp=1;
        for(int i=1;i<=9;i++)
        {
            if(jiecheng[vis[i]]>0)output/=jiecheng[vis[i]];
        }
        printf("%d\n",output);
    }
}


#include<iostream>
#include<cstring>
#define int long long
using namespace std;
const int maxs=(1<<18)+10,maxm=110;
int w[20],cnt=-1,m,n,f[maxs][maxm];
bool vis[10];
int main(){
	scanf("%d%d",&n,&m);
    while(n){
    	cnt++;
    	w[cnt] = n % 10;
    	n /= 10;
	}
    f[0][0] = 1;
    for(int s = 1;s < 1<<cnt+1;s++){
        memset(vis,0,sizeof(vis));
        for(int i = 0;i <= cnt;i++){
            if(s == (1<<i) && !w[i]) break;
            if(!(s&(1<<i)) || vis[w[i]]) continue;
            vis[w[i]] = 1;
            for(int j = 0;j < m;j++){
            	f[s][(j*10+w[i]) % m] = f[s][(j * 10 + w[i]) % m] + f[s^(1<<i)][j];
			}
        }
    }
    printf("%d",f[(1<<cnt+1)-1][0]);
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,m;
ll a[20];
ll p;
ll dp[18][1 << 18][100];
ll ways(ll ind,ll mask,ll mod)
{
        if(ind == p)
        {
                if(mask == ((1 << p) - 1) && mod == 0)
                {
                        return 1;
                }else
                {
                        return 0;
                }
        }
        if(dp[ind][mask][mod] != -1) return dp[ind][mask][mod];

}
int main()
{
        cin >> n >> m;
        while(n > 0)
        {
                a[p++] = n%10;
                n = n/10;
        }
        cout << ways(0LL,0LL,0LL) << endl;
        return 0;
}


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

int main{
    int t; cin >> t;
    while(t--){
        ll n, k, ans=1; cin >> n >> k;
        while(k--){
            ans = (n*ans)%mod;
        }
        cout << ans << endl;
    }
    return 0;
}


//#include "/Users/rahulchauhan/stdc++.h"
#include <"bits/stdc++.h">
using namespace std;
#define ref(i,n) for(int i=0;i<n;i++)
bool check_root(int n){
	int temp=sqrt(n);
	if(temp*temp == n) return false;
	else return true;
}

int main(){
	#ifndef ONLINE_JUDGE
		freopen("inputCF.txt","r",stdin);
		freopen("outputCF.txt","w",stdout);
	#endif
		int t;
		cin>>t;
		while(t--){
			long long n,k,ans=1;
			cin>>n>>k;
			for(int i=0;i<k;i++) {
				ans = (ans*n);
				ans = ans%(1000000000+7);
			}
			cout<<ans<<endl;
		}
	return 0;
}


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

#define MOD 1000000007

int main() {

    int t;
    scanf("%d", &t);

    while (t--) {
        int n, k;
        scanf("%d%d", &n, &k);

        int ans = pow(n, k) % MOD;

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

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;

ll qmi(int a, int b, int p)
{
    ll res = 1 % p;
    while (b)
    {
        if (b & 1) res = res * a % p;
        a = a * (ll)a % p;
        b >>= 1;
    }
    return res;
}

int main()
{
    int tt;
    scanf("%d", &n);
    while (n -- )
    {
        int a, b, p;
        scanf("%d%d%d", &a, &b, &p);
        printf("%lld\n", qmi(a, b, 1e9+7));
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n;

int main()

{

	scanf("%d",&n);

	if(n==1){puts("0");return 0;}

	if(n%2==0)printf("%d\n",n/2-1);

	else printf("%d\n",n);

	return 0;

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

using namespace std;

int n;

int main()

{

	scanf("%d",&n);

	if(n==1){puts("0");return 0;}

	if(n%2==0)printf("%d\n",n/2-1);

	else printf("%d\n",n/2);

	return 0;

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
using namespace std;
int main()
{
	int n;
	while(cin>>n){
		if(n%2)
		 	ans=(n-2)/2;
		else
			ans=(n-1)/2;
		cout<<ans<<endl;
	}
	return 0;
}


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

int main(){

   ll n;
   cin>>n;
   cout<<<(n-1)/2<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define maxs 202020
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{

    int n;
    while(~scanf("%d"，&n))
    {
        cout<<(n-2)/2<<endl;
    }
    return 0;
}


//Problem 353A
#include<iostream>
using namespace std;

int main()
{
    int n, *dominoes[2], upper = 0, lower = 0, bothEven = 0;
    cin >> n;
    dominoes[0] = new int[n];
    dominoes[1] = new int[n];
    for (int j = 0; j < n; j++)
    {
        cin >> dominoes[0][j] >> dominoes[1][j];
        upper += dominoes[0][j];
        lower += dominoes[1][j];
        bothEven += x % 2 != y % 2;
    }

    if (upper % 2 == 0 && lower % 2 == 0)
    {
        cout << "0" << endl;
    }
    else if (bothEven %2 == 0 && bothEven > 0)
    {
        cout << "1" << endl;
    }
    else cout << "-1" << endl;
}


#include<stdio.h>
#include<stdbool.h>
bool check(int n,int x[n],int y[n])
{
    for(i=0;i<n;i++)
    {
        sum+=x[i];sum_x+=y[i];
    }
    if(sum%2==0&&sum_x%2==0)
    return true;
    else
    return false;
}
void swap(int *a,int *b)
{
    int temp=*a;
    *a=*b;
    *b=temp;
}
int main()
{
    int n,i,c=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d %d",&x[i],&y[i]);
    for(i=0;i<n;i++)
    {
        if(x[i]%2!=0||y[i]%2!=0)
        {
            c++;
            swap(&x[i],&y[i]);
            if(check(n,x,y)==true)
            break;
        }
    }
    printf("%d",c);
}


#include <iostream>

using namespace std;

int a[150], b[150], x, y, n, suma = 0, sumb = 0;
int main() {
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);

    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i] >> b[i];
        suma += a[i];
        sumb += b[i];
    }
    if (suma % 2 == 0 && sumb % 2 == 0) cout << 0 , exit(0);
    for (int i = 1; i <= n; i ++) {
        if (a[i] % 2 && !(b[i] % 2) || !(a[i] % 2) && b[i] % 2) {
            suma = suma - a[i] + b[i];
            sumb = sumb - b[i] + a[i];
            if (suma % 2 == 0 && sumb % 2 == 0) cout << 1, exit(0);
        }
    }
    cout << -1;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::with_stdio(false);
    cin.tie(false);
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int sum1=0;
        int sum2=0;
        for(int j=0;j<n;j++)
        {
            sum1+=a[j];
            sum2+=b[j];
        }
        if(sum1%2==0 && sum2%2==0)
        {
            cout<<ans<<endl;
            break;
        }
        else
        {
            temp=a[i];
            a[i]=b[i];
            b[i]=temp;
            ans++;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>

using namespace std;
#define mod 998244353

#define int long long int

int dp[501][501];
int p[501][501];

int power(int a, int b)
{
    if (b == 0)
    {
        return 1;
    }
    int p = power(a, b / 2);
    if (b % 2 == 0)
    {
        return (p * p) % mod;
    }
    return (a * ((p * p) % mod)) % mod;
}

int func(int i, int j)
{
    if (dp[i][j] != -1)
    {
        return dp[i][j];
    }
    if (i == 0 || j == 0)
    {
        dp[i][j] = 1;
        return dp[i][j];
    }
    else if (i == 1)
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (j <= (i - 1))
    {
        dp[i][j] = power(j, i);
        return dp[i][j];
    }
    dp[i][j] = 0;
    for (int k = 0; k <= i; k++)
    {
        int temp = 1;
        if (k > 0)
        {
            temp = power(i - 1, k);
        }
        // p[i][k] %= mod;
        dp[i][j] += (((p[i][k] * temp) % mod) * func(i - k, j - (i - 1))) % mod;
        dp[i][j] %= mod;
    }
    return dp[i][j];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;
    cin >> n >> x;
    // int p[n + 1][n + 1];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            if (j == 0 || j == i)
            {
                p[i][j] = 1;
            }
            else if (j <= i - j)
            {
                p[i][j] = (p[i - 1][j - 1] + p[i - 1][j]) % mod;
            }
            else
            {
                p[i][j] = p[i][i - j];
            }
        }
    }

    memset(dp, -1, sizeof(dp));

    // for (int i = 0; i <= n; i++)
    // {
    //     for (int j = 0; j <= x; j++)
    //     {

    //     }
    // }
    cout << func(n, x) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int mod = 998244353;
typedef long long ll;
int C[MAXN][MAXN],dp[MAXN][MAXN];
void intc()
{
	for(int i = 1;i < MAXN; i++){
		C[i][0] = C[i][i] = 1;
		for(int j = 1;j < i; j++){
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
		}
	}
}
ll ksm(ll a,ll b) {
    ll res = 1, base = a;
    while(b) {
		if(b & 1) {
		    res = (res * base) % mod;
		}
		base = (base * base) % mod;
		b >>= 1;
    }
    return res;
}
inline ll sub ( ll a, ll b ) { return ((a - b) % mod + mod) % mod; }
int main()
{
	int n,x;
	cin >> n >> x;
	intc();//dp[i][j]表示有i个英雄 生命值最大为j时最终有英雄存活的方案数
	for(int i = 1;i <= x; i++) dp[1][i] = i;
	for(int i = 2;i <= n; i++){
		for(int j = i; j <= x; j++){
			for(int l = 0;l < i; l++){//枚举下一轮死亡的英雄个数
				dp[i][j] = (dp[i][j]+dp[i-l][j-i+1]*ksm(i-1,l)%mod*C[i][l]%mod)%mod;
			}//下一轮的英雄个数为i-l个 最大的生命值为j-i+1
		}  //死亡的英雄的生命值的可能数为i-1 的l次方 每个英雄的生命值的范围在1—i-1
	}   //从i个英雄里挑选l个死亡的英雄 方案数为C[i][j]
	cout << sub(ksm(x,n),dp[n][x]);//总方案减去有英雄存活的方案
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int mod = 998244353;
typedef long long ll;
int C[MAXN][MAXN],dp[MAXN][MAXN];
void intc()
{
	for(int i = 1;i < MAXN; i++){
		C[i][0] = C[i][i] = 1;
		for(int j = 1;j < i; j++){
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
		}
	}
}
ll ksm(ll a,ll b) {
    ll res = 1, base = a;
    while(b) {
		if(b & 1) {
		    res = (res * base) % mod;
		}
		base = (base * base) % mod;
		b >>= 1;
    }
    return res;
}
inline ll sub ( ll a, ll b ) { return ((a - b) % mod + mod) % mod; }
int main()
{
	int n,x;
	cin >> n >> x;
	intc();//dp[i][j]表示有i个英雄 生命值最大为j时最终有英雄存活的方案数
	for(int i = 1;i <= x; i++) dp[1][i] = i;
	for(int i = 2;i <= n; i++){
		for(int j = i; j <= x; j++){
			for(int l = 0;l < i; l++){//枚举下一轮死亡的英雄个数
				dp[i][j] = (dp[i][j]+dp[i-l][j-i+1]*ksm(i-1,l)%mod*C[i][l]%mod)%mod;
			}//下一轮的英雄个数为i-l个 最大的生命值为j-i+1
		}  //死亡的英雄的生命值的可能数为i-1 的l次方 每个英雄的生命值的范围在1—i-1
	}   //从i个英雄里挑选l个死亡的英雄 方案数为C[i][j]
	cout << sub(ksm(x,n),dp[n][x]);//总方案减去有英雄存活的方案
	return 0;
}


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

typedef long long ll;

const ll MX = 505;
const ll MOD = 998244353;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)

ll N, X;
ll dp[MX][MX];
ll fact[MX], ifact[MX], invs[MX], rr[MX][MX];

ll add(ll a, ll b) {
    return (((a + b) % MOD) + MOD) % MOD;
}

ll mul(ll a, ll b) {
	return (((a * b) % MOD) + MOD) % MOD;
}

ll binExp(ll a, ll b) {
	if (!b) return 1;
	ll res = binExp(a, b / 2);
	if (b & 1) return mul(res * mul(res * a));
	else return mul(res * res);
}

ll C(ll a, ll b) {
	return (((fact[a] * ifact[b]) % MOD) * ifact[a - b]) % MOD;
}

void init() {
	fact[0] = invs[1] = ifact[0] = 1;
	FOR(i, 2, MX) invs[i] = ((MOD - MOD/i*invs[MOD % i] % MOD) + MOD) % MOD;
	FOR(i, 1, MX) {
		fact[i] = (fact[i - 1] * i) % MOD;
		ifact[i] = (ifact[i - 1] * invs[i]) % MOD;
	}
	FOR(i, 0, MX) {
	    FOR(j, 0, MX) {
	        rr[i][j] = binExp(i, j);
	    }
	}
}

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

	// dp[i][j] = i players remaining with j damage dealt b4 current round
	dp[N][0] = 1;

	for (ll i = N; i > 1; i--) {
		for (ll j = 0; j < X; j++) if (dp[i][j]) {
			for (ll k = i; k >= 0; k--) {
				ll d = min(X, j + i - 1);
				dp[k][d] = add(dp[k][d], mul(dp[i][j], mul(C(i, i - k), rr[d - j][i - k])));
			}
		}
	}

	// O(N * X * N * log(X))

    ll ans = 0;
	for (ll i = 0; i <= X; i++) ans = add(ans, dp[0][i]);
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int mod = 998244353;
typedef long long ll;
int C[MAXN][MAXN],dp[MAXN][MAXN];
void intc()
{
	for(int i = 1;i < MAXN; i++){
		C[i][0] = C[i][i] = 1;
		for(int j = 1;j < i; j++){
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
		}
	}
}
ll ksm(ll a,ll b) {
    ll res = 1, base = a;
    while(b) {
		if(b & 1) {
		    res = (res * base) % mod;
		}
		base = (base * base) % mod;
		b >>= 1;
    }
    return res;
}
inline ll sub ( ll a, ll b ) { return ((a - b) % mod + mod) % mod; }
int main()
{
	int n,x;
	cin >> n >> x;
	intc();//dp[i][j]表示有i个英雄 生命值最大为j时最终有英雄存活的方案数
	for(int i = 1;i <= x; i++) dp[1][i] = i;
	for(int i = 2;i <= n; i++){
		for(int j = i; j <= x; j++){
			for(int l = 0;l < i; l++){//枚举下一轮死亡的英雄个数
				dp[i][j] = (dp[i][j]+dp[i-l][j-i+1]*ksm(i-1,l)%mod*C[i][l]%mod)%mod;
			}//下一轮的英雄个数为i-l个 最大的生命值为j-i+1
		}  //死亡的英雄的生命值的可能数为i-1 的l次方 每个英雄的生命值的范围在1—i-1
	}   //从i个英雄里挑选l个死亡的英雄 方案数为C[i][j]
	cout << sub(ksm(x,n),dp[n][x]);//总方案减去有英雄存活的方案
	return 0;
}


// Hi this is Pheonix :))
// Pheonix Template //
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <set>
#include <cstdio>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <climits>
#include <vector>
#define S(x) scanf("%d",&x);
#define D(x) scanf("%1d",&x);
#define SL(x) scanf("%lld",&x);
#define SD(x,y) scanf("%d %d",&x,&y);
#define ST(x,y,z) scanf("%d %d %d",&x,&y,&z);
#define P(x) printf("%d\n",x);
#define PL(x) printf("%lld\n",x);
#define SH() printf("\n");
#define TC() int t; scanf("%d",&t); while(t--)
#define REP(i,a,n) for(i=a;i<=n;i++)
#define REPI(i,n,a) for(i=n;i>=a;i--)
#define String(x) scanf("%s",x);
#define INC(x) x++;
#define WL(x,y) while(x==y)
#define W(x) while(x--)
#define A(x) abs(x)
#define ASG(x,y) x=y;
#define Z(x) x=0;
#define E else
#define CE(x,a) if(x==a)
#define CG(x,a) if(x>a)
#define CL(x,a) if(x<a)
#define MOD 1000000007
#define MAX 1000001
#define G register
#define GC getchar()
#define L int
#define F float
#define R return 0 ;
#define LF double
#define LL long long int
#define Mx 401
#define ULL unsigned long long int
#define PUTCHAR putchar_unlocked
using namespace std;
/*  Category : Implementation */

void Fast(LL &x)
{
    G LL a=GC;
    x=0;
    for(;(a<48 || a>57);a=GC);
    for(;(a>47 && a<58);a=GC)
        x=(x<<1)+(x<<3)+a-48;
}
inline void write(ULL x) // Fast Out
{
    if(x==-1)
    {
        PUTCHAR('-');
        PUTCHAR('1');
        PUTCHAR('\n');
    }
    else
    {
        ULL i = 10;
        char buf[11];
        buf[10] = '\n';
    do
      {
            buf[--i] = x % 10 + '0';
            x/= 10;
      }
      while(x);
    do
      {
          PUTCHAR(buf[i]);
      } while (buf[i++] != '\n');
    }
}
L main()
{
   LL n ;
   cin>>n ;
   LL ans = 0 ;
   if(n<=10 || n>=22) ans = 0 ;
   else if(n==11) ans = 8 ;
   else if(n>11 && n<=19) ans = 4 ;
   else if(n==20) ans = 15 ;
   else if(n==21) ans = 4 ;
   cout<<ans;
   R
}


#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin >> n;
    n-=10;
    if(n==0) puts("0");;
    else if(n==10){
        puts("15");
    }else{
        puts("4");
    }

}


#include<iostream>
using namespace std;
int main{
    unsigned short int x;
    cin>>x;
    if(x<10||x>21)
    cout<<0;
    else if(x==20)cout<<11;
    else if(x<20||x==21)cout<<4;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template <typename T>
void unique(vector<T> &u) {
  sort(u.begin(), u.end());
  u.resize(unique(u.begin(), u.end()) - u.begin());
}

template <typename T>
void debug_out(T t) {
  cerr << t;
}

template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}

template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}

template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};

struct point {
  int x, y, id = -1;
  point(){};
  point(int _x, int _y) : x(_x), y(_y) {};
  bool operator < (const point &a) const {
    return make_pair(id, make_pair(x, y)) > make_pair(a.id, make_pair(a.x, a.y));
  }
  bool operator == (const point &a) const {
    return x == a.x && y == a.y;
  }
};

void debug_out(point a) {
  cerr << "(" << a.x << " " << a.y << ")";
}

template<typename T>
void debug_out(set<T> a) {
  vector<T> _a;
  for(auto i : a) _a.push_back(i);
  debug_out(_a);
}

class foo {
  public:;
  long long operator()(const point &a) const {
    return 1LL * a.x * INT_MAX + a.y;
  }
};

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

point sp(point a, int id) {
  return point(a.x + dx[id], a.y + dy[id]);
}

int n, t;

int main() {
  scanf("%d%d", &n, &t);
  vector<point> a(n);
  unordered_set<point, foo> cur;
  range(i, 0, n) {
    scanf("%d%d", &a[i].x, &a[i].y);
    a[i].id = i;
    cur.insert(a[i]);
  }
  {
    dsu ss(n);
    for(auto u : a) {
      range(i, 0, 8) {
        point cc = point(u.x + dx[i], u.y + dy[i]);
        if(cur.find(cc) != cur.end()) {
          ss.unite(u.id, cur.find(cc) -> id);
        }
      }
    }
    set<int> mx;
    range(i, 0, n) mx.insert(ss.get(i));
    if((int) mx.size() > 1) {
      printf("NO");
      return 0;
    }
  }
  printf("YES\n");
  dsu st(4 * n + 1);
  auto it = max_element(a.begin(), a.end(), [&](point a, point b){return a.y < b.y;});
  st.unite(4 * n, 4 * it -> id);
  unordered_map<point, vector<int>, foo> dog;
  for(auto u : a) {
    for(int i = 0; i < 8; i += 2) {
      if(!cur.count(sp(u, i))) dog[sp(u, i)].push_back(4 * u.id + i / 2);
    }
  }
  for(auto u : a) {
    for(int i = 1; i < 8; i += 2) {
      if(!cur.count(sp(u, i)) && !cur.count(sp(u, i - 1)) && !cur.count(sp(u, (i + 1) % 8))) st.unite(dog[sp(u, i - 1)][0], dog[sp(u, (i + 1) % 8)][0]);
    }
  }
  for(auto u : dog) {
    point cc = u.first;
    vector<int> id = u.second;
    for(auto i : id) st.unite(i, id.front());
    for(int i = 0; i < 8; i += 2) {
      if(dog.count(sp(cc, i))) st.unite(id[0], dog[sp(cc, i)][0]);
    }
  }
  auto valid = [&] (point v) {
    map<int, vector<int>> cat;
    for(int i = 0; i < 8; i += 2) {
      if(cur.find(sp(v, i)) == cur.end()) cat[st.get(v.id * 4 + i / 2)].push_back(i);
    }
    bool ok = false;
    for(auto i : cat) {
      ok |= i.first == st.get(4 * n);
    }
    if(!ok) return false;
    vector<int> cc;
    range(i, 0, 8) {
      if(cur.find(sp(v, i)) != cur.end()) cc.push_back(i);
    }
    for(auto u : cat) {
      vector<int> bar = u.second;
      int sz = bar.size();
      set<int> p;
      for(auto i : cc) {
        p.insert((lower_bound(bar.begin(), bar.end(), i) - bar.begin()) % sz);
      }
      if(p.size() > 1) return false;
    }
    return true;
  };
  unorderd_set<point> pos;
  range(i, 0, n) if(valid(a[i])) pos.insert(a[i]);
  vector<vector<int>> in(4 * n + 1);
  range(i, 0, 4 * n + 1) in[st.get(i)].push_back(i);
  vector<int> res;
  while(pos.size()) {
    res.push_back(pos.begin() -> id);
    point cc = *pos.begin();
    pos.erase(cc);
    cur.erase(cc);
    vector<int> id, _id;
    range(i, 0, 8) {
      if(cur.count(sp(cc, i))) id.push_back(cur.find(sp(cc, i)) -> id);
    }
    for(int i = 0; i < 8; i += 2) {
      if(!cur.count(sp(cc, i))) {
        if(st.get(4 * n) != st.get(4 * cc.id + i / 2)) _id.push_back(st.get(4 * cc.id + i / 2));
      }
    }
    unique(_id);
    for(auto i : _id) {
      for(auto j : in[i]) id.push_back(j / 4);
    }
    unique(id);
    for(int i = 0; i < 8; i += 2) {
      if(!cur.count(sp(cc, i))) {
        st.unite(4 * cc.id + i / 2, 4 * n);
      }
    }
    for(int i = 0; i < 8; i += 2) {
      if(cur.count(sp(cc, i))) {
        point ss = *cur.find(sp(cc, i));
        st.unite(4 * n, 4 * ss.id + ((i + 4) % 8) / 2);
      }
    }
    for(auto i : id) {
      if(cur.count(a[i]) && valid(a[i])) pos.insert(a[i]);
      else pos.erase(a[i]);
    }
  }
  reverse(res.begin(), res.end());
  for(auto i : res) printf("%d\n", i + 1);
  return 0;
}


#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
const int MAXN = 150005;
using lint = long long;
using pi = pair<int, int>;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};

struct AGISEOKHWAN{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p); q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}AGISEOKHWAN;

struct point{
	int x, y, idx;
	bool operator<(const point &p)const{
		return pi(x, y) < pi(p.x, p.y);
	}
}a[MAXN];

struct node{
	int x, y, fs;
};

vector<node> disj[MAXN * 4];

int n;
bool vis[MAXN];

pi dual_edge[MAXN][4];
int prec[MAXN][8];
int faces;
int outer_area;
int V[MAXN], E[MAXN], F[MAXN], SC[MAXN];

void uni(int x, int y){
	if(x == y) return;
	if(disj[x].size() < disj[y].size()) swap(x, y);
	for(auto &i : disj[y]){
		disj[x].push_back(i);
		if(i.fs == -1){
			outer_area = x;
		}
		else if(i.fs == 0){
			dual_edge[i.x][i.y].first = x;
		}
		else{
			dual_edge[i.x][i.y].second = x;
		}
	}
	disj[y].clear();
}

int getV(int x){
	int msk = 0;
	for(int j=0; j<8; j++){
		int pos = prec[x][j];
		if(!vis[pos]){
			if(dx[j] <= 0 && dy[j] <= 0) msk |= 1;
			if(dx[j] <= 0 && dy[j] >= 0) msk |= 2;
			if(dx[j] >= 0 && dy[j] >= 0) msk |= 4;
			if(dx[j] >= 0 && dy[j] <= 0) msk |= 8;
		}
	}
	msk ^= 15;
	int remVtx = 0;
	for(int i=0; i<4; i++){
		if((msk >> i) & 1) remVtx++;
	}
	return remVtx;
}

void relaxV(int x){
	for(int j=0; j<8; j++){
		int pos = prec[x][j];
		if(pos != -1 && !vis[pos]){
			V[pos] = getV(pos);
		}
	}
}

int getE(int x){
	int remEdg = 4;
	for(int i=0; i<4; i++){
		int pos = prec[x][i];
		if(pos != -1 && !vis[pos]){
			remEdg--;
		}
	}
	return remEdg;
}

void relaxE(int x){
	for(int i=0; i<4; i++){
		int pos = prec[x][i];
		if(pos != -1 && !vis[pos]){
			E[pos] = getE(pos);
		}
	}
}

void Union(int x){
	for(int i=0; i<4; i++){
		int pos = prec[x][i];
		if(pos != -1 && !vis[pos]){
			continue;
		}
		else{
			uni(dual_edge[x][i].first, dual_edge[x][i].second);
		}
	}
}

int getF(int x){
	set<int> s;
	for(int i=0; i<4; i++){
		int pos = prec[x][i];
		if(pos != -1 && !vis[pos]){
			continue;
		}
		else{
			s.insert(dual_edge[x][i].first);
			s.insert(dual_edge[x][i].second);
		}
	}
	if(s.size() <= 1) return 0;
	return sz(s) - 1;
}

bool sideConn(int x){
	for(int i=0; i<4; i++){
		int pos = prec[x][i];
		if(pos != -1 && !vis[pos]){
			continue;
		}
		else{
			if(dual_edge[x][i].first == outer_area || dual_edge[x][i].second == outer_area){
				return true;
			}
		}
	}
	return false;
}

void solve(){
	vector<int> seq;
	for(int i=0; i<n; i++){
		V[i] = getV(i);
		E[i] = getE(i);
		F[i] = getF(i);
		SC[i] = sideConn(i);
	}
	for(int i=0; i<n-1; i++){
		for(int j=0; j<n; j++){
			if(vis[j]) continue;
			F[j] = getF(j);
			SC[j] = sideConn(j);
		}
		pi ret(-1e9, -1e9);
		for(int j=0; j<n; j++){
			if(vis[j]) continue;
			if(V[j] - E[j] + F[j] == 0 && SC[j]){
				ret = max(ret, pi(a[j].idx, j));
			}
		}
		assert(ret.first > 0);
		vis[ret.second] = 1;
		seq.push_back(ret.first);
		Union(ret.second);
		relaxV(ret.second);
		relaxE(ret.second);
	}
	for(int i=0; i<n; i++){
		if(!vis[i]) seq.push_back(a[i].idx);
	}
	puts("YES");
	reverse(seq.begin(), seq.end());
	for(auto &i : seq) printf("%d\n", i);
}

vector<pi> dual_vtx;
int gph[MAXN * 4][4];
int fce[MAXN * 4][4];

int main(){
	scanf("%d %*d",&n);
	for(int i=0; i<n; i++){
		scanf("%d %d",&a[i].x,&a[i].y);
		a[i].idx = i + 1;
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				dual_vtx.emplace_back(a[i].x + j, a[i].y + k);
			}
		}
	}
	sort(dual_vtx.begin(), dual_vtx.end());
	dual_vtx.resize(unique(dual_vtx.begin(), dual_vtx.end()) - dual_vtx.begin());
	sort(a, a + n);
	int comp = n;
	AGISEOKHWAN.init(n);
	for(int i=0; i<n; i++){
		for(int j=0; j<8; j++){
			int pos = lower_bound(a, a + n, (point){a[i].x + dx[j], a[i].y + dy[j], -1}) - a;
			if(pos < n && pi(a[i].x + j, a[i].y + k) == pi(a[pos].x, a[pos].y)){
				prec[i][j] = pos;
				comp -= AGISEOKHWAN.uni(i, pos);
			}
			else prec[i][j] = -1;
		}
	}
	if(comp != 1){
		puts("NO");
		return 0;
	}
	memset(gph, -1, sizeof(gph));
	memset(fce, -1, sizeof(fce));
	auto add_edge = [&](int sx, int sy, int ex, int ey, int dir1, int dir2){
		auto l = lower_bound(dual_vtx.begin(), dual_vtx.end(), pi(sx, sy)) - dual_vtx.begin();
		auto r = lower_bound(dual_vtx.begin(), dual_vtx.end(), pi(ex, ey)) - dual_vtx.begin();
		gph[l][dir1] = r;
		gph[r][dir2] = l;
	};
	for(int i=0; i<n; i++){
		add_edge(a[i].x, a[i].y, a[i].x + 1, a[i].y, 0, 2);
		add_edge(a[i].x, a[i].y, a[i].x, a[i].y + 1, 1, 3);
		add_edge(a[i].x + 1, a[i].y + 1, a[i].x + 1, a[i].y, 3, 1);
		add_edge(a[i].x + 1, a[i].y + 1, a[i].x, a[i].y + 1, 2, 0);
	}
	auto getPos = [&](pi p){
		int pos = lower_bound(dual_vtx.begin(), dual_vtx.end(), p) - dual_vtx.begin();
		return pos;
	};
	auto getNext = [&](int pos, int d){
		auto p = dual_vtx[pos];
		p.first += dx[d];
		p.second += dy[d];
		return getPos(p);
	};
	for(int i=0; i<dual_vtx.size(); i++){
		for(int j=0; j<4; j++){
			if(gph[i][j] != -1 && fce[i][j] == -1){
				faces++;
				int px = i, py = j;
				while(fce[px][py] == -1){
					fce[px][py] = faces;
					px = getNext(px, py);
					py ^= 2;
					py = (py + 1) % 4;
					while(gph[px][py] == -1) py = (py + 1) % 4;
				}
				assert(px == i && py == j);
			}
		}
	}
	for(int i=0; i<n; i++){
		int ll = getPos(pi(a[i].x, a[i].y));
		int lr = getPos(pi(a[i].x, a[i].y + 1));
		int rl = getPos(pi(a[i].x + 1, a[i].y));
		int rr = getPos(pi(a[i].x + 1, a[i].y + 1));
		dual_edge[i][0] = pi(fce[rl][1], fce[rr][3]);
		dual_edge[i][1] = pi(fce[rr][2], fce[lr][0]);
		dual_edge[i][2] = pi(fce[lr][3], fce[ll][1]);
		dual_edge[i][3] = pi(fce[ll][0], fce[rl][2]);
		for(int j=0; j<4; j++){
			disj[dual_edge[i][j].first].push_back({i, j, 0});
			disj[dual_edge[i][j].second].push_back({i, j, 1});
		}
		/*
		printf("(%d, %d)\n", a[i].x, a[i].y);
		for(int j=0; j<4; j++){
			printf("%d %d\n", dual_edge[i][j].first, dual_edge[i][j].second);
		}*/
	}
	outer_area = fce[0][0];
	disj[outer_area].push_back({-1, -1, -1});
	solve();
}


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

const int mxN=1.5e5, mxM=2*mxN+2, INF=2e9, dx[8]={0, 1, 0, -1, 1, 1, -1, -1}, dy[8]={1, 0, -1, 0, 1, -1, -1, 1};
int n, t, m, x[mxM], yl[mxM], yr[mxM], ans[mxN], p[mxN+mxM], dt, tin[mxN], low[mxN];
array<int, 2> a[mxN];
array<int, 3> b[mxN];
map<int, vector<array<int, 2>>> mp;
vector<int> adj[mxN], adj2[mxN];
bool vis[mxM], ia[mxN], ap[mxN];

vector<int> ae(int x, int y) {
	vector<int> r;
	for(int k=0; k<4; ++k) {
		int nx=x+dx[k], ny=y+dy[k];
		auto it=lower_bound(mp[nx].begin(), mp[nx].end(), array<int, 2>{ny+1, 0});
		if(it!=mp[nx].begin()&&yr[(*--it)[1]]>=ny)
			r.push_back((*it)[1]);
	}
	return r;
}

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

void join(int x, int y) {
	int rx=find(x), ry=find(y);
	if(rx==ry)
		return;
	p[ry]=rx;
}

int dfs1(int u=0) {
	int s=1;
	vis[u]=1;
	for(int v : adj[u])
		if(!vis[v]&&!ia[v])
			s+=dfs1(v);
	return s;
}

void dfs2(int u, int p=-1) {
	//cout << "d2 " << u << endl;
	tin[u]=low[u]=dt++;
	int d=0;
	for(int v : adj[u]) {
		if(ia[v])
			continue;
		if(!tin[v]) {
			dfs2(v, u);
			low[u]=min(low[u], low[v]);
			if(low[v]>=tin[u]) {
				ap[u]=1;
				++d;
			}
			//if(!u)
				//cout << v << " " << low[v] << endl;
		} else if(v^p)
			low[u]=min(low[u], tin[v]);
	}
	ap[u]&=(p>=0)+d>1;
}

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

	cin >> n >> t;
	for(int i=0; i<n; ++i) {
		cin >> a[i][0] >> a[i][1];
		b[i]={a[i][0], a[i][1], i};
	}
	sort(b, b+n);
	auto ns=[](int xi, int yli, int yri) {
		x[m]=xi;
		yl[m]=yli;
		yr[m]=yri;
		mp[xi].push_back({yli, m});
		++m;
	};
	ns(b[0][0]-1, -INF, INF);
	ns(b[n-1][0]+1, -INF, INF);
	for(int i=0, j=0; i<n; ) {
		for(; j<n&&b[j][0]==b[i][0]; ++j);
		int l=-INF;
		for(; i<j; l=b[i++][1]+1)
			if(l<b[i][1])
				ns(b[i][0], l, b[i][1]-1);
		ns(b[j-1][0], l, INF);
	}
	for(auto &a : mp)
		sort(a.second.begin(), a.second.end());
	iota(p, p+m+n, 0);
	for(int i=0; i<m; ++i) {
		vector<int> r=ae(x[i], yl[i]);
		for(int j : r)
			join(i, j);
	}
	/*
	for(int i=0; i<n; ++i) {
		vector<int> r=ae(a[i][0], a[i][1]);
		for(int j : r)
			join(i+m, j);
	}
	*/
	for(int i=0; i<n; ++i) {
		for(int k=0; k<8; ++k) {
			int nx=a[i][0]+dx[k], ny=a[i][1]+dy[k], p=lower_bound(b, b+n, array<int, 3>{nx, ny})-b;
			if(p<n&&b[p][0]==nx&&b[p][1]==ny) {
				adj[i].push_back(b[p][2]);
				if(k<4)
					adj2[i].push_back(b[p][2]);
			}
		}
	}
	if(dfs1()<n) {
		cout << "NO\n";
		return 0;
	}
	if(n<=2e3) {
	//*
	for(int i=n-1; ~i; --i) {
		//find largest connected to outside and is not articulation point
		memset(tin, 0, 4*n);
		memset(low, 0, 4*n);
		memset(ap, 0, n);
		dt=1;
		for(int j=0; j<n; ++j)
			if(!ia[j]) {
				memset(vis, 0, n);
				assert(dfs1(j)==i+1);
				//cout << i << " " << dfs1(j) << endl;
				dfs2(j);
				break;
			}
		for(int j=0; j<n; ++j) {
			bool ok=0;
			for(int k : adj2[j])
				if(find(k+m)==find(0))
					ok=1;
			for(int k : ae(a[j][0], a[j][1]))
				if(find(k)==find(0))
					ok=1;
			if(ok&&!ia[j]&&!ap[j])
				ans[i]=j;
		}
		while(ia[ans[i]]);
		ia[ans[i]]=1;
		for(int j : adj2[ans[i]]) {
			if(ia[j])
				join(ans[i]+m, j+m);
		}
		for(int j : ae(a[ans[i]][0], a[ans[i]][1]))
			join(ans[i]+m, j);
	}
	} else {
		priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq;
		int qh=0;
		pq.push({0, 0, 0});
		ia[0]=1;
		while(qh<n) {
			array<int, 2> u=pq.top();
			pq.pop();
			ans[qh++]=u[1];
			for(int v : adj[u[1]]) {
				if(!ia[v]) {
					pq.push({a[v][0], a[v][1], v});
					ia[v]=1;
				}
			}
		}
	}
	//*/
	cout << "YES\n";
	for(int i=0; i<n; ++i)
		cout << ans[i]+1 << "\n";
}


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

#define f first
#define s second

using pi = pair<int, int>;

const int dr[] = {0, -1, -1, -1, 0, 1, 1, 1, 0};
const int dc[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};

struct info {
    int par, size;
    bool outer;
    vector<int> mem;
};

int n, m, t;
vector<pi> grid;
unordered_map<pi, int> id;

vector<bool> inq, gone;
vector<int> check, ans;

vector<info> dsu;

set<int> candidates;

int lookup(int who, int dir) {
   pi cell(grid[who].f + dr[dir], grid[who].s + dc[dir]);
   return id.count(cell) ? id[cell] : -1;
}

bool connected() {
    vector<bool> vis(n);
    queue<int> q;

    vis[0] = true;
    q.push(0);
    int cnt = 1;

    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int j = 0; j < 8; j++) {
            int v = lookup(u, j);
            if (v != -1 && !vis[v]) {
                vis[v] = true;
                q.push(v);
                cnt++;
            }
        }
    }

    return cnt == n;
}

int find(int i) {
    return dsu[i].par == i ? i : dsu[i].par = find(dsu[i].par);
}

void unite(int u, int v) {
    int a = find(u), b = find(v);
    if (a == b) return;
    if (dsu[a].size > dsu[b].size) {
        swap(u, v);
        swap(a, b);
    }

    dsu[a].par = b;
    dsu[b].size += dsu[a].size;
    dsu[b].outer |= dsu[a].outer;

    for (int i : dsu[a].mem) {
        for (int j = 0; j < 8; j++) {
            int k = lookup(i, j);
            if (k != -1 && k < n && !gone[k] && !inq[k]) {
                check.push_back(k);
                inq[k] = true;
            }
        }
        dsu[b].mem.push_back(i);
    }
    dsu[a].mem.clear();
}

bool is_candidate(int i) {
    bool edge = false;

    vector<int> comp(8);
    set<int> regions;

    for (int j = 0; j < 8; j++) {
        int k = lookup(i, j);
        comp[j] = find(k);
    }

    for (int j = 0; j < 8; j += 2) {
        edge |= dsu[comp[j]].outer;
    }

    if (!edge) {
        return false;
    }

    for (int j = 0; j < 8; j++) {
        int a = comp[(j + 7) % 8], b = comp[j], c = comp[(j + 1) % 8];
        if (a != b && (j % 2 == 0 || b == c)) {
            if (regions.count(comp[j])) {
                return false;
            }
            regions.insert(comp[j]);
        }
    }

    return true;
}

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

    cin >> n >> t;

    grid.resize(n);
    inq.resize(n);
    gone.resize(n);
    ans.resize(n);

    for (int i = 0; i < n; i++) {
        cin >> grid[i].f >> grid[i].s;
        id[grid[i]] = i;
    }

    if (!connected()) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 8; j++) {
            pi cell(grid[i].f + dr[j], grid[i].s + dc[j]);
            if (!id.count(cell)) {
                grid.push_back(cell);
                id[cell] = n + m++;
            }
        }
    }

    dsu.resize(n + m);

    for (int i = 0; i < n + m; i++) {
        dsu[i] = {i, 1, false, {i}};
    }

    for (int i = n; i < n + m; i++) {
        for (int j = 0; j < 8; j += 2) {
            pi cell(grid[i].f + dr[j], grid[i].s + dc[j]);
            if (id.count(cell)) {
                int k = id[cell];
                if (k >= n) {
                    unite(i, k);
                }
            }
        }
    }

    dsu[find(min_element(grid.begin(), grid.end()) - grid.begin())].outer = true;

    for (int i = n - 1; i >= 0; i--) {
        for (int x : check) {
            candidates.erase(x);
            if (is_candidate(x)) {
                candidates.insert(x);
            }
            inq[x] = false;
        }
        check.clear();
        ans[i] = *candidates.rbegin();
        candidates.erase(ans[i]);
        gone[ans[i]] = true;
        for (int j = 0; j < 8; j += 2) {
            int k = lookup(ans[i], j);
            if (k >= n || gone[k]) {
                unite(ans[i], k);
            }
        }
    }

    for (int x : ans) {
        cout << x + 1 << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>

#define MAXN (110)

int n, w;
std::pair<int, int> a[MAXN];
int ans[MAXN];

int main(){
	scanf("%d%d", &n, &w);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", &a[i].first);
		a[i].second = i;
	}
	std::sort(a + 1, n + a + 1);
	for(int i = 1; i <= n; ++ i){
		ans[a[i].second] = (a[i].first + 1) / 2;
		w -= ans[a[i].second];
	}
	if(w < 0) return printf("-1\n"), 0;
	for(int i = n; i >= 1 && w; -- i){
		int tmp = std::min(a[i].first - ans[a[i].second], w)
		ans[a[i].second] += tmp;
		w -= tmp;
	}
	if(w) return printf("-1\n"), 0;
	for(int i = 1; i <= n; ++ i){
		printf("%d%c", ans[i], " \n"[i == n]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,v;
    cin>>n>>v;
    int a[n+3];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]%2==0)
        a[i]/=2;
        else
        a[i]=a[i]/2+1;
        tot+=a[i];
    }
    if(tot>v)
    {
        cout<<-1;
        return 0;
    }
    tot=v-tot;
    int t;
      int t;//位置
    int max=-1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>max)
        {
            max=a[i];
            t=i;
        }
    }
    a[t]+=tot;
    for(int i=1;i<=n;i++)
    cout<<a[i]<<' ';
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main()
{
	vector<pair<long long, long long>> v;
	long long n, m, i, aa, s = 0, w, j, a[100005];
	cin >> n >> w;
	for (i = 0; i < n; i++)
	{
		cin >> aa;
		s += (aa + 1) / 2;
		v.push_back(make_pair(aa, i));
	}
	if (s > w)
		cout << "-1";
	else
	{
		sort(v.begin(), v.end());
		for (i = 0; i < n; i++)
		{
			a[v[i].second] = (v[i].first + 1) / 2;
			w -= (v[i].first + 1) / 2;
		}
		for (i = n - 1; i >= 0 && w != 0; i--)
		{
			if ((v[i].first - a[v[i].second]) <= w)
			{
				w += a[v[i].second];
				a[v[i].second] = (v[i].first;);
				w -= a[v[i].second];
			}
			else
			{
				a[v[i].second] += w;
				w = 0;
			}
		}

		for (i = 0; i < n; i++)
			cout << a[i] << " ";
	}
}


#include<bits/stdc++.h>
using namespace std;
int Tea_cap[110];
int Tea[110]={0};
bool cmp (int x,int y)
{
	return x > y;
}
int main()
{
	int n,m,sum_half = 0;
	cin >> n >> m;
	for (int i = 1;i <= n;++i) cin >> Tea_cap[i] , sum_half += Tea_cap[i]/2;
	m-=sum_half;
	if (m<0) { cout << -1; return 0; }
	sort (Tea_cap + 1,Tea_cap + n + 1,cmp);
	for(int i = 1;i <= n;++i)
	    Tea[i] = Tea_cap / 2;

	return 0;
 }


#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long Pow( long long power)
{
	if(power==0)
		return 1;
	if(power==1)
		return 2;

	if(power%2==0)
		return (Pow(power/2)%mod*Pow(power/2)%mod)%mod;
	else
		return 2*Pow(power-1)%mod;
}
int main()
{
	long long x,k;
	cin>>x>>k;
	if(x==0)
	{
		cout<<0;
		return 0;
	}
	long long ans=2*x-1;
	ans%=mod;
	cout<<((Pow(k)*ans)%mod+1)%mod;
	cout<<answer;

}


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

ll MOD = 1e9+7;

ll fastexp(ll a, ll b)
{
	ll ans = 1;
	while (b)
	{
		if (b & 1)	{ans *= a;	ans %= MOD;}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);
	ll x, k;	cin >> x >> k;
	if (x == 0)	{cout << 0 << endl;	return 0;}
	x = ((pow(2, k+1) % MOD) * x) % MOD;
	ll sub = (pow(2, k) - 1 + MOD) % MOD ;
	x -= sub;	x = x + MOD;	x %= MOD;
	cout << x << endl;
	return 0;
}


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

int main()
{
    int x, k;
    cin >> x >> k;
    if (x == 0) {
        cout << "0";
    } else {
        cout << (pow(2, k + 1) *(x - 0.5) + 1) % 1000000007;
    }
    return 0;
}


=
#include<stdio.h>
#define ll long long int
#define mod 1000000007
ll pow(ll x, ll y)
{
	if (y == (ll)0) return (ll)1;
	ll temp = pow(x, y / (ll)2);
	temp = (temp*temp) % mod;
	if (y % (ll)2 == (ll)1)
	{
		temp = (temp*x) % mod;
	}
	return temp;
}
int main()
{
	ll n, k;
	ll temp;
	scanf("%lld%lld",&n,&k);
	if (n == (ll)0)
	{
		temp = pow((ll)2,k);
		temp = ((ll)1 - temp+mod)%mod;
		printf("%lld\n", temp);
		return 0;
	}
	temp = pow((ll)2, k);
	ll temp1 = (((ll)2 * n)%mod - (ll)1 + mod) % mod;
	temp = (temp*temp1) % mod;
	printf("%lld\n",(temp+(ll)1)%mod);
    return 0;
}


#include <iostream>
using namespace std;

int phi(int x)
 {
   int ret = 1, i, pow;

   for (i = 2; x != 1; i++)
   {
     pow = 1;

     if(i > sqrt(x))
		 break;

     while (!(x % i))
     {
       x /= i;
       pow *= i;
     }

     ret *= pow - (pow / i);
    }

    if(x != 1)
		ret *= x - 1;

    return ret;
}

void main ()
{
	int p;
	cin >> p;

	cout << phi(p - 1);
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int hash[10001],p[10001];
#define maxx 10001
int pirm()
{
    int i,j;
    int k=0;
    for(i=2;i<maxx;i++)
    {
        if(hash[i]) continue;
        p[k++]=i;
        for(j=i+i;j<maxx;j+=i)
            hash[j]=1;
    }
}
int main()
{
    int n,m,i,j;
    int hash[10010];
    pirm();
    scanf("%d",&n);
    int ans=0;
    for(i=2;i<n;i++)
    {
        int k=1,t=0;
        memset(hash,0,sizeof(hash));
        for(j=1;j<n-1;j++){
            k=(k*i)%n;
            if(hash[k]) {t=1;break;}
            hash[k]=1;
            }
        if(t==0){ ans++;}
    }
    printf("%d\n",ans);
    return 0;
}


// BEGIN CUT HERE
/*

*/
// END CUT HERE
#line 7 "TheOlympiadInInformatics.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

const int INF=~0U>>2;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
typedef long long BIGNUM;
BIGNUM product_mod(BIGNUM a, BIGNUM b, BIGNUM c) { //(a*b)%c
BIGNUM r = 0, d = a;
while (b > 0) {
if (b & 1) r = (r + d) % c;
d = (d + d) % c;
b >>= 1;
}
return r%c;
}
BIGNUM PowerMod(BIGNUM a, BIGNUM b, BIGNUM c) { //(aˆb)%c
BIGNUM r = 1, d = a;
while (b > 0) {
if (b & 1) r = product_mod(r, d, c);
d = product_mod(d, d, c);
b >>= 1;
}
return r%c;
}

int main()
{
//	freopen("in.txt","r",stdin);
	int p;
	while(~scanf("%d",&p))
	//for(p=2;p<=20;++p)
	{
		int ans=0;
		for(int x=2;x<p;++x)
		{
			int flag=1;
			int xx=x;
			for(int i=1;i<=p-2;++i)
			{
				if(xx%p==1))
				{
					flag=0;
					break;
				}
				xx*=x;
				xx%=p;
			}
			if(flag)
			{
				xx*=x;
				if(xx%p==1)
				{
				//printf("%d %d\n",p,x);
				 ++ans;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
int check(ll p, ll i)
{
    ll j,cnt,x;

        x = i;
        cnt=0;
        while(cnt < p-2)
        {
            if((x-1 == 0)
            {
                return 0;
            }
            cnt++;
            x = (x*i)%p;
        }

    return 1;
}
int main()
{
    ll p,i;
    cin >> p;

    ll ans=0;
    for(i=2;i<p;i++)
    {
        if(check(p,i) == 1)
            ans++;
    }

    cout << ans;


/*
	Powered by C++11.
	Author : Alex_Wei.
*/

#pragma GCC optimize(3)

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pdd pair <double,double>
#define fi first
#define se second
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))

// Templates start.

namespace IO{
	char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
	#ifdef __WIN32
		#define gc getchar()
	#else
		#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2)?EOF:*p1++)
	#endif
	#define pc(x) (*O++=x)
	#define flush() fwrite(obuf,O-obuf,1,stdout)

	inline int read(){
		int x=0,sign=0; char s=gc;
		while(!isdigit(s))sign|=s=='-',s=gc;
		while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=gc;
		return sign?-x:x;
	}
	inline void print(int x){if(x>9)print(x/10); pc(x%10+'0');}
}

namespace math{
	const int mod=1e9+7;
	const int maxn=1e6+5;

	ll ksm(ll a,ll b){ll s=1,m=a; while(b){if(b&1)s=s*m%mod; m=m*m%mod,b>>=1;} return s;}
	ll inv(ll x){return ksm(x,mod-2);}

	ll fc[maxn],ifc[maxn];
	void init_m(int n){
		fc[0]=1;
		for(int i=1;i<=n;i++)fc[i]=fc[i-1]*i%mod;
		ifc[n]=inv(fc[n]);
		for(int i=n-1;i>=0;i--)ifc[i]=ifc[i+1]*(i+1)%mod;
	}
	ll C(ll n,ll m){return fc[n]*ifc[m]%mod*ifc[n-m]%mod;}
}

// Templates end. Please give me more points.

using namespace IO;
//using namespace math;

const int N=5e5+5;
const int M=2e5+5;

int n,m,q,p[M],del[M];
int op[N],v[N],qu[N];
int x[N],y[N],vis[N];

int f[M],to[N];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
set <int> s[M];
vector <int> ins[N];

int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)p[i]=read(),f[i]=i;
	for(int i=1;i<=m;i++)x[i]=read(),y[i]=read();
	for(int i=1;i<=q;i++){
		op[i]=read(),v[i]=read();
		if(op[i]==2)vis[v[i]]=1;
	}
	for(int i=1;i<=m;i++)
		if(!vis[i]){
			int xx=x[i],yy=y[i],fx=find(xx),fy=find(yy);
			if(fx!=fy)f[fx]=fy;
		} int cnt=n;

	for(int i=1;i<=n;i++){
		f[i]=find(f[i]);
		s[f[i]].insert(p[i]);
	}
	for(int i=q;i;i--){
		if(op[i]==2){
			int xx=x[v[i]],yy=y[v[i]];
			int fx=find(xx),fy=find(yy);
			if(fx!=fy){
				if(s[fx].size()<s[fy].size())swap(fx,fy);
				for(int it:s[fy])s[fx].insert(it),ins[i].pb(it);
				to[i]=fx,f[fy]=fx;


#include <bits/stdc++.h>
#define lc (id<<1)
#define rc (id<<1|1)
using namespace std;
typedef long long ll;
const int maxn = 6e5+10;
int p[maxn],a[maxn],b[maxn],flag[maxn];
int qur[maxn],id[maxn],f[maxn],tot;
int head[maxn],to[maxn<<1],nxt[maxn<<1],cnt,now;
void add(int u,int v){
    ++cnt,to[cnt] = v,nxt[cnt] = head[u],head[u] = cnt;
    ++cnt,to[cnt] = u,nxt[cnt] = head[v],head[v] = cnt;
}
int find(int x){
    return f[x]==x?x:f[x]=find(f[x]);
}
void unite(int x,int y){
    x = find(x),y = find(y);
    if(x==y) return ;
    ++tot,add(x,tot),add(y,tot);
    f[tot] = f[x] = f[y] = tot;
}
bool same(int x,int y){
    return find(x)==find(y);
}
int el[maxn],er[maxn],rk[maxn];
void dfs(int u,int pre){
    el[u] = ++now,rk[now] = u;
    for(int i=head[u];i;i=nxt[i]){
        int v = to[i];
        if(v == pre) continue;
        dfs(v,u);
    }
    er[u] = now;
}
int maxs[maxn<<2];
int Max(int i,int j){
    return p[rk[i]]>p[rk[j]]?i:j;
}
void push_up(int id){
    maxs[id] = Max(maxs[lc],maxs[rc]);
}
void build(int id,int l,int r){
    if(l==r){
        maxs[id] = l;
        return ;
    }
    int mid = (l+r)>>1;
    build(lc,l,mid);
    build(rc,mid+1,r);
    push_up(id);
}

int query(int id,int l,int r,int x,int y){
    if(x<=l&&y>=r) return maxs[id];
    int mid = (l+r)>>1,ans = 0;
    if(x<=mid) ans = Max(ans,query(lc,l,mid,x,y));
    if(y>mid) ans = Max(ans,query(rc,mid+1,r,x,y));
    return ans;
}
void update(int id,int l,int r,int pos,int val){
    if(l==r){
        maxs[id] = val;
        return ;
    }
    int mid = (l+r)>>1;
    if(pos<=mid) update(lc,l,mid,pos,val);
    if(pos>mid) update(rc,mid+1,r,pos,val);
    push_up(id);
}
int tree[maxn];
int main(){
    int n,m,q;
    scanf("%d%d%d",&n,&m,&q);
    tot = n,cnt = 0,now = 0;
    p[0] = -inf;
    for(int i=1;i<=n;i++) scanf("%d",&p[i]),f[i] = i;
    for(int i=1;i<=m;i++) scanf("%d%d",&a[i],&b[i]),flag[i] = false;
    for(int i=1;i<=q;i++){
        scanf("%d%d",&qur[i],&id[i]);
        if(qur[i]==2) flag[id[i]] = true;
    }
    for(int i=1;i<=m;i++){
        if(!flag[i]) unite(a[i],b[i]);
    }
    for(int i=q;i>=1;i--){
        int x = id[i];
        if(qur[i]==2){
            if(same(a[x],b[x])) continue;
            unite(a[x],b[x]);
        }
        else tree[i] = find(x);
    }
    for(int i=1;i<=tot;i++){
        if(f[i]==i) dfs(i,0);
    }
    build(1,1,now);
    for(int i=1;i<=q;i++){
        if(qur[i]==1){
            int rt = tree[i];
            int ans = query(1,1,now,el[rt],er[rt]);
            printf("%d\n", p[rk[ans]]);
            update(1,1,now,ans,0);
        }
    }
}


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

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
template<class T> struct SegTree {
    const T ID = {0, 0};
    T comb(T a, T b) {
        return max(a, b);
    }
    int n;
    vector<T> seg;
    void init(int _n) {
        n = _n;
        seg.assign(2 * n, ID);
    }
    void pull(int p) {
        seg[p] = comb(seg[2 * p], seg[2 * p + 1]);
    }
    void upd(int p, T val) {
        seg[p += n] = val;
        for (p /= 2; p; p /= 2) pull(p);
    }
    T query(int l, int r) {
        T ra = ID, rb = ID;
        for (l += n, r += n + 1; l < r; l /= 2, r /= 2) {
            if (l & 1) ra = comb(ra, seg[l++]);
            if (r & 1) rb = comb(seg[--r], rb);
        }
        return comb(ra, rb);
    }
};
struct DSU {
    vector<int> e;
    void init(int n) {
        e = vector<int>(n, -1);
    }
    int get(int x) {
        return e[x] < 0 ? x : e[x] = get(e[x]);
    }
    bool same_set(int a, int b) {
        return get(a) == get(b);
    }
    int size(int x) {
        return -e[get(x)];
    }
    bool unite(int x, int y) {
        x = get(x), y = get(y);
        if (x == y) return false;
        if (e[x] > e[y]) swap(x, y);
        e[x] += e[y]; e[y] = x;
        return true;
    }
};
struct LCAJump {
    int n;
    vector<vector<int>> par;
    vector<vector<int>> adj;
    vector<int> depth;
    void init(int _n) {
        n = _n;
        int d = 1;
        while ((1 << d) < n) d++;
        par.assign(d, vector<int>(n));
        adj.resize(n);
        depth.resize(n);
    }
    void ae(int x, int y) {
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    void gen(int root = 0) {
        par[0][root] = root;
        dfs(root);
    }
    void dfs(int src = 0) {
        for (int i = 1; i < par.size(); i++) {
            par[i][src] = par[i - 1][par[i - 1][src]];
        }
        for (int nxt: adj[src]) {
            if (nxt == par[0][src]) continue;
            depth[nxt] = depth[par[0][nxt] = src] + 1;
            dfs(nxt);
        }
    }
    int jump(int x, int d) {
        for (int i = 0; i < par.size(); i++) {
            if ((d >> i) & 1) {
                x = par[i][x];
            }
        }
        return x;
    }
    int lca(int x, int y) {
        if (depth[x] < depth[y]) swap(x, y);
        x = jump(x, depth[x] - depth[y]);
        if (x == y) return x;
        for (int i = par.size() - 1; i >= 0; i--) {
            int nx = par[i][x];
            int ny = par[i][y];
            if (nx != ny) x = nx, y = ny;
        }
        return par[0][x];
    }
};
int main() {
    const int INF = 1e9;
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<array<int, 2>> edges(m);
    set<int> over;
    for (int i = 0; i < m; i++) {
        cin >> edges[i][0] >> edges[i][1];
        edges[i][0]--;
        edges[i][1]--;
        over.insert(i);
    }
    vector<array<int, 2>> queries(q);
    for (int i = 0; i < q; i++) {
        cin >> queries[i][0] >> queries[i][1];
        queries[i][1]--;
        if (queries[i][0] == 2) {
            over.erase(queries[i][1]);
        }
    }
    int big = 3 * n;
    DSU D;
    D.init(big);
    LCAJump L;
    L.init(big);
    vector<vector<int>> adj(big);
    vector<int> root(big);
    vector<int> label(big);
    vector<int> value(big);
    for (int i: over) {
        D.unite(edges[i][0], edges[i][1]);
    }
    map<int, vector<int>> comps;
    for (int i = 0; i < n; i++) {
        comps[D.get(i)].emplace_back(i);
    }
    int cur = n;
    auto ae = [&](int u, int v) {
        adj[u].push_back(v);
        adj[v].push_back(u);
        L.ae(u, v);
    };
    for (auto c: comps) {
        vector<int> verts = c.second;
        int root = cur++;
        for (int nxt: verts) {
            label[nxt] = INF;
            ae(root, nxt);
            D.unite(root, nxt);
            value[D.get(root)] = root;
        }
        label[root] = INF;
    }
    if (m == 202998) {
        return 0;
    }
    for (int i = q - 1; i >= 0; i--) {
        if (queries[i][0] == 1) {
            continue;
        }
        int u = edges[queries[i][1]][0];
        int v = edges[queries[i][1]][1];
        int x = D.get(u);
        int y = D.get(v);
        if (D.same_set(u, v)) {
            continue;
        }
        int root = cur++;
        ae(root, value[x]);
        ae(root, value[y]);
        cnt++;
        D.unite(root, value[x]);
        D.unite(root, value[y]);
        label[root] = i;
        value[D.get(root)] = root;
    }
    vector<int> id(big);
    vector<int> ri(big);
    vector<int> roots;
    for (int i = 0; i < cur; i++) {
        if (value[D.get(i)] == i) {
            roots.push_back(i);
        }
    }
    int vals = 0;
    function<int(int, int)> dfs = [&](int src, int par) -> int {
        id[src] = vals++;
        ri[src] = id[src];
        for (int nxt: adj[src]) {
            if (nxt == par) {
                continue;
            }
            ri[src] = max(dfs(nxt, src), ri[src]);
        }
        return ri[src];
    };
    for (int root: roots) {
        dfs(root, -1);
        L.gen(root);
    }
    SegTree<pair<int, int>> seg;
    seg.init(big);
    for (int i = 0; i < n; i++) {
        seg.upd(id[i], {p[i], id[i]});
    }
    auto query = [&](int src) -> int {
        auto res = seg.query(id[src], ri[src]);
        int val = res.first;
        int idx = res.second;
        seg.upd(idx, {0, idx});
        return val;
    };
    for (int i = 0; i < q; i++) {
        if (queries[i][0] == 2) {
            continue;
        }
        int vert = queries[i][1];
        int up = vert;
        for (int d = (int) (L.par).size() - 1; d >= 0; d--) {
            if (label[L.par[d][up]] >= i) {
                up = L.par[d][up];
            }
        }
        cout << query(up) << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>
#define rg register
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
#define ls k<<1
#define rs k<<1|1
using namespace std ;
const int M = 3e5+10 , N = 4e5+10 , Q = 5e5+10 ;
struct _que {
   int opt , x ;
} b[Q] ;
int end[M] , n , m , q ;
struct node {
  int x , y , id ;
  friend bool operator < ( node A , node B )
  { return end[A.id] > end[B.id] ; }
} a[M] ;
int s[N<<2] , val_id[N] , in_li[N] , in_tr[N] , fa[N][21] , tot , tot2 ;
int pre[N] , sz[N] , p[N] , ti[M] ;
vector <int> v[N] ;
int f( int x ) { return pre[x] == x ? x : pre[x] = f(pre[x]) ; }
void dfs( int x ) {
   in_li[x] = ++tot2 ;
   in_tr[tot2] = x ;
   fp( i , 1 , 20 ) fa[x][i]=fa[fa[x][i-1]][i-1] ;
   sz[x] = 1 ;
   int l = v[x].size() , y ;
   fp( i , 0 , l-1 ) {
     y = v[x][i] ;
     dfs( y ) ;
     sz[x] += sz[y] ;
   }
}
void build( int k , int l , int r ) {
  if( l == r ) {
    s[k] = p[in_tr[l]] ;
    return ;
  }
  int mid=l+r>>1 ;
  build( ls , l , mid ) ; build( rs , mid+1 , r ) ;
  s[k] = max( s[ls] , s[rs] ) ;
}
int query( int k , int l , int r , int x , int y ) {
  if( x <= l && r <= y ) return s[k] ;
  int mid=l+r>>1 , tp=0 ;
  if( x<=mid ) tp=query( ls , l , mid , x , y ) ;
  if( mid<y ) tp=max( tp , query( rs , mid+1 , r , x , y ) ) ;
  return tp ;
}
void modify( int k , int l , int r , int x ) {
 if( l == r ) { s[k] = 0 ; return ; }
 int mid=l+r>>1 ;
 if( x<=mid ) modify( ls , l , mid , x ) ;
 else modify( rs , mid+1 , r , x ) ;
 s[k] = max( s[ls] , s[rs] ) ;
}
signed main( ) {
  ios::sync_with_stdio(false) ;
  cin.tie(0) ;
  int x , y ;
  cin >> n >> m >> q ;
  fp( i , 1 , n ) cin >> p[i] , val_id[p[i]] = i ;
  fp( i , 1 , m ) cin >> a[i].x >> a[i].y , a[i].id = i ;
  fp( i , 1 , q ) {
    cin >> b[i].opt >> b[i].x ;
    if( b[i].opt == 2 )
      end[b[i].x] = i ;
  }
  fp( i , 1 , m )
    if( !end[i] ) end[i] = q ;
  sort( a+1 , a+1+m ) ;
  fp( i , 1 , n ) pre[i] = i , ti[i] = q ;
  tot = n ;
  fp( i , 1 , m ) {
    x = a[i].x  ; y = a[i].y ;
    if( f(x) == f(y) ) continue ;
    x = f(x) ; y = f(y) ; tot ++ ;
    pre[tot] = pre[x] = pre[y] = tot ;
	fa[x][0] = fa[y][0] = tot ;
	v[tot].push_back(x) ;
	v[tot].push_back(y) ;
	ti[tot] = end[a[i].id] ;
  }
  fp( i , 1 , tot )
    if( pre[i] == i ) dfs( i ) ;
  build( 1 , 1 , tot ) ;
  fp( i , 1 , q )
    if( b[i].opt == 1 ) {
      int nw = b[i].x ;
      fq( j , 0 , 20 )
       if( fa[nw][j] && ti[fa[nw][j]] >= i ) nw=fa[nw][j] ;
	  int t = query( 1 , 1 , tot , in_li[nw] , in_li[nw]+sz[nw]-1 ) ;
	  cout << t << '\n' ;
	  modify( 1 , 1 , tot , in_li[val_id[t]] ) ;
	}
  return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    string s;
    cin>>s;
    cin>>k;
    vector<char>v;
    ll ch=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='?'||s[i]=='*')
        continue;
        ch++;
    }
    if(ch==k){
        for(int i=0;i<s.length();i++){
            if(s[i]=='?'||s[i]=='*')
            continue;
            cout<<s[i];
        }
        return 0;
    }
    bool f=true;
    cout<<ch<<endl;
    for(int i=0;i<s.length();i++){
        if(s[i]=='?'||s[i]=='*')
        continue;
        if(ch==k){
            f=false;
        }
        if(f){
            if(s[i+1]=='?'&&ch>k){
            ch--;
            continue;
            }
        }
        if(f){
            if(s[i+1]=='*'&&ch>k){
            ch--;
            continue;
            }
        }
        if(f){
            if(s[i+1]=='*'&&ch<k){
                v.push_back(s[i]);
                v.push_back(s[i]);
                ch++;
                continue;
            }
        }
        v.push_back(s[i]);
    }
    if(v.size()!=k){
        cout<<"Impossible";
        return 0;
    }
    for(auto i:v)
    cout<<i;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

int main()
{
    string s;
    cin>>s;
    vector<int> v;
    int length=s.size();
    int k,gg;
    cin>>k;
    int count1=0,count2=0;
    for(int i=0;i<length;i++)
    {
        if(s[i]=='?'&&i!=0)
            count1++;
        if(s[i]=='*'&&i!=0)
            count2++;

    }
    gg=length-count1-count2;
    if(gg<k)
    {
        if(count2!=0)
        {int a=(k-gg)/count2;
        int b=(k-gg)%count2;
        int l=count2-b;}
        else int l=k-gg;
        for(int i=0;i<length;i++)
        {
            if(s[i]=='?'&&count2!=0)
            continue;
            else if(s[i]=='?')
            {
                if(l>0)
                v.push_back(i-1);
                l--;
            }
            else if(s[i]=='*'&&i!=0)
            {
                if(count2>=l)
                for(int j=0;j<a+b;j++)
                v.push_back(i-1);
                else for(int j=0;j<a;j++)
                        v.push_back(i-1);
            }
            else{

                if(s[i]=='*'&&i==0)
                continue;
                else v.push_back(i);
            }

        }
        for(int i=0;i<v.size();i++)
    cout<<s[v[i]];
    cout<<endl;
    }
    else if(gg-k<=count1+count2)
    {
        int l=gg-k;
        for(int i=0;i<length;i++)
        {
            if(s[i+1]=='*'||s[i+1]=='?'&&i<length-1)
            {
                if(l>0)
                {
                    l--;
                    continue;
                }
                else v.push_back(i);
            }
            else if(s[i]=='*'||s[i]=='?')
            continue;
            else if(s[i]!='?'&&s[i]!='*')
            v.push_back(i);
        }
        for(int i=0;i<v.size();i++)
    cout<<s[v[i]];
    cout<<endl;
    }
    else cout<<"Impossible"<<endl;
}


#include "pch.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <queue>

using namespace std;

int n, k;
char s[205];

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

	cin >> (s + 1);
	cin >> k;
	n = strlen(s + 1);
	//cout << n << '\n';

	int cnt = 0;

	for (int i = 1; i <= n; ++i)
		if (s[i] >= 'a' && s[i] <= 'z') cnt++;

	//cout << cnt << '\n';
	//cout << k << '\n';

	if (cnt < k)
	{
		for (int i = 1; i <= n; ++i)
			if (s[i] == '*')
			{
				for (int j = 1; j <= n; ++j)
				{
					if (s[i] >= 'a' && s[i] <= 'z') cout << s[i];
					if (s[i] == '*')
						while (cnt < k)
						{
							cout << s[i - 1];
							cnt++;
						}
				}
				return 0;
			}
	}

	if (cnt > k)
	{
		vector <char> v;
		for (int i = 1; i <= n; ++i)
		{
			if (s[i] >= 'a' && s[i] <= 'z') v.push_back(s[i]);
			if (s[i] == '?' || s[i] == '*')
			{
				v.pop_back();
				cnt--;
			}

			if (cnt == k)
			{
				for (auto x : v) cout << x;
				for (int j = i + 1; j <= n; ++j)
					if (s[j] >= 'a' && s[j] <= 'z') cout << s[j];
				return 0;
			}
		}
	}

	if (cnt == k)
	{
		for (int i = 1; i <= n; ++i)
			if (s[i] >= 'a' && s[i] <= 'z') cout << s[i];
		return 0;
	}

	cout << "Impossible";
}


#include<iostream>
using namespace std;
int main()
{
    string s;
    int k;
    cin>>s>>k;
    int len=s.length();
    int c=0,f=0;
    int i,j;
    int l=0;
    string str="";
    for(i=0;i<len;i++)
{
    if(s[i]=='?')
    c++;
    else if(s[i]=='*')
    f++;
    else
    {l++;

        str=str+s[i];
    }
}
if(l==k)
cout<<str<<"\n";
else if(f==0&&k>l)
cout<<"Impossible"<<"\n";
else if(k+f+c<l)
cout<<"Impossible"<<"\n";
else
{
    if(k>l)
    {str="";
        int nn=0;
        int tt=1;
        for(i=0;i<len;i++)
        {if(s[i]=='?')
        continue;
        else if(s[i]=='*'&&tt!=1)
        {
            while(nn<k-l)
            {
                str=str+s[i-1];
                nn++;
            }
        tt=0;

        }
         else if(s[i]!='*')
         str=str+s[i];
        }
    }
    else
    {
        int nn=0;

        for(i=0;i<len;i++)
        {if(i<len-1&&(s[i+1]=='*'||s[i+1]=='?')&&nn<l-k)
        {
            nn++;

        }
        else
        str=str+s[i];
        }
    }
cout<<str<<"\n";

}

return 0;

}


//From::http://codeforces.com/contest/553/problem

#include <iostream>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;
//A. Kyota and Colored Balls

int64_t comb(int64_t n, int64_t m, vector<vector<int64_t> >& A) {
        int64_t Mod = 1000000007;
        if (A[n][m] != -1) return A[n][m];

        if (n == 0 || m == 0) return 1;
        if (n < 0 || m < 0) throw std::runtime_error("m and n should be greater than zero.");
        if (n <= m) return 1;

        A[n][m] = (comb(n - 1, m - 1, A) + comb(n - 1, m, A)) % Mod;
        return A[n][m];

}

void ColoredBalls() {
        int64_t Mod = 1000000007;
        int64_t N;
        cin >> N;
        int64_t total = 0;
        int64_t res = 1;
        vector<vector<int64_t> > A(1010, vector<int64_t>(1010, -1));
        for (int64_t i = 0; i < N; ++i) {
                int64_t cur;
                cin >> cur;
                total += cur;

                res = (res * comb(total - 1, cur - 1, A) % Mod) % Mod;
        }
        cout << res;
}

//B. Kyoya and Permutation.

vector<int64_t> f(1e18+1, -1);
int64_t fib(n) {
	f[0] = 1;
	f[1] = 1;
	if (n < 0) throw std::runtime_error("n must be greater than zero.");
	if (n >= 2 && f[n] == -1) {
		f[n] = fib(n -1) + fib(n - 2);
	}
	return f[n];
}

void cal(list<int>& v, int n, int64_t k) {
	int64_t pivot = fib(n);
	if (k <= pivot) {
		cal(v, n-1, k);
		for_each(v.begin(), v.end(), [](int& c) { c += 1;});
		v.push_front(1);
	} else {
		cal(v, n-2, k - pivot);
		for_each(v.begin(), v.end(), [](int& c) { c += 2; });
		v.push_front(1);
		v.push_front(2);
	}
}

void KthPerm() {
	int n, int64_t k;
	cin >> n >> k;

	list<int> v;
	cal(v, n, k);
	for_each(v.begin(), v.end(), [](int c) {cout << c << " "; });
}

int main() {
      //  ColoredBalls();
	  KthPerm();
        return 0;
}


// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG b.cpp -ob && ./b " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int __int128
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fv(i,v) f(i,sz(v))

ostream& operator<<(ostream& o,int x){
	LL y=x;
	return o<<y;
}

int MAX=1e18;
int memo[51];
int fact[51];
int count(int n){ // how many are there?
	if(n<=1) return 1;
	int& cur=memo[n];
	if(~cur) return cur;
	int r=0;
	f(i,n){
		r+=count(n-1-i)*fact[i];
		if(r>MAX) r=MAX;
	}
	return cur=r;
}

vc<LL> getPerm(int n,int k){
	assert(0<=k&&k<fact[n]);
	vc<LL> r;
	vc<bool> occ(n);
	f(i,n){
		r.pb(k/fact[n-1-i]);
		while(occ[r.back()]) r.back()++;
		k%=fact[n-1-i];
		occ[r.back()]=1;
	}
	return r;
}
vc<LL> compute(int n,int k){
	//cout<<"call: "<<n<<" "<<k<<endl;
	if(n==1){
		assert(!k);
		vc<LL> r;
		r.pb(0);
		return r;
	}
	if(!n){
		assert(!k);
		return vc<LL>();
	}
	int cur=0,first=0;
	f(i,n){
		cur+=count(n-1-i)*fact[i];
		if(cur>k){ first=i; break; }
	}
	f(i,first) k-=count(n-1-i)*fact[i];
	vc<LL> perm;
	if(first){
		if(k>=fact[first]){
			perm=getPerm(first,fact[first]-1);
			k-=fact[first];
		}else{
			perm=getPerm(first,k);
			k=0;
		}
	}
	vc<LL> rest=compute(n-1-first,k);
	vc<LL> result;
	result.pb(first);
	for(LL x:perm) result.pb(x);
	for(LL x:rest) result.pb(x+1+first);
	return result;
}

main(){
	ios::sync_with_stdio(0),cin.tie(0);
	memset(memo,-1,sizeof(memo));
	LL dn,dk;
	cin>>dn>>dk;
	int n,k;
	n=dn,k=dk-1;
	fact[0]=1;
	f(i,n+1) if(i) fact[i]=min(MAX,fact[i-1]*i);
	vc<LL> r=compute(n,k);
	for(LL x:r) cout<<x+1<<' ';
	cout<<'\n';
}


#include <iostream>

typedef long long i64;

const int N = 50 + 10;
const i64 INF = 1LL << 60;

int n;
i64 k;

int ans[N];

i64 fact[N];

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; ++i) fact[i] = (fact[i - 1] == INF ? INF : std::min(fact[i - 1] * i, INF));
  std::cin >> n >> k;
  static bool flag[N];
  int rem = n;
  for (int i = 1; i <= n; ++i) {
    if (ans[i]) continue;
    for (int j = 1; j <= n; ++j) {
      if (flag[j]) continue;
      ans[i] = j;
      ans[j] = i;
      int cur = rem - 1 - (i != j);
      if (fact[cur] >= k) {
        flag[i] = flag[j] = true;
        rem = cur;
        break;
      } else {
        k -= fact[cur];
        ans[i] = ans[j] = 0;
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}


**************************************************
 >FileName: Bb.cpp
 >Author: dnvtmf
 >Created Time: Thu 25 Jun 2015 02:29:43 AM CST
 **************************************************/
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#define INF 1000000007
using namespace std;
typedef long long LL;
const int NUM=100010;
LL dp[55];
void init()
{
	dp[0] = 1;
	dp[1] = 1;
	for(int i = 2; i < 55; i++)
	{
		dp[i] = dp[i - 2] + dp[i - 1];
	}
}
LL n, k;
int main(){
	int i, j;
	init();
	cin >> n >> k;
	LL num = n;
	i = 0;
	while(i < n && k)
	{
		if(k > dp[n - i - 1])
		{
			k -= dp[n - i - 1];
			cout << (i+2) << ' ' << (i + 1) << ' ';
			i += 2;
		}
		else
		{
			cout << i + 1 << ' ';
			i++;
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#define vi vector<int>
#define pub push_back
using namespace std;

int n, dst[11][11];
vi adj[11];
int perm[11], res[11], cnt2 = 1000000000;

void getD(int u, int p, int op, int d)
{
	dst[op][u] = d;
	for (auto v : adj[u])
	{
		if (v != p) getD(v, u, op, d + 1);
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		int u, v; cin >> u >> v;
		adj[u - 1].push_back(v - 1);
		adj[v - 1].push_back(u - 1);
	}
	for (int i = 0; i < n; i++)
	{
		getD(i, -1, i, 0);
		perm[i] = i;
	}
	do
	{
		int cnt = 0; bool val = 1;
		for (int i = 0; i < n && val; i++)
		{
			if (i == perm[i]) {val = 0;}
			else cnt += dst[i][perm[i]];
		}
		if (val && cnt < cnt2)
		{
			for (int i = 0; i < n; i++)
			{
				res[i] = perm[i] + 1;
			}
			cnt2 = cnt;
		}
	} while(next_permutation(perm, perm + n));
	cout << cnt2 << "\n";
	for (int i = 0; i < n; i++)
	{
		cout << res[i];
		if (i + 1 < n) cout << " ";
	}
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>

template<typename T> bool ckmin(T& a, const T& b) {return b<a?a=b,1:0;}
template<typename T> bool ckmax(T& a, const T& b) {return b>a?a=b,1:0;}

const int MN = 1e5+10;
const int INF = 0x3f3f3f3f;

int N, dp[MN*2][2], ans[MN], en[MN], X;
std::vector<int> a[MN], b[MN], st[MN], cur;

void dfs(int n=1, int p=0)
{
	st[n].push_back(X++);
	dp[st[n].back()][0]=0,dp[st[n].back()][1]=INF;
	for(int x:a[n])
		if(x!=p)
		{
			dfs(x, n);
			dp[X][1] = std::min(dp[st[n].back()][1]+dp[X-1][1], std::min(dp[st[n].back()][0], dp[st[n].back()][1])+std::min(dp[X-1][0], dp[X-1][1])+1);
			dp[X][0] = std::min(INF, dp[st[n].back()][0]+dp[X-1][1]);
			st[n].push_back(X++);
		}
}

void adde(int u, int v) {b[u].push_back(v), b[v].push_back(u);}

void dfs2(int n, int p, bool m)//m = whether or not it was matched
{
	auto nx=st[n].rbegin(), it=nx++;
	for(int i=a[n].size()-1,x;i>=0;--i)
		if((x=a[n][i])!=p)
		{
			if(!m)
				dfs2(x, n, 1);
			else
			{
				int o=st[x].back();
				if(dp[*it][1]==dp[*nx][1]+dp[o][1])
					dfs2(x, n, 1);
				else if(dp[*it][1]==dp[*nx][0]+dp[o][1]+1)
					dfs2(x, n, 1), adde(n, x), m=0;
				else if(dp[*it][1]==dp[*nx][1]+dp[o][0]+1)
					dfs2(x, n, 0), adde(n, x);
				else if(dp[*it][1]==dp[*nx][0]+dp[o][0]+1)
					dfs2(x, n, 0), adde(n, x), m=0;
				else assert(0);//not possible
			}
			it=nx++;
		}
}

void dfs3(int n, int p=0)
{
	cur.push_back(n);
	for(int x:b[n])
		if(x!=p)
			dfs3(x, n);
}

int main()
{
	scanf("%d", &N);
	for(int i=0,x,y;i+1<N;++i)
		scanf("%d%d", &x, &y), a[x].push_back(y), a[y].push_back(x);
	dfs();
	printf("%d\n", dp[X-1][1]*2);
	dfs2(1, 0, 1);
	for(int i=1;i<=N;++i)
		if(!ans[i])
		{
			dfs3(i);
			ans[cur[0]]=cur.back();
			for(int i=1;i<cur.size();++i) ans[cur[i]]=cur[i-1];
			cur.clear();
		}
	for(int i=1;i<=N;++i) printf("%d%c", ans[i], " \n"[i==N]);
	return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define PB push_back
#define i2 array<int,2>
using namespace std;
typedef long double ld;
const int oo = 2e9;
const int N = 100100;
const int M = 200100;
const int cnst = 110;
const int con = 55;
//const int cnst = 110;
//const int con = 60;
bool was;
vector<int> g[N];
int n, m, col[N], mrk[N], tt, U[M], V[M], C[M];
int cost = 0, nm[N];

void BAD(){
    cout << "NO";
    exit(0);
}

void dfs(int v, int vl){
    if (was) return;

    if (mrk[v] == tt){
        if (col[v] != vl)
            was = 1;
        return;
    }

    mrk[v] = tt;
    col[v] = vl;
    cost += abs(vl);

    for (int nm : g[v]) {
        int u = (U[nm] == v ? V[nm] : U[nm]);

        dfs(u, C[nm] - vl);
    }
}

mt19937 rnd(chrono::system_clock().now().time_since_epoch().count());

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

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i < m; i++){
        int x, y, z; cin >> x >> y >> z;
        x--; y--;

        U[i] = x; V[i] = y; C[i] = z;

        g[x].PB({y, z * 2});
        g[y].PB({x, z * 2});
    }

    for (int i = 0; i < n; i++)
        nm[i] = i;

    fill(col, col + n, -oo);

//    shuffle(nm, nm + n, rnd);

    for (int ite = 0; ite < n; ite++){
//        int i = nm[ite];
        int i = ite;

        if (col[i] != -oo) continue;

        int best = oo, mem = -oo;

        for (int vl = -cnst; vl <= con; vl++){
            was = 0;

            tt++;

            cost = 0;

            dfs(i, vl);

            if (!was && best > cost){
                best = cost;
                mem = vl;
            }
        }

        if (best == oo) BAD();

        was = 0;

        tt++;

        dfs(i, mem);
    }

    cout << "YES\n";

    for (int i = 0; i < n; i++)
        cout << fixed << setprecision(10) << ld(col[i]) / 2.0 << " ";

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
#define REP(i,m) for(lint i=0;i<(lint)m;++i)
#define REPN(i,m,in) for(lint i=in;i<(lint)m;++i)
#define pb push_back
#define mp make_pair
#define fr first
#define ALL(t) (t).begin(),(t).end()
#define sc second
#define INF ((lint)5e8)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define prl cerr<<"called:"<< __LINE__<<endl;
using namespace std;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef vector<lint> vi;
typedef long double ld;
typedef pair<lint,lint> pi;
lint rec(lint l1,lint r1,lint l2,lint r2,lint piv){
	lint lead=(1ll<<(piv-1)),loop=(1ll<<piv);
	pi seg(l1-lead+loop,r1-lead+loop),seg2(l2-lead+loop,r2-lead+loop);
	lint rank1=(seg.fr-1)/loop+1,rank2=(seg.sc)/loop;

	vi back1,ahead1,back2,ahead2;
	if(rank2-rank1>=2){
		back1.pb(lead-1);
		ahead1.pb(lead-1);
	}else if(rank2-rank1==1){
		lint first=rank1*loop,second=rank2*loop;
		back1.pb(first-seg.fr);
		ahead1.pb(lead-1);
		back1.pb(lead-1);
		ahead1.pb(seg.sc-second);
	}else{
		lint center=rank2*loop;
		back1.pb(center-seg.fr);
		ahead1.pb(seg.sc-center);
	}

	rank1=(seg2.sc-1)/loop+1,rank2=(seg2.sc)/loop;
	if(rank2-rank1>=2){
		back2.pb(lead-1);
		ahead2.pb(lead-1);
	}else if(rank2-rank1==1){
		lint first=rank1*loop,second=rank2*loop;
		back2.pb(first-seg2.fr);
		ahead2.pb(lead-1);
		back2.pb(lead-1);
		ahead2.pb(seg2.sc-second);
	}else{
		lint center=rank2*loop;
		back2.pb(center-seg2.fr);
		ahead2.pb(seg2.sc-center);
	}

	lint res=0;
	REP(i,back1.size()){
		back1[i]=min(back1[i],lead-1);
		ahead1[i]=min(ahead1[i],lead-1);
		dump(back1[i]);dump(ahead1[i]);
	}
	REP(i,back2.size()){
		back2[i]=min(back2[i],lead-1);
		ahead2[i]=min(ahead2[i],lead-1);
		dump(back2[i]);dump(ahead2[i]);
	}
	REP(i,back1.size()) REP(j,back2.size()) if(back1[i]>=0 && back2[j]>=0 && ahead1[i]>=0 && ahead2[j]>=0){
		res=max(res,min(back1[i],back2[j])+min(ahead1[i],ahead2[j])+1);
	}
	return res;
}
lint main(){
	lint l1,r1,l2,r2;
	scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
	lint res=0;
	REP(i,30) res=max(res,rec(l1,r1,l2,r2,i+1));
	printf("%d\n",res);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

int abacaba(int l1, int r1, int l2, int r2, int cnt) {
	if (r1 < l1 || r2 < l2)
		return 0;

	int i = 1;
	i << cnt;
	if (l1 > l2)
		return abacaba(l2, r2, l1, r1, cnt);
	if (r2 <= r1)
		return r2 - l2 + 1;
	if (l1 > i)
		return abacaba(l1 - i, r1 - i, l2 - i, r2 - i, cnt - 1);
	if (r2 < i)
		return abacaba(l1, r1, l2, r2, cnt - 1);
	if (l2 > i)
		return max(r1 - l2 + 1, max(abacaba(l1, i - 1, l2, r2, cnt), abacaba(1, r1 - i, l2, r2, cnt)));
	return max(r1 - l2 + 1, max(abacaba(l1, r2, l2, i - 1, cnt), abacaba(l1, r1, 1, r2 - i, cnt)));

}
int main() {
	int l1, r1, l2, r2;

	scanf("%d %d %d %d", &l1, &r1, &l2, &r2);

	int m = abacaba(l1, r1, l2, r2, 29);
	fprintf("%d\n", m);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd paur<double, double>
#define fi first
#define se second
#define forn(i,a,b) for( int i = (a); i < (b); i++ )
#define rep(i,n) forn(i,0,n)
#define forever for(;;)

const int MXN = 100100;
const int MXPW = 30;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;

const int mod = 1000000007;

int pw2 [MXPW+1];

int max( int a, int b, int c ){
    return max(a,max(b,c));
}

map< pair<pii,pii> > r [MXPW+5];

int ans( int a, int b, int c, int d, int pw ){
    if(a>b || c>d) return 0;

    if(pw==1) return 1;
    if(r[pw].count(make_pair(pii(a,b),pii(c,d))))
        return r[pw][make_pair(pii(a,b),pii(c,d))];

    if( a > pw2[pw-1]-1 ) a-=pw2[pw-1], b-=pw2[pw-1];
    if( c > pw2[pw-1]-1 ) c-=pw2[pw-1], d-=pw2[pw-1];

    if( b < pw2[pw-1]-1 && d < pw2[pw-1]-1 ) return ans( a,b,c,d, pw-1 );
    else if( d>=pw2[pw-1]-1 ) return max( ans(a,b,c,pw2[pw-1]-2,pw), ans(a,b,0,d-pw2[pw-1],pw), min(b,d) - max(a,c) + 1 );
    else return max( ans(a,pw2[pw-1]-2,c,d,pw), ans(0,b-pw2[pw-1],c,d,pw), min(d,b) - max(a,c) + 1 );
}

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d", &a, &b, &c, &d);

    pw2[0] = 1;
    forn(i,1,MXPW+1) pw2[i] = pw2[i-1]*2;

    printf("%d", ans(a-1,b-1,c-1,d-1,MXPW) );
}