Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. 

Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. 

Peter has very many envelopes and very little time, this hard task is entrusted to you.

Input

The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106).

Output

In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.

If the card does not fit into any of the envelopes, print number 0 in the single line.

Examples

Input

2 1 1
2 2
2 2


Output

1
1 


Input

3 3 3
5 4
12 11
9 8


Output

3
1 3 2

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Sorting
Skill types: Dynamic programming

Sorting

Starter code:

Solutions:
inputi = [int(i) for i in input().split(' ')]
amt = inputi[0]
cardW = inputi[1]
cardH = inputi[2]
envelopes = []
cur_amt = 1
for i in range(amt):
	inputi = [int(i) for i in input().split(' ')]
	if inputi[0] > cardW and inputi[1] > cardH:
		envelopes.append((inputi[0], inputi[1], inputi[0] * inputi[1], cur_amt))
	cur_amt += 1
envelopes = sorted(envelopes, key=lambda x: x[2])
amounts = [1 for a in envelopes]
back_pointers = [-1 for a in envelopes]
for c in range(len(envelopes)):
	cur_tuple = envelopes[c]
	for prev in range(c):
		compare_tuple = envelopes[prev]
		if cur_tuple[0] > compare_tuple[0] and cur_tuple[1] > compare_tuple[1] and (amounts[prev] + 1 > amounts[c]):
			amounts[c] = amounts[prev] + 1
			back_pointers[c] = prev
max_amt = None
max_idx = None
for c in range(len(envelopes)):
	cur_tuple = envelopes[c]
	if max_amt == None or amounts[c] > max_amt:
		max_idx = c
		max_amt = amounts[c]
if max_amt == None:
	print(0)
else:
	print(max_amt)
	tmp_back_ptr = back_pointers[max_idx]
	back_ptr_list = []
	back_ptr_list.append(envelopes[max_idx][3])
	while tmp_back_ptr != -1:
		back_ptr_list.append(envelopes[tmp_back_ptr][3])
		tmp_back_ptr = back_pointers[tmp_back_ptr]
	for a in range(len(back_ptr_list)):
		print(back_ptr_list[len(back_ptr_list) - a - 1], end=' ')


from bisect import bisect_left
(n, w, h) = map(int, input().split())
l = []
for i in range(n):
	(wi, hi) = map(int, input().split())
	if wi > w and hi > h:
		l.append([wi, -hi, i])
l.sort()
n = len(l)
(u, v) = ([], [0] * n)
for (i, h) in enumerate((-i[1] for i in l)):
	k = bisect_left(u, h)
	v[i] = k
	if k < len(u):
		u[k] = h
	else:
		u.append(h)
k = len(u)
print(k)
d = [''] * k
k -= 1
for i in range(n - 1, -1, -1):
	if v[i] == k:
		d[k] = str(l[i][2] + 1)
		k -= 1
print(' '.join(d))


import sys
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
(n, w, h) = RI()
l = []
d = {}
for i in range(n):
	(a, b) = RI()
	l.append((a, b, i))
l.sort()
index = -1
for i in range(n):
	if l[i][0] > w and l[i][1] > h:
		index = i
		break
if index == -1:
	print(0)
else:
	temp = [0] * n
	parent = [0] * n
	temp[index] = 1
	parent[index] = index
	for i in range(index + 1, n):
		parent[i] = i
		if l[i][0] > w and l[i][1] > h:
			temp[i] = 1
		else:
			continue
		for j in range(index, i):
			if l[i][0] > l[j][0] and l[i][1] > l[j][1]:
				if temp[j] + 1 > temp[i]:
					temp[i] = temp[j] + 1
					parent[i] = j
	maxo = max(temp)
	ans = []
	for i in range(n):
		if temp[i] == maxo:
			j = i
			while parent[j] != j:
				ans.append(l[j][2] + 1)
				j = parent[j]
			ans.append(l[j][2] + 1)
			break
	print(maxo)
	print(*ans[::-1])


import sys

def log(*args):
	print(*args, file=sys.stderr)

def line():
	return sys.stdin.readline().split()

def main():
	(n, w, h) = (int(x) for x in line())
	d = [[int(x) for x in line()] for _ in range(n)]
	e = sorted(range(n), key=lambda x: d[x])
	c = [None for _ in range(n)]
	for i in range(n):
		if d[e[i]][0] <= w or d[e[i]][1] <= h:
			c[i] = []
			continue
		cmax = []
		for j in range(i):
			if d[e[j]][0] < d[e[i]][0] and d[e[j]][1] < d[e[i]][1]:
				if len(c[j]) > len(cmax):
					cmax = c[j]
		c[i] = cmax + [e[i]]
	cmax = []
	for i in c:
		if len(i) > len(cmax):
			cmax = i
	print(len(cmax))
	if len(cmax) > 0:
		print(*(i + 1 for i in cmax))
main()


class Envelope:

	def __init__(self, w, h, n, prev):
		self.w = w
		self.h = h
		self.n = n
		self.prev = prev

def max_chain_size(envelopes, w, h):
	dp = list()
	dp.append(0)
	for i in range(1, len(envelopes) + 1):
		dp.append(1)
		env = envelopes[i - 1]
		env.prev = None
		for j in range(1, i):
			if env.h > envelopes[j - 1].h and env.w > envelopes[j - 1].w:
				if dp[j] + 1 > dp[i]:
					env.prev = envelopes[j - 1]
					dp[i] = dp[j] + 1
	max_elem = 0
	max_index = 0
	index = 0
	for d in dp:
		if d > max_elem:
			max_elem = max(max_elem, d)
			max_index = index
		index += 1
	return (max_elem, max_index)
input_line = input().split()
n = int(input_line[0])
card_width = int(input_line[1])
card_height = int(input_line[2])
envelopes = list()
for i in range(0, n):
	envelope_dim = input().split()
	env = Envelope(int(envelope_dim[0]), int(envelope_dim[1]), i + 1, None)
	envelopes.append(env)
envelopes = sorted(envelopes, key=lambda envelope: envelope.w)
envelopes = list(filter(lambda envelope: envelope.w > card_width and envelope.h > card_height, envelopes))
chain = list()
res = max_chain_size(envelopes, card_width, card_height)
print(res[0])
if res[1] - 1 >= 0:
	start_env = envelopes[res[1] - 1]
	result = list()
	env = start_env
	while env:
		result.append(env)
		env = env.prev
	result.reverse()
	for res in result:
		print(res.n, end=' ')
elif len(envelopes):
	print(envelopes[0].n)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 998244353

def solve():
	(N, WW, HH) = getInts()
	nodes = []
	for n in range(N):
		(w, h) = getInts()
		if w > WW and h > HH:
			nodes.append((w, h, n + 1))
	if not nodes:
		print(0)
		return
	nodes.sort()
	N = len(nodes)
	ans = [1] * N
	D = dd(int)
	best_ind = -1
	best_len = -1
	for i in range(N - 1, -1, -1):
		D[i] = N
		if i == N - 1:
			ans[i] = 1
			best_len = 1
			best_ind = N - 1
			continue
		(wi, hi) = (nodes[i][0], nodes[i][1])
		best = 1
		for j in range(i + 1, N):
			(wj, hj) = (nodes[j][0], nodes[j][1])
			if wi < wj and hi < hj:
				if ans[j] + 1 > best:
					best = ans[j] + 1
					D[i] = j
		ans[i] = best
		if ans[i] > best_len:
			best_len = ans[i]
			best_ind = i
	i = best_ind
	path = []
	print(best_len)
	while True:
		if i == N:
			break
		path.append(nodes[i][2])
		i = D[i]
	print(*path)
	return
solve()


(n, w, h) = map(int, input().split())
arr = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	if x > w and y > h:
		arr.append((x, y, i))
arr.sort(key=lambda x: (x[0], -x[1]))
n = len(arr)
dp = [(1, -1) for i in range(0, n)]
res = 0
end = 0
for i in range(0, n):
	(x, y, _) = arr[i]
	for j in range(0, i):
		if arr[j][0] < x and arr[j][1] < y and (dp[j][0] + 1 > dp[i][0]):
			dp[i] = (dp[j][0] + 1, j)
	if dp[i][0] > res:
		res = dp[i][0]
		end = i
if res == 0:
	print(0)
else:
	print(res)
	chain = []
	while end >= 0:
		chain.insert(0, arr[end][2] + 1)
		end = dp[end][1]
	print(' '.join(map(str, chain)))


def f(L):
	return L[0] * L[1]
ln = input().split(' ')
n = int(ln[0])
w = int(ln[1])
h = int(ln[2])
nums = dict()
envs = []
x_max = 0
y_max = 0
start = (w, h)
envs.append(start)
blank = (0, [])
nums[start] = 0
for i in range(1, n + 1):
	(w1, h1) = [int(x) for x in input().split(' ')]
	if w1 <= w or h1 <= h:
		continue
	e = (w1, h1)
	nums[e] = i
	envs.append(e)
n = len(envs)
envs = sorted(envs, key=f, reverse=True)
opt = [0] * n
prev = [-1] * n
for i in range(1, n):
	curr = envs[i]
	for j in range(i):
		comp = envs[j]
		if comp[0] > curr[0] and comp[1] > curr[1]:
			if opt[j] + 1 > opt[i]:
				opt[i] = opt[j] + 1
				prev[i] = j
best_ind = prev[n - 1]
print(opt[-1])
if opt[-1] != 0:
	while best_ind != -1:
		print(nums[envs[best_ind]], end=' ')
		best_ind = prev[best_ind]


(n, x, y) = map(int, input().strip().split())
envs = []
for h in range(n):
	envs.append(list(map(int, input().strip().split())) + [h])
envs.sort(key=lambda x: (x[0], x[1]))
dp = [1 for i in range(n)]
anc = [-1 for i in range(n)]
flag = 0
for i in range(n):
	if envs[i][0] > x and envs[i][1] > y:
		flag = 1
		for j in range(i):
			if envs[j][1] < envs[i][1] and envs[j][0] < envs[i][0]:
				if dp[i] < dp[j] + 1:
					dp[i] = dp[j] + 1
					anc[i] = j
	else:
		dp[i] = 0
if flag:
	maxi = [0, -1]
	for i in range(n):
		if dp[i] > maxi[0]:
			maxi = [dp[i], i]
	ans = []
	print(maxi[0])
	start = maxi[1]
	while start != -1:
		ans.append(envs[start][2] + 1)
		start = anc[start]
	print(*ans[::-1])
else:
	print(0)


from operator import itemgetter
import sys
(n, w, h) = [int(x) for x in input().split()]
bags = [input().split() for _ in range(n)]
bags = [(i + 1, int(bag[0]), int(bag[1])) for (i, bag) in enumerate(bags)]
bags = [bag for bag in bags if bag[1] > w and bag[2] > h]
n = len(bags)
if n == 0:
	print(0)
	sys.exit(0)
bags = sorted(bags, key=itemgetter(1, 2))
mls = [1] * n
prev = list(range(n))
for i in range(1, n):
	for j in range(0, i):
		if bags[j][1] < bags[i][1] and bags[j][2] < bags[i][2] and (mls[j] + 1 > mls[i]):
			mls[i] = mls[j] + 1
			prev[i] = j
maxls = max(mls)
print(maxls)
max_id = 0
for i in range(n):
	if mls[i] == maxls:
		max_id = i
output = [''] * maxls
for i in range(maxls):
	output[maxls - 1 - i] = str(bags[max_id][0])
	max_id = prev[max_id]
print(' '.join(output))


from _bisect import bisect_left
(n, w_plic, h_plic) = map(int, input().split())
envs = []
for i in range(1, n + 1):
	(w, h) = map(int, input().split())
	if w > w_plic and h > h_plic:
		envs.append([w, -h, i])
if len(envs) < 1:
	print(0)
	exit()
envs.sort()
longest_subseq = []
priority = [0] * len(envs)
for i in range(len(envs)):
	current_height = -envs[i][1]
	idx = bisect_left(longest_subseq, current_height)
	priority[i] = idx
	if idx < len(longest_subseq):
		longest_subseq[idx] = current_height
	else:
		longest_subseq.append(current_height)
res = [0] * len(longest_subseq)
print(len(longest_subseq))
order = len(longest_subseq) - 1
for i in range(len(envs) - 1, -1, -1):
	if priority[i] == order:
		res[order] = envs[i][2]
		order -= 1
print(*res, sep=' ')


class A:

	def solve(self):
		n = int(input())
		other = n - 2
		if other > 0 and other % 2 == 0:
			print('YES')
		else:
			print('NO')

class B:

	def solve(self):
		[d, w] = [int(x) for x in input().split(' ')]
		times = []
		for i in range(d):
			times.append(tuple([int(x) for x in input().split(' ')]))
		sum_l = sum([t[0] for t in times])
		sum_h = sum([t[1] for t in times])
		if not sum_l <= w <= sum_h:
			print('NO')
			return
		print('YES')
		for (l, h) in times:
			lb = l
			sum_l -= l
			sum_h -= h
			while lb <= h:
				if sum_l <= w - lb <= sum_h:
					break
				else:
					lb += 1
			print('{} '.format(lb), end='')
			w -= lb

class C:

	def solve(self):
		n = int(input())
		name_index = {}
		for i in range(n):
			name = input()
			if name not in name_index:
				print('OK')
				name_index[name] = 1
			else:
				print('{}{}'.format(name, name_index[name]))
				name_index[name] += 1

class D:

	def solve(self):
		[n, w, h] = [int(x) for x in input().split(' ')]
		envelopes = []
		envelope_indices = {}
		for i in range(n):
			envelopes.append(tuple([int(x) for x in input().split(' ')]))
			envelope_indices[envelopes[-1]] = i
		sorted_envelopes = sorted(envelopes, key=lambda x: x[1])
		sorted_envelopes = sorted(sorted_envelopes, key=lambda x: x[0])
		lis = [0 for x in range(n)]
		back = [0 for x in range(n)]
		for k in range(n):
			if sorted_envelopes[k][0] <= w or sorted_envelopes[k][1] <= h:
				continue
			lis[k] = 1
			back[k] = -1
			for i in range(k):
				if sorted_envelopes[i][0] > w and sorted_envelopes[i][1] > h and (sorted_envelopes[i][0] < sorted_envelopes[k][0]) and (sorted_envelopes[i][1] < sorted_envelopes[k][1]) and (lis[i] + 1 > lis[k]):
					lis[k] = lis[i] + 1
					back[k] = i
		max_val = max(lis)
		if max_val == 0:
			print('0')
		else:
			print(max_val)
			max_index = -1
			for i in range(n):
				if lis[i] == max_val:
					max_index = i
					break
			back_val = back[max_index]
			n_seq = [max_index]
			while back_val != -1:
				n_seq.append(back_val)
				back_val = back[back_val]
			n_seq = list(reversed(n_seq))
			selected_evelopes = [sorted_envelopes[i] for i in range(n) if i in n_seq]
			for e in selected_evelopes:
				print('{} '.format(envelope_indices[e] + 1), end='')
D().solve()


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
(n, w, h) = rl()
a = []
a.append((w, h, 0))
for i in range(n):
	(x, y) = rl()
	if x > w and y > h:
		a.append((x, y, i + 1))
a.sort()
if len(a) == 1:
	print(0)
	exit()
else:
	dp = [0] * (n + 1)
	p = [0] * (n + 1)
	idx = 1
	length = 1
	for i in range(1, len(a)):
		maxi = 0
		for j in range(i):
			if dp[j] > maxi and a[i][0] > a[j][0] and (a[i][1] > a[j][1]):
				p[i] = j
				maxi = dp[j]
		dp[i] = maxi + 1
		if dp[i] > length:
			length = dp[i]
			idx = i
print(length)
k = idx
ans = []
while dp[k] > 1:
	ans.append(a[k][2])
	k = p[k]
ans.append(a[k][2])
print(*ans[::-1])


import sys
from array import array

def readline():
	return sys.stdin.buffer.readline().decode('utf-8')

class BIT_RMQ(object):
	__slots__ = ['nodes', 'size']

	def __init__(self, size: int):
		self.nodes = [(0, 0)] * (size + 1)
		self.size = size + 1

	def update(self, index: int, value: int):
		while index < self.size:
			if self.nodes[index] < value:
				self.nodes[index] = value
			index += index & -index

	def get(self, right: int):
		result = (0, 0)
		while right:
			if result < self.nodes[right]:
				result = self.nodes[right]
			right -= right & -right
		return result
(n, w, h) = map(int, readline().split())
envelopes = [tuple(map(int, readline().split())) + (i,) for i in range(1, n + 1)]
envelopes.sort(key=lambda x: (x[0], -x[1]))
bit = BIT_RMQ(10 ** 6 + 10)
prev = array('h', [0]) * (n + 1)
(ans, max_i) = (0, 0)
for (wi, hi, i) in envelopes:
	if wi <= w or hi <= h:
		continue
	res = bit.get(hi - 1) if hi > 1 else (0, 0)
	nest = res[0] + 1
	if ans < nest:
		ans = nest
		max_i = i
	if bit.get(hi) < (nest, 0):
		bit.update(hi, (nest, i))
		prev[i] = res[1]
print(ans)
if ans:
	ch = max_i
	a = []
	while ch != 0:
		a.append(ch)
		ch = prev[ch]
	print(*map(str, reversed(a)))


import sys
import collections

def sol1():
	(n, card_width, card_height) = map(int, sys.stdin.readline().strip().split())
	Envelope = collections.namedtuple('envelope', 'number width height')
	envelope = Envelope(0, card_width, card_height)
	envelopes = [envelope]
	for i in range(n):
		envelope = Envelope(i + 1, *map(int, sys.stdin.readline().strip().split()))
		if envelope.width > card_width and envelope.height > card_height:
			envelopes.append(envelope)
	if len(envelopes) > 1:
		envelopes.sort(key=lambda x: x.width * x.height)
		sorted_positions = [0] * len(envelopes)
		dp_max_chain = [0] * len(envelopes)
		for (i, outside) in enumerate(envelopes[1:], 1):
			max_chain_pos = max([j for (j, inside) in enumerate(envelopes[:i]) if outside.width > inside.width and outside.height > inside.height], key=lambda x: dp_max_chain[x])
			sorted_positions[i] = max_chain_pos
			dp_max_chain[i] = dp_max_chain[max_chain_pos] + 1
		max_chain = max(dp_max_chain)
		chain = []
		pos = dp_max_chain.index(max_chain)
		for _ in range(max_chain):
			chain.append(envelopes[pos].number)
			pos = sorted_positions[pos]
		sys.stdout.write(str(max_chain) + '\n')
		sys.stdout.write(' '.join(map(str, chain[::-1])) + '\n')
	else:
		sys.stdout.write('0\n')
import bisect
import functools

def sol2():
	(n, card_width, card_height) = map(int, sys.stdin.readline().strip().split())
	Envelope = collections.namedtuple('envelope', 'width height number')
	envelopes = []
	for i in range(n):
		(width, height) = map(int, sys.stdin.readline().strip().split())
		if width > card_width and height > card_height:
			envelopes.append(Envelope(width, height, i + 1))
	if envelopes:
		envelopes.sort(key=lambda x: (x[0], -x[1]))
		pile_tops = []
		indices = [0] * len(envelopes)
		for (i, envelope) in enumerate(envelopes):
			pile = bisect.bisect_left(pile_tops, envelope.height)
			if pile == len(pile_tops):
				pile_tops.append(envelope.height)
			else:
				pile_tops[pile] = envelope.height
			indices[i] = pile
		max_chain = len(pile_tops)
		sys.stdout.write(str(max_chain) + '\n')
		chain = []
		for i in range(len(envelopes) - 1, -1, -1):
			if max_chain - 1 == indices[i]:
				chain.append(envelopes[i].number)
				max_chain -= 1
				if max_chain <= 0:
					break
		sys.stdout.write(' '.join(map(str, chain[::-1])) + '\n')
	else:
		sys.stdout.write('0\n')
sol2()


(n, w, h) = map(int, input().split())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x > w and y > h:
		a.append([x, y, i + 1])
r = [1] * len(a)
p = [0] * (n + 1)
ans = 0
a.sort()
for j in range(len(a)):
	for i in range(j):
		if a[j][0] > a[i][0] and a[j][1] > a[i][1]:
			if r[j] < r[i] + 1:
				r[j] = r[i] + 1
				p[a[j][2]] = a[i][2]
	if r[j] > ans:
		ans = r[j]
		q = a[j][2]
c = []
if len(a) != 0:
	while q != 0:
		c.append(q)
		q = p[q]
c.reverse()
print(ans)
print(*c)


(n, w, h) = map(int, input().split())
A = []
for i in range(n):
	(wi, hi) = map(int, input().split())
	if wi > w and hi > h:
		A.append((wi, hi, i + 1))
A.sort()
n = len(A)
Length = [(10000000, -1)] * (n + 1)
Length[0] = (0, -1)
Before = [-1] * 5000

def bs(h):
	(beg, last) = (0, n)
	while 1:
		mid = (last + beg) // 2
		if beg + 1 >= last:
			if Length[last][0] < h:
				return last
			else:
				return beg
		if Length[mid][0] < h and Length[mid + 1][0] >= h:
			return mid
		elif Length[mid][0] > h:
			last = mid - 1
		else:
			beg = mid
i = 0
while i < n:
	start = i
	last = start + 1
	while last < n and A[last][0] == A[start][0]:
		last += 1
	for k in range(last - 1, start - 1, -1):
		h = A[k][1]
		Id = bs(h)
		if Length[Id + 1][0] > h and Length[Id][0] < h:
			Length[Id + 1] = (h, k)
			Before[k] = Length[Id][1]
	i = last
Max = 0
iMax = -1
for k in range(n, -1, -1):
	if Length[k][1] != -1:
		Max = k
		iMax = Length[k][1]
		break
print(Max)
R = [-1] * Max
while iMax != -1:
	R[Max - 1] = A[iMax][2]
	Max -= 1
	iMax = Before[iMax]
for i in R:
	print(i, end=' ')
print()


import bisect
import sys
import math
mod = 10 ** 9 + 7
input = sys.stdin.readline
t = 1
for _ in range(t):
	(n, w, h) = map(int, input().split())
	l2 = []
	for __ in range(n):
		(w1, h1) = map(int, input().split())
		if w1 > w and h1 > h:
			l2.append([w1, h1, __])
	l2.sort()
	n2 = len(l2)
	dp = [1] * (n2 + 1)
	if n2 == 0:
		print(0)
	else:
		for i in range(1, n2):
			maxi = 1
			for j in range(i):
				if l2[j][0] < l2[i][0] and l2[j][1] < l2[i][1]:
					maxi = max(maxi, dp[j] + 1)
			dp[i] = maxi
		maxi = max(dp[:])
		for i in range(n2):
			if dp[i] == maxi:
				ind = i
				break
		print(maxi)
		ans = []
		while 1:
			ans.append(l2[ind][2] + 1)
			if dp[ind] == 1:
				break
			for j in range(ind):
				if dp[j] == dp[ind] - 1 and l2[j][0] < l2[ind][0] and (l2[j][1] < l2[ind][1]):
					ind1 = j
					break
			ind = ind1
		print(*ans[::-1])


from bisect import bisect_left

def main():
	(n, card_width, card_height) = map(int, input().split())
	envelopes = list()
	add_envelope = envelopes.append
	for k in range(1, n + 1):
		(w, h) = map(int, input().split())
		if w > card_width and h > card_height:
			add_envelope((-w, h, k))
	if not envelopes:
		print(0)
		return
	envelopes.sort(reverse=True)
	available = len(envelopes)
	chosen = 0
	candidate = [0] * available
	order = [0] * available
	for (k, (_, h, _)) in enumerate(envelopes):
		position = bisect_left(order, h, hi=chosen)
		candidate[k] = position
		if position < chosen:
			order[position] = h
		else:
			order[chosen] = h
			chosen += 1
	chain = [''] * chosen
	chosen -= 1
	for k in range(available - 1, -1, -1):
		if candidate[k] == chosen:
			chain[chosen] = envelopes[k][2]
			chosen -= 1
	print(len(chain))
	if chain:
		print(*chain)
main()


(n, cw, ch) = map(int, input().split())
envs = []
for i in range(n):
	(w, h) = map(int, input().split())
	if w > cw and h > ch:
		envs.append((w, h, i + 1))
envs.sort()
l = len(envs)
if l > 0:
	adj = [[1, -1] for _ in range(l)]
	(mx, x) = (1, 0)
	for i in range(l - 2, -1, -1):
		m = 0
		for j in range(i + 1, l):
			if envs[i][0] < envs[j][0] and envs[i][1] < envs[j][1] and (adj[j][0] > m):
				m = adj[j][0]
				adj[i][0] = m + 1
				adj[i][1] = j
				if m + 1 > mx:
					mx = m + 1
					x = i
	print(mx)
	while x >= 0:
		print(envs[x][2], end=' ')
		x = adj[x][1]
else:
	print(0)


from _bisect import bisect_left
(n, a, b) = map(int, input().split())
t = []
for i in range(1, n + 1):
	(w, h) = tuple(map(int, input().split()))
	if w > a and h > b:
		t.append((w, -h, i))
t.sort()
n = len(t)
(u, v) = ([], [0] * n)
for (i, h) in enumerate((-i[1] for i in t)):
	k = bisect_left(u, h)
	v[i] = k
	if k < len(u):
		u[k] = h
	else:
		u.append(h)
k = len(u)
print(k)
d = [''] * k
k -= 1
for i in range(n - 1, -1, -1):
	if v[i] == k:
		d[k] = str(t[i][2])
		k -= 1
print(' '.join(d))


(n, w, h) = map(int, input().split())
whi = [list(map(int, input().split())) + [_ + 1] for _ in range(n)]
whi.sort(key=lambda _: _[0])
whi = list(filter(lambda _: _[0] > w and _[1] > h, whi))
whi = [(w, h, 0)] + whi
answer = [(0, 0) for _ in range(n + 1)]
n = len(whi)
for i in range(0, n):
	for j in range(i + 1, n):
		if whi[i][0] < whi[j][0] and whi[i][1] < whi[j][1] and (answer[j][0] <= answer[i][0]):
			answer[j] = (answer[i][0] + 1, i)
if len(whi) > 1:
	pos = list(map(lambda _: _[0], answer)).index(max(map(lambda _: _[0], answer)))
	depth = answer[pos][0]
	path = str(whi[pos][2])
	while answer[pos][1] != 0:
		path = str(whi[answer[pos][1]][2]) + ' ' + path
		pos = answer[pos][1]
	print(depth)
	print(path)
else:
	print(0)


import sys
input = sys.stdin.readline
(n, w, h) = map(int, input().split())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x > w and y > h:
		a.append([x, y, i + 1])
a.sort()
n = len(a)
dp = [[1, i] for i in range(n)]
for i in range(1, n):
	for j in range(i):
		if a[j][0] < a[i][0] and a[j][1] < a[i][1]:
			if dp[j][0] + 1 > dp[i][0]:
				dp[i][0] = dp[j][0] + 1
				dp[i][1] = j
m = 0
for i in range(n):
	if dp[i][0] > m:
		m = dp[i][0]
		ind = i
print(m)
ans = []
while m:
	ans.append(a[ind][-1])
	m -= 1
	ind = dp[ind][1]
print(*ans[::-1])


(n, w, h) = map(int, input().split())
ans = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x > w and y > h:
		ans.append([x, y, i + 1])
ans.sort()
dp = [1 for i in range(len(ans))]
index = [[ans[i][2]] for i in range(len(ans))]
for i in range(len(ans)):
	cover = 1
	end = -1
	for j in range(len(ans)):
		if ans[j][0] < ans[i][0] and ans[j][1] < ans[i][1]:
			if dp[j] + 1 > cover:
				cover = dp[j] + 1
				end = index[j]
	if end != -1:
		index[i] = end + index[i]
		dp[i] = len(index[i])
if len(dp) == 0:
	print(0)
	exit()
maxa = dp.index(max(dp))
print(dp[maxa])
print(*index[maxa])


class Size:

	def __init__(self, width, height, id=''):
		self._w = width
		self._h = height
		self.id = id

	def __lt__(self, other):
		return self._w < other._w and self._h < other._h

	def __str__(self):
		return '({}, {})'.format(self._w, self._h)
(num, cardWidth, cardHeight) = [int(d) for d in input().split(' ')]
cardSize = Size(cardWidth, cardHeight)
envolopes = []
for i in range(num):
	(w, h) = [int(d) for d in input().split(' ')]
	es = Size(w, h, str(i + 1))
	if cardSize < es:
		envolopes.append(es)
if len(envolopes) == 0:
	print(0)
else:
	envolopes = sorted(envolopes, key=lambda x: x._h * x._w)
	dp = [(1, -1)] * len(envolopes)
	for i in range(1, len(envolopes)):
		tmp = []
		for j in range(0, i):
			if envolopes[j] < envolopes[i]:
				tmp.append((dp[j][0], j))
		if len(tmp) > 0:
			prev = max(tmp)
			dp[i] = (prev[0] + 1, prev[1])
		else:
			dp[i] = (1, -1)
	lastNodeIdx = 0
	for i in range(1, len(dp)):
		if dp[i][0] > dp[lastNodeIdx][0]:
			lastNodeIdx = i
	chainLen = dp[lastNodeIdx][0]
	chainIds = []
	p = lastNodeIdx
	while p != -1:
		chainIds.append(envolopes[p].id)
		p = dp[p][1]
	print(chainLen)
	print(' '.join(reversed(chainIds)))


(numPackages, width_param, height_param) = map(int, input().split(' '))
first_list = list()
first_list.append([0, width_param, height_param, 0])
(max_width, max_height) = (0, 0)
for i in range(numPackages):
	(width, height) = map(int, input().split(' '))
	max_width = max(max_width, width)
	max_height = max(max_height, height)
	first_list.append([i + 1, width, height, 0])
if width_param >= max_width or height_param >= max_height:
	print(0)
else:
	sorted_pairs = sorted(first_list, key=lambda x: x[1], reverse=True)
	h = [[sorted_pairs[0]]]
	for pair in sorted_pairs[1:]:
		cond_1 = True
		j = len(h) - 1
		while j >= 0:
			if pair[2] < h[j][0][2]:
				cond_2 = True
				for g in h[j]:
					if g[1] > pair[1] and g[2] > pair[2]:
						cond_2 = False
						pair[3] = g[0]
						break
				if cond_2:
					j -= 1
					continue
				elif j + 1 < len(h):
					h[j + 1].append(pair)
					h[j + 1].sort(key=lambda x: x[2], reverse=True)
				else:
					h.append([pair])
				cond_1 = False
				break
			else:
				j -= 1
		if cond_1:
			h[0].append(pair)
			h[0].sort(key=lambda x: x[2], reverse=True)
		if pair[0] == 0:
			break
	only_most_important = first_list[0]
	result = list()
	while only_most_important[3] != 0:
		result.append(str(only_most_important[3]))
		only_most_important = first_list[only_most_important[3]]
	result_length = len(result)
	print(result_length)
	print(' '.join(result))


R = lambda : map(int, input().split())
(n, w, h) = R()
arr = []
for i in range(n):
	(wi, hi) = R()
	if wi > w and hi > h:
		arr.append((wi, hi, i))
if not arr:
	print(0)
	exit(0)
arr.sort()
ls = [0] * n
for x in arr:
	ls[x[-1]] = 1
ps = [-1] * n
for i in range(len(arr)):
	(wi, hi, idxi) = arr[i]
	for j in range(i):
		(wj, hj, idxj) = arr[j]
		if wi > wj and hi > hj and (ls[idxj] + 1 > ls[idxi]):
			ls[idxi] = ls[idxj] + 1
			ps[idxi] = idxj
idx = max(((x, i) for (i, x) in enumerate(ls)))[1]
res = []
while idx >= 0:
	res.append(idx)
	idx = ps[idx]
print(len(res))
print(' '.join(map(str, (x + 1 for x in res[::-1]))))


from bisect import bisect_left
(n, w, h) = map(int, input().split())
q = list()
for i in range(n):
	(wi, hi) = map(int, input().split())
	if wi > w and hi > h:
		q.append([wi, -hi, i])
q.sort()
n = len(q)
(u, v) = ([], [0] * n)
for (i, h) in enumerate((-i[1] for i in q)):
	g = bisect_left(u, h)
	v[i] = g
	if g < len(u):
		u[g] = h
	else:
		u.append(h)
z = len(u)
print(z)
d = [''] * z
z -= 1
for i in range(n - 1, -1, -1):
	if v[i] == z:
		d[z] = str(q[i][2] + 1)
		z -= 1
print(' '.join(d))


import sys

class Envelope:

	def __init__(self, w=0, h=0, e_id=0, pre=0, num=0):
		self.w = w
		self.h = h
		self.e_id = e_id
		self.pre = pre
		self.num = num

	def __str__(self):
		return 'Envelope: w is % s, h is % s, id is %s' % (self.w, self.h, self.e_id)

def compare(a, b):
	if a.w != b.w:
		return a.w < b.w
	else:
		return a.h < b.h

def get_envelopes():
	data = [line.rstrip().split() for line in sys.stdin.readlines()]
	data = [[int(x) for x in row] for row in data]
	n = data[0][0]
	w = data[0][1]
	h = data[0][2]
	envelopes = [Envelope()] * (n + 1)
	dp = [Envelope()] * (n + 1)
	for i in range(1, n + 1):
		wi = data[i][0]
		hi = data[i][1]
		e = Envelope(w=wi, h=hi, e_id=i)
		envelopes[i] = e
	envelopes.sort(key=lambda x: (x.w, x.h))
	for i in range(1, n + 1):
		if envelopes[i].w <= w or envelopes[i].h <= h:
			continue
		else:
			e = Envelope()
			e.w = envelopes[i].w
			e.h = envelopes[i].h
			e.num = 1
			e.pre = 0
			e.e_id = envelopes[i].e_id
			dp[i] = e
		for j in range(1, i):
			if dp[j].num > 0 and envelopes[i].w > dp[j].w and (envelopes[i].h > dp[j].h) and (dp[j].num + 1 > dp[i].num):
				dp[i].pre = j
				dp[i].num = dp[j].num + 1
				dp[i].w = envelopes[i].w
				dp[i].h = envelopes[i].h
				dp[i].e_id = envelopes[i].e_id
	maxL = 0
	i_d = 0
	for i in range(1, n + 1):
		if dp[i].num > maxL:
			maxL = dp[i].num
			i_d = i
	print(maxL)
	ans = []
	while i_d != 0:
		ans.append(dp[i_d].e_id)
		i_d = dp[i_d].pre
	ans.reverse()
	print(*ans)
get_envelopes()


import bisect
import sys

def create_envelope_chain(envelopes):
	envelopes.sort(reverse=True)
	env_all = len(envelopes)
	dp = [0]
	index = [0] * env_all
	for i in range(env_all):
		envelope_height = envelopes[i][1]
		candidate_pos = bisect.bisect_left(dp, envelope_height)
		if candidate_pos >= len(dp):
			dp.append(envelope_height)
		else:
			dp[candidate_pos] = envelope_height
		index[i] = candidate_pos
	chain = []
	env_chosen = len(dp) - 1
	for i in range(env_all - 1, -1, -1):
		if index[i] == env_chosen:
			chain.append(envelopes[i][2])
			env_chosen -= 1
	return chain[::-1]

def get_fitting_envelopes(envelopes, card_width, card_height):
	fitting_envelopes = []
	it = 1
	for line in envelopes:
		(env_width, env_height) = map(int, line.split())
		if card_height < env_height and card_width < env_width:
			fitting_envelopes.append((-env_width, env_height, it))
		it += 1
	return fitting_envelopes

def main(sinp=sys.stdin, sout=sys.stdout):
	(n, card_width, card_height) = map(int, sinp.readline().split())
	fitting_envelopes = get_fitting_envelopes(sinp, card_width, card_height)
	if not fitting_envelopes:
		sout.write('0')
		return
	envelopes_chain = create_envelope_chain(fitting_envelopes)
	sout.write('{0}\n'.format(len(envelopes_chain)))
	sout.write(' '.join(map(str, envelopes_chain)))
main()


import sys

def get_ints():
	return map(int, sys.stdin.readline().split())
(n, w, h) = get_ints()
A = []
for i in range(n):
	(x, y) = get_ints()
	if x > w and y > h:
		A.append([x, y, i + 1])
A = sorted(A, key=lambda x: (x[0], x[1]))
n1 = len(A)
if n1 == 0:
	print(0)
elif n1 == 1:
	print(1)
	print(A[0][2])
else:
	dp = [1] * n1
	a = [0] * n1
	for i in range(0, n1):
		a1 = []
		a11 = -1
		for j in range(i - 1, -1, -1):
			if A[i][0] > A[j][0] and A[i][1] > A[j][1]:
				if dp[i] < dp[j] + 1:
					dp[i] = dp[j] + 1
					a11 = j
		if a11 > -1:
			for kkk in a[a11]:
				a1.append(kkk)
		a1.append(A[i][2])
		a[i] = a1
	maxx = 0
	for i in range(n1):
		if dp[i] > maxx:
			maxx = dp[i]
			ind = i
	print(dp[ind])
	for k in a[ind]:
		print(k, end=' ')


import sys
firstline = sys.stdin.readline().split()
n = int(firstline[0])
w = int(firstline[1])
h = int(firstline[2])
envelopes = [(w, h)]
locations = {(w, h): 0}
for i in range(n):
	e = tuple(map(int, sys.stdin.readline().split()))
	if e[0] > w and e[1] > h:
		locations[e] = i + 1
		envelopes.append(e)
envelopes.sort()
dp_lengths = [0] * len(envelopes)
dp_nexts = [None] * len(envelopes)
for i in reversed(range(len(envelopes))):
	for j in range(i + 1, len(envelopes)):
		if envelopes[j][0] > envelopes[i][0] and envelopes[j][1] > envelopes[i][1]:
			if dp_lengths[j] + 1 >= dp_lengths[i]:
				dp_lengths[i] = dp_lengths[j] + 1
				dp_nexts[i] = j
print(dp_lengths[0])
current = dp_nexts[0]
while current:
	print(locations[envelopes[current]], end=' ')
	current = dp_nexts[current]


__author__ = 'Darren'

def solve():
	import sys
	stdin = sys.stdin if True else open('data')
	(n, *card) = map(int, next(stdin).split())
	envelopes = []
	for i in range(n):
		(width, height) = map(int, next(stdin).split())
		if width <= card[0] or height <= card[1]:
			continue
		envelopes.append((width, height, i + 1))
	if not envelopes:
		print(0)
		return
	envelopes.sort()
	n = len(envelopes)
	chain_length = [1 for i in range(n)]
	last_envelop = [-1 for i in range(n)]
	max_chain_length = 0
	max_chain_index = -1
	for i in range(n):
		for j in range(i - 1, -1, -1):
			if larger(envelopes[i], envelopes[j]) and chain_length[j] + 1 > chain_length[i]:
				chain_length[i] = chain_length[j] + 1
				last_envelop[i] = j
		if chain_length[i] > max_chain_length:
			max_chain_length = chain_length[i]
			max_chain_index = i
	print(max_chain_length)
	envelope_sequence = []
	while max_chain_index >= 0:
		envelope_sequence.append(str(envelopes[max_chain_index][2]))
		max_chain_index = last_envelop[max_chain_index]
	envelope_sequence.reverse()
	print(' '.join(envelope_sequence))

def solve1():
	import sys
	stdin = sys.stdin if True else open('data')
	(n, *card) = map(int, next(stdin).split())
	envelopes = []
	for i in range(n):
		(width, height) = map(int, next(stdin).split())
		if width <= card[0] or height <= card[1]:
			continue
		envelopes.append((width, height, i + 1))
	if not envelopes:
		print(0)
		return
	envelopes.sort(key=lambda x: (x[0], -x[1]))
	n = len(envelopes)
	dp = []
	d = [0 for i in range(n)]
	from bisect import bisect_left
	for (i, envelope) in enumerate(envelopes):
		insert_index = bisect_left(dp, envelope[1])
		d[i] = insert_index
		if insert_index < len(dp):
			dp[insert_index] = envelope[1]
		else:
			dp.append(envelope[1])
	l = len(dp)
	print(l)
	envelope_sequence = []
	for i in range(n - 1, -1, -1):
		if d[i] == l - 1:
			envelope_sequence.append(str(envelopes[i][2]))
			l -= 1
			if l <= 0:
				break
	envelope_sequence.reverse()
	print(' '.join(envelope_sequence))

def larger(env1, env2):
	return env1[0] > env2[0] and env1[1] > env2[1]
solve1()


class Envelope:

	def __init__(self, w, h, i):
		self.w = w
		self.h = h
		self.i = i
		self.a = w * h
(n, w, h) = list(map(int, input().split()))
card = Envelope(w, h, -1)
envs = []
for i in range(n):
	(w, h) = list(map(int, input().split()))
	envs.append(Envelope(w, h, i))
envs = sorted(envs, key=lambda env: env.a)
fits = lambda e1, e2: e1.h < e2.h and e1.w < e2.w
dp = [0 for _ in range(n)]
parents = {}
for i in range(n):
	if envs[i].a < card.a:
		continue
	if fits(card, envs[i]):
		maxEnvs = 1
		maxIdx = -1
		for j in range(i):
			if fits(envs[j], envs[i]) and dp[j] + 1 > maxEnvs:
				maxEnvs = dp[j] + 1
				maxIdx = j
		dp[i] = maxEnvs
		parents[i] = maxIdx
maxEnvs = 0
maxIdx = -1
for i in range(n):
	if dp[i] > maxEnvs:
		maxEnvs = dp[i]
		maxIdx = i
print(maxEnvs)
idxs = []
while maxIdx != -1:
	idxs.append(envs[maxIdx].i + 1)
	maxIdx = parents[maxIdx]
while len(idxs) > 0:
	print(idxs.pop(), end=' ')
print()


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
(n, w, h) = map(int, input().split())
l = []
for i in range(n):
	t = list(map(int, input().split()))
	l.append(t + [i + 1])
l.sort()
z = [0 for i in range(n)]
for i in range(n - 1, -1, -1):
	if l[i][0] > w and l[i][1] > h:
		ma = 0
		for j in range(i + 1, n):
			if l[j][0] > l[i][0] and l[j][1] > l[i][1]:
				ma = max(ma, z[j])
		z[i] = ma + 1
	else:
		z[i] = -1
t = max(z)
if t == -1:
	print(0)
else:
	ans = []
	prev = -1
	for i in range(n):
		if z[i] == t:
			if prev == -1:
				t -= 1
				prev = i
				ans.append(l[i][2])
			elif l[prev][0] < l[i][0] and l[prev][1] < l[i][1]:
				t -= 1
				prev = i
				ans.append(l[i][2])
	print(len(ans))
	print(*ans)


import sys
from array import array
from typing import List, Tuple, TypeVar, Generic, Sequence

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
T = TypeVar('T')

class FenwickMax(Generic[T]):
	__slots__ = ['nodes', 'size', 'unit']

	def __init__(self, size: int, default: T, unit: T=-10 ** 9):
		self.nodes = [default] * (size + 1)
		self.size = size + 1
		self.unit = unit

	def update(self, index: int, value: T):
		while index < self.size:
			if self.nodes[index] < value:
				self.nodes[index] = value
			index += index & -index

	def find(self, right: int) -> T:
		result = self.unit
		while right:
			if result < self.nodes[right]:
				result = self.nodes[right]
			right -= right & -right
		return result
(n, W, H) = map(int, input().split())
cards = sorted((tuple(map(int, input().split())) + (i,) for i in range(1, n + 1)), key=lambda x: (x[0], -x[1]))
fenwick = FenwickMax[Tuple[int, int]](10 ** 6 + 100, (0, -1), (0, -1))
prev = [-1] * (n + 1)
for (w, h, i) in cards:
	if W >= w or H >= h:
		continue
	(nest, from_i) = fenwick.find(h - 1)
	prev[i] = from_i
	fenwick.update(h, (nest + 1, i))
(_, i) = fenwick.find(10 ** 6 + 100)
ans = []
while i != -1:
	ans.append(i)
	i = prev[i]
print(len(ans))
if ans:
	print(*reversed(ans))


def main():
	(n, w, h) = map(int, input().split())
	cards = []
	for i in range(n):
		(wi, hi) = map(int, input().split())
		if wi > w and hi > h:
			cards.append((wi, hi, i + 1))
	cards.sort()
	if not cards:
		print(0)
		return
	ans = []
	dp = [1] * len(cards)
	backpointer = [-1] * len(cards)
	for i in range(1, len(cards)):
		(w1, h1) = (cards[i][0], cards[i][1])
		for j in range(i):
			(w2, h2) = (cards[j][0], cards[j][1])
			if w2 < w1 and h2 < h1:
				if dp[j] + 1 > dp[i]:
					dp[i] = max(dp[i], dp[j] + 1)
					backpointer[i] = j
	index = dp.index(max(dp))
	while index >= 0:
		ans.append(cards[index][2])
		index = backpointer[index]
	ans.reverse()
	print(len(ans))
	for i in ans:
		print(i, end=' ')
main()


def contains(a, b):
	if a[0] > b[0] and a[1] > b[1]:
		return True
	return False
(n, w, h) = map(int, input().split(' '))
postcard = (w, h)
envelopes = []
for _ in range(n):
	(w, h) = map(int, input().split(' '))
	envelopes += [(w, h)]
eh = sorted(enumerate(envelopes), key=lambda p: p[1])
envelopes = [e[1] for e in eh]
indices = [e[0] + 1 for e in eh]
chain = [-1] * n
max_envelopes = [0] * n
for (i, e1) in enumerate(envelopes):
	if not contains(e1, postcard):
		continue
	for (j, e2) in enumerate(envelopes[:i]):
		if contains(e1, e2) and max_envelopes[i] < max_envelopes[j]:
			max_envelopes[i] = max_envelopes[j]
			chain[i] = j
	max_envelopes[i] += 1
(max_index, max_value) = max(enumerate(max_envelopes), key=lambda p: p[1])
print(max_value)
i = max_index
if max_value > 0:
	out = [indices[i]]
	while chain[i] != -1:
		out += [indices[chain[i]]]
		i = chain[i]
	out.reverse()
	print(' '.join(map(str, out)))


(n, w, h) = [int(x) for x in input().split()]
data = []
for i in range(1, n + 1):
	(wd, ht) = [int(x) for x in input().split()]
	if wd > w and ht > h:
		data.append([wd, ht, i])
data.sort()
rem = len(data)
if rem == 0:
	print(0)
else:
	from collections import defaultdict as dd
	lis = [1 for i in range(rem)]
	prev = dd(int)
	for i in range(1, rem):
		for j in range(i):
			if (data[i][0] > data[j][0] and data[i][1] > data[j][1]) and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
				prev[data[i][2]] = data[j][2]
	ln = max(lis)
	ele = lis.index(ln)
	chain = [data[ele][2]]
	ele = chain[-1]
	while prev[ele] != 0:
		ele = prev[chain[-1]]
		chain.append(ele)
	print(ln)
	print(*chain[::-1])


cards = []
(a, w, h) = map(int, input().split(' '))
for i in range(a):
	(w1, h1) = map(int, input().split(' '))
	if w < w1 and h < h1:
		cards.append([w1, h1, i + 1])
if len(cards) == 0:
	print(0)
	quit()
cards.sort()
rem = len(cards)
dp = [1] * rem
seq = [[cards[_][2]] for _ in range(rem)]
for i in range(rem):
	best = 1
	add = -1
	for j in range(i):
		if cards[j][0] < cards[i][0] and cards[j][1] < cards[i][1]:
			if dp[j] + 1 > best:
				best = dp[j] + 1
				add = seq[j]
	if add != -1:
		dp[i] = best
		seq[i] = add + seq[i]
m = 0
finalseq = []
for i in range(rem):
	if dp[i] > m:
		finalseq = seq[i]
		m = dp[i]
print(m)
print(' '.join([str(x) for x in finalseq]))


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, W, H, A):
	A = [(w, h, i) for (i, (w, h)) in enumerate(A) if w > W and h > H]
	A.sort()
	N = len(A)
	if N <= 0:
		return (0, [])
	dp = [1 for _ in range(N)]
	pre = [-1 for _ in range(N)]
	dp[0] = 1
	(maxsize, maxi) = (1, 0)
	for i in range(1, N):
		for j in range(i):
			if A[j][0] < A[i][0] and A[j][1] < A[i][1]:
				if dp[j] + 1 > dp[i]:
					dp[i] = dp[j] + 1
					pre[i] = j
		if dp[i] > maxsize:
			maxsize = dp[i]
			maxi = i
	path = []
	i = maxi
	while i >= 0:
		path.append(A[i][2] + 1)
		i = pre[i]
	return (maxsize, path[::-1])
(N, W, H) = map(int, input().split())
A = []
for i in range(N):
	(w, h) = map(int, input().split())
	A.append((w, h))
(c, p) = solve(N, W, H, A)
print(c)
if c > 0:
	print(' '.join(map(str, p)))


def solution(a):
	if len(a) <= 1:
		return a
	dp = [1] * len(a)
	back = {}
	maxval = 0
	for j in range(len(a)):
		for i in range(j):
			if a[i][0] < a[j][0] and a[i][1] < a[j][1]:
				if dp[i] + 1 > dp[j]:
					dp[j] = dp[i] + 1
					back[j] = i
				maxval = max(maxval, dp[j])
	j = 0
	for i in range(len(dp)):
		if dp[i] == maxval:
			j = i
			break
	res = []
	while j in back:
		res.append(a[j])
		j = back[j]
	res.append(a[j])
	return res[::-1]
(N, W, H) = input().split()
cnt = 1
dic = {}
res = []
for _ in range(int(N)):
	(w, h) = input().split()
	if int(W) < int(w) and int(H) < int(h):
		res.append([int(w), int(h)])
		dic[int(w), int(h)] = cnt
	cnt += 1
res = sorted(res, key=lambda x: (x[0], x[1]))
li = solution(res)
if not li:
	print(0)
else:
	print(len(li))
	for (x, y) in li:
		print(dic[x, y], end=' ')


(n, w, h) = map(int, input().split())
g = []
for i in range(n):
	g.append(list(map(int, input().split())) + [i])
g.sort()
dp = [0] * n
par = [-1] * n
for i in range(n):
	if g[i][0] > w and g[i][1] > h:
		dp[i] = 1
for i in range(n):
	for j in range(i):
		if g[i][0] > g[j][0] and g[i][1] > g[j][1] and (g[j][0] > w) and (g[j][1] > h) and (dp[j] + 1 > dp[i]):
			par[i] = j
			dp[i] = dp[j] + 1
mx = 0
for i in range(n):
	if dp[i] > dp[mx]:
		mx = i
res = []
print(dp[mx])
for i in range(dp[mx]):
	res.append(g[mx][2])
	mx = par[mx]
res = reversed(res)
for i in res:
	print(i + 1, end=' ')


[n, W, H] = [int(a) for a in input().split(' ')]
arr = []
for i in range(n):
	[w, h] = [int(a) for a in input().split(' ')]
	arr.append((w, h, i, 0, 0))
arr.sort()
arr.append((10000000, 10000000, n, 0, 0))
cnt = 0
for i in range(n + 1):
	(w, h, x, a, pre) = arr[i]
	a = 0
	pre = -1
	if W < w and H < h:
		a = 1
	cnt1 = 0
	for j in arr:
		if cnt == cnt1:
			break
		(w1, h1, x0, a0, t) = j
		if a0 > 0 and a < a0 + 1 and (w1 < w) and (h1 < h):
			a = a0 + 1
			pre = cnt1
		cnt1 += 1
	cnt += 1
	arr[i] = (w, h, x, a, pre)
print(arr[-1][3] - 1)
idx = len(arr) - 1
l = []
for i in range(arr[-1][3] - 1):
	idx = arr[idx][4]
	l.append(str(arr[idx][2] + 1))
l.reverse()
print(' '.join(l))


from _bisect import bisect_left
(n, w, h) = map(int, input().split())
A = []
for i in range(1, n + 1):
	(w1, h1) = map(int, input().split())
	if w1 > w and h1 > h:
		A.append([w1, -h1, i])
A.sort()
n = len(A)
(u, v) = ([], [0] * n)
for i in range(n):
	h2 = -A[i][1]
	k = bisect_left(u, h2)
	v[i] = k
	if k < len(u):
		u[k] = h2
	else:
		u.append(h2)
dem = len(u)
dt = [0] * dem
print(dem)
dem -= 1
for i in range(n - 1, -1, -1):
	if v[i] == dem:
		dt[dem] = str(A[i][2])
		dem -= 1
print(' '.join(dt))


from collections import defaultdict
from sys import stdin

def fits(element, cover):
	return element[0] < cover[0] and element[1] < cover[1]

def main():
	data = stdin.readline().strip()
	(n, pc_w, pc_h) = map(int, data.split())
	pc = (pc_w, pc_h)
	envelopes = {}
	for i in range(n):
		envelope = tuple(map(int, stdin.readline().strip().split()))
		envelopes[envelope] = i + 1
	suitable_envelopes = [x for x in sorted(envelopes.keys()) if fits(pc, x)]
	if len(suitable_envelopes) < 1:
		print(0)
		exit(0)
	max_distances = [(1, None)] * len(suitable_envelopes)
	longest_chain_head = suitable_envelopes[0]
	max_distance = 0
	for (i, envelope) in enumerate(suitable_envelopes):
		for j in range(i):
			if fits(suitable_envelopes[j], envelope) and max_distances[j][0] + 1 > max_distances[i][0]:
				max_distances[i] = (max_distances[j][0] + 1, j)
				if max_distances[i][0] > max_distance:
					max_distance = max_distances[i][0]
					longest_chain_head = envelope
	next_index = max(max_distances, key=lambda x: x[0])[1]
	chain = [longest_chain_head]
	while next_index is not None:
		chain.append(suitable_envelopes[next_index])
		next_index = max_distances[next_index][1]
	longest_chain = [envelopes[x] for x in reversed(chain)]
	print(len(longest_chain))
	print(' '.join(map(str, longest_chain)))
main()


(n, w, h) = list(map(int, input().split()))
x = []
for i in range(n):
	(a, b) = map(int, input().split())
	x.append((a, b, i + 1))
x.sort()
dp = [0] * (n + 1)
p = [-1] * (n + 1)
found = False
for i in range(n):
	if x[i][0] > w and x[i][1] > h:
		dp[i] = 1
		found = True
	for j in range(i):
		if dp[j] and x[i][0] > x[j][0] and (x[i][1] > x[j][1]) and (dp[j] + 1 > dp[i]):
			dp[i] = dp[j] + 1
			p[i] = j
if not found:
	print(0)
	exit(0)
anw = []
m = 0
for i in range(n):
	if dp[i] > dp[m]:
		m = i
while p[m] != -1:
	anw.append(x[m][2])
	m = p[m]
anw.append(x[m][2])
print(len(anw))
for x in anw[::-1]:
	print(x, end=' ')


from operator import itemgetter
(n, w, h) = [int(x) for x in input().strip().split()]
obj = []
for i in range(n):
	(u, v) = [int(x) for x in input().strip().split()]
	if u > w and v > h:
		e = (u, v, i)
		obj.append(e)
obj = sorted(obj, key=itemgetter(1, 0))
n = len(obj)
sum = [0 for i in range(n)]
next = [-1 for i in range(n)]
for i in range(n - 1, -1, -1):
	for j in range(i + 1, n):
		if obj[j][0] > obj[i][0] and obj[j][1] > obj[i][1] and (sum[j] + 1 > sum[i]):
			sum[i] = sum[j] + 1
			next[i] = j
ans = 0
ans_ind = -1
for i in range(n):
	if sum[i] >= ans:
		ans = sum[i]
		ans_ind = i
if ans_ind == -1:
	print(0)
else:
	print(ans + 1)
	while ans_ind != -1:
		print(obj[ans_ind][2] + 1, end=' ')
		ans_ind = next[ans_ind]


def lis(arr):
	n = len(arr)
	lis = [1] * n
	back = []
	for i in range(0, n):
		back.append(i)
	for i in range(1, n):
		for j in range(0, i):
			if arr[i][0] > arr[j][0] and arr[i][1] > arr[j][1] and (lis[i] < lis[j] + 1):
				lis[i] = lis[j] + 1
				back[i] = j
	maximum = 0
	ptr = 0
	for i in range(n):
		if maximum < lis[i]:
			ptr = i
		maximum = max(maximum, lis[i])
	ans = []
	while ptr != back[ptr]:
		ans.append(arr[ptr][2] + 1)
		ptr = back[ptr]
	ans.append(arr[ptr][2] + 1)
	ans = ans[::-1]
	return ans
(n, w, h) = map(int, input().split())
L = []
for i in range(n):
	(wi, hi) = map(int, input().split())
	if wi > w and hi > h:
		L.append((wi, hi, i))
L.sort()
if len(L) == 0:
	print(0)
else:
	ans = lis(L)
	print(len(ans))
	print(*ans)


def lis(arr):
	n = len(arr)
	lis = [1] * n
	back = []
	for i in range(0, n):
		back.append(i)
	for i in range(1, n):
		for j in range(0, i):
			if arr[i][0] > arr[j][0] and arr[i][1] > arr[j][1] and (lis[i] < lis[j] + 1):
				lis[i] = lis[j] + 1
				back[i] = j
	maximum = 0
	ptr = 0
	for i in range(n):
		if maximum < lis[i]:
			ptr = i
		maximum = max(maximum, lis[i])
	ans = []
	while ptr != back[ptr]:
		ans.append(arr[ptr][2] + 1)
		ptr = back[ptr]
	ans.append(arr[ptr][2] + 1)
	ans = ans[::-1]
	return ans
(n, w, h) = map(int, input().split())
L1 = []
L2 = []
pos = [0] * (n + 1)
kk = dict()
for i in range(n):
	(wi, hi) = map(int, input().split())
	if wi > w and hi > h and (kk.get((wi, hi)) == None):
		L1.append((wi, hi, i))
	kk[wi, hi] = 1
L1.sort()
if len(L1) == 0:
	print(0)
else:
	ans = lis(L1)
	print(len(ans))
	print(*ans)


(n, max_width, max_height) = map(int, input().split())
array_w_h_i = list()
array_w_h_i.append([max_width, max_height, 0])
for i in range(n):
	(width, height) = map(int, input().split())
	if width > max_width and height > max_height:
		array_w_h_i.append([width, height, i + 1])
array_w_h_i.sort()
length = len(array_w_h_i)
lis = [0] * length
path = [0] * (n + 1)
lis_answer = 0
idx = 0
for i in range(1, length):
	for j in range(0, i):
		if array_w_h_i[i][0] > array_w_h_i[j][0] and array_w_h_i[i][1] > array_w_h_i[j][1]:
			if lis[j] + 1 > lis[i]:
				lis[i] = lis[j] + 1
				path[array_w_h_i[i][2]] = array_w_h_i[j][2]
			if lis[i] > lis_answer:
				lis_answer = lis[i]
				idx = array_w_h_i[i][2]
print(lis_answer)
s = []
while idx > 0:
	s.append(idx)
	idx = path[idx]
print(' '.join((str(i) for i in s[::-1])))


from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import heapq
(n, w, h) = stdin.readline().strip().split(' ')
(n, w, h) = (int(n), int(w), int(h))
arr = []
for i in range(n):
	(wi, hi) = stdin.readline().strip().split(' ')
	wi = int(wi)
	hi = int(hi)
	if wi > w and hi > h:
		arr.append((wi, hi, i))
n = len(arr)
if n == 0:
	stdout.write('0\n')
else:
	arr = sorted(arr, key=lambda e: e[1])
	lis = [1 for i in range(n)]
	lisselect = [None for i in range(n)]
	for i in range(n):
		for j in range(i):
			if arr[j][0] < arr[i][0] and arr[j][1] != arr[i][1] and (lis[j] + 1 > lis[i]):
				lis[i] = lis[j] + 1
				lisselect[i] = j
	slis = max(lis)
	sel = None
	for i in range(len(lis)):
		if lis[i] == slis:
			sel = i
	stdout.write(str(slis) + '\n')
	tarr = []
	while sel != None:
		tarr.append(arr[sel][2] + 1)
		sel = lisselect[sel]
	tarr = tarr[::-1]
	for i in tarr:
		stdout.write(str(i) + ' ')


(n, w, h) = [int(j) for j in input().split()]
e = list()
e.append([0, w, h, 0])
(mwi, mhi) = (0, 0)
for i in range(n):
	(wi, hi) = [int(j) for j in input().split()]
	mwi = max(mwi, wi)
	mhi = max(mhi, hi)
	e.append([i + 1, wi, hi, 0])
if w >= mwi or h >= mhi:
	print(0)
	exit()
s = sorted(e, key=lambda x: x[1], reverse=True)
h = [[s[0]]]
for u in s[1:]:
	f = True
	j = len(h) - 1
	while j >= 0:
		if u[2] < h[j][0][2]:
			fg = True
			for g in h[j]:
				if g[1] > u[1] and g[2] > u[2]:
					fg = False
					u[3] = g[0]
					break
			if fg:
				j -= 1
				continue
			if j + 1 < len(h):
				h[j + 1].append(u)
				h[j + 1].sort(key=lambda x: x[2], reverse=True)
			else:
				h.append([u])
			f = False
			break
		else:
			j -= 1
	if f:
		h[0].append(u)
		h[0].sort(key=lambda x: x[2], reverse=True)
	if u[0] == 0:
		break
t = e[0]
res = list()
while t[3] != 0:
	res.append(str(t[3]))
	t = e[t[3]]
print(len(res))
print(' '.join(res))


import random, math, sys, os, heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from io import BytesIO, IOBase
input = sys.stdin.readline

def solution(cards, n):
	if not n:
		return []
	cards.sort(key=lambda x: x[0])
	LIS = [1] * n
	LIS_val = [0] * n
	for i in range(n):
		par = i + 1 - 1
		for j in range(i):
			if cards[i][0] > cards[j][0] and cards[i][1] > cards[j][1]:
				if LIS[j] + 1 > LIS[i]:
					par = j + 1 - 1
				LIS[i] = max(LIS[i], LIS[j] + 1)
		LIS_val[i] = par + 1 - 1
	indi = LIS.index(max(LIS))
	out = []
	while indi != LIS_val[indi]:
		out.append(cards[indi][2])
		indi = LIS_val[indi]
	out.append(cards[indi][2])
	out.reverse()
	return out

def input_test():
	(n, cw, ch) = map(int, input().strip().split(' '))
	cards = []
	leng = 0
	for i in range(1, n + 1):
		(w, h) = map(int, input().strip().split(' '))
		if w > cw and h > ch:
			cards.append([w, h, i])
			leng += 1
	out = solution(cards, leng)
	if not out:
		print(0)
		return
	print(len(out))
	print(' '.join(map(str, out)))

def test():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
input_test()


(N, w, h) = [int(_) for _ in input().split()]
envs = []
for i in range(1, N + 1):
	env = [int(_) for _ in input().split()]
	if env[0] <= w or env[1] <= h:
		continue
	envs.append([env[0], env[1], i])
for env in envs:
	env[1] = -env[1]
envs.sort()
cnt = 0
import sys
dp = [sys.maxsize] * len(envs)
records = [[] for _ in range(len(envs))]
import bisect
for i in range(len(envs)):
	idx = bisect.bisect_left(dp, -envs[i][1])
	if idx == cnt:
		cnt += 1
	dp[idx] = -envs[i][1]
	records[idx].append(i)
res = []
idx = sys.maxsize
for i in range(cnt - 1, -1, -1):
	while records[i][-1] > idx:
		records[i].pop(-1)
	idx = records[i][-1]
	res.append(str(envs[records[i][-1]][-1]))
print(cnt)
print(' '.join(res[::-1]))


from collections import namedtuple
Node = namedtuple('Node', 'i w h area')
FORMER_INDEX = 0
CHAIN_COUNT = 1
(N, ew, eh) = tuple(map(int, input().split()))
env = []
for i in range(N):
	(w, h) = tuple(map(int, input().split()))
	if w > ew and h > eh:
		env.append([-1, 1, Node(i + 1, w, h, w * h)])
if len(env) == 0:
	print(0)
	exit()
env.sort(key=lambda t: t[2].area)
minchild = env[0][2]
for i in range(1, len(env)):
	curr = env[i][2]
	maxj = -1
	maxcount = -1
	for j in range(i - 1, -1, -1):
		child = env[j][2]
		child_chaincount = env[j][CHAIN_COUNT]
		if curr.w > child.w and curr.h > child.h and (child_chaincount > maxcount):
			maxj = j
			maxcount = child_chaincount
	if maxj >= 0:
		env[i][FORMER_INDEX] = maxj
		env[i][CHAIN_COUNT] += maxcount
maxcount = 0
maxidx = -1
for i in range(len(env)):
	if env[i][CHAIN_COUNT] > maxcount:
		maxcount = env[i][CHAIN_COUNT]
		maxidx = i
chain = [maxidx]
nextidx = env[maxidx][FORMER_INDEX]
while nextidx >= 0:
	curridx = nextidx
	chain.append(curridx)
	nextidx = env[curridx][FORMER_INDEX]
print(maxcount)
print(' '.join([str(env[e][2].i) for e in chain[::-1]]))


import functools
(n, w, h) = [int(x) for x in input().split(' ')]
(widths, heights) = ([], [])
indices = list(range(n))
paths = [-1] * n
M = [1] * n
for envelope in range(n):
	(w_e, h_e) = [int(x) for x in input().split(' ')]
	widths.append(w_e)
	heights.append(h_e)

def valid(a, b, c, d):
	return a < c and b < d
indices = sorted(indices, key=lambda x: widths[x] * heights[x], reverse=True)
for i in range(1, n):
	x = indices[i]
	for j in range(i):
		y = indices[j]
		if valid(widths[x], heights[x], widths[y], heights[y]):
			if M[j] + 1 > M[i]:
				M[i] = M[j] + 1
				paths[i] = j
(max_chain, max_idx) = (0, -1)
for i in range(n):
	x = indices[i]
	if valid(w, h, widths[x], heights[x]) and M[i] > max_chain:
		(max_chain, max_idx) = (M[i], i)
print(max_chain)
if max_idx != -1:
	chain = []
	i = max_idx
	while paths[i] != -1:
		print(indices[i] + 1, end=' ')
		i = paths[i]
	print(indices[i] + 1)