/*
Author: QAQAutomaton
Lang: C++
Code: E.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		memset(&inf,0x3f,sizeof(inf));
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
char str[10000005],*s[755];
int to[10000005][2],id[10000005],las[10000005],fail[10000005],t=1;
int q[10000005],*l,*r;
bitset<755> a[755];
int sx[755],sy[755];
namespace match{
	int xn;
	int beg[1505],to[1919810],lst[1919810],w[1919810],e=1;
	void add(int u,int v,int c){
		to[++e]=v;lst[e]=beg[u];beg[u]=e;w[e]=c;
		to[++e]=u;lst[e]=beg[v];beg[v]=e;w[e]=0;
	}
	int q[1505],*l,*r;
	int dis[1505],vis[1505],cur[1505];
	bool bfs(int s,int t){
		for(int i=1;i<=xn;++i){
			dis[i]=114514;
			cur[i]=beg[i];
		}
		dis[s]=0;
		*(l=r=q)=s;
		while(l<=r){
			for(int i=beg[*l];i;i=lst[i])if(w[i]){
				if(chkmin(dis[to[i]],dis[*l]+1))
					*(++r)=to[i];
			}
			++l;
		}
		return dis[t]!=114514;
	}
	int dfs(int s,int t,int flw){
		if(s==t)return flw;
		for(int &i=cur[s];i;i=lst[i])if(w[i] && dis[to[i]]==dis[s]+1){
			int mx=dfs(to[i],t,min(flw,w[i]));
			if(mx){
				w[i]-=mx;w[i^1]+=mx;
				return mx;
			}
		}
		return 0;
	}
	int dinic(int s,int t){
		int ans=0,flow;
		while(bfs(s,t)){
			while(flow=dfs(s,t,114514))ans+=flow;
		}
		return ans;
	}
	void dfs(int s){
		if(vis[s])return;
		vis[s]=1;
		for(int i=beg[s];i;i=lst[i])if(w[i]){
			dfs(to[i]);
		}
	}
	void match(int n){
		xn=n*2+2;
		for(int i=1;i<=n;++i)add(1,i+2,1);
		for(int i=1;i<=n;++i)add(i+2+n,2,1);
		for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)if(a[i][j])add(i+2,j+n+2,114514);
		write(n-dinic(1,2),'\n');
		dfs(1);
		for(int i=1;i<=n;++i)if(vis[i+2])sx[i]=1;
		for(int i=1;i<=n;++i)if(!vis[i+2+n])sy[i]=1;
	}
}
signed main(){
#ifdef QAQAutoMaton
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int n;
	read(n);
	s[1]=str;
	for(int i=1;i<=n;++i){
		read(s[i]);
		s[i+1]=s[i]+strlen(s[i]);
		for(char *j=s[i];j<s[i+1];++j)*j-='a';
	}
	for(int i=1;i<=n;++i){
		int at=1;
		for(char *j=s[i];j<s[i+1];++j){
			if(!to[at][*j])to[at][*j]=++t;
			at=to[at][*j];
		}
		id[at]=i;
	}
	fail[*(l=r=q)=1]=1;
	while(l<=r){
		las[*l]=id[fail[*l]];
		if(!id[*l])id[*l]=las[*l];
		for(int j=0;j<2;++j)if(to[*l][j]){
			*(++r)=to[*l][j];
			if(*l==1)fail[*r]=1;
			else{
				int x=fail[*l];
				while(x!=1 && !to[x][j])x=fail[x];
				if(to[x][j])fail[*r]=to[x][j];
				else fail[*r]=1;
			}
		}
		++l;
	}

	for(int i=1;i<=n;++i){
		int at=1;
		for(char *j=s[i];j<s[i+1];++j){
			at=to[at][*j];
			if(id[at]!=i)a[i][id[at]]=1;
			else a[i][las[at]]=1;
		}
	}
	for(int k=1;k<=n;++k)for(int i=1;i<=n;++i)if(a[i][k])a[i]|=a[k];
	match::match(n);
	for(int i=1;i<=n;++i)if(sx[i]&&sy[i])write(i,' ');
	putc('\n');
	return 0;
}


/*
Author: QAQAutomaton
Lang: C++
Code: E.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T>int chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>int chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		memset(&inf,0x3f,sizeof(inf));
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
char str[10000005],*s[755];
int to[10000005][2],id[10000005],las[10000005],fail[10000005],t=1;
int q[10000005],*l,*r;
bitset<755> a[755];
int sx[755],sy[755];
namespace match{
	int xn;
	int beg[1505],to[1919810],lst[1919810],w[1919810],e=1;
	void add(int u,int v,int c){
		to[++e]=v;lst[e]=beg[u];beg[u]=e;w[e]=c;
		to[++e]=u;lst[e]=beg[v];beg[v]=e;w[e]=0;
	}
	int q[1505],*l,*r;
	int dis[1505],vis[1505];
	bool bfs(int s,int t){
		for(int i=1;i<=xn;++i)dis[i]=114514;
		dis[s]=0;
		*(l=r=q)=s;
		while(l<=r){
			for(int i=beg[*l];i;i=lst[i])if(w[i]){
				if(chkmin(dis[to[i]],dis[*l]+1))
					*(++r)=to[i];
			}
			++l;
		}
		return dis[t]!=114514;
	}
	int dfs(int s,int t,int flw){
		if(s==t)return flw;
		int cnt=0;
		for(int i=beg[s];i;i=lst[i])if(w[i] && dis[to[i]]==dis[s]+1){
			int mx=dfs(to[i],t,min(flw,w[i]));
			w[i]-=mx;w[i^1]+=mx;flw-=mx;cnt+=mx;
			if(!flw)return cnt;
		}
		return cnt;
	}
	int dinic(int s,int t){
		int ans=0;
		while(bfs(s,t)){
			ans+=dfs(s,t,114514);
		}
		return ans;
	}
	void dfs(int s){
		if(vis[s])return;
		vis[s]=1;
		for(int i=beg[s];i;i=lst[i])if(w[i]){
			dfs(to[i]);
		}
	}
	void match(int n){
		xn=n*2+2;
		for(int i=1;i<=n;++i)add(1,i+2,1);
		for(int i=1;i<=n;++i)add(i+2+n,2,1);
		for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)if(a[i][j])add(i+2,j+n+2,114514);
		write(n-dinic(1,2),'\n');
		dfs(1);
		for(int i=1;i<=n;++i)if(vis[i+2])sx[i]=1;
		for(int i=1;i<=n;++i)if(!vis[i+2+n])sy[i]=1;
	}
}
signed main(){
#ifdef QAQAutoMaton
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int n;
	read(n);
	s[1]=str;
	for(int i=1;i<=n;++i){
		read(s[i]);
		s[i+1]=s[i]+strlen(s[i]);
		for(char *j=s[i];j<s[i+1];++j)*j-='a';
	}
	for(int i=1;i<=n;++i){
		int at=1;
		for(char *j=s[i];j<s[i+1];++j){
			if(!to[at][*j])to[at][*j]=++t;
			at=to[at][*j];
		}
		id[at]=i;
	}
	fail[*(l=r=q)=1]=1;
	while(l<=r){
		las[*l]=id[fail[*l]];
		if(!id[*l])id[*l]=las[*l];
		for(int j=0;j<2;++j)if(to[*l][j]){
			*(++r)=to[*l][j];
			if(*l==1)fail[*r]=1;
			else{
				int x=fail[*l];
				while(x!=1 && !to[x][j])x=fail[x];
				if(to[x][j])fail[*r]=to[x][j];
				else fail[*r]=1;
			}
		}
		++l;
	}

	for(int i=1;i<=n;++i){
		int at=1;
		for(char *j=s[i];j<s[i+1];++j){
			at=to[at][*j];
			if(id[at]!=i)a[i][id[at]]=1;
			else a[i][las[at]]=1;
		}
	}
	for(int k=1;k<=n;++k)for(int i=1;i<=n;++i)if(a[i][k])a[i]|=a[k];
	match::match(n);
	for(int i=1;i<=n;++i)if(sx[i]&&sy[i])write(i,' ');
	putc('\n');
	return 0;
}


#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;

const int N=750, L=1e7+N, V=N*2+2, E=N*(N+3);
int n, tot, tr[L][2], fail[L], id[L], queue[L], e, head[V], to[E], next[E], cap[E], dis[V], cur[V], sid[N], tid[N], eid[N][N], match[N];
bool lvis[N], rvis[N];
char pool[L], *s[N];
std::bitset<N> edge[N];
int init() {
	tr[tot][0]=tr[tot][1]=id[tot]=-1;
	return tot++;
}
void add(int u, int v, int w) {
	to[e]=v, cap[e]=w, next[e]=head[u], head[u]=e++;
	to[e]=u, cap[e]=0, next[e]=head[v], head[v]=e++;
}
bool bfs() {
	int *qhead=queue, *qtail=queue;
	memset(dis, -1, (2*n+2)*sizeof(int));
	dis[*qtail++=2*n+1]=0;
	while(qhead!=qtail) {
		int u=*qhead++;
		if(u==2*n) return true;
		for(int i=head[u]; ~i; i=next[i])
			if(cap[i^1]&&dis[to[i]]==-1)
				dis[*qtail++=to[i]]=dis[u]+1;
	}
	return false;
}
int dfs(int x, int lim) {
	int save=lim;
	if(x==2*n+1) return lim;
	for(int &i=cur[x]; ~i; i=next[i])
		if(cap[i]&&dis[x]==dis[to[i]]+1) {
			int flow=dfs(to[i], std::min(lim, cap[i]));
			cap[i]-=flow, cap[i^1]+=flow;
			lim-=flow;
			if(lim==0) break;
		}
	return save-lim;
}
void construct(int r) {
	rvis[r]=true;
	for(int &i=head[n+r]; ~i; )
		if(cap[i^1]) {
			int u=to[i];
			i=next[i];
			lvis[u]=true;
			construct(match[u]);
		} else i=next[i];
}
int main() {
	char *mem=pool;
	int ans, *qhead=queue, *qtail=queue;
	assert(scanf("%d", &n)==1);
	init();
	for(int i=0; i<n; ++i) {
		int at=0;
		assert(scanf("%s", s[i]=mem)==1);
		for(; *mem; ++mem) {
			int &to=tr[at][*mem-'a'];
			if(to==-1) to=init();
			at=to;
		}
		id[at]=i;
		++mem;
	}
	for(int i=0; i<2; ++i) {
		int &v=tr[0][i];
		if(~v) *qtail++=v; else v=0;
	}
	while(qhead!=qtail) {
		int u=*qhead++;
		for(int i=0; i<2; ++i) {
			int &v=tr[u][i], w=tr[fail[u]][i];
			if(~v) {
				*qtail++=v;
				fail[v]=w;
				if(id[v]==-1) id[v]=id[w]; else if(id[w]!=-1) edge[id[w]].set(id[v]);
			} else v=w;
		}
	}
	for(int i=0; i<n; ++i) {
		int at=0;
		for(auto j=s[i]; *j; ++j) {
			at=tr[at][*j-'a'];
			if(id[at]!=-1&&id[at]!=i) edge[id[at]].set(i);
		}
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[j].test(i)) edge[j]|=edge[i];
	memset(head, -1, (2*n+2)*sizeof(int));
	for(int i=0; i<n; ++i) sid[i]=e, add(2*n, i, 1), tid[i]=e, add(i+n, 2*n+1, 1);
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)) eid[i][j]=e, add(i, j+n, 1);
	ans=n;
	while(bfs()) {
		memcpy(cur, head, (2*n+2)*sizeof(int));
		ans-=dfs(2*n, 1<<30);
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)&&cap[eid[i][j]]==0) match[i]=j;
	for(int i=0; i<n; ++i) if(cap[tid[i]]) construct(i);
	printf("%d\n", ans);
	for(int i=0; i<n; ++i) if(!lvis[i]&&rvis[i]) printf("%d ", i+1);
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;

const int N=750, L=1e7+N, V=750*2+2, E=N*N+3*N;
int n, tot, tr[L][2], fail[L], id[L], queue[L], e, head[V], to[E], next[E], cap[E], dis[V], cur[V], sid[N], tid[N], eid[N][N], match[N];
bool lvis[N], rvis[N];
char pool[L], *s[N];
std::bitset<N> edge[N];
int init() {
	tr[tot][0]=tr[tot][1]=id[tot]=-1;
	return tot++;
}
void add(int u, int v, int w) {
	to[e]=v, cap[e]=w, next[e]=head[u], head[u]=e++;
	to[e]=u, cap[e]=0, next[e]=head[v], head[v]=e++;
}
bool bfs() {
	int *qhead=queue, *qtail=queue;
	memset(dis, -1, (2*n+2)*sizeof(int));
	dis[*qtail++=2*n+1]=0;
	while(qhead!=qtail) {
		int u=*qhead++;
		if(u==2*n) return true;
		for(int i=head[u]; ~i; i=next[i])
			if(cap[i^1]&&dis[to[i]]==-1)
				dis[*qtail++=to[i]]=dis[u]+1;
	}
	return false;
}
int dfs(int x, int lim) {
	int save=lim;
	if(x==2*n+1) return lim;
	for(int &i=cur[x]; ~i; i=next[i])
		if(cap[i]&&dis[x]==dis[to[i]]+1) {
			int flow=dfs(to[i], std::min(lim, cap[i]));
			cap[i]-=flow, cap[i^1]+=flow;
			lim-=flow;
			if(lim==0) break;
		}
	return save-lim;
}
void construct(int r) {
	rvis[r]=true;
	for(int &i=head[n+r]; ~i; i=next[i])
		if(cap[i^1]) {
			lvis[to[i]]=true;
			construct(match[to[i]]);
		}
}
int main() {
	char *mem=pool;
	int ans, *qhead=queue, *qtail=queue;
	assert(scanf("%d", &n)==1);
	init();
	for(int i=0; i<n; ++i) {
		int at=0;
		assert(scanf("%s", s[i]=mem)==1);
		for(; *mem; ++mem) {
			int &to=tr[at][*mem-'a'];
			if(to==-1) to=init();
			at=to;
		}
		id[at]=i;
		++mem;
	}
	for(int i=0; i<2; ++i) {
		int &v=tr[0][i];
		if(~v) *qtail++=v; else v=0;
	}
	while(qhead!=qtail) {
		int u=*qhead++;
		for(int i=0; i<2; ++i) {
			int &v=tr[u][i], w=tr[fail[u]][i];
			if(~v) {
				*qtail++=v;
				fail[v]=w;
				if(id[v]==-1) id[v]=id[w]; else if(id[w]!=-1) edge[id[w]].set(id[v]);
			} else v=w;
		}
	}
	for(int i=0; i<n; ++i) {
		int at=0;
		for(auto j=s[i]; *j; ++j) {
			at=tr[at][*j-'a'];
			if(id[at]!=-1&&id[at]!=i) edge[id[at]].set(i);
		}
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[j].test(i)) edge[j]|=edge[i];
	memset(head, -1, (2*n+2)*sizeof(int));
	for(int i=0; i<n; ++i) sid[i]=e, add(2*n, i, 1), tid[i]=e, add(i+n, 2*n+1, 1);
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)) eid[i][j]=e, add(i, j+n, 1);
	ans=n;
	while(bfs()) {
		memcpy(cur, head, (2*n+2)*sizeof(int));
		ans-=dfs(2*n, 1<<30);
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)&&cap[eid[i][j]]==0) match[i]=j;
	for(int i=0; i<n; ++i) if(cap[tid[i]]) construct(i);
	printf("%d\n", ans);
	for(int i=0; i<n; ++i) if(!lvis[i]&&rvis[i]) printf("%d ", i+1);
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;

const int N=750, L=1e7+N, V=N*2+2, E=N*(N+3);
int n, tot, tr[L][2], fail[L], id[L], queue[L], e, head[V], to[E], next[E], cap[E], dis[V], cur[V], sid[N], tid[N], eid[N][N], match[N];
bool lvis[N], rvis[N];
char pool[L], *s[N];
std::bitset<N> edge[N];
int init() {
	tr[tot][0]=tr[tot][1]=id[tot]=-1;
	return tot++;
}
void add(int u, int v, int w) {
	to[e]=v, cap[e]=w, next[e]=head[u], head[u]=e++;
	to[e]=u, cap[e]=0, next[e]=head[v], head[v]=e++;
}
bool bfs() {
	int *qhead=queue, *qtail=queue;
	memset(dis, -1, (2*n+2)*sizeof(int));
	dis[*qtail++=2*n+1]=0;
	while(qhead!=qtail) {
		int u=*qhead++;
		if(u==2*n) return true;
		for(int i=head[u]; ~i; i=next[i])
			if(cap[i^1]&&dis[to[i]]==-1)
				dis[*qtail++=to[i]]=dis[u]+1;
	}
	return false;
}
int dfs(int x, int lim) {
	int save=lim;
	if(x==2*n+1) return lim;
	for(int &i=cur[x]; ~i; i=next[i])
		if(cap[i]&&dis[x]==dis[to[i]]+1) {
			int flow=dfs(to[i], std::min(lim, cap[i]));
			cap[i]-=flow, cap[i^1]+=flow;
			lim-=flow;
			if(lim==0) break;
		}
	return save-lim;
}
void construct(int r) {
	rvis[r]=true;
	for(int l=0; l<n; ++l)
		if(!lvis[l]&&edge[l].test(r)&&cap[eid[l][r]]) {
			lvis[l]=true;
			construct(match[l]);
		}
}
int main() {
	char *mem=pool;
	int ans, *qhead=queue, *qtail=queue;
	assert(scanf("%d", &n)==1);
	init();
	for(int i=0; i<n; ++i) {
		int at=0;
		assert(scanf("%s", s[i]=mem)==1);
		for(; *mem; ++mem) {
			int &to=tr[at][*mem-'a'];
			if(to==-1) to=init();
			at=to;
		}
		id[at]=i;
		++mem;
	}
	for(int i=0; i<2; ++i) {
		int &v=tr[0][i];
		if(~v) *qtail++=v; else v=0;
	}
	while(qhead!=qtail) {
		int u=*qhead++;
		for(int i=0; i<2; ++i) {
			int &v=tr[u][i], w=tr[fail[u]][i];
			if(~v) {
				*qtail++=v;
				fail[v]=w;
				if(id[v]==-1) id[v]=id[w]; else if(id[w]!=-1) edge[id[w]].set(id[v]);
			} else v=w;
		}
	}
	for(int i=0; i<n; ++i) {
		int at=0;
		for(auto j=s[i]; *j; ++j) {
			at=tr[at][*j-'a'];
			if(id[at]!=-1&&id[at]!=i) edge[id[at]].set(i);
		}
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[j].test(i)) edge[j]|=edge[i];
	memset(head, -1, (2*n+2)*sizeof(int));
	for(int i=0; i<n; ++i) sid[i]=e, add(2*n, i, 1), tid[i]=e, add(i+n, 2*n+1, 1);
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)) eid[i][j]=e, add(i, j+n, 1);
	ans=n;
	while(bfs()) {
		memcpy(cur, head, (2*n+2)*sizeof(int));
		ans-=dfs(2*n, 1<<30);
	}
	for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if(edge[i].test(j)&&cap[eid[i][j]]==0) match[i]=j;
	for(int i=0; i<n; ++i) if(cap[tid[i]]) construct(i);
	printf("%d\n", ans);
	for(int i=0; i<n; ++i) if(!lvis[i]&&rvis[i]) printf("%d ", i+1);
	puts("");
	return 0;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

struct Edge {
  int t,f,next;
  Edge() {}
  Edge(int a,int b,int c):t(a),f(b),next(c) {}
};

Edge e[1000000];
int head[1505],vs,vt,tot=-1;

inline void addEdge(int x,int y,int z) {
  e[++tot]=Edge(y,z,head[x]);
  head[x]=tot;
  e[++tot]=Edge(x,0,head[y]);
  head[y]=tot;
}

namespace Flow {

int d[1505],cur[1505];
queue <int> q;

bool bfs() {
  while (!q.empty()) q.pop();
  memset(d,255,sizeof(d));
  d[vs]=0;cur[vs]=head[vs];
  q.push(vs);
  while (!q.empty()) {
  	int x=q.front();q.pop();
  	for(int i=head[x];i!=-1;i=e[i].next)
  	  if (e[i].f&&d[e[i].t]==-1) {
  	  	  int u=e[i].t;
  	  	  d[u]=d[x]+1;
  	  	  cur[u]=head[u];
  	  	  if (u==vt) return 1;
  	  	  q.push(u);
		}
  }
  return 0;
}

int dfs(int x,int a) {
  if (x==vt||!a) return a;
  int ans=0;
  for(int &i=cur[x];i!=-1;i=e[i].next)
    if (e[i].f&&d[e[i].t]==d[x]+1) {
    	int u=e[i].t;
    	int f=dfs(u,min(a,e[i].f));
    	if (f) {
    		e[i].f-=f;
    		e[i^1].f+=f;
    		ans+=f;
    		a-=f;
    		if (!a) break;
		}
	}
  return ans;
}

int maxflow() {
  int ans=0;
  while (bfs())
    ans+=dfs(vs,inf);
  return ans;
}

}

bool ee[755][755];

void floyd(int n) {
  for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++) ee[i][j]|=(ee[i][k]&ee[k][j]);
}

namespace AC {

int ch[10000005][2],tot=1;
int ed[10000005],p[10000005];

int insert(char *s,int n,int id) {
  int x=1;
  for(int i=0;i<n;i++) {
  	int v=s[i]-'a';
  	if (!ch[x][v]) {
	  ch[x][v]=++tot;
	  p[tot]=x;
    }
  	x=ch[x][v];
  }
  ed[x]=id;
  return x;
}

int fail[10000005],q[10000005];

void bfs() {
  int l=1,r=0;
  for(int i=0;i<2;i++)
    if (ch[1][i]) {
    	fail[ch[1][i]]=1;
    	q[++r]=ch[1][i];
	}
	else ch[1][i]=1;
  while (l<=r) {
  	int x=q[l++];
  	for(int i=0;i<2;i++)
  	  if (ch[x][i]) {
  	  	  fail[ch[x][i]]=ch[fail[x]][i];
  	  	  if (!ed[ch[x][i]]) ed[ch[x][i]]=ed[x];
  	  	  q[++r]=ch[x][i];
		}
	  else ch[x][i]=ch[fail[x]][i];
  }
}

void match(int x,int id) {
  if (ed[fail[x]]) ee[id][ed[fail[x]]]=1;
  x=p[x];
  while (x>1) {
  	if (ed[x]) ee[id][ed[x]]=1;
  	x=p[x];
  }
}

}

int pos[755];
char str[10000005];

int main() {
  memset(head,255,sizeof(head));
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	scanf("%s",str);
  	int len=strlen(str);
  	pos[i]=AC::insert(str,len,i);
  }
  AC::bfs();
  for(int i=1;i<=n;i++) AC::match(pos[i],i);
  floyd(n);
  vs=0;vt=2*n+1;
  for(int i=1;i<=n;i++) {
  	addEdge(vs,i,1);
  	addEdge(n+i,vt,1);
  	for(int j=1;j<=n;j++)
  	  if (ee[i][j]) addEdge(i,n+j,1);
  }
  printf("%d\n",n-Flow::maxflow());
  Flow::bfs();
  for(int i=1;i<=n;i++)
    if (Flow::d[i]!=-1&&Flow::d[n+i]==-1) printf("%d ",i);
  printf("\n");
  return 0;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f

using namespace std;

struct Edge {
  int t,f,next;
  Edge() {}
  Edge(int a,int b,int c):t(a),f(b),next(c) {}
};

Edge e[1000000];
int head[1505],vs,vt,tot=-1;

inline void addEdge(int x,int y,int z) {
  e[++tot]=Edge(y,z,head[x]);
  head[x]=tot;
  e[++tot]=Edge(x,0,head[y]);
  head[y]=tot;
}

namespace Flow {

int d[1505],cur[1505];
queue <int> q;

bool bfs() {
  while (!q.empty()) q.pop();
  memset(d,255,sizeof(d));
  d[vs]=0;cur[vs]=head[vs];
  q.push(vs);
  while (!q.empty()) {
  	int x=q.front();q.pop();
  	for(int i=head[x];i!=-1;i=e[i].next)
  	  if (e[i].f&&d[e[i].t]==-1) {
  	  	  int u=e[i].t;
  	  	  d[u]=d[x]+1;
  	  	  cur[u]=head[u];
  	  	  if (u==vt) return 1;
  	  	  q.push(u);
		}
  }
  return 0;
}

int dfs(int x,int a) {
  if (x==vt||!a) return a;
  int ans=0;
  for(int &i=cur[x];i!=-1;i=e[i].next)
    if (e[i].f&&d[e[i].t]==d[x]+1) {
    	int u=e[i].t;
    	int f=dfs(u,min(a,e[i].f));
    	if (f) {
    		e[i].f-=f;
    		e[i^1].f+=f;
    		ans+=f;
    		a-=f;
    		if (!a) break;
		}
	}
  return ans;
}

int maxflow() {
  int ans=0;
  while (bfs())
    ans+=dfs(vs,inf);
  return ans;
}

}

bool ee[755][755];

void floyd(int n) {
  for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++) ee[i][j]|=(ee[i][k]&ee[k][j]);
}

namespace AC {

int ch[10000005][2],tot=1;
int ed[10000005],p[10000005];

int insert(char *s,int n,int id) {
  int x=1;
  for(int i=0;i<n;i++) {
  	int v=s[i]-'a';
  	if (!ch[x][v]) {
	  ch[x][v]=++tot;
	  p[tot]=x;
    }
  	x=ch[x][v];
  }
  ed[x]=id;
  return x;
}

int fail[10000005],q[10000005];

void bfs() {
  int l=1,r=0;
  for(int i=0;i<2;i++)
    if (ch[1][i]) {
    	fail[ch[1][i]]=1;
    	q[++r]=ch[1][i];
	}
	else ch[1][i]=1;
  while (l<=r) {
  	int x=q[l++];
  	for(int i=0;i<2;i++)
  	  if (ch[x][i]) {
  	  	  fail[ch[x][i]]=ch[fail[x]][i];
  	  	  if (!ed[ch[x][i]]) ed[ch[x][i]]=ed[fail[ch[x][i]]];
  	  	  q[++r]=ch[x][i];
		}
	  else ch[x][i]=ch[fail[x]][i];
  }
}

void match(int x,int id) {
  if (ed[fail[x]]) ee[id][ed[fail[x]]]=1;
  x=p[x];
  while (x>1) {
  	if (ed[x]) ee[id][ed[x]]=1;
  	x=p[x];
  }
}

}

int pos[755];
char str[10000005];

int main() {
  memset(head,255,sizeof(head));
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	scanf("%s",str);
  	int len=strlen(str);
  	pos[i]=AC::insert(str,len,i);
  }
  AC::bfs();
  for(int i=1;i<=n;i++)
    AC::match(pos[i],i);
  floyd(n);
  vs=0;vt=2*n+1;
  for(int i=1;i<=n;i++) {
  	addEdge(vs,i,1);
  	addEdge(n+i,vt,1);
  	for(int j=1;j<=n;j++)
  	  if (ee[i][j]) addEdge(i,n+j,1);
  }
  printf("%d\n",n-Flow::maxflow());
  Flow::bfs();
  for(int i=1;i<=n;i++)
    if (Flow::d[i]!=-1&&Flow::d[n+i]==-1) printf("%d ",i);
  printf("\n");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
const int M = 1e7 + 5;
int n, tot;
char st[M]; int hd[N], len;
int nxt[M][2], fail[M];
int ter[M], del[N];
int pre[N][N];
int que[M], front, tail;
int vis[N], par[N], ans;
queue <int> Q;
int dwn[N], era[N];
int dfs(int t)
{
    for (int i = 1; i <= n; ++ i) if (pre[t][i] && !vis[i])
    {
        vis[i] = 1;
        if (!par[i] || dfs(par[i]))
        {
            par[i] = t;
            return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d", &n); tot = 1;
    for (int i = 1; i <= n; ++ i)
    {
        scanf("%s", st + hd[i]);
        hd[i + 1] = strlen(st + hd[i]) + hd[i];
        int p = 1;
        for (int j = hd[i]; j < hd[i + 1]; ++ j)
        {
            if (!nxt[p][st[j] - 'a']) nxt[p][st[j] - 'a'] = ++ tot;
            p = nxt[p][st[j] - 'a'];
        }
        if (ter[p]) del[i] = 1;
        else ter[p] = i;
    }
    front = 1; tail = 0;
    for (int p = 0; p < 2; ++ p) if (nxt[1][p]) que[++ tail] = nxt[1][p], fail[nxt[1][p]] = 1;
    while (front <= tail)
    {
        int t = que[front ++];
        for (int p = 0; p < 2; ++ p)
            if (nxt[t][p])
            {
                que[++ tail] = nxt[t][p];
                fail[nxt[t][p]] = nxt[fail[t]][p];
            }
            else nxt[t][p] = nxt[fail[t]][p];
    }
    for (int i = 1; i <= n; ++ i)
    {
        int p = 1;
        for (int j = hd[i]; j < hd[i + 1]; ++ j)
        {
            p = nxt[p][st[j] - 'a'];
            if (ter[p] && j != hd[i + 1] - 1) pre[i][ter[p]] = 1;
            if (ter[fail[p]]) pre[i][ter[fail[p]]] = 1;
        }
    }
    for (int i = 1; i <= n; ++ i)
        if (del[i])
            for (int j = 1; j <= n; ++ j) if (i != j)
                pre[j][i] = 1;
    for (int k = 1; k <= n; ++ k)
        for (int i = 1; i <= n; ++ i)
            for (int j = 1; j <= n; ++ j)
                pre[i][j] |= pre[i][k] && pre[k][j];
    // for (int i = 1; i <= n; ++ i)
    // {
    //     for (int j = 1; j <= n; ++ j)
    //         printf("%d ", pre[i][j]);
    //     puts("");
    // }
    ans = n;
    for (int i = 1; i <= n; ++ i)
    {
        for (int j = 1; j <= n; ++ j) vis[j] = 0;
        if (dfs(i)) ans --;
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; ++ i)
        if (par[i]) dwn[par[i]] = i;
        else Q.push(i);
    while (!Q.empty())
    {
        int t = Q.front(); Q.pop();
        for (int i = 1; i <= n; ++ i)
            if (pre[i][t] && !era[i])
                era[i] = 1, Q.push(i);
    }
    for (int i = 1; i <= n; ++ i)
        if (!par[i])
        {
            int j = i;
            while (era[j]) j = dwn[j];
            printf("%d ", j);
        }
    puts("");
}


#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
using namespace std;
const int N = 2e5 + 10;
int n, T;
struct node{
    int id,a,t;
    bool operator<(const node&rhs)const{
        return t < rhs.t;
    }
}b[N];
vector<int> ans, tmp;
bool check(int cnt){
    int ccount = 0,cost = 0;
    tmp.clear();
    for(int i = 0;i < n;i++){
        if(b[i].a >= cnt){
            if(b[i].t + cost > T) break;
            cost += b[i].t;
            tmp.push_back(b[i].id);
            if(++ccount == cnt) {
                if(tmp.size() > ans.size()) ans = tmp;
                return true;
            }
        }
    }
    return false;
}
int main()
{
   cin>>n>>T;
   for(int i = 0;i < n;i++){
        scanf("%d%d",&b[i].a, &b[i].t);
        b[i].id = i;
   }
   sort(b, b + n);
   int l = 0,r = n;
   while(l <= r){
    int mid = l + r >> 1;
    if(check(mid)) l = mid + 1;
    else r = mid - 1;
   }
   cout<<ans.size()<<endl;
   cout<<ans.size()<<endl;
   for(auto v:ans) cout<<v + 1<<" ";
   cout<<endl;
   return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
using namespace std;
const int N = 2e5 + 10;
int n, T;
struct node{
    int id,a,t;
    bool operator<(const node&rhs)const{
        return a > rhs.a;
    }
}b[N];
int main()
{
   cin>>n>>T;
   for(int i = 0;i < n;i++){
        scanf("%d%d",&b[i].a, &b[i].t);
        b[i].id = i;
   }
   sort(b, b + n);
   int siz = 0;
   set<pair<int,int> > se;
   for(int i = 0;i < n;i++) se.insert(P(b[i].t,b[i].id));
   set<P> ans;
   set<P> re;
   for(int i = n - 1;i >= 0;i--){
        if(i == n - 1|| b[i].a != b[i+1].a){
            for(auto v:re) se.erase(v);
            re.clear();
                if(se.size() > ans.size()){
                set<pair<int,int> >tmp;
                int cnt = b[i].a,tt = 0;
                for(auto v:se){
                    if(v.first + tt > T) break;
                    tt += v.first;
                    tmp.insert(v);
                    if(--cnt == 0) break;
                }
                if(tmp.size() > ans.size()) ans = tmp;
                if(cnt > 0) break;
            }
        }
        re.insert(P(b[i].t,b[i].id));
   }
   cout<<ans.size()<<endl;
   cout<<ans.size()<<endl;
   for(auto v:ans) cout<<v.second + 1<<" ";
   cout<<endl;
   return 0;
}


#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
using namespace std;
const int N = 2e5 + 10;
int n, T;
struct node{
    int id,a,t;
    bool operator<(const node&rhs)const{
        return a > rhs.a;
    }
}b[N];
int main()
{
   cin>>n>>T;
   for(int i = 0;i < n;i++){
        scanf("%d%d",&b[i].a, &b[i].t);
        b[i].id = i;
   }
   sort(b, b + n);
   int siz = 0;
   set<pair<int,int> > se;
   for(int i = 0;i < n;i++) se.insert(P(b[i].t,b[i].id));
   set<P> ans;
   set<P> re;
   for(int i = n - 1;i >= 0;i--){
        if(i == n - 1|| b[i].a != b[i+1].a){
            for(auto v:re) se.erase(v);
                if(se.size() > ans.size()){
                set<pair<int,int> >tmp;
                int cnt = b[i].a,tt = 0;
                for(auto v:se){
                    if(v.first + tt > T) break;
                    tt += v.first;
                    tmp.insert(v);
                    if(--cnt == 0) break;
                }
                if(tmp.size() > ans.size()) ans = tmp;
                if(cnt > 0) break;
            }
        }
        re.insert(P(b[i].t,b[i].id));
   }
   cout<<ans.size()<<endl;
   cout<<ans.size()<<endl;
   for(auto v:ans) cout<<v.second + 1<<" ";
   cout<<endl;
   return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)break ;
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	aa=1;
	return true ;
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=1,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(f(mid))
		{
			cnt=sum;
			for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	int u=0;
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)
		{
			u=1;
			break ;
		}
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	aa=1;
	return true ;
	/*if(!u)
	{

	}
	else return true ;*/
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=1,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		//cout<<mid<<endl;
		if(f(mid))
		{
			if(sum>cnt)
			{
				cnt=sum;
				for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			}
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	int u=0;
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)
		{
			u=1;
			break ;
		}
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	aa=1;
	return true ;
	/*if(!u)
	{

	}
	else return true ;*/
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=1,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		cout<<mid<<endl;
		if(f(mid))
		{
			if(sum>cnt)
			{
				cnt=sum;
				for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			}
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)break ;
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	aa=1;
	return true ;
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=0,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(f(mid))
		{
			cnt=sum;
			for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	int u=0;
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)
		{
			u=1;
			break ;
		}
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	if(!u)
	{
		aa=1;
		return true ;
	}
	else return true ;
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=0,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(f(mid))
		{
			cnt=sum;
			for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define ll long long
using namespace std;
const int maxx=600010;
ll t,n,m,k;
ll a[maxx],b[maxx],bj[maxx];
ll ans=0,total=0,sum=0,cnt=0,res=0,aa=0;
struct node
{
	ll num;
	ll a;
	ll t;
}s[maxx];
bool cmp(node a,node b)
{
	if(a.t==b.t)return a.a>b.a;
	return a.t<b.t;
}
bool f(ll x)
{
	int u=0;
	total=sum=res=aa=0;
	for(register int i=1;i<=n;i++)
	{
		if(s[i].a<x)continue ;
		if(total+s[i].t>t)
		{
			u=1;
			break ;
		}
		b[++sum]=s[i].num;
		total+=s[i].t;
		if(sum==x)return true ;
	}
	aa=1;
	return true ;
	/*if(!u)
	{

	}
	else return true ;*/
}
int main()
{
	scanf("%lld%lld",&n,&t);
	for(register int i=1;i<=n;i++)scanf("%lld%lld",&s[i].a,&s[i].t),s[i].num=i;
	sort(s+1,s+n+1,cmp);
	ll l=0,r=n;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(f(mid))
		{
			if(sum>cnt)
			{
				cnt=sum;
				for(register int i=1;i<=cnt;i++)bj[i]=b[i];
			}
			if(!aa)l=mid+1;
			else r=mid-1;
		}
		else r=mid-1;
	}
	printf("%lld\n%lld\n",cnt,cnt);
	for(register int i=1;i<=cnt;i++)printf("%lld ",bj[i]);
	return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(ti - t >= 0){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);
                  }
             }
      }
      return ans >= mid;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);

    int n , T ;
    cin >> n >> T ;

    vector <  pair < pair < int , int > , int > > ve ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    vector < pair < int , int > > res ;
    int ans = 0 ;

    for(auto x : ve){

        int t = x.first.first ;
        int p = x.first.second;
        int i = x.second ;

        if(res.size() <= p && t <= T){
            T -= t ;
            res.push_back({i , p});
            ans++ ;
        }
    }
    int ans1 = 0 ;
    for(auto x : res) if(x.second <= ans) ans1 ++ ;

      ans = ans1 ;
    cout << ans << endl ;
    cout << res.size() << endl ;
    for(auto x : res) cout << x.first << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      if(mid == 0) return true ;

      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(ti - t >= 0){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);

                       if(ans == mid) return true ;
                  }
             }
      }
      return false;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      if(mid == 0) return true ;

      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(t <= ti){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);

                       if(ans == mid) return true ;
                  }
             }
      }
      return false;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      if(mid == 0) return true ;

      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(ti - t >= 0){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);
                  }
             }
      }
      return ans >= mid;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      if(mid == 0) return true ;

      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(ti - t >= 0){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);

                       if(ans == mid) return true ;
                  }
             }
      }
      return false;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;
      vector < int > temp ;
bool check(int mid)
{
       temp.clear() ;
      vector < pair < pair < int , int > , int > > res ;

      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                 res.push_back(ve[i]);
             }
      }
      int ans = 0 ;
      int tt = T ;

      for(auto x : res){
           int t = x.first.first ;
           int p = x.first.second ;
           int i = x.second;

           if(t <= tt){
                 tt -= t ;
                 ans++ ;
                 temp.push_back(i);
           }
      }
      return ans >= mid;

}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid))
               ans = mid , low = mid + 1  , ret = temp;
           else
               high = mid - 1;
    }

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


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

int n , T ;
vector <  pair < pair < int , int > , int > > ve ;
vector < int > ret ;

bool check(int mid , bool b)
{
      if(mid == 0) return true ;

      int ti = T , ans = 0 ;
      for(int i = 0 ; i < ve.size() ; i++){
             if(ve[i].first.second >= mid){
                  int t = ve[i].first.first ;
                  int p = ve[i].first.second ;
                  int j = ve[i].second ;
                  if(ti - t >= 0){
                       ti -= t ;
                       ans++ ;
                       if(b) ret.push_back(j);
                  }
             }
      }
      return ans == mid;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n >> T ;

    for(int i = 0 ; i < n ; i++){
           int p , tt ;
           cin >> p >> tt ;
           ve.push_back({{tt , p} , i + 1});
    }
    sort(ve.begin() , ve.end());

    int low = 0 , high = n + 1 , ans = 0 ;

    while(low <= high){
           int mid = (low + high)/2 ;

           if(check(mid , 0))
               ans = mid , low = mid + 1 ;
           else
               high = mid - 1;
    }
    check(ans , 1);

    cout << ans << endl ;
    cout << ret.size() << endl ;
    for(auto x : ret) cout << x << " " ;

    return 0;
}


#pragma GCC optimize(2)
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 200005
#define DB double
#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define Int register int
#define Lson Son[x][0]
#define Rson Son[x][1]
using namespace std;
inline void read(LL &x)
{
	x = 0;
	LL f = 1;
	char s = getchar();
	while (s < '0' ||s > '9')
	{
		if (s == '-')
			f = -1;
		s = getchar();
	}
	while (s >= '0' && s <= '9')
	{
		x = (x << 3) + (x << 1) + (s ^ 48);
		s = getchar();
	}
	x *= f;
}
inline LL Max(LL x,LL y)
{
	return x > y ? x : y;
}
inline LL Min(LL x,LL y)
{
	return x < y ? x : y;
}
LL Gcd(LL a,LL b)
{
	if (! b)
		return a;
	return Gcd(b, a % b);
}
inline LL Abs(LL x)
{
	if (x < 0)
		return -x;
	return x;
}
inline DB Fabs(DB x)
{
	if (x > 0)
		return x;
	return -x;
}
struct node
{
	LL a, t;
	node(){}
	node(LL A,LL T)
	{
		a = A;
		t = T;
	}
	friend bool operator <(node x,node y)
	{
		if (x.a < y.a)
			return 1;
		if (x.a == y.a && x.t < y.t)
			return 1;
		return 0;
	}
}W[MAXN];
vector<node> G[MAXN];
priority_queue<node> Q;
int main()
{
	LL n, T;
	read( n ); read( T );
	for (Int i = 1; i <= n; ++ i)
	{
		read( W[i].a );
		read( W[i].t );
		G[W[i].a].push_back(node(W[i].t, i));
	}
	LL Sum = 0;
	for (Int i = n; i >= 0; -- i)
	{
		int l = G[i].size();
		for (Int j = 0; j < l; ++ j)
		{
			Q.push( G[i][j] );
			Sum += G[i][j].a;
		}
		while (Q.size() > i)
		{
			Sum -= Q.top().a;
			Q.pop();
		}
		if (Q.size() == i && Sum <= T)
		{
			printf("%lld\n%lld\n", i, i);
			while (! Q.empty())
			{
				printf("%lld ", Q.top().t);
				Q.pop();
			}
			return 0;
		}
	}
	return 0;
}
/*
a * b = x ^ 2
b * c = y ^ 2
if a * c = z ^ 2
那么 sqrt(ac) * b == sqrt(ab) * sqrt(bc)
即 sqrt(abbc) = sqrt(abbc)
*/


#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = a; i < n; ++i)
#define mst(a, b) memset(a, b, sizeof a)
typedef long long ll;
inline int read() {
    int c = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        c = c * 10 + ch - '0';
        ch = getchar();
    }
    return c * f;
}

const int N = 2e5 + 10;
struct Node {
    int a, t, id;
    bool operator<(const Node &b) const {
        return t < b.t;
    }
} x[N];
int n, cnt;
bool judge(int k, int T) {
    cnt = 0;
    REP(i, 0, n) {
        if (x[i].t > T) break;
        if (x[i].a < k) continue;
        T -= x[i].t;
        cnt++;
    }
    // cout << k << ' ' << cnt << ' ' << T << endl;
    return cnt >= k;
}
int main() {
    n = read();
    int T = read();
    REP(i, 0, n) x[i].a = read(), x[i].t = read(), x[i].id = i + 1;
    sort(x, x + n);
    int l = 1, r = n + 1;
    while (l < r) {
        // cout << l << ' ' << r << endl;
        int m = l + r >> 1;
        if (judge(m, T))
            l = m + 1;
        else
            r = m;
    }
    printf("%d\n%d\n", l - 1, cnt);
    REP(i, 0, n) {
        if (x[i].t > T) break;
        if (x[i].a < l - 1) continue;
        T -= x[i].t;
        printf("%d ", x[i].id);
    }
    puts("");
}


#include<bits/stdc++.h>
#define MAXN 200005
using namespace std;
int n,T,l=0,r,ans[MAXN];
struct quiz{
		int h,t,u;
}a[MAXN],b[MAXN];
bool cmp1(const quiz &a,const quiz &b){
		return a.h<b.h;
}
bool cmp2(const quiz &a,const quiz &b){
		return a.t>b.t;
}
bool chk(int p){
		int j=n,s=0,f=T;
		while(j>0&&a[j].h>=p){
				b[j].h=a[j].h;
				b[j].t=a[j].t;
				b[j].u=a[j].u;
				j--;
		}
		sort(b+j+1,b+n+1,cmp2);
		for(int i=n;i>j;i--){
				if(b[i].t<=f){
						f-=b[i].t;
						ans[++s]=b[i].u;
				}
		}
		return s>=p;
}
int main(){
		scanf("%d%d",&n,&T);
		r=n;
		for(int i=1;i<=n;i++){
				scanf("%d%d",&a[i].h,&a[i].t);
				a[i].u=i;
		}
		sort(a+1,a+n+1,cmp1);
		while(r-l>4){
				int mid=(l+r)/2;
				//cout<<l<<" "<<r<<" "<<mid<<endl;
				if(chk(mid)){
						l=mid;
				}
				else{
						r=mid;
				}
		}
		for(int i=r;i>=l;i--){
				if(chk(i)){
						printf("%d\n%d\n",i,i);
						for(int j=1;j<=i;j++){
								printf("%d ",ans[j]);
						}
						break;
				}
		}
		return 0;
}


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

struct node{
	int a,t,id;
}q[200005];

int n,T,ans,CNT;

bool cmp(node x,node y){
	return x.t<y.t;
}

int main(){
	cin>>n>>T;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&q[i].a,&q[i].t);
		q[i].id=i;
	}
	sort(q+1,q+n+1,cmp);
	int L=0,R=n,mid,cnt,tot;

	while(L+2<R){
		mid=(L+R)/2;
		cnt=0;
		tot=T;
		for(int i=1;i<=n;i++){
			if(tot<q[i].t) break;
			if(q[i].a<mid) continue;
			tot-=q[i].t;
			cnt++;
		}
		if(cnt>=mid) L=mid;
		else R=mid-1;
	}
	for(int i=L;i<=R;i++){
		cnt=0;
		tot=T;
		for(int j=1;j<=n;j++){
			if(tot<q[i].t) break;
			if(q[j].a<i) continue;
			tot-=q[j].t;
			cnt++;
		}
		if(cnt>=i&&ans<i) ans=i,CNT=cnt;
	}
	if(ans==0){
		cout<<0<<endl<<0<<endl;
	}
	else{
		cout<<ans<<endl;
		cout<<CNT<<endl;
		for(int i=1;i<=n;i++){
			if(T<q[i].t) break;
			if(q[i].a<ans) continue;
			T-=q[i].t;
			cout<<q[i].id<<" ";
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 2e5+5;
typedef long long LL;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
struct zz{
	int req,a,id;
}s[maxn];
bool cmp(const zz &x,const zz &y){
	return x.a<y.a;
}
int tim,n;
bool check(int x){
	int ans=0;
	for(int i=1;i<=n;i++){
		if(tim<s[i].a)
			break;
		if(s[i].req<x)
			continue;
		ans++;
		tim-=s[i].a;
	}
	return ans>=x;
}
int main (){
	int ans=0;
	n=readint();
	int t=readint();
	for(int i=1;i<=n;i++){
		s[i].req=readint();
		s[i].a=readint();
		s[i].id=i;
	}
	sort(s+1,s+n+1,cmp);
	int l=0,r=n;
	while(l<=r){
		tim=t;
		int mid=(l+r)>>1;
		if(check(mid))
			ans=mid,l=mid+1;
		else
			r=mid-1;
	}
	cout<<ans<<endl<<ans<<endl;
	tim=t;
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(tim<s[i].a)
			break;
		if(s[i].req<ans)
			continue;
		tim-=s[i].a;
		cout<<s[i].id<<" ";
		/*cnt++;
		if(ans==cnt)
			break;*/
	}
	return 0;
}


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

struct pr
{
	ll a,t,r;
};
bool cmp(pr A,pr B)
{
	return A.t < B.t;
}

vector<pr> check(const vector<pr> v,const ll T,const ll s)
{

	ll rt(T),cnt(0);
	vector<pr> res;
	for(ri i=0; i<v.size(); i++)
	{
		if(v[i].a<s)
		{
			continue;
		}
		if(v[i].t>rt)
		{
			break;
		}
		cnt++;
		rt-=v[i].t;
		res.push_back(v[i]);
		if(cnt>=s)
		{
			break;
		}
	}

	return res;
}

int main()
{

	ll n,T;
	scanf("%lld %lld",&n,&T);
	vector<pr> v(n);
	for(ri i=0; i< n; i++)
	{
		scanf("%lld %lld",&v[i].a,&v[i].t);
		v[i].r=i+1;
	}
	sort(v.begin(),v.end(),cmp);

	ll l(0),r(n);
	vector<pr> res;
	while(l <=r)
	{
		ll mid=(l+r)/ 2;
		vector<pr> cand=check(v,T,mid);
		if(cand.size()>=mid)
		{
			res=cand;
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	printf("%ld\n%ld\n",res.size(),res.size());
	for(ri i=0; i<res.size(); i++)
	{
		printf("%lld ",res[i].r);
	}
	puts("");

	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 2e5+5;
typedef long long LL;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
struct zz{
	int req,a,id;
}s[maxn];
bool cmp(const zz &x,const zz &y){
	return x.a<y.a;
}
int tim,n;
bool check(int x){
	int ans=0;
	for(int i=1;i<=n;i++){
		if(tim<s[i].a)
			break;
		if(s[i].req<x)
			continue;
		ans++;
		tim-=s[i].a;
	}
	return ans>=x;
}
int main (){
	int ans=0;
	n=readint();
	int t=readint();
	for(int i=1;i<=n;i++){
		s[i].req=readint();
		s[i].a=readint();
		s[i].id=i;
	}
	sort(s+1,s+n+1,cmp);
	int l=0,r=n;
	while(l<=r){
		tim=t;
		int mid=(l+r)>>1;
		if(check(mid))
			ans=mid,l=mid+1;
		else
			r=mid-1;
	}
	cout<<ans<<endl<<ans<<endl;
	tim=t;
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(tim<s[i].a)
			break;
		if(s[i].req<ans)
			continue;
		tim-=s[i].a;
		cout<<s[i].id<<" ";
		cnt++;
		if(ans==cnt)
			break;
	}
	return 0;
}


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

const int maxn=2e5+10;
vector<pair<int,int> > v[maxn];
priority_queue<pair<int,int> > q;//优先队列默认最大堆
int n,T;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a,c,i;
    //freopen("in.txt","r",stdin);
    cin>>n>>T;
    for(i=1;i<=n;i++)
    {
        cin>>a>>c;
        v[a].push_back(make_pair(c,i));//把ai一样的存在一起
    }

    ll sum=0;
    for(i=n;i>=0;i--){
    	int l = v[i].size();
        for(int j = 0; j < l; ++ j){
            q.push(v[i][j]);
            sum+=v[i][j].first;
        }

        while(q.size()>i){
            sum-=q.top().first;
            q.pop();//把最耗时的出队
        }

        if(q.size()==i&&sum<=T){//贪得最大满足条件，因为往后i--不可能比现在大了
            cout<<i<<endl<<i<<endl;
            while(q.size()){
                cout<<q.top().second<<' ';
                q.pop();
            }
            cout<<endl;
            return 0;
        }
    }

}
/*
5 1000
5 100
5 100
5 100
5 100
4 100
*/


#include<cstdio>
#include<iostream>
#include<algorithm>
#define maxn 200010
using namespace std;
int n,T,cnt;
struct node{
	int a,t,h;
}A[maxn],B[maxn];
int cmp(node c,node d){
	return c.t<d.t;
}
int check(int k){
	cnt=0;
	for (int i=1;i<=n;i++)
		if (A[i].a>=k) B[++cnt]=A[i];
	sort(B+1,B+cnt+1,cmp);
	int sum=0;
	if (cnt<k) return 0;
	for (int i=1;i<=k;i++) sum+=B[i].t;
	if (sum<=T) return 1;
	return 0;
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	cin>>n>>T;
	for (int i=1;i<=n;i++){
		scanf("%d%d",&A[i].a,&A[i].t);
		A[i].h=i;
	}
	int l=0,r=n;
	while (l<=r){
		int m=(l+r)>>1;
		if (check(m)) l=m+1;
		else r=m-1;
	}
	l--;
	cout<<l<<endl;
	cout<<l<<endl;
	check(l);
	for (int i=1;i<=l;i++){
		printf("%d%c",B[i].h,i<l?' ':'\n');
	}
	return 0;
}


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

struct node{
	int a,t,id;
}q[200005];

int n,T,ans,CNT;

bool cmp(node x,node y){
	return x.t<y.t;
}

int main(){
	cin>>n>>T;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&q[i].a,&q[i].t);
		q[i].id=i;
	}
	sort(q+1,q+n+1,cmp);
	int L=0,R=n,mid,cnt,tot;

	while(L+2<R){
		mid=(L+R)/2;
		cnt=0;
		tot=T;
		for(int i=1;i<=n;i++){
			if(q[i].a<mid) continue;
			tot-=q[i].t;
			if(tot<0) break;
			cnt++;
		}
		if(cnt>=mid) L=mid;
		else R=mid-1;
	}
	for(int i=L;i<=R;i++){
		cnt=0;
		tot=T;
		for(int j=1;j<=n;j++){
			if(q[j].a<i) continue;
			tot-=q[j].t;
			if(tot<0) break;
			cnt++;
		}
		if(cnt==i&&ans<i) ans=i,CNT=cnt;
	}
	if(ans==0){
		cout<<0<<endl<<0<<endl;
	}
	else{
		cout<<ans<<endl;
		cout<<CNT<<endl;
		for(int i=1;i<=n;i++){
			if(q[i].a<ans) continue;
			T-=q[i].t;
			if(T<0) break;
			cout<<q[i].id<<" ";
		}
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define MAXN 200005
typedef long long LL;
#define int LL
typedef pair<int,int> pii;
const int INF=0x7f7f7f7f7f7f;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
int n,t;
struct ming{
	int a,t,id;
	bool operator < (const ming &x)const{
		return t<x.t;
	}
}s[MAXN];
bool tant(int k){
	int tmp=t,num=0;
	for(int i=1;i<=n;i++){
		if(tmp<s[i].t)break;
		if(s[i].a<k)continue;
		num++,tmp-=s[i].t;
	}
	return num>=k;
}
signed main(){
	read(n);read(t);
	for(int i=1;i<=n;i++)read(s[i].a),read(s[i].t),s[i].id=i;
	sort(s+1,s+n+1);
	int l=0,r=n+1;
	while(l<r-1){
		int mid=l+r>>1;
		if(tant(mid))l=mid;
		else r=mid;
	}
	printf("%d\n%d\n",l,l);
	int tmp=t,num=0;
	for(int i=1;i<=n;i++){
		if(tmp<s[i].t) break;
		if(s[i].a<l)continue;
		printf("%d ",s[i].id);tmp-=s[i].t,num++;
		if(num==l)break;
	}
	return 0;
}


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

const int N = 2e5+10;

int a[N], t[N];
vector<int> ans;
int n, T;

bool cmp(int i, int j){
    return t[i] < t[j];
}

bool check(int k){
    vector<int> problems;
    for(int i = 0; i < n; i++){
        if( a[i] >= k) problems.push_back(i);
    }
    if(problems.size() < k) return false;
    sort(problems.begin(), problems.end(), cmp);
    int sum = 0;
    ans.clear();
    for(int i = 0; i < k; i++) {
        sum += t[problems[i]];
        ans.push_back(problems[i] + 1);
    }
    return sum <= T;
}

int main(){
    scanf("%d %d", &n, &T);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &t[i]);
    }
    int l = 0, r = n+1;
    while(l < r){
        int mid = (l + r) >> 1;
        if( check(mid) ) l = mid + 1;
        else r = mid;
    }
    printf("%d\n%d\n", ans.size(), ans.size());
    for(auto it: ans) printf("%d ", it);
    printf("\n");
    return 0;
}


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

const int N = 2e5+10;

int a[N], t[N];
vector<int> ans;
int n, T;

bool cmp(int i, int j){
    return t[i] < t[j];
}

bool check(int k){
    vector<int> problems;
    for(int i = 0; i < n; i++){
        if( a[i] >= k) problems.push_back(i);
    }
    if(problems.size() < k) return false;
    sort(problems.begin(), problems.end(), cmp);
    int sum = 0;
    ans.clear();
    for(int i = 0; i < k; i++) {
        sum += t[problems[i]];
    }
    if(sum <= T){
        for(int i = 0; i < k; i++) ans.push_back(problems[i]);
    }
    return sum <= T;
}

int main(){
    scanf("%d %d", &n, &T);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &t[i]);
    }
    int l = 0, r = n+1;
    while(l < r){
        int mid = (l + r) >> 1;
        if( check(mid) ) l = mid + 1;
        else r = mid;
    }
    printf("%d\n%d\n", ans.size(), ans.size());
    for(auto it: ans) printf("%d ", it);
    printf("\n");
    return 0;
}


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

const int N = 2e5+10;

int a[N], t[N];
vector<int> ans;
int n, T;

bool cmp(int i, int j){
    return t[i] < t[j];
}

bool check(int k){
    vector<int> problems;
    for(int i = 0; i < n; i++){
        if( a[i] >= k) problems.push_back(i);
    }
    if(problems.size() < k) return false;
    sort(problems.begin(), problems.end(), cmp);
    int sum = 0;
    ans.clear();
    for(int i = 0; i < k; i++) {
        sum += t[problems[i]];
        ans.push_back(problems[i] + 1);
    }
    return sum <= T;
}

int main(){
    scanf("%d %d", &n, &T);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &t[i]);
    }
    int l = 0, r = n+1;
    while(l < r){
        int mid = (l + r) >> 1;
        if( check(mid) ) l = mid + 1;
        else r = mid;
    }
    printf("%d\n%d\n", l-1, l-1);
    for(auto it: ans) printf("%d ", it);
    printf("\n");
    return 0;
}


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

const int N = 2e5+10;

int a[N], t[N];
vector<int> ans;
int n, T;

bool cmp(int i, int j){
    return t[i] < t[j];
}

bool check(int k){
    vector<int> problems;
    for(int i = 0; i < n; i++){
        if( a[i] >= k) problems.push_back(i);
    }
    if(problems.size() < k) return false;
    sort(problems.begin(), problems.end(), cmp);
    int sum = 0;

    for(int i = 0; i < k; i++) {
        sum += t[problems[i]];
    }
    if(sum <= T){
        ans.clear();
        for(int i = 0; i < k; i++) ans.push_back(problems[i]+1);
    }
    return sum <= T;
}

int main(){
    scanf("%d %d", &n, &T);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &t[i]);
    }
    int l = 0, r = n+1;
    while(l < r){
        int mid = (l + r) >> 1;
        if( check(mid) ) l = mid + 1;
        else r = mid;
    }
    printf("%d\n%d\n", ans.size(), ans.size());
    for(auto it: ans) printf("%d ", it);
    printf("\n");
    return 0;
}


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

const int N = 2e5+10;

int a[N], t[N];
vector<int> ans;
int n, T;

bool cmp(int i, int j){
    return t[i] < t[j];
}

bool check(int k){
    vector<int> problems;
    for(int i = 0; i < n; i++){
        if( a[i] >= k) problems.push_back(i);
    }
    if(problems.size() < k) return false;
    sort(problems.begin(), problems.end(), cmp);
    int sum = 0;
    ans.clear();
    for(int i = 0; i < k; i++) {
        sum += t[problems[i]];
    }
    if(sum <= T){
        for(int i = 0; i < k; i++) ans.push_back(problems[i]+1);
    }
    return sum <= T;
}

int main(){
    scanf("%d %d", &n, &T);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i], &t[i]);
    }
    int l = 0, r = n+1;
    while(l < r){
        int mid = (l + r) >> 1;
        if( check(mid) ) l = mid + 1;
        else r = mid;
    }
    printf("%d\n%d\n", ans.size(), ans.size());
    for(auto it: ans) printf("%d ", it);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut,cev;
ii a[N];
ll ans[N];
vector<ii> v;

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		while(i-1>=1 && a[i].st==a[i-1].st)
		{q.push(a[i].nd);
		sum+=a[i].nd;
}
		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) ans[i]=sum;
		else ans[i]=M;

		if(ans[i]<=T) {

			cev=a[i].st;
			break ;

		}

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=cev) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut,cev;
ii a[N];
ll ans[N];
vector<ii> v;

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		while(i-1>=1 && a[i].st==a[i-1].st) {

			q.push(a[i].nd);
			sum+=a[i].nd;
			i--;

		}

		q.push(a[i].nd);
		sum+=a[i].nd;

		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) ans[i]=sum;
		else ans[i]=M;

		if(ans[i]<=T) {

			cev=a[i].st;
			break ;

		}

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=cev) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut;
ii a[N];
ll cev[N];
vector<ii> v;

bool ok(int val) {

	for(int i=1;i<=n;i++) {

		if(a[i].st>=val) {

			if(cev[i]<=T) return true;

		}

	}

	return false;

}

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		q.push(a[i].nd);
		sum+=a[i].nd;

		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) cev[i]=sum;
		else cev[i]=M;

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

	int bas=1,son=n;

	while(bas<=son) {

		if(ok(orta)) bas=orta+1;
		else son=orta-1;

	}

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=son) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut,cev;
ii a[N];
ll ans[N];
vector<ii> v;

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		while(i-1>=1 && a[i].st==a[i-1].st)
		{q.push(a[i].nd);
		sum+=a[i].nd;i--;
}
		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) ans[i]=sum;
		else ans[i]=M;

		if(ans[i]<=T) {

			cev=a[i].st;
			break ;

		}

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=cev) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut,cev;
ii a[N];
ll ans[N];
vector<ii> v;

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		q.push(a[i].nd);
		sum+=a[i].nd;

		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) ans[i]=sum;
		else ans[i]=M;

		if(ans[i]<=T) {

			cev=a[i].st;
			break ;

		}

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=cev) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 100005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut;
ii a[N];
ll cev[N];
vector<ii> v;

bool ok(int val) {

	for(int i=1;i<=n;i++) {

		if(a[i].st>=val) {

			if(cev[i]<=T) return true;

		}

	}

	return false;

}

void build() {

	int sum=0;

	priority_queue<int> q;

	for(int i=n;i>=1;i--) {

		q.push(a[i].nd);
		sum+=a[i].nd;

		while(q.size()>a[i].st) sum-=q.top(),q.pop();

		if(q.size()==a[i].st) cev[i]=sum;
		else cev[i]=M;

	}

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	sort(a+1,a+1+n);

	build();

	int bas=1,son=n;

	while(bas<=son) {

		if(ok(orta)) bas=orta+1;
		else son=orta-1;

	}

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=son) {

			tut=i;
			break ;

		}

	}

	for(int i=tut;i<=n;i++) {

		v.pb(mp(a[i].nd,i));

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


#include<bits/stdc++.h>
#define lf double
#define ll long long
#define ull unsigned ll
#define ii pair<int,int>
#define lolo pair<ll,ll>
#define il pair<int,ll>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define pll pair<ll,ll>
#define ld long int
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define MOD 1000000007
#define inf 1000000009
#define N 200005
#define LOG 1005
#define M 1000000000000000000
#define KOK 400
#define EPS 0.0000001
#define B 10
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;

int n,T,tut,cev;
ii a[N];
vector<ii> v;

bool ok(int val) {

	int res=0;

	vector<int> pos;

	for(int i=1;i<=n;i++) {

		if(a[i].st>=val) pos.pb(a[i].nd);

	}

	sort(all(pos));

	if(sz(pos)<val) return false;

	for(int i=0;i<val;i++) res+=pos[i];

	return (res<=T);

}

int main() {

	scanf("%d %d",&n,&T);

	for(int i=1;i<=n;i++) {

		scanf("%d %d",&a[i].st,&a[i].nd);

	}

	int bas=1,son=n;

	while(bas<=son) {

		if(ok(orta)) bas=orta+1;
		else son=orta-1;

	}

	cev=son;

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

	for(int i=1;i<=n;i++) {

		if(a[i].st>=cev) {

			v.pb(mp(a[i].nd,i));

		}

	}

	sort(all(v));

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

		printf("%d ",v[i].nd);

	}

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l <= r) {
        long long m = (l + r)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        auto mid = lower_bound(data.begin(), data.end(), m, cmpl);
        if (mid != data.end()) {

            vector<el> tmp(++mid, data.end());
            if (tmp.size() < m - 1) {
                r = m - 1;
                continue;
            }
            sort(tmp.begin(), tmp.end(), cmp2);
            long long tmpsum = (--mid)->t;
            for(int i = 0; i < m - 1; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok
                if (m  > ans) {
                    //ok

                    ans = m;
                }
                l = m + 1;
            } else {
                r = m - 1;
            }

        }

    }
    if (ans) {
        auto mid = lower_bound(data.begin(), data.end(), ans, cmpl);
        ansInd.push_back(mid->ind);

        vector<el> tmp(++mid, data.end());
        sort(tmp.begin(), tmp.end(), cmp2);
        for(int i = 0; i < ans - 1; ++i) {
            ansInd.push_back(tmp[i].ind);
        }
    }

    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l <= r) {
        long long m = (l + r)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        auto mid = lower_bound(data.begin(), data.end(), m, cmpl);
        if (mid != data.end()) {

            vector<el> tmp(++mid, data.end());
            sort(tmp.begin(), tmp.end(), cmp2);
            long long tmpsum = (--mid)->t;
            for(int i = 0; i < m - 1; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok
                if (m > ans) {
                    //ok

                    ans = m;
                }
                l = m + 1;
            } else {
                r = m - 1;
            }

        }

    }
    if (ans) {
        auto mid = lower_bound(data.begin(), data.end(), ans, cmpl);
        ansInd.push_back(mid->ind);

        vector<el> tmp(++mid, data.end());
        sort(tmp.begin(), tmp.end(), cmp2);
        for(int i = 0; i < ans - 1; ++i) {
            ansInd.push_back(tmp[i].ind);
        }
    }

    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l < r) {
        long long m = (l + r)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        auto mid = lower_bound(data.begin(), data.end(), m, cmpl);
        if (mid != data.end()) {
            m = mid->a;
            vector<el> tmp(++mid, data.end());
            sort(tmp.begin(), tmp.end(), cmp2);
            long long tmpsum = (--mid)->t;
            for(int i = 0; i < m - 1; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok
                if (m > ans) {
                    //ok

                    ans = m;
                }
                l = m + 1;
            } else {
                r = m - 1;
            }

        }

    }
    auto mid = lower_bound(data.begin(), data.end(), ans, cmpl);
    ansInd.push_back(mid->ind);

    vector<el> tmp(++mid, data.end());
    sort(tmp.begin(), tmp.end(), cmp2);
    for(int i = 0; i < ans - 1; ++i) {
        ansInd.push_back(tmp[i].ind);
    }

    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l <= r) {
        long long m = (l + r)/2;
        vector<el> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= m) {
                tmp.push_back(data[i]);
            }
        }
        sort(tmp.begin(), tmp.end(), cmp2);
        if (tmp.size() < m) {
            r = m - 1;
            continue;
        }
        long long tmpsum = 0;
        for(int i = 0; i < m; ++i) {
            tmpsum += tmp[i].t;
        }
        if (tmpsum <= t) {
            ans = m;
            l = m + 1;
        } else {
            r = m - 1;
        }
    }
    if (ans) {
        vector<el> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= ans) {
                tmp.push_back(data[i]);
            }
        }
        sort(tmp.begin(), tmp.end(), cmp2);

        for(int i = 0; i < ans; ++i) {
            ansInd.push_back(tmp[i].ind);
        }
    }
    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }
    return 0;
}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l <= r) {
        long long m = (l + r)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        auto mid = lower_bound(data.begin(), data.end(), m, cmpl);
        if (mid != data.end()) {

            vector<el> tmp(++mid, data.end());
            if (tmp.size() < m - 1) {
                r = m - 1;
                continue;
            }
            sort(tmp.begin(), tmp.end(), cmp2);
            long long tmpsum = (--mid)->t;
            for(int i = 0; i < m - 1; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok
                if (m  > ans) {
                    //ok

                    ans = m;
                }
                l = m + 1;
            } else {
                r = m - 1;
            }
        }
    }
    if (ans) {
        auto mid = lower_bound(data.begin(), data.end(), ans, cmpl);
        ansInd.push_back(mid->ind);
        vector<el> tmp(++mid, data.end());
        sort(tmp.begin(), tmp.end(), cmp2);
        for(int i = 0; i < ans - 1; ++i) {
            ansInd.push_back(tmp[i].ind);
        }
    }
    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 0;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l < r) {
        long long m = (l + r + 1)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        vector<el> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= m) {
                tmp.push_back(data[i]);
            }
        }
        sort(tmp.begin(), tmp.end(), cmp2);
        if (tmp.size() < m) {
            r = m - 1;
            continue;
        }
        long long tmpsum = 0;
            for(int i = 0; i < m; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok

                    ans = m;

                l = m;
            } else {
                r = m - 1;
            }

    }
    if (ans) {
        vector<long long> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= ans) {
                tmp.push_back(data[i].ind);
            }
        }
        sort(tmp.begin(), tmp.end());

        for(int i = 0; i < ans; ++i) {
            ansInd.push_back(tmp[i]);
        }
    }
    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}


//
//  main.cpp
//  code1
//
//  Created by Irina Korneeva on 08/01/2018.
//  Copyright © 2018 Irina. All rights reserved.
//
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <iostream>
using namespace std;
struct el {
    long long a, t, ind;
};

int cmp(el a, el b) {
    if (a.a == b.a) {
        return a.t < b.t;
    }
    return a.a < b.a;
}

int cmp2(el a, el b) {
    return a.t < b.t;
}
int cmpl(el a, long long x) {
    return a.a < x;
}

int main(int argc, const char * argv[]) {
    long long n, t;
    cin >> n >> t;
    vector<el> data;
    for (int i = 0; i < n; ++i) {
        el elem;
        cin >> elem.a >> elem.t;
        elem.ind = i + 1;
        data.push_back(elem);
    }
    sort(data.begin(), data.end(), cmp);
    long long l = 1;
    long long r = n;
    long long ans = 0;
    vector<long long> ansInd;
    while(l <= r) {
        long long m = (l + r)/2;
        //cout << l << ' ' << m << ' ' << r << '\n';
        vector<el> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= m) {
                tmp.push_back(data[i]);
            }
        }
        sort(tmp.begin(), tmp.end(), cmp2);
        if (tmp.size() < m) {
            r = m - 1;
            continue;
        }
        long long tmpsum = 0;
            for(int i = 0; i < m; ++i) {
                tmpsum += tmp[i].t;
                //cout << tmp[i].t << " ";
            }
            //cout << "lol\n";
            //cout << tmpsum << endl;
            if (tmpsum <= t) {
                //ok
                if (m  > ans) {
                    //ok

                    ans = m;
                }
                l = m + 1;
            } else {
                r = m - 1;
            }

    }
    if (ans) {
        vector<long long> tmp;
        for(int i = 0; i < n; ++i) {
            if (data[i].a >= ans) {
                tmp.push_back(data[i].ind);
            }
        }
        sort(tmp.begin(), tmp.end());

        for(int i = 0; i < ans; ++i) {
            ansInd.push_back(tmp[i]);
        }
    }
    cout << ansInd.size() << "\n";
    cout << ansInd.size() << "\n";
    for (int i = 0; i < ansInd.size(); ++i) {
        cout << ansInd[i] << " ";

    }

    return 0;

}