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

#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define rev(i,a,b) for(i=(a);i>=(b);--i)
#define max2(a,b)  ((a)>(b)?(a):(b))
#define min2(a,b)  ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (long long)x.size()
#define fi first
#define se second
#define pb emplace_back // push_back
#define mp make_pair
#define endl '\n'

#ifdef Wild4Stone
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.fi); __p(a.se); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define autra(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#else
#define trace(...) {}
#define autra(...) {}
#endif

typedef long long int ll;
typedef pair<ll, ll> pll;

const ll mod = 1000000007;  //998244353;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);

ll i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
// inline ll gcd(ll a, ll b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
// inline ll power(ll x, ll n, ll m = LLONG_MAX)
//        {  ll res=1; x = (x%m + m)%m;
//             while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
//        }

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	int t = 1;
	// cin>>t;
	while (t--)  solve();
	return 0;
}

//***************** Code Starts Here *******************//

void solve()
{
	ll n, x1, x2; cin >> n >> x1 >> x2;
	vector<pll> v, t;

	rep(i, 1, n)
	{
		ll x; cin >> x;
		v.pb(mp(x, i));
	}
	sort(all(v));
	t = v;

	ll max = max2(x1, x2);
	ll min = min2(x1, x2);

	vector<pll> maxx1, minn1, maxx2, minn2;
	bool pos1 = 1;

	while (sz(v))
		if (double(max) / (sz(maxx1) + 1) <= v.back().fi)
		{
			maxx1.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			maxx1.pb(v.back());
			v.pop_back();
		}

	if (double(max) / sz(maxx1) > maxx1.back().fi) pos1 = 0;

	while (sz(v))
		if (double(min / (sz(minn1) + 1)) <= v.back().fi)
		{
			minn1.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			minn1.pb(v.back());
			v.pop_back();
		}

	if (double(min) / sz(minn1) > minn1.back().fi) pos1 = 0;

	if (pos1)
	{
		if (x1 == max) swap(minn1, maxx1);

		cout << "Yes\n";
		cout << sz(minn1) << " " << sz(maxx1) << endl;
		for (auto it : minn1) cout << it.se << " "; cout << endl;
		for (auto it : maxx1) cout << it.se << " "; cout << endl;
		return;
	}

	v = t;
	pos1 = 1;
	while (sz(v))
		if (double(min) / (sz(maxx2) + 1) <= v.back().fi)
		{
			maxx2.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			maxx2.pb(v.back());
			v.pop_back();
		}

	if (double(min) / sz(maxx2) > maxx2.back().fi) pos1 = 0;

	while (sz(v))
		if (double(max / (sz(minn2) + 1)) <= v.back().fi)
		{
			minn2.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			minn2.pb(v.back());
			v.pop_back();
		}

	if (double(max) / sz(minn2) > minn2.back().fi) pos1 = 0;

	if (pos1)
	{
		if (x1 == min) swap(minn2, maxx2);

		cout << "Yes\n";
		cout << sz(minn2) << " " << sz(maxx2) << endl;
		for (auto it : minn2) cout << it.se << " "; cout << endl;
		for (auto it : maxx2) cout << it.se << " "; cout << endl;
		return;
	}
	cout << "No\n";
}


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

#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define rev(i,a,b) for(i=(a);i>=(b);--i)
#define max2(a,b)  ((a)>(b)?(a):(b))
#define min2(a,b)  ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (long long)x.size()
#define fi first
#define se second
#define pb emplace_back // push_back
#define mp make_pair
#define endl '\n'

#ifdef Wild4Stone
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.fi); __p(a.se); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define autra(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#else
#define trace(...) {}
#define autra(...) {}
#endif

typedef long long int ll;
typedef pair<ll, ll> pll;

const ll mod = 1000000007;  //998244353;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);

ll i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
// inline ll gcd(ll a, ll b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
// inline ll power(ll x, ll n, ll m = LLONG_MAX)
//        {  ll res=1; x = (x%m + m)%m;
//             while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
//        }

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	int t = 1;
	// cin>>t;
	while (t--)  solve();
	return 0;
}

//***************** Code Starts Here *******************//

void solve()
{
	ll n, x1, x2; cin >> n >> x1 >> x2;
	ll upto1[n + 1] = {0}, upto2[n + 1] = {0};

	pll p[n + 1];
	rep(i, 1, n) cin >> p[i].fi, p[i].se = i;
	sort(p + 1, p + n + 1);

	rep(i, 1, n)
	{
		ll lo = i, hi = n, mid , ans = mod;
		while (lo <= hi)
		{
			mid = (lo + hi) >> 1;
			if (p[i].fi * (mid - i + 1) >= x1)
			{
				ans = min2(ans, mid);
				hi = mid - 1;
			}
			else lo = mid + 1;
		}
		if (ans == mod) ans = -1;
		upto1[i] = ans;
	}

	rep(i, 1, n)
	{
		ll lo = i , hi = n, mid, ans = mod;
		while (lo <= hi)
		{
			mid = (lo + hi) >> 1;
			if (p[i].fi * (mid - i + 1) >= x2)
			{
				ans = min2(ans, mid);
				hi = mid - 1;
			}
			else lo = mid + 1;
		}
		if (ans == mod) ans = -1;
		upto2[i] = ans;
	}

	int next1[n + 2] = {0}, next2[n + 2] = {0};
	next1[n + 1] = next2[n + 1] = -1;

	rev(i, n, 1)
	if (upto1[i] != -1) next1[i] = i;
	else next1[i] = next1[i + 1];

	rev(i, n, 1)
	if (upto2[i] != -1) next2[i] = i;
	else next2[i] = next2[i + 1];

	rep(i, 1, n)
	{
		if (upto1[i] != -1)
		{
			j = upto1[i] + 1;

			if (next2[j] != -1)
			{
				j = next2[j];
				cout << "Yes\n";
				cout << (upto1[i] - i + 1) << " " << (upto2[j] - j + 1) << endl;

				rep(k, i, upto1[i])
				cout << p[k].se << " "; cout << endl;
				rep(k, j, upto2[j])
				cout << p[k].se << " "; cout << endl;

				return;
			}
		}

		if (upto2[i] != -1)
		{
			j = upto2[i] + 1;

			if (next1[j] != -1)
			{
				j = next1[j];
				cout << "Yes\n";
				cout << (upto1[j] - j + 1) << " " << (upto2[i] - i + 1) << endl;

				rep(k, j, upto1[j])
				cout << p[k].se << " "; cout << endl;
				rep(k, i, upto2[i])
				cout << p[k].se << " "; cout << endl;

				return;
			}
		}
	}

	cout << "No\n";
}


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

#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define rev(i,a,b) for(i=(a);i>=(b);--i)
#define max2(a,b)  ((a)>(b)?(a):(b))
#define min2(a,b)  ((a)<(b)?(a):(b))
#define all(x) x.begin(),x.end()
#define sz(x) (long long)x.size()
#define fi first
#define se second
#define pb emplace_back // push_back
#define mp make_pair
#define endl '\n'

#ifdef Wild4Stone
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.fi); __p(a.se); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define autra(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#else
#define trace(...) {}
#define autra(...) {}
#endif

typedef long long int ll;
typedef pair<ll, ll> pll;

const ll mod = 1000000007;  //998244353;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const double PI = acos(-1);

ll i, j, k;
void solve(void);
inline bool equal(double a, double b) { return fabs(a - b) < eps; }
// inline ll gcd(ll a, ll b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
// inline ll power(ll x, ll n, ll m = LLONG_MAX)
//        {  ll res=1; x = (x%m + m)%m;
//             while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
//        }

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	int t = 1;
	// cin>>t;
	while (t--)  solve();
	return 0;
}

//***************** Code Starts Here *******************//

void solve()
{
	ll n, x1, x2; cin >> n >> x1 >> x2;
	vector<pll> v, t;

	rep(i, 1, n)
	{
		ll x; cin >> x;
		v.pb(mp(x, i));
	}
	sort(all(v));
	t = v;

	ll max = max2(x1, x2);
	ll min = min2(x1, x2);

	vector<pll> maxx1, minn1, maxx2, minn2;
	bool pos1 = 1;

	while (sz(v))
		if (double(max) / (sz(maxx1) + 1) <= v.back().fi)
		{
			maxx1.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			maxx1.pb(v.back());
			v.pop_back();
		}

	if (double(max) / sz(maxx1) > maxx1.back().fi) pos1 = 0;

	while (sz(v))
		if (double(min / (sz(minn1) + 1)) <= v.back().fi)
		{
			minn1.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			minn1.pb(v.back());
			v.pop_back();
		}

	if (double(min) / sz(minn1) > minn1.back().fi) pos1 = 0;

	if (pos1)
	{
		if (x1 == max) swap(minn1, maxx1);

		cout << "Yes\n";
		cout << sz(minn1) << " " << sz(maxx1) << endl;
		for (auto it : minn1) cout << it.se << " "; cout << endl;
		for (auto it : maxx1) cout << it.se << " "; cout << endl;
		return;
	}

	v = t;
	pos1 = 1;
	while (sz(v))
		if (double(min) / (sz(maxx2) + 1) <= v.back().fi)
		{
			maxx2.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			maxx2.pb(v.back());
			v.pop_back();
		}

	if (double(min) / sz(maxx2) > maxx2.back().fi) pos1 = 0;

	while (sz(v))
		if (double(max / (sz(minn2) + 1)) <= v.back().fi)
		{
			minn2.pb(v.back());
			v.pop_back();
			break;
		}
		else
		{
			minn2.pb(v.back());
			v.pop_back();
		}

	if (double(max) / sz(minn2) > minn2.back().fi) pos1 = 0;

	if (pos1)
	{
		if (x1 == min) swap(minn1, maxx1);

		cout << "Yes\n";
		cout << sz(minn2) << " " << sz(maxx2) << endl;
		for (auto it : minn2) cout << it.se << " "; cout << endl;
		for (auto it : maxx2) cout << it.se << " "; cout << endl;
		return;
	}
	cout << "No\n";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ppp{ll v,pos;}a[300005];
ll n,x[2],vis[300005];
bool cmp(ppp x,ppp y){
	return x.v<y.v;
}
bool check(ll p,ll tag){
	memset(vis,0,sizeof(vis));
	ll num=(x[tag]+p-1)/p,t=p;
	for(ll i=1;i<=n;i++){
		if(p==0) break;
		if(a[i].v>=num){
			p--;vis[i]=1;
		}
	}
	if(p) return false;
	ll cnt=0,now=-1;
	for(ll i=1;i<=n;i++){
		if(vis[i]) continue;
		if(a[i].v*(n-t-cnt)>=x[tag^1]){
			now=i;break;
		}
		cnt++;
	}
	if(now!=-1){
		cout<<"Yes"<<endl;
		if(tag==0){
			cout<<t<<" "<<n-t-cnt<<endl;
			for(int i=1;i<=n;i++){
				if(vis[i]) cout<<a[i].pos<<" ";
			}cout<<endl;
			while(now<=n){
				if(!vis[now]) cout<<a[now].pos<<" ";
				now++;
			}cout<<endl;
		}
		else{
			cout<<n-t-cnt<<" "<<t<<endl;
			while(now<=n){
				if(!vis[now]) cout<<a[now].pos<<" ";
				now++;
			}cout<<endl;
			for(int i=1;i<=n;i++){
				if(vis[i]) cout<<a[i].pos<<" ";
			}cout<<endl;
		}
		exit(0);
	}
	return true;
}
int main(){
	cin>>n>>x[0]>>x[1];
	for(ll i=1;i<=n;i++){
		cin>>a[i].v;
		a[i].pos=i;
	}
	sort(a+1,a+1+n,cmp);
	ll l=1,r=n;
	while(r>=l){
		ll mid=(l+r)/2;
		if(check(mid,0)) r=mid-1;
		else l=mid+1;
	}
	l=1,r=n;
	while(r>=l){
		ll mid=(l+r)/2;
		if(check(mid,1)) r=mid-1;
		else l=mid+1;
	}
	cout<<"No"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ppp{ll v,pos;}a[300005];
ll n,x[2],vis[300005];
bool cmp(ppp x,ppp y){
	return x.v<y.v;
}
bool check(ll p,ll tag){
	memset(vis,0,sizeof(vis));
	ll num=(x[tag]+p-1)/p,t=p;
	for(ll i=1;i<=n;i++){
		if(p==0) break;
		if(a[i].v>=num){
			p--;vis[i]=1;
		}
	}
	if(p) return false;
	ll cnt=0,now=-1;
	for(ll i=1;i<=n;i++){
		if(vis[i]) continue;
		if(a[i].v*(n-t-cnt)>=x[tag^1]){
			now=i;break;
		}
		cnt++;
	}
	if(now!=-1){
		cout<<"Yes"<<endl;
		if(tag=0){
			cout<<t<<" "<<n-t-cnt<<endl;
			for(int i=1;i<=n;i++){
				if(vis[i]) cout<<a[i].pos<<" ";
			}cout<<endl;
			while(now<=n){
				if(!vis[now]) cout<<a[now].pos<<" ";
				now++;
			}cout<<endl;
		}
		else{
			cout<<n-t-cnt<<" "<<t<<endl;
			while(now<=n){
				if(!vis[now]) cout<<a[now].pos<<" ";
				now++;
			}cout<<endl;
			for(int i=1;i<=n;i++){
				if(vis[i]) cout<<a[i].pos<<" ";
			}cout<<endl;
		}
		exit(0);
	}
	return true;
}
int main(){
	cin>>n>>x[0]>>x[1];
	for(ll i=1;i<=n;i++){
		cin>>a[i].v;
		a[i].pos=i;
	}
	sort(a+1,a+1+n,cmp);
	ll l=1,r=n;
	while(r>=l){
		ll mid=(l+r)/2;
		if(check(mid,0)) r=mid-1;
		else l=mid+1;
	}
	l=1,r=n;
	while(r>=l){
		ll mid=(l+r)/2;
		if(check(mid,1)) r=mid-1;
		else l=mid+1;
	}
	cout<<"No"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ppp{
	ll v,pos;
}a[300005];
ll n,x1,x2,vis[300005];
bool cmp(ppp x,ppp y){
	return x.v<y.v;
}
bool check(ll x){
	memset(vis,0,sizeof(vis));
	ll num=(x1+x-1)/x,t=x;
	for(int i=1;i<=n;i++){
		if(x==0) break;
		if(a[i].v>=num){
			x--;vis[i]=1;
		}
	}
	if(x) return false;
	ll cnt=0,now=-1;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		if(a[i].v*(n-t-cnt)>=x2){
			now=i;break;
		}
		cnt++;
	}
	if(now!=-1){
		cout<<"Yes"<<endl;
		cout<<t<<" "<<n-t-cnt<<endl;
		for(int i=1;i<=n;i++){
			if(vis[i]) cout<<a[i].pos<<" ";
		}cout<<endl;
		while(now<=n){
			if(!vis[now]) cout<<a[now].pos<<" ";
			now++;
		}
		exit(0);
	}
	return true;
}
int main(){
	cin>>n>>x1>>x2;
	for(int i=1;i<=n;i++){
		cin>>a[i].v;
		a[i].pos=i;
	}
	sort(a+1,a+1+n,cmp);
	ll l=1,r=n;
	while(r>=l){
		ll mid=(l+r)/2;
		if(check(mid)) r=mid-1;
		else l=mid+1;
	}
	cout<<"No"<<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

pair<int, int> c[300000];

int checkResources(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

void output(pair<int, int> a[], void* b) {
    while (a < b)
        cout << a++->second + 1 << ' ';
    cout << endl;
}

int solve1(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x1);
    d2 = checkResources(d1, x2);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << n - d1 << ' ' << d1 - d2 << endl;
    output(c + d1, c + n);
    output(c + d2, c + d1);
    return 1;
}

int solve2(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x2);
    d2 = checkResources(d1, x1);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << d1 - d2 << ' ' << n - d1 << endl;
    output(c + d2,c + d1);
    output(c + d1,c + n);
    return 1;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n, i, x1, x2;
    cin >> n >> x1 >> x2;
    for (i = 0; i < n; ++i) {
        cin >> c[i].first;
        c[i].second = i;
    }
    sort(c, c + n);
    if (!solve1(n, x1, x2) && !solve2(n, x1, x2))
        cout << "No";

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

pair<int, int> c[300000];

int checkResources(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

int checkNext(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

void output(pair<int, int> a[], void* b) {
    while (a < b)
        cout << a++->second + 1 << ' ';
    cout << endl;
}

int solve1(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x1);
    d2 = checkResources(d1, x2);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << n - d1 << ' ' << d1 - d2 << endl;
    output(c + d1, c + n);
    output(c + d2, c + d1);
    return 1;
}

int solve2(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x2);
    d2 = checkResources(d1, x1);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << d1 - d2 << ' ' << n - d1 << endl;
    output(c + d2,c + d1);
    output(c + d1,c + n);
    return 1;
}

int main()
{
    int n, i, x1, x2;
    cin >> n >> x1 >> x2;
    for (i = 0; i < n; ++i) {
        cin >> c[i].first;
        c[i].second = i;
    }
    sort(c, c + n);
    if (!solve1(n, x1, x2) && !solve2(n, x1, x2))
        cout << "No";

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

pair<int, int> c[300000];

int checkResources(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

int checkNext(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

void output(pair<int, int> a[], void* b) {
    while (a < b)
        cout << a++->second + 1 << ' ';
    cout << endl;
}

int solve1(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x1);
    d2 = checkResources(d1, x2);
    if (d2 == -1) return 0;
    cout << n - d1 << d1 - d2 << endl;
    output(c + d1, c + n);
    output(c + d2, c + d1);
    return 1;
}

int solve2(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x2);
    d2 = checkResources(d1, x1);
    if (d2 == -1) return 0;
    cout << d1 - d2 << ' ' << n - d1 << endl;
    output(c + d2,c + d1);
    output(c + d1,c + n);
    return 1;
}

int main()
{
    int n, i, x1, x2;
    cin >> n >> x1 >> x2;
    for (i = 0; i < n; ++i) {
        cin >> c[i].first;
        c[i].second = i;
    }
    sort(c, c + n);
    if (!solve1(n, x1, x2) && !solve2(n, x1, x2))
        cout << "No";

    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

pair<int, int> c[300000];

int checkResources(int n, int x) {
    int res;
    for (int i = n-1; i >= 0; --i) {
        res = c[i].first * (n - i);
        if (res >= x)
            return i;
    }
    return -1;
}

void output(pair<int, int> a[], void* b) {
    while (a < b)
        cout << a++->second + 1 << ' ';
    cout << endl;
}

int solve1(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x1);
    d2 = checkResources(d1, x2);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << n - d1 << ' ' << d1 - d2 << endl;
    output(c + d1, c + n);
    output(c + d2, c + d1);
    return 1;
}

int solve2(int n, int x1, int x2) {
    int d1, d2;
    d1 = checkResources(n, x2);
    d2 = checkResources(d1, x1);
    if (d2 == -1) return 0;
    cout << "Yes" << endl << d1 - d2 << ' ' << n - d1 << endl;
    output(c + d2,c + d1);
    output(c + d1,c + n);
    return 1;
}

int main()
{
    int n, i, x1, x2;
    cin >> n >> x1 >> x2;
    for (i = 0; i < n; ++i) {
        cin >> c[i].first;
        c[i].second = i;
    }
    sort(c, c + n);
    if (!solve1(n, x1, x2) && !solve2(n, x1, x2))
        cout << "No";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value > rhs.value;
	}
}Item;

ll n;
ll k[3];
Item p[MAXN];

bool check(int dir){
	//printf("dir = %d %d\n", dir, dir ^ 1);
	map<int, int> vis;
	int pos = 0;	int len[2];	bool found = false;
	for(len[dir] = 1; pos < n; len[dir]++, pos++){
		//printf("pos = %d, value = %lld\n", pos, p[pos].value);
		if(p[pos].value >= (k[dir] - 1) / len[dir] + 1){
			found = true;	break;
		}
	}//printf("pos = %d\n", pos);
	if(!found)	return false;	found = false;	pos++;
	for(len[dir ^ 1] = 1; pos < n; len[dir ^ 1]++, pos++){
		//printf("pos = %d, value = %lld\n", pos, p[pos].value);
		if(p[pos].value >= (k[dir ^ 1] - 1) / len[dir ^ 1] + 1){
			found = true;	break;
		}
	}//printf("pos = %d\n", pos);
	if(!found)	return false;
	printf("Yes\n%d %d\n", len[0], len[1]);	pos = 0;
	for(int t = 0; t < 2; t++){
		if(dir == 1){
			if(!t)	pos = len[1];
			else pos = 0;
			for(int i = 0; pos < len[1] + (!t ? len[0] : 0); pos++, i++){
				if(i)	printf(" ");
				printf("%d", p[pos].pos);
			}printf("\n");	continue;
		}
		for(int i = 0; pos < len[t] + (t ? len[t ^ 1] : 0); pos++, i++){
			if(i)	printf(" ");
			printf("%d", p[pos].pos);
		}printf("\n");
	}return true;
}

int main(void)
{
	scanf("%lld", &n);
	for(ll i = 0; i < 2; i++)	scanf("%lld", &k[i]);
	for(ll i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	if(!check(0) && !check(1))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value < rhs.value;
	}
}Item;

int n;
ll k[3];
Item p[MAXN];
ll lena, lenb;

bool b_s(ll l, ll r){
	if(l > r)	return false;	//printf("(%lld %lld)\n", l, r);
	ll lena = l + (r - l) / 2;	bool found = false;
	for(int i = 0, j = i + lena - 1; j < n; i++, j++){
		if(p[i].value >= (k[0] - 1) / lena + 1){
			found = true;	lenb = 0;
			for(int u = n - 1; u >= 0; u--){
				lenb++;
				if(u >= i && u <= j){
					u = i - 1;
				}if(u < 0)	break;
				if(p[u].value >= (k[1] - 1) / lenb + 1){
					printf("Yes\n");
					printf("%lld %lld\n", lena, lenb);
					for(int t = i; t <= j; t++){
						if(t !=	i)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					for(int t = u; t < n; t++){
						if(t >= i && t <= j)	t = j + 1;
						if(t >= n)	break;
						if(t != u)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					return true;
				}
			}break;
		}
	}if(!found)	return b_s(lena + 1, r);
	return b_s(l, lena - 1);
}

int main(void)
{
	scanf("%d", &n);
	for(int i = 0; i < 2; i++)	scanf("%lld", &k[i]);
	for(int i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	if(!b_s(1, n))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value < rhs.value;
	}
}Item;

ll n;
ll k[3];
Item p[MAXN];
ll lena, lenb;

bool b_s(ll l, ll r){
	if(l > r)	return false;	//printf("(%lld %lld)\n", l, r);
	ll lena = l + (r - l) / 2;	bool found = false;
	for(ll i = 0, j = i + lena - 1; j < n; i++, j++){
		if(p[i].value >= (k[0] - 1) / lena + 1){
			found = true;	lenb = 0;
			for(ll u = n - 1; u >= 0; u--){
				lenb++;
				if(u >= i && u <= j){
					u = i - 1;
				}if(u < 0)	break;
				if(p[u].value >= (k[1] - 1) / lenb + 1){
					printf("Yes\n");
					printf("%lld %lld\n", lena, lenb);
					for(ll t = i; t <= j; t++){
						if(t !=	i)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					for(ll t = u; t < n; t++){
						if(t >= i && t <= j)	t = j + 1;
						if(t >= n)	break;
						if(t != u)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					return true;
				}
			}
		}
	}if(!found)	return b_s(lena + 1, r);
	return b_s(l, lena - 1);
}

int main(void)
{
	scanf("%lld", &n);
	for(ll i = 0; i < 2; i++)	scanf("%lld", &k[i]);
	for(ll i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	if(!b_s(1, n))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value < rhs.value;
	}
}Item;

int n, k[3];
Item p[MAXN];
ll pre[MAXN];
ll lena, lenb;
ll a[MAXN], b[MAXN];

bool b_s(ll l, ll r){
	if(l > r)	return false;	//printf("(%lld %lld)\n", l, r);
	ll lena = l + (r - l) / 2;	bool found = false;
	for(int i = 0, j = i + lena - 1; j < n; i++, j++){
		if(p[i].value >= (k[0] - 1) / lena + 1){
			found = true;	lenb = 0;
			for(int u = n - 1; u >= 0; u--){
				lenb++;
				if(u >= i && u <= j){
					u = i - 1;
				}if(u < 0)	break;
				if(p[u].value >= (k[1] - 1) / lenb + 1){
					printf("Yes\n");
					printf("%lld %lld\n", lena, lenb);
					for(int t = i; t <= j; t++){
						if(t !=	i)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					for(int t = u; t < n; t++){
						if(t >= i && t <= j)	t = j + 1;
						if(t >= n)	break;
						if(t != u)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					return true;
				}
			}
		}
	}if(!found)	return b_s(lena + 1, r);
	return b_s(l, lena - 1);
}

int main(void)
{
	scanf("%d", &n);
	for(int i = 0; i < 2; i++)	scanf("%d", &k[i]);	sort(k, k + 2);
	for(int i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	for(int i = 0; i < n; i++){
		if(!i)	pre[i] = p[i].value;
		else pre[i] = pre[i - 1] + p[i].value;
	}if(!b_s(1, n))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value < rhs.value;
	}
}Item;

ll n;
ll k[3];
Item p[MAXN];
ll lena, lenb;

bool b_s(ll l, ll r){
	if(l > r)	return false;	//printf("(%lld %lld)\n", l, r);
	ll lena = l + (r - l) / 2;	bool found = false;
	for(int i = 0, j = i + lena - 1; j < n; i++, j++){
		if(p[i].value >= (k[0] - 1) / lena + 1){
			found = true;	lenb = 0;
			for(int u = n - 1; u >= 0; u--){
				lenb++;
				if(u >= i && u <= j){
					u = i - 1;
				}if(u < 0)	break;
				if(p[u].value >= (k[1] - 1) / lenb + 1){
					printf("Yes\n");
					printf("%lld %lld\n", lena, lenb);
					for(int t = i; t <= j; t++){
						if(t !=	i)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					for(int t = u; t < n; t++){
						if(t >= i && t <= j)	t = j + 1;
						if(t >= n)	break;
						if(t != u)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					return true;
				}
			}break;
		}
	}if(!found)	return b_s(lena + 1, r);
	return b_s(l, lena - 1);
}

int main(void)
{
	scanf("%lld", &n);
	for(int i = 0; i < 2; i++)	scanf("%lld", &k[i]);
	for(int i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	if(!b_s(1, n))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAXN = 1e7 + 10;
typedef struct Item{
	ll value;	int pos;
	bool operator < (const Item &rhs) const{
		return value < rhs.value;
	}
}Item;

int n, k[3];
Item p[MAXN];
ll lena, lenb;

bool b_s(ll l, ll r){
	if(l > r)	return false;	//printf("(%lld %lld)\n", l, r);
	ll lena = l + (r - l) / 2;	bool found = false;
	for(int i = 0, j = i + lena - 1; j < n; i++, j++){
		if(p[i].value >= (k[0] - 1) / lena + 1){
			found = true;	lenb = 0;
			for(int u = n - 1; u >= 0; u--){
				lenb++;
				if(u >= i && u <= j){
					u = i - 1;
				}if(u < 0)	break;
				if(p[u].value >= (k[1] - 1) / lenb + 1){
					printf("Yes\n");
					printf("%lld %lld\n", lena, lenb);
					for(int t = i; t <= j; t++){
						if(t !=	i)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					for(int t = u; t < n; t++){
						if(t >= i && t <= j)	t = j + 1;
						if(t >= n)	break;
						if(t != u)	printf(" ");
						printf("%d", p[t].pos);
					}printf("\n");
					return true;
				}
			}
		}
	}if(!found)	return b_s(lena + 1, r);
	return b_s(l, lena - 1);
}

int main(void)
{
	scanf("%d", &n);
	for(int i = 0; i < 2; i++)	scanf("%d", &k[i]);	sort(k, k + 2);
	for(int i = 0; i < n; i++)	scanf("%lld", &p[i].value), p[i].pos = i + 1;
	sort(p, p + n);
	if(!b_s(1, n))	printf("No\n");	return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define EPS 10e-6
#define pi acos(-1)
#define N 300010
struct node {
    ll num;
    int pos;
}c[N];
ll n, x1,x2;
bool cmp (node a, node b)
{
    return a.num > b.num;
}
int main()
{
    scanf("%lld%lld%lld", &n, &x1, &x2);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &c[i].num);
        c[i].pos = i;
    }
    int flag = 0;
    sort(c + 1, c + n + 1, cmp);
    int pos1 = 0, pos2 = 0;
    ll ans = 0, cnt1 = 0, cnt2 = 0;
    for(int i = 1; i <= n; i++) {
        cnt1 ++;
        double sum = 1.0*x1/cnt1;
        if(c[i].num-sum>=0) {
            pos1 = i;
            break;
        }
    }

    for(int i = pos1+1; i <= n; i++) {
        cnt2 ++;
        double sum = 1.0*x2/cnt2;
        if(c[i].num-sum >= 0) {
            pos2 = i;
            break;
        }
    }
    if(pos2 == 0 || pos2 == 0) {
        pos2 = 0, pos1 = 0;
        ans = 0, cnt1 = 0, cnt2 = 0;
        swap(x1, x2);
        flag = 1;
        for(int i = 1; i <= n; i++) {
            cnt1 ++;
            double sum = 1.0*x1/cnt1;
            if(c[i].num-sum>=0) {
                pos1 = i;
                break;
            }
        }

        for(int i = pos1+1; i <= n; i++) {
            cnt2 ++;
            double sum = 1.0*x2/cnt2;
            if(c[i].num-sum >= 0) {
                pos2 = i;
                break;
            }
        }
    }
    if(pos1==0||pos2==0) {
        printf("No\n");
        return 0;
    }
    //cout << cnt1 << " " << cnt2 << endl;
    printf("Yes\n");
    if(!flag) {
        printf("%d %d\n", pos1, pos2-pos1);
        printf("%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
    }else {
        printf("%d %d\n", pos2-pos1, pos1);
        printf("%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define EPS 10e-6
#define pi acos(-1)
#define N 300010
struct node {
    ll num;
    int pos;
}c[N];
ll n, x1,x2;
bool cmp (node a, node b)
{
    return a.num > b.num;
}
int main()
{
    scanf("%lld%lld%lld", &n, &x1, &x2);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &c[i].num);
        c[i].pos = i;
    }
    int flag = 0;
    sort(c + 1, c + n + 1, cmp);
    int pos1 = 0, pos2 = 0;
    ll ans = 0, cnt1 = 0, cnt2 = 0;
    for(int i = 1; i <= n; i++) {
        cnt1 ++;
        double sum = 1.0*x1/cnt1;
        if(c[i].num-sum>=0) {
            pos1 = i;
            break;
        }
    }

    for(int i = pos1+1; i <= n; i++) {
        cnt2 ++;
        double sum = 1.0*x2/cnt2;
        if(c[i].num-sum >= 0) {
            pos2 = i;
            break;
        }
    }
    if(pos2 == 0 || pos2 == 0) {
        pos2 = 0, pos1 = 0;
        ans = 0, cnt1 = 0, cnt2 = 0;
        swap(x1, x2);
        flag = 1;
        for(int i = 1; i <= n; i++) {
            cnt1 ++;
            double sum = 1.0*x1/cnt1;
            if(c[i].num-sum>=0) {
                pos1 = i;
                break;
            }
        }

        for(int i = pos1+1; i <= n; i++) {
            cnt2 ++;
            double sum = 1.0*x2/cnt2;
            if(c[i].num-sum >= 0) {
                pos2 = i;
                break;
            }
        }
    }
    if(pos1==0||pos2==0) {
        printf("No\n");
        return 0;
    }
    //cout << cnt1 << " " << cnt2 << endl;
    printf("Yes\n");
    if(!flag) {
        printf("%d %d\n", pos1, pos2-pos1);
        printf("%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
    }else {
        printf("%d %d\n", pos2-pos1, pos1);
        printf("%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
    }
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/hash_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define XINF INT_MAX
#define INF 0x3F3F3F3F
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
#define RIT reverse_iterator
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
typedef tree<PII, null_type, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree_set;
typedef tree<PII, PII, greater<PII>, rb_tree_tag, tree_order_statistics_node_update > rb_tree;
#define PQ std::priority_queue
#define HEAP __gnu_pbds::priority_queue
#define X first
#define Y second
#define lson(X) ((X)<<1)
#define rson(X) ((X)<<1|1)
#define EPS 10e-6
#define pi acos(-1)
#define N 300010
struct node {
    ll num;
    ll pos;
}c[N];
ll n, x1,x2;
bool cmp (node a, node b)
{
    return a.num > b.num;
}
int main()
{
    scanf("%lld%lld%lld", &n, &x1, &x2);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &c[i].num);
        c[i].pos = i;
    }
    int flag = 0;
    sort(c + 1, c + n + 1, cmp);
    int pos1 = 0, pos2 = 0;
    ll ans = 0, cnt1 = 0, cnt2 = 0;
    for(int i = 1; i <= n; i++) {
        cnt1 ++;
        double sum = 1.0*x1/cnt1;
        if(c[i].num-sum>=0) {
            pos1 = i;
            break;
        }
    }

    for(int i = pos1+1; i <= n; i++) {
        cnt2 ++;
        double sum = 1.0*x2/cnt2;
        if(c[i].num-sum >= 0) {
            pos2 = i;
            break;
        }
    }
    if(pos2 == 0 || pos2 == 0) {
        pos2 = 0, pos1 = 0;
        ans = 0, cnt1 = 0, cnt2 = 0;
        swap(x1, x2);
        flag = 1;
        for(int i = 1; i <= n; i++) {
            cnt1 ++;
            double sum = 1.0*x1/cnt1;
            if(c[i].num-sum>=0) {
                pos1 = i;
                break;
            }
        }

        for(int i = pos1+1; i <= n; i++) {
            cnt2 ++;
            double sum = 1.0*x2/cnt2;
            if(c[i].num-sum >= 0) {
                pos2 = i;
                break;
            }
        }
    }
    if(pos1==0||pos2==0) {
        printf("No\n");
        return 0;
    }
    //cout << cnt1 << " " << cnt2 << endl;
    printf("Yes\n");
    if(!flag) {
        printf("%d %d\n", pos1, pos2-pos1);
        printf("%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
    }else {
        printf("%d %d\n", pos2-pos1, pos1);
        printf("%lld", c[pos1+1].pos);
        for(int i = pos1+2; i <= pos2; i++)
            printf(" %lld", c[i].pos);
        printf("\n%lld", c[1].pos);
        for(int i = 2 ; i <= pos1; i++)
            printf(" %lld", c[i].pos);
    }
    printf("\n");
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
pli sav[333333];
ll a,b,c[333333];
int na[333333];
int nb[333333];
int can[333333];
int cntc[333333];

void Print(int a1,int a2,int b1,int b2){
	Tone("Yes");
	cout<<a2-a1<<" "<<b2-b1<<endl;
  FOR(i,a1,a2){
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	FOR(i,b1,b2){
	  cout<<sav[i].second+1<<" ";
	}
	Tone("");
	exit(0);
}

void PPrint(int a1,int a2,int b1,int b2){
	Tone("Yes");
	cout<<a2-a1<<" "<<b2-b1<<endl;
  FOR(i,a1,a2){
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	FOR(i,b1,b2){
	  if(i>=a1&&i<a2)continue;
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	exit(0);
}

int I_Love_Hashimoto_Kanna() {
  fastio;
  memset(cntc,-1,sizeof(cntc));
  cin>>n>>a>>b;
  FOR(i,0,n){
  	cin>>sav[i].first;
  	sav[i].second=i;
	}
	sort(sav,sav+n);
	FOR(i,0,n){
		c[i]=sav[i].first;
		na[i]=(a+c[i]-1)/c[i];
		nb[i]=(b+c[i]-1)/c[i];
	}
	for(int i=n-1;i>=0;i--){
		can[i]=((n-i)>=nb[i]);
		cntc[i]=(can[i]?i:cntc[i+1]);
	}
	int pre=inf;
	int pos=0;
	FOR(st,0,n){
		int ed=st+na[st];
		if(ed>n){
			if(pre>st+nb[st]){
				pre=st+nb[st];
				pos=st;
			}
			continue;
		}
		if(cntc[ed]!=-1){
			//ans behind
			int a1,a2,b1,b2;
			a1=st;
			a2=ed;
			b1=cntc[ed];
			b2=cntc[ed]+nb[b1];
			Print(a1,a2,b1,b2);
		}
		if(pre+na[st]<=n){
			//ans front
			int a1=st;
			int a2=ed;
			int b1=pos;
			PPrint(a1,a2,b1,pre+na[st]);
		}

		if(pre>st+nb[st]){
			pre=st+nb[st];
			pos=st;
		}

	}

	Tone("No");
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
pli sav[333333];
ll a,b,c[333333];
int na[333333];
int nb[333333];
int can[333333];
int cntc[333333];

void Print(int a1,int a2,int b1,int b2){
	Tone("Yes");
	cout<<a2-a1<<" "<<b2-b1<<endl;
  FOR(i,a1,a2){
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	FOR(i,b1,b2){
	  cout<<sav[i].second+1<<" ";
	}
	Tone("");
	exit(0);
}

void PPrint(int a1,int a2,int b1,int b2){
	Tone("Yes");
	cout<<a2-a1<<" "<<b2-b1-(a2-a1)<<endl;
  FOR(i,a1,a2){
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	FOR(i,b1,b2){
	  if(i>=a1&&i<a2)continue;
		cout<<sav[i].second+1<<" ";
	}
	Tone("");
	exit(0);
}

int I_Love_Hashimoto_Kanna() {
  fastio;
  memset(cntc,-1,sizeof(cntc));
  cin>>n>>a>>b;
  FOR(i,0,n){
  	cin>>sav[i].first;
  	sav[i].second=i;
	}
	sort(sav,sav+n);
	FOR(i,0,n){
		c[i]=sav[i].first;
		na[i]=(a+c[i]-1)/c[i];
		nb[i]=(b+c[i]-1)/c[i];
	}
	for(int i=n-1;i>=0;i--){
		can[i]=((n-i)>=nb[i]);
		cntc[i]=(can[i]?i:cntc[i+1]);
	}
	int pre=inf;
	int pos=0;
	FOR(st,0,n){
		int ed=st+na[st];
		if(ed>n){
			if(pre>st+nb[st]){
				pre=st+nb[st];
				pos=st;
			}
			continue;
		}
		if(cntc[ed]!=-1){
			//ans behind
			int a1,a2,b1,b2;
			a1=st;
			a2=ed;
			b1=cntc[ed];
			b2=cntc[ed]+nb[b1];
			Print(a1,a2,b1,b2);
		}
		if(pre+na[st]<=n){
			//ans front
			int a1=st;
			int a2=ed;
			int b1=pos;
			PPrint(a1,a2,b1,pre+na[st]);
		}

		if(pre>st+nb[st]){
			pre=st+nb[st];
			pos=st;
		}

	}

	Tone("No");
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;
typedef vector<vi> mat;

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<Kanna;I_Love++)cout<<Hashimoto[I_Love]<<(I_Love==Kanna-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<Kanna;I_Love++)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define inf (int)1e9
#define linf (ll)1e18
#define mod (inf+7)

int n;
pli sav[333333];
ll a,b,c[333333];
int na[333333];
int nb[333333];
int can[333333];
int cntc[333333];

void Print(int a1,int a2,int b1,int b2){
	Tone("Yes");
	cout<<a2-a1<<" "<<b2-b1<<endl;
			FOR(i,a1,a2){
				cout<<sav[i].second+1<<" ";
			}
			Tone("");
			FOR(i,b1,b2){
				cout<<sav[i].second+1<<" ";
			}
			Tone("");
			exit(0);
}

int I_Love_Hashimoto_Kanna() {
  fastio;
  memset(cntc,-1,sizeof(cntc));
  cin>>n>>a>>b;
  FOR(i,0,n){
  	cin>>sav[i].first;
  	sav[i].second=i;
	}
	sort(sav,sav+n);
	FOR(i,0,n){
		c[i]=sav[i].first;
		na[i]=(a+c[i]-1)/c[i];
		nb[i]=(b+c[i]-1)/c[i];
	}
	for(int i=n-1;i>=0;i--){
		can[i]=((n-i)>=nb[i]);
		cntc[i]=(can[i]?i:cntc[i+1]);
	}
	int pre=inf;
	int pos=0;
	FOR(st,0,n){
		int ed=st+na[st];
		if(ed>n){
			if(pre>st+nb[st]){
				pre=st+nb[st];
				pos=st;
			}
			continue;
		}
		if(cntc[ed]!=-1){
			//ans behind
			int a1,a2,b1,b2;
			a1=st;
			a2=ed;
			b1=cntc[ed];
			b2=cntc[ed]+nb[b1];
			Print(a1,a2,b1,b2);
		}
		if(pre+na[st]<=n){
			//ans front
			int a1=st;
			int a2=ed;
			int b1=pos;
			int b2=pre;
			Print(a1,a2,b1,b2);
		}

		if(pre>st+nb[st]){
			pre=st+nb[st];
			pos=st;
		}

	}

	Tone("No");
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 300005
using namespace std;
int n,po[N],tot;ll x1,x2;
struct info{
  int x,id;
  bool operator<(const info &p)const{return x<p.x;}
}s[N];

ll cal(int x,int len)
{
  return (ll)(n-x+1-len)*s[x].x;
}

int qry(int l,int r,int tmp)
{
  while(r-l>1)
  {
    int len=(r-l+1)/3;
    int lx=l+len,rx=r-len;
    if(cal(lx,tmp)<cal(rx,tmp))l=lx;
    else r=rx;
  }
  if(cal(l,tmp)>cal(r,tmp))return l;
  return r;
}

int main()
{
  int x,num,pos,p1,p2,p;ll v1,v2;
  scanf("%d%lld%lld",&n,&x1,&x2);
  for(int i=1;i<=n;i++)
    scanf("%d",&x),s[i]=(info){x,i};
  sort(s+1,s+n+1);
  for(int i=1;i<=n;i++)
  {
    num=x1/i;if(x1%i)num++;
    pos=lower_bound(s+1,s+n+1,(info){num,0})-s;
    while(pos<=n&&s[pos].x<num)pos++;
    if(pos+i-1>n)continue;
    p1=qry(1,pos-1,i);p2=qry(pos+i,n,0);
	v1=(n-p1-i+1)*s[p1].x;v2=(n-p2+1)*s[p2].x;
	if(max(v1,v2)<x2)continue;

	tot=0;p=v1>v2?p1:p2;
	for(int j=n;j>=pos+i&&j>=p;j--)po[++tot]=j;
	for(int j=pos-1;j>=p;j--)po[++tot]=j;

	printf("Yes\n");
    printf("%d %d\n",i,tot);
    for(int j=pos;j<pos+i;j++)printf("%d ",s[j].id);
    printf("\n");
    for(int j=1;j<=tot;j++)printf("%d ",s[po[j]].id);
    printf("\n");
    return 0;
  }
  printf("No\n");
  return 0;
}


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
if (k<n and arr[k-1]!=arr[k]) or k==n:
    print(arr[k-1])
else:
    print(-1)


n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(1)
a.sort()
if a[k+1]-a[k]==0:
    print(-1)
else:
    print(a[k])


n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
if a[k]-a[k-1]<=1:
    print(-1)
else:
    print(a[k-1]+1)


n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(1)
a.sort()
if k==n:
    print(a[k])
else:
    if a[k+1]-a[k]==0:
        print(-1)
    else:
        print(a[k])


n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
if a[k]-a[k-1]==0:
    print(-1)
else:
    print(a[k-1])


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

if k == 0:
    if arr[0] > 1:
        print(arr[0]-1)
    else:
        print(-1)
    exit()

if arr[k-1] == arr[k]:
    print(-1)
else:
    print(arr[k-1])


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

if k == 0:
    if arr[0] > 1:
        print(arr[0]-1)
    else:
        print(-1)
    exit()

if n == 1:
    print(arr[0])
    exit()

if k == n:
    print(arr[-1])
    exit()

if arr[k-1] == arr[k]:
    print(-1)
else:
    print(arr[k-1])


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

if k == 0:
    if arr[0] > 1:
        print(arr[0]-1)
    else:
        print(-1)
    exit()

if n == 1:
    print(arr[0])
    exit()

if arr[k-1] == arr[k]:
    print(-1)
else:
    print(arr[k-1])


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

if k == 0:
    print(arr[0]-1)
    exit()

if arr[k-1] == arr[k]:
    print(-1)
else:
    print(arr[k-1])


n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)

if arr[k-1] == arr[k]:
    print(-1)
else:
    print(arr[k-1])


import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n,k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
dp ={}
cont = 0
for i in list(dict.fromkeys(arr)):
    dp[i] = arr.count(i)+cont
    cont+=arr.count(i)
if(dp[arr[k-1]]==k):
    print(arr[k-1])
else:
    print(-1)


import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n,k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
dp ={}
cont = 0
if(k==0):
    if(min(arr)<=1):
        print(-1)
    else:
        print(min(arr)-1)
else:
    cnt = 0
    pnt = 0
    while(cnt< k):
        mark = int(pnt)
        while(arr[mark]==arr[pnt]):
            cnt+=1
            pnt+=1
    if(cnt==k):
        print(arr[pnt-1])
    else:
        print(-1)


import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n,k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
if(k==0):
    if(min(arr)<=1):
        print(-1)
    else:
        print(min(arr)-1)
else:
    cnt = 0
    pnt = 0
    while(cnt < k):
        mark = int(pnt)
        while(arr[mark]==arr[pnt]):
            cnt+=1
            pnt+=1
    if(cnt==k):
        print(arr[pnt-1])
    else:
        print(-1)


import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n,k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
dp ={}
cont = 0
if(k==0):
    if(min(arr)<=1):
        print(-1)
    else:
        print(min(arr)-1)
else:
    for i in list(dict.fromkeys(arr)):
        dp[i] = arr.count(i)+cont
        cont+=arr.count(i)
    if(dp[arr[k-1]]==k):
        print(arr[k-1])
    else:
        print(-1)


import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n,k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
if(k==0):
    if(min(arr)<=1):
        print(-1)
    else:
        print(min(arr)-1)
else:
    cnt = 0
    pnt = 0
    while(cnt < k):
        mark = int(pnt)
        while(arr[mark]==arr[pnt]):
            cnt+=1
            pnt+=1
            if(pnt == len(arr)):
                break
    if(cnt==k):
        print(arr[pnt-1])
    else:
        print(-1)


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()

if(l[k]==l[k-1] or l[k]==l[k+1]):
	print(-1)
else:
	print(l[k])


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()

if(k==1):
	if(l[0]!=l[1]):
		print(l[k])
	else:
		print(-1)
else:
	if(l[k-1]==l[k-2] or l[k-1]==l[k]):
		print(-1)
	else:
		print(l[k-1])


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(k==0):
	print(l[1])
if(k==1):
	if(l[0]!==l[1]):
		print(l[k])
	else:
		print(-1)
else:
	if(l[k-1]==l[k-2] or l[k-1]==l[k]):
		print(-1)
	else:
		print(l[k-1])


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(k==0):
	print(l[1])
if(k==1):
	if(l[0]!=l[1]):
		print(l[k])
	else:
		print(-1)
else:
	if(l[k-1]==l[k-2] or l[k-1]==l[k]):
		print(-1)
	else:
		print(l[k-1])


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
if(k==0):
	print(-1)
elif(k==1):
	if(n>1):
		if(l[0]!=l[1]):
			print(l[k])
		else:
			print(-1)
	else:
		print(l[0])
else:
	if(l[k-1]==l[k-2] or l[k-1]==l[k]):
		print(-1)
	else:
		print(l[k-1])


n,k=map(int,input().split())
l1=[1]
l=list(map(int,input().split()))

l=l1+l
l.sort()
if(n==k or l[k]!=l[k+1]):
	print(l[k])
else:
	print(-1)


n,k=map(int,input().split())
l=list(map(int,input().split()))
l.sort()

if(k==1):
	if(l[0]!==l[1]):
		print(l[k])
	else:
		print(-1)
else:
	if(l[k-1]==l[k-2] or l[k-1]==l[k]):
		print(-1)
	else:
		print(l[k-1])


(n, k), a = map(int, input().split()), sorted(list(map(int, input().split())))
cnt, d = 0, dict()
for i in a:
    d[i] = d.get(i, 0) + 1
a = sorted([i for i in d.items()])
for i in a:
    if cnt == k and i[0] != 1:
        print(i[0] - 1)
        exit(0)
    if cnt > k:
        print(-1)
        exit(0)
    cnt += i[1]
print(a[-1][0] if cnt == k else -1)


(n, k), a = map(int, input().split()), sorted(list(map(int, input().split())))
cnt, d = 0, dict()
for i in a:
    d[i] = d.get(i, 0) + 1
a = sorted([i for i in d.items()])
for i in a:
    if cnt == k and i[0] != 1:
        print(i[0] - 1)
        exit(0)
    if cnt > k:
        print(-1)
        exit(0)
    cnt += i[1]
print(-1)


(n, k), a = map(int, input().split()), sorted(list(map(int, input().split())))
cnt, d = 0, dict()
for i in a:
    d[i] = d.get(i, 0) + 1
a = sorted([i for i in d.items()])
for i in a:
    cnt += i[1]
    if cnt == k:
        print(i[0])
        exit(0)
    elif cnt > k:
        print(-1)
        exit(0)


(n, k), a = map(int, input().split()), sorted(list(map(int, input().split())))
cnt, d = 0, dict()
for i in a:
    d[i] = d.get(i, 0) + 1
a = sorted([i for i in d.items()])
for i in a:
    if cnt == k:
        print(i[0] - 1)
        exit(0)
    if cnt > k:
        print(-1)
        exit(0)
    cnt += i[1]


(n, k), a = map(int, input().split()), sorted(list(map(int, input().split())))
cnt, d = 0, dict()
for i in a:
    d[i] = d.get(i, 0) + 1
a = sorted([i for i in d.items()])
for i in a:
    if cnt == k and i[0] != 1:
        print(i[0] - 1)
        exit(0)
    if cnt > k:
        print(-1)
        exit(0)
    cnt += i[1]


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    k = inlt()[1]
    lst = inlt()
    lst.sort()
    if k == len(lst):
        if lst[-1] == 1000000000:
            print(-1)
        else:
            print(lst[-1])

    if lst[k] > get(lst, k - 1, 1):
        print(lst[k] - 1)
    else:
        print(-1)

def get(lst, idx, default):
    if idx == -1:
        return default
    return lst[idx]

BUFSIZE = 8192

def inp():
    return (int(input()))

def inlt():
    return (list(map(int, input().split())))

def insr():
    return (input().strip())

def invr():
    return (map(int, input().split()))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    k = inlt()[1]
    lst = inlt()
    lst.sort()
    if k == len(lst):
        print(1000000000)
        return
    if lst[k] > get(lst, k - 1, 1):
        print(lst[k] - 1)
    else:
        print(-1)

def get(lst, idx, default):
    if idx == -1:
        return default
    return lst[idx]

BUFSIZE = 8192

def inp():
    return (int(input()))

def inlt():
    return (list(map(int, input().split())))

def insr():
    return (input().strip())

def invr():
    return (map(int, input().split()))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    k = inlt()[1]
    lst = inlt()
    lst.sort()
    if k == len(lst):
        if lst[-1] == 10E9:
            print(-1)
        else:
            print(lst[-1])

    if lst[k] > get(lst, k - 1, 1):
        print(lst[k] - 1)
    else:
        print(-1)

def get(lst, idx, default):
    if idx == -1:
        return default
    return lst[idx]

BUFSIZE = 8192

def inp():
    return (int(input()))

def inlt():
    return (list(map(int, input().split())))

def insr():
    return (input().strip())

def invr():
    return (map(int, input().split()))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    k = inlt()[1]
    lst = inlt()
    lst.sort()
    if k == len(lst):
        if lst[-1] == 1000000000:
            print(-1)
        else:
            print(lst[-1])
        return
    if lst[k] > get(lst, k - 1, 1):
        print(lst[k] - 1)
    else:
        print(-1)

def get(lst, idx, default):
    if idx == -1:
        return default
    return lst[idx]

BUFSIZE = 8192

def inp():
    return (int(input()))

def inlt():
    return (list(map(int, input().split())))

def insr():
    return (input().strip())

def invr():
    return (map(int, input().split()))

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define hr cout<<'\n'
#define pb push_back
#define mid ((l+r)>>1)
#define lc (o<<1)
#define rc (lc|1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false);
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){b?exgcd(b,a%b,d,y,x),y-=a/b*x:x=1,y=0,d=a;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head

const int N = 1e4+10, INF = 0x3f3f3f3f;
int n, m, x;
int a[20][N], vis[N];
bool g[20][20];
int dp[100000][20][20];

int dfs(int s, int lst, int f) {
	int &ans = dp[s][lst][f];
	if (~ans) return ans;
	int t = 0;
	REP(i,1,n) if (!(s>>i&1)) {
		t = 1;
		if (g[i][lst]&&dfs(s^1<<i,i,f)) return ans=1;
	}
	if (!t) {
		REP(i,1,m-1) if (abs(a[lst][i]-a[f][i+1])<x) return ans=0;
		return ans=1;
	}
	return ans=0;
}

int chk() {
	memset(g,1,sizeof g);
	REP(i,1,m) {
		REP(j,1,n) REP(k,1,n) {
			if (abs(a[j][i]-a[k][i])<x) {
				g[j][k] = 0;
			}
		}
	}
	memset(dp, -1, sizeof dp);
	REP(i,1,n) {
		if (dfs(1<<i,0,i)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	REP(i,1,n) REP(j,1,m) scanf("%d", &a[i][j]);
	int l=0, r=1e9+10, ans;
	while (l<=r) {
		x = mid;
		if (chk()) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n", ans);
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <string.h>
#include <queue>
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define hr cout<<'\n'
#define pb push_back
#define mid ((l+r)>>1)
#define lc (o<<1)
#define rc (lc|1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false);
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){b?exgcd(b,a%b,d,y,x),y-=a/b*x:x=1,y=0,d=a;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head

const int N = 1e4+10, INF = 0x3f3f3f3f;
int n, m, x;
int a[20][N], vis[N];
bool g[20][20];
int dp[270000][20][20];

int dfs(int s, int lst, int f) {
	int &ans = dp[s][lst][f];
	if (~ans) return ans;
	int t = 0;
	REP(i,1,n) if (!(s>>i&1)) {
		t = 1;
		if (g[i][lst]&&dfs(s^1<<i,i,f)) return ans=1;
	}
	if (!t) {
		REP(i,1,m-1) if (abs(a[lst][i]-a[f][i+1])<x) return ans=0;
		return ans=1;
	}
	return ans=0;
}

int chk() {
	memset(g,1,sizeof g);
	REP(i,1,m) {
		REP(j,1,n) REP(k,1,n) {
			if (abs(a[j][i]-a[k][i])<x) {
				g[j][k] = 0;
			}
		}
	}
	memset(dp, -1, sizeof dp);
	REP(i,1,n) {
		if (dfs(1<<i,0,i)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%d", &n, &m);
	REP(i,1,n) REP(j,1,m) scanf("%d", &a[i][j]);
	int l=0, r=1e9+10, ans;
	while (l<=r) {
		x = mid;
		if (chk()) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n", ans);
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <tuple>
#include <iomanip>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define readfile freopen("input.txt", "r", stdin);
#define writefile freopen("output.txt", "w", stdout);
#define endl '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<vector<int>> graph;
typedef long long ll;

int inf = (int) 2e9;
int mod = 999999937;

int get(int mask, int ind) {
    return ((mask >> ind) & 1);
}

int dec(int mask, int ind) {
    return (mask ^ (1 << ind));
}

vector<vector<vector<int>>> dp;
vector<vector<int>> a, mins;
int n, m;

int rec(int first, int last, int mask) {
    if (dp[first][last][mask] != -inf) return dp[first][last][mask];
    if (first == last || !get(mask, first) || !get(mask, last)) {
        dp[first][last][mask] = -1;
        return -1;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) cnt += get(mask, i);
    if (cnt == 2) {
        dp[first][last][mask] = mins[first][last];
        return dp[first][last][mask];
    }
    int new_mask = dec(mask, last);
    for (int i = 0; i < n; ++i) {
        if (i == first || !get(new_mask, i)) continue;
        dp[first][i][new_mask] = rec(first, i, new_mask);
        int k = min(dp[first][i][new_mask], mins[last][i]);
        dp[first][last][mask] = max(dp[first][last][mask], k);
    }
    return dp[first][last][mask];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    readfile;
#endif
    cin >> n >> m;
    a.resize(n, vector<int>(m));
    mins.resize(n, vector<int>(n, inf));
    int p = (1 << n);
    dp.resize(n, vector<vector<int>>(n, vector<int>(p, -inf)));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < m; ++k) {
                mins[i][j] = min(mins[i][j], abs(a[i][k] - a[j][k]));
            }
        }
    }
    if (n == 1) {
        int k = inf;
        for (int i = 1; i < m; ++i) k = min(k, abs(a[0][i] - a[0][i - 1]));
        cout << k;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int cur = rec(i, j, p - 1);
            for (int k = 1; k < m; ++k) {
                cur = min(cur, abs(a[i][k] - a[j][k - 1]));
            }
            ans = max(ans, cur);
        }
    }
    cout << ans;
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <tuple>
#include <iomanip>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define readfile freopen("input.txt", "r", stdin);
#define writefile freopen("output.txt", "w", stdout);
#define endl '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<vector<int>> graph;
typedef long long ll;

int inf = (int) 2e9;
int mod = 999999937;

int get(int mask, int ind) {
    return ((mask >> ind) & 1);
}

int dec(int mask, int ind) {
    return (mask ^ (1 << ind));
}

vector<vector<vector<int>>> dp;
vector<vector<int>> a;
int n, m;

int rec(int first, int last, int mask) {
    if (dp[first][last][mask] != -inf) return dp[first][last][mask];
    if (first == last || !get(mask, first) || !get(mask, last)) {
        dp[first][last][mask] = -1;
        return -1;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) cnt += get(mask, i);
    if (cnt == 2) {
        int k = inf;
        for (int i = 0; i < m; ++i) {
            k = min(k, abs(a[first][i] - a[last][i]));
        }
        dp[first][last][mask] = k;
        return k;
    }
    int new_mask = dec(mask, last);
    for (int i = 0; i < n; ++i) {
        if (i == first || !get(new_mask, i)) continue;
        dp[first][i][new_mask] = rec(first, i, new_mask);
        int k = dp[first][i][new_mask];
        for (int j = 0; j < m; ++j) {
            k = min(k, abs(a[last][j] - a[i][j]));
        }
        dp[first][last][mask] = max(dp[first][last][mask], k);
    }
    return dp[first][last][mask];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    readfile;
#endif
    cin >> n >> m;
    a.resize(n, vector<int>(m));
    int p = (1 << n);
    dp.resize(n, vector<vector<int>>(n, vector<int>(p, -inf)));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    if (n == 1) {
        int k = inf;
        for (int i = 1; i < m; ++i) k = min(k, abs(a[0][i] - a[0][i - 1]));
        cout << k;
        return 0;
    }
    int ans = 0;
/*    for (int i = 2; i <= n; ++i) {
        vector<int> tt(n, 0);
        for (int j= n - 1; j >= n - i; --j) {
            tt[j] = 1;
        }
        do {

        } while (next_permutation(all(tt)));
    }*/
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int cur = rec(i, j, p - 1);
            /*for (int k = 1; k < m; ++k) {
                cur = min(cur, abs(a[i][k] - a[j][k - 1]));
            }*/
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int cur = dp[i][j][p - 1];
            for (int k = 1; k < m; ++k) {
                cur = min(cur, abs(a[i][k] - a[j][k - 1]));
            }
            ans = max(ans, cur);
        }
    }
    cout << ans;
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <tuple>
#include <iomanip>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define readfile freopen("input.txt", "r", stdin);
#define writefile freopen("output.txt", "w", stdout);
#define endl '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<vector<int>> graph;
typedef long long ll;

int inf = (int) 2e9;
int mod = 999999937;

int get(int mask, int ind) {
    return ((mask >> ind) & 1);
}

int dec(int mask, int ind) {
    return (mask ^ (1 << ind));
}

vector<vector<vector<int>>> dp;
vector<vector<int>> a;
int n, m;

int rec(int first, int last, int mask) {
    if (dp[first][last][mask] != -inf) return dp[first][last][mask];
    if (first == last || !get(mask, first) || !get(mask, last)) {
        dp[first][last][mask] = -1;
        return -1;
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) cnt += get(mask, i);
    if (cnt == 2) {
        int k = inf;
        for (int i = 0; i < m; ++i) {
            k = min(k, abs(a[first][i] - a[last][i]));
        }
        dp[first][last][mask] = k;
        return k;
    }
    int new_mask = dec(mask, last);
    for (int i = 0; i < n; ++i) {
        if (i == first || !get(new_mask, i)) continue;
        dp[first][i][new_mask] = rec(first, i, new_mask);
        int k = dp[first][i][new_mask];
        for (int j = 0; j < m; ++j) {
            k = min(k, abs(a[last][j] - a[i][j]));
        }
        dp[first][last][mask] = max(dp[first][last][mask], k);
    }
    return dp[first][last][mask];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    readfile;
#endif
    cin >> n >> m;
    a.resize(n, vector<int>(m));
    int p = (1 << n);
    dp.resize(n, vector<vector<int>>(n, vector<int>(p, -inf)));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    if (n == 1) {
        int k = inf;
        for (int i = 1; i < m; ++i) k = min(k, abs(a[0][i] - a[0][i - 1]));
        cout << k;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int cur = rec(i, j, p - 1);
            for (int k = 1; k < m; ++k) {
                cur = min(cur, abs(a[i][k] - a[j][k - 1]));
            }
            ans = max(ans, cur);
        }
    }
    cout << ans;
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <tuple>
#include <iomanip>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define readfile freopen("input.txt", "r", stdin);
#define writefile freopen("output.txt", "w", stdout);
#define endl '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<vector<int>> graph;
typedef long long ll;

int inf = (int) 2e9;
int mod = 999999937;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    readfile;
#endif
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
        }
    }
    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        p[i] = i;
    }
    int cnt = 0;
    int ans = 0;
    while (cnt < 10000) {
        int k = inf;
        for (int i = m; i < n * m; ++i) {
            k = min(k, abs(a[p[i / m]][i % m] - a[p[i / m - 1]][i % m]));
        }
        ans = max(ans, k);
        cnt++;
        next_permutation(all(p));
    }
    cout << ans;
}


#include <iostream>
#include <vector>
#include <cmath>
#define large 1000000000
using namespace std;
int p2[17];
int emt[16][16][65536];
vector <vector <int>> m1(16,vector <int> (16,large));
int ans(int i,int j,int u)
{
    int s=u,x=0;
    if(emt[i][j][u]==-1)
    while(s!=0)
    {
        if(s%2==1 && x!=i && x!=j)
        { if(emt[i][x][u-p2[j]]==-1)
        emt[i][j][u]=max(emt[i][j][u],min(m1[x][j],ans(i,x,u-p2[j])));
        else
        emt[i][j][u]=max(emt[i][j][u],min(m1[x][j],emt[i][x][u-p2[j]]));
        }
        s=s/2;
        x++;
    }
    return emt[i][j][u];
}

int main()
{
    for(int i=0;i<16;i++)
        for(int j=0;j<16;j++)
        for(int u=0;u<65536;u++)
        emt[i][j][u]=-1;
    p2[0]=1;
    for(int i=1;i<17;i++)
        p2[i]=2*p2[i-1];
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vector <vector <int>> mx(n,vector <int>(m,0)),m2(n,vector<int>(n,large));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mx[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {   if(i!=j)
            for(int k=0;k<m;k++)
            {
                m1[i][j]=min(m1[i][j],abs(mx[i][k]-mx[j][k]));
                if(k!=m-1)
                m2[i][j]=min(m2[i][j],abs(mx[i][k+1]-mx[j][k]));
            }
        }
    }
     for(int i=0;i<n;i++)
     {   int v;
         for(int j=0;j<n;j++)
         {   if(i!=j)
             v=emt[i][j][p2[i]+p2[j]]=m1[i][j];

         }
     }

    int ansx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           if(i!=j)
           {
               int zx=ans(i,j,p2[n]-1);
           ansx=max(ansx,min(zx,m2[i][j]));}
    if(n==1)
    {   ansx=large;
        for(int i=0;i<m-1;i++)
            ansx=min(ansx,abs(mx[0][i]-mx[0][i+1]));
    }

    cout<<ansx;
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#define large 1000000000
using namespace std;
int p2[17];
int emt[16][16][65536];
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int ans(int i,int j,int u,vector <vector <int>> m1)
{
    int s=u,x=0;

    if(emt[i][j][u]==-1)
    while(s!=0)
    {
        if(s%2==1 && x!=i && x!=j)
        { if(emt[i][x][u-p2[j]]==-1)
        emt[i][j][u]=max(emt[i][j][u],min(m1[x][j],ans(i,x,u-p2[j],m1)));
        else
        emt[i][j][u]=max(emt[i][j][u],min(m1[x][j],emt[i][x][u-p2[j]]));
        }
        s=s/2;
        x++;
    }
    return emt[i][j][u];
}

int main()
{
    for(int i=0;i<16;i++)
        for(int j=0;j<16;j++)
        for(int u=0;u<65536;u++)
        emt[i][j][u]=-1;
    p2[0]=1;
    for(int i=1;i<17;i++)
        p2[i]=2*p2[i-1];
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vector <vector <int>> mx(n,vector <int>(m,0)),m1(n,vector<int>(n,large)),m2(n,vector<int>(n,large));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mx[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {   if(i!=j)
            for(int k=0;k<m;k++)
            {
                m1[i][j]=min(m1[i][j],abs(mx[i][k]-mx[j][k]));
                if(k!=m-1)
                m2[i][j]=min(m2[i][j],abs(mx[i][k+1]-mx[j][k]));
            }
        }
    }
     for(int i=0;i<n;i++)
     {   int v;
         for(int j=0;j<n;j++)
         {   if(i!=j)
             v=emt[i][j][p2[i]+p2[j]]=m1[i][j];

         }
     }

    int ansx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           if(i!=j)
           {
               int zx=ans(i,j,p2[n]-1,m1);
           ansx=max(ansx,min(zx,m2[i][j]));}
    if(n==1)
    {   ansx=large;
        for(int i=0;i<m-1;i++)
            ansx=min(ansx,abs(mx[0][i]-mx[0][i+1]));
    }

    cout<<ansx;
    return 0;
}


#include <iostream>
#include <vector>
#define large 1000000000
using namespace std;
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int ans(vector <bool> bl,int j,vector <vector <int>> m1,int cnt,int i)
{  int x=0;
   if(cnt==2)
      return m1[i][j];

   bl[j]=0;
   for(int v=0;v<m1.size();v++)
   {   if(bl[v]==1 && v!=i)
       x=max(x,min(m1[v][j],ans(bl,v,m1,cnt-1,i)));
   }
   return x;
}
int main()
{   ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vector <vector <int>> mx(n,vector <int>(m,0)),m1(n,vector<int>(n,large)),m2(n,vector<int>(n,large));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mx[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {   if(i!=j)
            for(int k=0;k<m;k++)
            {
                m1[i][j]=min(m1[i][j],abs(mx[i][k]-mx[j][k]));
                if(k!=m-1)
                m2[i][j]=min(m2[i][j],abs(mx[i][k+1]-mx[j][k]));
            }
        }
    }
    vector <bool> bl(n,1);
    int ansx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           if(i!=j)
           {
               int zx=ans(bl,j,m1,n,i);
           ansx=max(ansx,min(zx,m2[i][j]));}
    if(n==1)
    {   ansx=large;
        for(int i=0;i<m-1;i++)
            ansx=min(ansx,abs(mx[0][i]-mx[0][i+1]));
    }
    cout<<ansx;
    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#define large 1000000000
using namespace std;
int p2[17];
int emt[16][16][65536];
vector <vector <int>> m1(16,vector <int> (16,large));
int ans(int i,int j,int u)
{
    int s=u,x=0;
    if(emt[i][j][u]==-1)
    while(s!=0)
    {
        if(s%2==1 && x!=i && x!=j)
        emt[i][j][u]=max(emt[i][j][u],min(m1[x][j],ans(i,x,u-p2[j])));

        s=s/2;
        x++;
    }
    return emt[i][j][u];
}

int main()
{
    for(int i=0;i<16;i++)
        for(int j=0;j<16;j++)
        for(int u=0;u<65536;u++)
        emt[i][j][u]=-1;
    p2[0]=1;
    for(int i=1;i<17;i++)
        p2[i]=2*p2[i-1];
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vector <vector <int>> mx(n,vector <int>(m,0)),m2(n,vector<int>(n,large));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mx[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {   if(i!=j)
            for(int k=0;k<m;k++)
            {
                m1[i][j]=min(m1[i][j],abs(mx[i][k]-mx[j][k]));
                if(k!=m-1)
                m2[i][j]=min(m2[i][j],abs(mx[i][k+1]-mx[j][k]));
            }
        }
    }
     for(int i=0;i<n;i++)
     {   int v;
         for(int j=0;j<n;j++)
         {   if(i!=j)
             v=emt[i][j][p2[i]+p2[j]]=m1[i][j];

         }
     }

    int ansx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           if(i!=j)
           {
               int zx=ans(i,j,p2[n]-1);
           ansx=max(ansx,min(zx,m2[i][j]));}
    if(n==1)
    {   ansx=large;
        for(int i=0;i<m-1;i++)
            ansx=min(ansx,abs(mx[0][i]-mx[0][i+1]));
    }

    cout<<ansx;
    return 0;
}


#include <iostream>
#include <vector>
#define large 1000000000
using namespace std;
int min3(int a,int b,int c)
{
    return min(min(a,b),c);
}
int ans(vector <bool> bl,int j,vector <vector <int>> m1,int cnt,int i)
{  int x=0;
   if(cnt==2)
      return m1[i][j];

   bl[j]=0;
   for(int v=0;v<m1.size();v++)
   {   if(bl[v]==1 && v!=i)
       x=max(x,min(m1[v][j],ans(bl,v,m1,cnt-1,i)));
   }
   return x;
}
int main()
{   ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    vector <vector <int>> mx(n,vector <int>(m,0)),m1(n,vector<int>(n,large)),m2(n,vector<int>(n,large));
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>mx[i][j];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {   if(i!=j)
            for(int k=0;k<m;k++)
            {
                m1[i][j]=min(m1[i][j],abs(mx[i][k]-mx[j][k]));
                if(k!=m-1)
                m2[i][j]=min(m2[i][j],abs(mx[i][k+1]-mx[j][k]));
            }
        }
    }
    vector <bool> bl(n,1);
    int ansx=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
           if(i!=j)
           {
               int zx=ans(bl,j,m1,n,i);
           ansx=max(ansx,min(zx,m2[i][j]));}
    cout<<ansx;
    return 0;
}


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

#define maxn 17
#define maxm 10001

int n,m;
int pos[maxn][maxn];
int dp[2<<(maxn)][maxn];
int a[maxn][maxm];

void pre(int k){
	int flag;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			flag=1;
			for(int l=1;l<=m;l++){
				if(abs(a[i][l]-a[j][l])<k){
					flag=0;
					break;
				}
			}
			pos[i][j]=pos[j][i]=flag;
		}
	}
	return;
}

int check(int k){
	pre(k);
	memset(dp, 0, sizeof(dp));
	for(int i=0;i<n;i++){
		dp[1<<i][i]=1;
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if(i & (1<<j) == 0) continue;
			for(int l=0;l<n;l++){
				if(i & (1<<l) == 0) continue;
				if(j==l) continue;
				if(pos[j+1][l+1]) dp[i][j] |= dp[i^(1<<j)][l];
			}
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		res |= dp[(1<<n)-1][i];
	}
	return res;
}

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

	cin>>n>>m;
	int maxa=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			maxa=max(maxa,a[i][j]);
		}
	}
	int l=0,r=maxa,res;
	int m=(l+r)/2;
	while(l<r){
		if(check(m)){
			res=m;
			l=m+1;
		}
		else r=m-1;
		m=(l+r)/2;
	}
	cout<<res<<"\n";
	return 0;
}


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

#define maxn 17
#define maxm 10001
#define maxk 1000000000

int n,m;
int pos[maxn][maxn];
int dp[2<<(maxn)][maxn];
int a[maxn][maxm];
int fst[maxn][maxn];

void pre(int k){
	int flag;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			flag=1;
			for(int l=1;l<=m;l++){
				if(abs(a[i][l]-a[j][l])<k){
					flag=0;
					break;
				}
			}
			pos[i][j]=pos[j][i]=flag;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			flag=1;
			for(int l=1;l<m;l++){
				if(abs(a[j][l]-a[i][l+1])<k){
					flag=0;
					break;
				}
			}
			fst[i][j]=flag;
		}
	}
	return;
}

int check(int k){
	pre(k);
	memset(dp, 0, sizeof(dp));
	for(int i=0;i<n;i++){
		dp[1<<i][i]=(1<<i);
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i & (1<<j)) == 0) continue;
			for(int l=0;l<n;l++){
				if((i & (1<<l)) == 0) continue;
				if(j==l) continue;
				if(pos[j+1][l+1]) dp[i][j] |= dp[i^(1<<j)][l];
			}
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j) continue;
			if((dp[(1<<n)-1][i] & (1<<j)) == 0) continue;
			if(fst[i+1][j+1]) res=1;
		}
	}
	return res;
}

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

	cin>>n>>m;
	int maxa=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			maxa=max(maxa,a[i][j]);
		}
	}
	if(n==1){
		int res=maxk;
		for(int i=1;i<m;i++){
			res=min(res,abs(a[1][i]-a[1][i+1]));
		}
		cout<<res<<"\n";
		return 0;
	}
	int l=0,r=maxa,res;
	int m=(l+r)/2;
	while(l<r){
		if(check(m)){
			res=m;
			l=m+1;
		}
		else r=m-1;
		m=(l+r)/2;
	}
	if(check(m)) res=m;
	cout<<res<<"\n";
	return 0;
}


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

#define maxn 17
#define maxm 10001

int n,m;
int pos[maxn][maxn];
int dp[2<<(maxn)][maxn];
int a[maxn][maxm];
int fst[maxn][maxn];

void pre(int k){
	int flag;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			flag=1;
			for(int l=1;l<=m;l++){
				if(abs(a[i][l]-a[j][l])<k){
					flag=0;
					break;
				}
			}
			pos[i][j]=pos[j][i]=flag;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j) continue;
			flag=1;
			for(int l=1;l<m;l++){
				if(abs(a[j][l]-a[i][l+1])<k){
					flag=0;
					break;
				}
			}
			fst[i][j]=flag;
		}
	}
	return;
}

int check(int k){
	pre(k);
	memset(dp, 0, sizeof(dp));
	for(int i=0;i<n;i++){
		dp[1<<i][i]=(1<<i);
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			if((i & (1<<j)) == 0) continue;
			for(int l=0;l<n;l++){
				if((i & (1<<l)) == 0) continue;
				if(j==l) continue;
				if(pos[j+1][l+1]) dp[i][j] |= dp[i^(1<<j)][l];
			}
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i==j) continue;
			if((dp[(1<<n)-1][i] & (1<<j)) == 0) continue;
			if(fst[i+1][j+1]) res=1;
		}
	}
	return res;
}

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

	cin>>n>>m;
	int maxa=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			maxa=max(maxa,a[i][j]);
		}
	}
	int l=0,r=maxa,res;
	int m=(l+r)/2;
	while(l<r){
		if(check(m)){
			res=m;
			l=m+1;
		}
		else r=m-1;
		m=(l+r)/2;
	}
	if(check(m)) res=m;
	cout<<res<<"\n";
	return 0;
}


#include <bits/stdc++.h>

#define bit(mask, i) (mask & (1 << i))
#define remove_bit(mask, i) (mask & ~(1<<i))
using namespace std;

typedef vector<int> vi;
typedef long long int ll;

typedef vector<vi> graph;

const int N = 16, M = 1e4, oo = 1e9;

graph g(N);

int n, m;

int a[N][M];
int min_dif1[N][N];
int min_dif2[N][N];
int dp[1 << N][N];

bool is_acceptable(int k) {

    for (int l = 0; l < n; ++l) g[l].clear();

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (min_dif1[i][j] >= k) {
                g[i].push_back(j);
                g[j].push_back(i);
            }

    for (int mask = 0; mask < (1 << n); ++mask)
        for (int i = 0; i < n; ++i)
            dp[mask][i] = -1;

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

    for (int mask = 3; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) {
            if (!bit(mask, i)) continue;
            for (int v : g[i]) {
                int f = dp[remove_bit(mask, i)][v], f1 = dp[mask][i];

                if (bit(mask, v) && f != -1) {
                    if (f1 == -1) dp[mask][i] = f;
                    else {
                        dp[mask][i] = (min_dif2[f][i] > min_dif2[f1][i]) ? f : f1;
                    }
                }
            }
        }
    }

    for (int last = 0; last < n; ++last) {
        int first = dp[(1 << n) - 1][last];
        if (first != -1 && min_dif2[first][last] >= k)
            return true;

    }
    return false;
}

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

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

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) {
            int v = oo;
            for (int k = 0; k < m; ++k)
                v = min(v, abs(a[i][k] - a[j][k]));
            min_dif1[i][j] = v;
            min_dif1[j][i] = v;
        }

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) {
            int v = oo;
            for (int k = 0; k < m - 1; ++k)
                v = min(v, abs(a[j][k] - a[i][k + 1]));
            min_dif2[i][j] = v;
        }

    int l = 0, r = oo;
    while (l < r - 1) {
        int mid = (l + r) / 2;
        if (is_acceptable(mid))
            l = mid;
        else
            r = mid;
    }
    cout << l << endl;
    return 0;
}


#include <bits/stdc++.h>

#define bit(mask, i) (mask & (1 << i))
#define remove_bit(mask, i) (mask & ~(1<<i))
using namespace std;

typedef vector<int> vi;
typedef long long int ll;

typedef vector<vi> graph;

const int N = 16, M = 10000;

graph g(N);

int n, m;

int a[N][M];
int min_dif1[N][N];
int min_dif2[N][N];
int dp[1 << N][N];

bool last_edge(int i, int j, int k) {
    for (int l = 0; l < m - 1; ++l) {
        if (abs(a[j][l] - a[i][l + 1]) < k) return false;
    }
    return true;
}

bool is_acceptable(int k) {

    for (int l = 0; l < n; ++l) g[l].clear();

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (min_dif1[i][j] >= k) {
                g[i].push_back(j);
                g[j].push_back(i);
            }

    for (int mask = 0; mask < (1 << n); ++mask)
        for (int i = 0; i < n; ++i)
            dp[mask][i] = -1;

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

    for (int mask = 3; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) {
            if (!bit(mask, i)) continue;
            for (int v : g[i])
                if (bit(mask, v) && dp[remove_bit(mask, i)][v] != -1) {
                    dp[mask][i] = dp[remove_bit(mask, i)][v];
                    break;
                }
        }
    }

    for (int last = 0; last < n; ++last) {
        int first = dp[(1 << n) - 1][last];
        if (first != -1 && min_dif2[first][last] >= k)
            return true;

    }
    return false;
}

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

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

    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j) {
            int v = 1000000000;
            for (int k = 0; k < m; ++k)
                v = min(v, abs(a[i][k] - a[j][k]));
            min_dif1[i][j] = v;
            min_dif1[j][i] = v;
        }
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) {
            int v = 1000000000;
            for (int k = 0; k < m - 1; ++k)
                v = min(v, abs(a[j][k] - a[i][k + 1]));
            min_dif2[i][j] = v;
        }

    int l = 0, r = 1000000000;
    while (l < r - 1) {
        int mid = (l + r) / 2;
        if (is_acceptable(mid))
            l = mid;
        else
            r = mid;
    }
    cout << l << endl;
    return 0;
}