You are given $n$ pairs of integers $(a_1, b_1), (a_2, b_2), \ldots, (a_n, b_n)$. All of the integers in the pairs are distinct and are in the range from $1$ to $2 \cdot n$ inclusive.

Let's call a sequence of integers $x_1, x_2, \ldots, x_{2k}$ good if either   $x_1 < x_2 > x_3 < \ldots < x_{2k-2} > x_{2k-1} < x_{2k}$, or  $x_1 > x_2 < x_3 > \ldots > x_{2k-2} < x_{2k-1} > x_{2k}$. 

You need to choose a subset of distinct indices $i_1, i_2, \ldots, i_t$ and their order in a way that if you write down all numbers from the pairs in a single sequence (the sequence would be $a_{i_1}, b_{i_1}, a_{i_2}, b_{i_2}, \ldots, a_{i_t}, b_{i_t}$), this sequence is good.

What is the largest subset of indices you can choose? You also need to construct the corresponding index sequence $i_1, i_2, \ldots, i_t$.


-----Input-----

The first line contains single integer $n$ ($2 \leq n \leq 3 \cdot 10^5$) — the number of pairs.

Each of the next $n$ lines contain two numbers — $a_i$ and $b_i$ ($1 \le a_i, b_i \le 2 \cdot n$) — the elements of the pairs.

It is guaranteed that all integers in the pairs are distinct, that is, every integer from $1$ to $2 \cdot n$ is mentioned exactly once.


-----Output-----

In the first line print a single integer $t$ — the number of pairs in the answer.

Then print $t$ distinct integers $i_1, i_2, \ldots, i_t$ — the indexes of pairs in the corresponding order.


-----Examples-----
Input
5
1 7
6 4
2 10
9 8
3 5

Output
3
1 5 3

Input
3
5 4
3 2
6 1

Output
3
3 2 1



-----Note-----

The final sequence in the first example is $1 < 7 > 3 < 5 > 2 < 10$.

The final sequence in the second example is $6 > 1 < 3 > 2 < 5 > 4$.

Difficulty: MEDIUM_HARD
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
def solve():
	n = int(input())
	sm = []
	bg = []
	for i in range(n):
		(a, b) = map(int, input().split())
		if a < b:
			sm.append((b, i + 1))
		else:
			bg.append((b, i + 1))
	if len(sm) > len(bg):
		sm.sort(reverse=True)
		print(len(sm))
		for i in range(len(sm)):
			print(sm[i][1], end=' ')
	else:
		print(len(bg))
		bg.sort()
		for i in range(len(bg)):
			print(bg[i][1], end=' ')

def main():
	solve()
main()


n = int(input())
a = []
b = []
for i in range(n):
	f = list(map(int, input().split())) + [i + 1]
	if f[0] < f[1]:
		a += [f]
	else:
		b += [f]
a.sort(key=lambda x: x[1], reverse=True)
b.sort(key=lambda x: x[1])
if len(a) < len(b):
	a = b
print(len(a))
print(' '.join((str(i[2]) for i in a)))


nb_pairs = int(input())
(bigger, smaller) = ([], [])
for i in range(nb_pairs):
	b = [int(a) for a in input().split()]
	if b[0] > b[1]:
		bigger.append(b + [i + 1])
	else:
		smaller.append(b + [i + 1])
if len(bigger) > len(smaller):
	ans = sorted(bigger)
else:
	ans = sorted(smaller, reverse=True)
print(len(ans))
print(*[x[2] for x in ans])


n = int(input())
v = []
u = []
for i in range(n):
	x = input().split(' ')
	a = int(x[0])
	b = int(x[1])
	if a > b:
		v.append((a, b, i + 1))
	else:
		u.append((a, b, i + 1))
if len(u) > len(v):
	u = sorted(u, key=lambda x: x[1], reverse=True)
	print(len(u))
	sol = []
	for i in range(len(u)):
		sol.append(str(u[i][2]))
	print(' '.join(sol))
else:
	v = sorted(v, key=lambda x: x[1], reverse=False)
	print(len(v))
	sol = []
	for i in range(len(v)):
		sol.append(str(v[i][2]))
	print(' '.join(sol))


from functools import cmp_to_key

def chave1(v1, v2):
	if v1[1] < v2[0]:
		return 1
	else:
		return -1

def chave2(v1, v2):
	if v1[1] > v2[0]:
		return 1
	else:
		return -1
lista_geral = []
indice = 1
for i in range(int(input())):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	lista_geral.append((a, b, indice))
	indice += 1
lista1 = [e for e in lista_geral if e[0] < e[1]]
lista2 = [e for e in lista_geral if e[0] > e[1]]
lista1.sort(key=cmp_to_key(chave1))
lista2.sort(key=cmp_to_key(chave2))
if len(lista1) > len(lista2):
	print(len(lista1))
	[print(e[2], '', end='') for e in lista1]
else:
	print(len(lista2))
	[print(e[2], '', end='') for e in lista2]


import sys
from bisect import bisect_left
input = sys.stdin.readline

def ii():
	return int(input())

def mi():
	return map(int, input().rstrip().split())

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

def li():
	return list(input().rstrip())
n = ii()
cnta = 0
cntb = 0
lista = []
listb = []
for i in range(n):
	(a, b) = mi()
	if a > b:
		cntb += 1
		listb.append((a, b, i + 1))
	else:
		cnta += 1
		lista.append((a, b, i + 1))
if cnta >= cntb:
	lista.sort(key=lambda x: x[0], reverse=True)
	print(len(lista))
	for i in lista:
		print(i[2], end=' ')
	print()
else:
	listb.sort(key=lambda x: x[1])
	print(len(listb))
	for i in listb:
		print(i[2], end=' ')
	print()


def solve():
	N = int(input())
	incr = []
	decr = []
	for i in range(1, N + 1):
		(a, b) = map(int, input().split())
		if a > b:
			decr.append((a, b, i))
		else:
			incr.append((a, b, i))
	result1 = []
	result2 = []
	if decr:
		decr.sort(key=lambda x: x[1])
		result1.append(decr[0])
		for i in range(1, len(decr)):
			(a, b, idx) = decr[i]
			if a > result1[i - 1][1]:
				result1.append((a, b, idx))
	if incr:
		incr.sort(key=lambda x: x[1])
		incr.reverse()
		result2.append(incr[0])
		for i in range(1, len(incr)):
			(a, b, idx) = incr[i]
			if a < result2[i - 1][1]:
				result2.append((a, b, idx))
	if len(result1) > len(result2):
		print(len(result1))
		print(' '.join((str(k[2]) for k in result1)))
	else:
		print(len(result2))
		print(' '.join((str(k[2]) for k in result2)))
solve()


import os
import sys
from io import BytesIO, IOBase
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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	n = N()
	arra = []
	arrb = []
	for i in range(n):
		(a, b) = RL()
		if a < b:
			arra.append((a, b, i + 1))
		else:
			arrb.append((a, b, i + 1))
	arra.sort(key=lambda a: -a[0])
	arrb.sort(key=lambda a: a[0])
	if len(arra) > len(arrb):
		print(len(arra))
		print(' '.join([str(i[2]) for i in arra]))
	else:
		print(len(arrb))
		print(' '.join([str(i[2]) for i in arrb]))
main()


import sys
input = sys.stdin.readline
N = int(input())
X = []
Y = []
for i in range(N):
	(a, b) = map(int, input().split())
	if a < b:
		X.append((a, b, i + 1))
	else:
		Y.append((a, b, i + 1))
if len(Y) > len(X):
	X = sorted(Y, key=lambda x: x[0])
else:
	X = sorted(X, key=lambda x: -x[0])
print(len(X))
print(*[x[2] for x in X])


from sys import stdin
from bisect import bisect_left as bl
input = stdin.readline
n = int(input())
a = []
b = []
for i in range(n):
	(c, d) = map(int, input().split())
	if c < d:
		a.append([d, i])
	else:
		b.append([c, i])
a.sort(reverse=True)
b.sort()
if len(a) > len(b):
	print(len(a))
	for i in a:
		print(i[1] + 1, end=' ')
else:
	print(len(b))
	for i in b:
		print(i[1] + 1, end=' ')


n = int(input())
downs = []
ups = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		ups.append([a, b, i + 1])
	else:
		downs.append([a, b, i + 1])
if len(ups) >= len(downs):
	ups.sort(key=lambda x: x[0], reverse=True)
	ans = []
	for (a, b, i) in ups:
		ans.append(i)
	print(len(ans))
	print(*ans)
else:
	downs.sort(key=lambda x: x[1])
	ans = []
	for (a, b, i) in downs:
		ans.append(i)
	print(len(ans))
	print(*ans)


def solve(n, p):
	i_p = list(enumerate(p))
	i_p.sort(key=lambda i_ab: (i_ab[1][1], i_ab[1][0], i_ab[0]))
	zig = list(reversed([i for (i, (a, b)) in i_p if a < b]))
	for i in range(len(zig) - 1):
		assert p[zig[i]][1] > p[zig[i + 1]][0]
	for i in zig:
		assert p[i][0] < p[i][1]
	zag = [i for (i, (a, b)) in i_p if a > b]
	for i in range(len(zag) - 1):
		assert p[zag[i]][1] < p[zag[i + 1]][0]
	for i in zag:
		assert p[i][0] > p[i][1]
	if len(zig) < len(zag):
		return zag
	return zig

def main():
	n = int(input())
	p = [None] * n
	for i in range(n):
		p[i] = tuple(map(int, input().split()))
	i = solve(n, p)
	print(len(i))
	print(*map(lambda ix: ix + 1, i))
main()


n = int(input())
D = []
U = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		U.append((a, b, i + 1))
	else:
		D.append((a, b, i + 1))
if len(U) <= len(D):
	D = sorted(D, key=lambda x: x[0])
	ans = []
	for i in range(len(D)):
		ans.append(D[i][2])
else:
	U = sorted(U, key=lambda x: -x[0])
	ans = []
	for i in range(len(U)):
		ans.append(U[i][2])
print(len(ans))
print(*ans)


n = int(input())
(l1, l2) = ([], [])
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		l1.append([[a, b], i + 1])
	else:
		l2.append([[a, b], i + 1])
l1.sort(reverse=True)
l2.sort()
if len(l1) > len(l2):
	print(len(l1))
	for i in l1:
		print(i[1], end=' ')
else:
	print(len(l2))
	for i in l2:
		print(i[1], end=' ')


import sys
input = sys.stdin.readline
mii = lambda : map(int, input().split())
n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = mii()
	if a < b:
		l1.append((-a, b, i))
	else:
		l2.append((a, b, i))
if len(l1) > len(l2):
	l1.sort()
	print(len(l1))
	print(' '.join(map(lambda x: str(x[2] + 1), l1)))
else:
	l2.sort()
	print(len(l2))
	print(' '.join(map(lambda x: str(x[2] + 1), l2)))


n = int(input())
big = []
small = []
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	if a > b:
		big.append((a, b, i))
	else:
		small.append((a, b, i))
if len(big) > len(small):
	print(len(big))
	for el in sorted(big):
		print(el[2], end=' ')
else:
	print(len(small))
	for el in sorted(small, reverse=True):
		print(el[2], end=' ')


h = int
M = input
X = range
s = list
t = map
c = True
T = len
o = print
H = str
n = h(M())
a = []
b = []
for i in X(n):
	f = s(t(h, M().split())) + [i + 1]
	if f[0] < f[1]:
		a += [f]
	else:
		b += [f]
a.sort(key=lambda x: x[1], reverse=c)
b.sort(key=lambda x: x[1])
if T(a) < T(b):
	a = b
o(T(a))
o(' '.join((H(i[2]) for i in a)))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
pa = []
pb = []
d = {}
ca = cb = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		ca += 1
		pa.append((a, b))
	else:
		cb += 1
		pb.append((a, b))
	d[a, b] = _ + 1
if ca > cb:
	stdout.write(str(ca) + '\n')
	pa.sort(key=lambda el: el[0], reverse=True)
	stdout.write(' '.join((str(d[el]) for el in pa)))
else:
	stdout.write(str(cb) + '\n')
	pb.sort(key=lambda el: el[1])
	stdout.write(' '.join((str(d[el]) for el in pb)))


import os
import heapq
import sys
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def binaryToDecimal(n):
	return int(n, 2)

def main():
	n = int(input())
	pair1 = []
	pair2 = []
	for i in range(n):
		(a, b) = map(int, input().split())
		if a < b:
			pair1.append([a, b, i + 1])
		else:
			pair2.append([a, b, i + 1])
	if len(pair1) > len(pair2):
		pair1 = sorted(pair1, key=lambda x: -x[0])
		print(len(pair1))
		for i in range(len(pair1)):
			print(pair1[i][2], end=' ')
		print()
	else:
		pair2 = sorted(pair2, key=lambda x: x[1])
		print(len(pair2))
		for i in range(len(pair2)):
			print(pair2[i][2], end=' ')
		print()
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')
main()


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		l1.append((a, i))
	else:
		l2.append((a, i))
l = l1
rev = True
if len(l2) > len(l1):
	l = l2
	rev = False
l.sort(reverse=rev)
print(len(l))
print(*[x[1] + 1 for x in l])


n = int(input())
l = []
negative = []
positive = []
for i in range(n):
	(a, b) = input().split()
	(a, b) = [int(a), int(b)]
	l.append([a, b])
	if b - a > 0:
		negative.append([a, b, i])
	else:
		positive.append([a, b, i])
if len(negative) > len(positive):
	print(len(negative))
	negative.sort(key=lambda negative: negative[0], reverse=True)
	print(' '.join(map(str, [i[2] + 1 for i in negative])))
else:
	print(len(positive))
	positive.sort(key=lambda positive: positive[0])
	print(' '.join(map(str, [i[2] + 1 for i in positive])))


import sys
input = sys.stdin.buffer.readline
n = int(input())
u_l = []
l_u = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x > y:
		l_u.append([y, i + 1])
	else:
		u_l.append([y, i + 1])
l_u.sort()
u_l.sort(reverse=True)
if len(l_u) > len(u_l):
	l = len(l_u)
	print(l)
	for i in range(l):
		print(l_u[i][1], end=' ')
else:
	l = len(u_l)
	print(l)
	for i in range(l):
		print(u_l[i][1], end=' ')


from sys import stdin

def input():
	return stdin.readline().strip()
import math
n = int(input())
count1 = []
count2 = []
nums = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x > y:
		count1.append((y, x, i + 1))
	elif y > x:
		count2.append((y, x, i + 1))
	nums.append((y, x, i))
print(max(len(count1), len(count2)))
if len(count1) > len(count2):
	count1.sort()
	for i in count1:
		print(i[2], end=' ')
	print('')
else:
	count2.sort(reverse=True)
	for i in count2:
		print(i[2], end=' ')
	print('')


def func(i):
	return 0 - ar[i][0]

def func2(i):
	return ar[i][0]
n = int(input())
ar = [[0 for x in range(2)] for y in range(n)]
for i in range(n):
	(ar[i][0], ar[i][1]) = map(int, input().split())
mn = []
mx = []
for i in range(n):
	if ar[i][0] < ar[i][1]:
		mn.append(i)
	else:
		mx.append(i)
if len(mn) > len(mx):
	mn = sorted(mn, key=func)
	print(len(mn))
	for x in mn:
		print(x + 1, end=' ')
else:
	mx = sorted(mx, key=func2)
	print(len(mx))
	for x in mx:
		print(x + 1, end=' ')


n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	if x > y:
		a.append([x, y, i])
	if x < y:
		b.append([x, y, i])
a.sort()
b.sort(reverse=True)
if len(a) > len(b):
	c = []
	for i in range(len(a)):
		c.append(a[i][2] + 1)
	print(len(c))
	print(*c)
else:
	c = []
	for i in range(len(b)):
		c.append(b[i][2] + 1)
	print(len(c))
	print(*c)


from sys import stdin
input = stdin.readline
n = int(input())
l = [tuple(map(int, line.split())) for line in stdin.read().splitlines()]
a = sorted([(v, i + 1) for (i, v) in enumerate(l) if v[0] > v[1]], key=lambda a: a[0][0])
b = sorted([(v, i + 1) for (i, v) in enumerate(l) if v[0] < v[1]], key=lambda a: -a[0][0])
if len(a) > len(b):
	print(len(a))
	print(*[i[1] for i in a])
else:
	print(len(b))
	print(*[i[1] for i in b])


import sys
input = sys.stdin.readline
n = int(input())
inc = []
dec = []
inc_cnt = 0
dec_cnt = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		inc.append((a, b, i + 1))
		inc_cnt += 1
	else:
		dec.append((a, b, i + 1))
		dec_cnt += 1
if inc_cnt > dec_cnt:
	print(inc_cnt)
	inc = sorted(inc, key=lambda x: -x[0])
	print(*[x[2] for x in inc])
else:
	print(dec_cnt)
	dec = sorted(dec, key=lambda x: x[0])
	print(*[x[2] for x in dec])


n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a < b:
		l1.append((a, b, i + 1))
	else:
		l2.append((b, a, i + 1))
l1.sort()
l1 = l1[::-1]
l2.sort()
if len(l1) >= len(l2):
	print(len(l1))
	for item in l1:
		print(item[2], end=' ')
else:
	print(len(l2))
	for item in l2:
		print(item[2], end=' ')


n = int(input())
asc = []
des = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x < y:
		asc.append([i + 1, y])
	else:
		des.append([i + 1, x])
if len(asc) >= len(des):
	print(len(asc))
	asc.sort(key=lambda x: -x[1])
	for i in range(len(asc)):
		print(asc[i][0], end=' ')
else:
	print(len(des))
	des.sort(key=lambda x: x[1])
	for i in range(len(des)):
		print(des[i][0], end=' ')


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
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')
n = int(input())
a = list()
b = list()
for i in range(n):
	(x, y) = map(int, input().split())
	if y >= x:
		a.append((x, y, i + 1))
	else:
		b.append((x, y, i + 1))
a.sort(reverse=True)
b.sort()
if len(a) >= len(b):
	print(len(a))
	for i in range(len(a)):
		print(a[i][2], end=' ')
	print()
else:
	print(len(b))
	for i in range(len(b)):
		print(b[i][2], end=' ')
	print()


n = int(input())
d = {}
d['+'] = []
d['-'] = []
for _ in range(n):
	(a, b) = list(map(int, input().split()))
	if a < b:
		d['+'].append([b, _])
	else:
		d['-'].append([b, _])
d['+'] = sorted(d['+'], key=lambda x: x[0], reverse=True)
d['-'] = sorted(d['-'], key=lambda x: x[0])
s = ''
if len(d['+']) > len(d['-']):
	print(len(d['+']))
	for x in d['+']:
		s += str(x[1] + 1) + ' '
else:
	print(len(d['-']))
	for x in d['-']:
		s += str(x[1] + 1) + ' '
print(s)


import sys

def solve(a, cmp):
	res = [-1 for _ in a]
	ptr = 0
	for (id, e) in enumerate(a):
		if ptr == 0 or cmp(a[res[ptr - 1]][0][1], e[0][0]):
			res[ptr] = id
			ptr += 1
	return [a[res[id]][1] for id in range(ptr)]
n = int(input())
a = [tuple((int(e) for e in line.split())) for line in sys.stdin]
up = [(e, id) for (id, e) in enumerate(a) if e[0] < e[1]]
down = [(e, id) for (id, e) in enumerate(a) if e[0] > e[1]]
up.sort(key=lambda e: -e[0][1])
down.sort(key=lambda e: e[0][1])
res = solve(up, lambda a, b: a > b)
res_down = solve(down, lambda a, b: a < b)
if len(res) < len(res_down):
	res = res_down
print(len(res))
print(' '.join((str(_ + 1) for _ in res)))


n = int(input())
a = list()
f = []
for i in range(n):
	cur = [list(map(int, input().split())), i + 1]
	if cur[0][0] < cur[0][1]:
		f.append(cur)
	else:
		a.append(cur)
if len(f) >= n // 2:
	f.sort(key=lambda x: x[0][0], reverse=True)
	print(len(f))
	ans = ''
	for i in f:
		ans += str(i[1]) + ' '
	print(ans)
else:
	a.sort(key=lambda x: x[0][0], reverse=False)
	print(len(a))
	ans = ''
	for i in a:
		ans += str(i[1]) + ' '
	print(ans)


n = int(input())
b = []
mx = []
mn = []
mx_i = []
mn_i = []
for i in range(n):
	(u, v) = [int(x) for x in input().strip().split()]
	if u > v:
		mx.append((u, v))
		mx_i.append(i + 1)
	else:
		mn.append((u, v))
		mn_i.append(i + 1)
if len(mx) > len(mn):
	print(len(mx))
	res = [x[1] for x in sorted(zip(mx, mx_i))]
else:
	print(len(mn))
	res = [x[1] for x in sorted(zip(mn, mn_i), reverse=True)]
for r in res:
	print(r, end=' ')
print()


import math
import os
import sys
from io import BytesIO, IOBase
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')

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z
n = int(input())
a = [0] * n
b = [0] * n
ac = 0
bc = 0
l = []
l1 = []
lq = []
lq1 = []
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
	if a[i] < b[i]:
		ac += 1
		l.append(b[i])
		lq.append(i + 1)
	else:
		bc += 1
		l1.append(b[i])
		lq1.append(i + 1)
if ac > bc:
	print(ac)
	lq = sort_list(lq, l)
	lq = lq[::-1]
	print(*lq, sep=' ')
else:
	print(bc)
	lq1 = sort_list(lq1, l1)
	print(*lq1, sep=' ')


import sys
import functools
commands = []

def less_int(x, y):
	return x[0] - y[0]

def more_int(x, y):
	return y[0] - x[0]
n = int(input())
ab = []
ba = []
for i in range(n):
	a_s = list(map(int, input().split(' ')))
	if a_s[0] > a_s[1]:
		ab.append((a_s[0], a_s[1], i + 1))
	else:
		ba.append((a_s[0], a_s[1], i + 1))
ab.sort(key=functools.cmp_to_key(less_int))
ba.sort(key=functools.cmp_to_key(more_int))
answ = ab
if len(ba) > len(ab):
	answ = ba
print(len(answ))
for (a, b, c) in answ:
	print(c, end=' ')


n = int(input())
(mn, mx) = ([], [])
for i in range(n):
	b = list(map(int, input().split()))
	if b[0] > b[1]:
		mx.append(b + [i + 1])
	else:
		mn.append(b + [i + 1])
if len(mx) > len(mn):
	ans = sorted(mx)
else:
	ans = sorted(mn, reverse=True)
print(len(ans))
print(*[x[2] for x in ans])


n = int(input())
p = [tuple((int(x) for x in input().split())) for _ in range(n)]
asc = [(x[0], i) for (i, x) in enumerate(p) if x[0] > x[1]]
desc = [(x[0], i) for (i, x) in enumerate(p) if x[0] < x[1]]
asc.sort()
desc.sort(reverse=True)
if len(asc) >= len(desc):
	print(len(asc))
	print(' '.join((str(x[1] + 1) for x in asc)))
else:
	print(len(desc))
	print(' '.join((str(x[1] + 1) for x in desc)))


from sys import stdin
n = int(stdin.readline().strip())
s = [list(map(int, stdin.readline().strip().split())) for i in range(n)]
s1 = []
s2 = []
for i in range(n):
	if s[i][0] > s[i][1]:
		s1.append(s[i][::-1] + [i])
	if s[i][0] < s[i][1]:
		s2.append(s[i][::-1] + [i])
s1.sort()
s2.sort(reverse=True)
ans1 = []
ans2 = []
if len(s1) > 0:
	ans1 = [s1[0]]
if len(s2) > 0:
	ans2 = [s2[0]]
for i in range(len(s1)):
	if ans1[-1][0] < s1[i][0]:
		ans1.append(s1[i])
for i in range(len(s2)):
	if ans2[-1][0] > s2[i][0]:
		ans2.append(s2[i])
if len(ans1) > len(ans2):
	r = []
	for i in ans1:
		r.append(i[2] + 1)
	print(len(r))
	print(*r)
else:
	r = []
	for i in ans2:
		r.append(i[2] + 1)
	print(len(r))
	print(*r)


import os
import sys
from io import IOBase
from bisect import bisect_right, bisect_left
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from cStringIO import StringIO
	from future_builtins import ascii, filter, hex, map, oct, zip
else:
	from io import BytesIO as StringIO
(sys.stdout, stream) = (IOBase(), StringIO())
sys.stdout.flush = lambda : os.write(1, stream.getvalue()) and (not stream.truncate(0)) and stream.seek(0)
sys.stdout.write = stream.write if sys.version_info[0] < 3 else lambda s: stream.write(s.encode())
(input, flush) = (sys.stdin.readline, sys.stdout.flush)
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

def sec(tup):
	return tup[1]
n = int(input())
inc = []
dec = []
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	if a < b:
		inc.append((a, b, i))
	else:
		dec.append((a, b, i))
inc.sort(reverse=True)
dec.sort(key=sec)
if len(inc) > len(dec):
	print(len(inc))
	print(' '.join([str(guy[2]) for guy in inc]))
else:
	print(len(dec))
	print(' '.join([str(guy[2]) for guy in dec]))


n = int(input())
(g, l) = ([], [])
for _ in range(n):
	i = [*map(int, input().split())]
	if i[0] > i[1]:
		g.append(i + [_ + 1])
	else:
		l.append(i + [_ + 1])
g.sort()
l.sort(reverse=True)
if len(g) < len(l):
	g = l
print(len(g))
print(' '.join(map(str, [i[2] for i in g])))


import sys
input = sys.stdin.readline
n = int(input())
li = []
for i in range(n):
	li.append(list(map(int, input().split())) + [i + 1])
li.sort(key=lambda x: x[0], reverse=True)
ans1 = 0
xx1 = []
for i in range(n):
	if li[i][1] > li[i][0]:
		ans1 += 1
		xx1.append(li[i][2])
ans2 = 0
xx2 = []
for i in range(n):
	if li[-(i + 1)][1] < li[-(i + 1)][0]:
		ans2 += 1
		xx2.append(li[-(i + 1)][2])
if ans1 >= ans2:
	print(ans1)
	print(*xx1)
else:
	print(ans2)
	print(*xx2)


n = int(input())
group1 = []
group2 = []
counter1 = counter2 = 0
for i in range(n):
	a = [int(x) for x in input().split()]
	if a[0] < a[1]:
		group1.append((a, i + 1))
		counter1 += 1
	else:
		group2.append((a, i + 1))
		counter2 += 1
answer = []
if counter1 > counter2:
	group1.sort(reverse=True)
	print(counter1)
	for item in group1:
		answer.append(item[1])
else:
	group2.sort()
	print(counter2)
	for item in group2:
		answer.append(item[1])
print(*answer)


from operator import gt, lt
from collections import deque, namedtuple
n = int(input())
pairs = [[int(t) for t in input().split(' ')] for _ in range(n)]
Pair = namedtuple('Pair', ['a', 'b', 'i'])
pairs = list((Pair(*p, i) for (i, p) in enumerate(pairs)))

def attempt(pairs, a_high):
	pairs = [p for p in pairs if a_high ^ (p.a < p.b)]
	pairs = deque(sorted(pairs, reverse=a_high, key=lambda p: p.a))
	if not pairs:
		return []
	result = [pairs.pop()]
	while pairs and a_high ^ (result[-1].b > pairs[-1].a):
		result.append(pairs.pop())
	return result
a_high = attempt(pairs, True)
a_low = attempt(pairs, False)
best = max(a_high, a_low, key=len)
print(len(best))
print(' '.join([str(p.i + 1) for p in best]))


N = int(input())
inc = []
dec = []
for i in range(N):
	(a, b) = map(int, input().split())
	if a < b:
		inc.append((a, b, i + 1))
	else:
		dec.append((a, b, i + 1))
inc.sort(key=lambda x: x[1], reverse=True)
dec.sort(key=lambda x: x[1])
if len(inc) >= len(dec):
	print(len(inc))
	for i in inc:
		print(i[2], end=' ')
else:
	print(len(dec))
	for i in dec:
		print(i[2], end=' ')


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	n = int(input())
	g = [[], []]
	for _ in range(n):
		(x, y) = map(int, input().split())
		g[y > x].append((x, y, _ + 1))

	def secondAsc(elem):
		return elem[1]

	def secondDsc(elem):
		return -elem[1]
	if len(g[0]) >= n / 2:
		g[0].sort(key=secondAsc)
		print(len(g[0]))
		for (i, j, k) in g[0]:
			print(k, end=' ')
	else:
		g[1].sort(key=secondDsc)
		print(len(g[1]))
		for (i, j, k) in g[1]:
			print(k, end=' ')
	print()
main()


import sys
n = int(input())
big = []
small = []
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	if a > b:
		big.append((a, b, i))
	else:
		small.append((a, b, i))
if len(big) > len(small):
	sys.stdout.write(str(len(big)) + '\n')
	for el in sorted(big):
		sys.stdout.write(str(el[2]) + ' ')
else:
	sys.stdout.write(str(len(small)) + '\n')
	for el in sorted(small, reverse=True):
		sys.stdout.write(str(el[2]) + ' ')


n = int(input())
(gt, lt, paris) = ([], [], [])
for i in range(n):
	(a, b) = map(int, input().split())
	paris.append((a, b))
	if a > b:
		gt.append(i + 1)
	else:
		lt.append(i + 1)

def comp(i):
	(a, b) = paris[i - 1]
	return a
gt.sort(key=comp)
lt.sort(key=comp, reverse=True)
if len(lt) > len(gt):
	print(len(lt))
	print(*lt)
else:
	print(len(gt))
	print(*gt)


n = int(input())
small = []
large = []
idx = {}
for i in range(1, n + 1):
	tup = input().split()
	tup[0] = int(tup[0])
	tup[1] = int(tup[1])
	tup = tuple(tup)
	idx[tup] = i
	if tup[0] > tup[1]:
		large.append(tup)
	else:
		small.append(tup)
small_best = False
if len(small) > len(large):
	small_best = True
	small.sort(reverse=True)
else:
	large.sort()
if small_best == True:
	print(len(small))
	for tup in small:
		print(idx[tup], end=' ')
	print()
else:
	print(len(large))
	for tup in large:
		print(idx[tup], end=' ')
	print()


import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
n = int(input())
a = []
b = []
for i in range(n):
	(x, y) = map(int, input().split())
	x = (x, y, i + 1)
	if x[0] > x[1]:
		a.append(x)
	else:
		b.append(x)
if len(a) > len(b):
	a.sort(key=lambda x: x[1])
	print(len(a))
	for c in a:
		print(c[2], end=' ')
else:
	b.sort(key=lambda x: -x[0])
	print(len(b))
	for c in b:
		print(c[2], end=' ')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

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

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	aa = [LI() for _ in range(n)]
	a = []
	b = []
	for i in range(1, n + 1):
		(c, d) = aa[i - 1]
		if c < d:
			a.append((c, i))
		else:
			b.append((c, i))
	if len(a) >= len(b):
		a.sort(key=lambda x: -x[0])
		r = a
	else:
		b.sort(key=lambda x: x[0])
		r = b
	return '{}\n{}'.format(len(r), ' '.join(map(lambda x: str(x[1]), r)))
print(main())


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(var):
	print(var, file=sys.stderr)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = []
b = []
for i in range(n):
	(x, y) = I()
	if x < y:
		a.append((x, y, i + 1))
	else:
		b.append((x, y, i + 1))
a.sort(reverse=1)
b.sort()
(n, m) = (len(a), len(b))
if n >= m:
	print(n)
	for i in a:
		print(i[2], end=' ')
else:
	print(m)
	for i in b:
		print(i[2], end=' ')
debug(a)
debug(b)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	if b > a:
		l1.append([a, b, i])
	else:
		l2.append([b, a, i])
ans = []
l1.sort(reverse=True)
l2.sort()
if len(l1) >= len(l2):
	for i in range(len(l1)):
		ans.append(l1[i][2] + 1)
	print(len(ans))
	print(*ans)
	exit()
for i in range(len(l2)):
	ans.append(l2[i][2] + 1)
print(len(ans))
print(*ans)


def seq1(diff, nums):
	index = diff[0][1]
	(a, b) = (nums[index][0], nums[index][1])
	if b > a:
		indices = [index]
	else:
		return []
	(x1, x2) = (a, b)
	for i in range(1, len(diff)):
		index = diff[i][1]
		(a, b) = (nums[index][0], nums[index][1])
		if x2 > a and a < b:
			indices.append(index)
			x2 = b
		else:
			break
	return indices

def seq2(diff, nums):
	index = diff[0][1]
	(a, b) = (nums[index][0], nums[index][1])
	if b < a:
		indices = [index]
	else:
		return []
	(x1, x2) = (a, b)
	for i in range(1, len(diff)):
		index = diff[i][1]
		(a, b) = (nums[index][0], nums[index][1])
		if a > x2 and a > b:
			indices.append(index)
			x2 = b
		else:
			break
	return indices

def main():
	n = int(input())
	nums = []
	diff1 = []
	diff2 = []
	for i in range(n):
		(a, b) = map(int, input().split())
		nums.append((a, b))
		if b - a > 0:
			diff1.append((b, i))
		else:
			diff2.append((a, i))
	diff1.sort(reverse=True)
	diff2.sort()
	if diff1:
		ans1 = seq1(diff1, nums)
	else:
		ans1 = []
	if diff2:
		ans2 = seq2(diff2, nums)
	else:
		ans2 = []
	if len(ans1) >= len(ans2):
		print(len(ans1))
		for i in ans1:
			print(i + 1, end=' ')
	else:
		print(len(ans2))
		for i in ans2:
			print(i + 1, end=' ')
main()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	n = int(input())
	(ans1, ans2) = ([], [])
	pairs = {}
	(small, large) = ([], [])
	for _ in range(n):
		(u, v) = num_input()
		pairs[u, v] = _
		if u < v:
			small.append([u, v])
		else:
			large.append([u, v])
	if len(small) > len(large):
		small.sort(reverse=True)
		print(len(small))
		for (u, v) in small:
			print(pairs[u, v] + 1, end=' ')
		print()
	else:
		large.sort()
		print(len(large))
		for (u, v) in large:
			print(pairs[u, v] + 1, end=' ')
		print()
t = 1
for _ in range(t):
	solve()


import sys
from collections import defaultdict, deque
a = []
b = []
t = int(sys.stdin.readline())
for _ in range(t):
	(u, v) = map(int, sys.stdin.readline().split())
	if u < v:
		a.append([v, u, _ + 1])
	else:
		b.append([u, v, _ + 1])
if len(a) > len(b):
	a.sort(reverse=True)
	ans = []
	for i in range(len(a)):
		ans.append(a[i][2])
	print(len(ans))
	print(*ans)
else:
	b.sort()
	ans = []
	for i in range(len(b)):
		ans.append(b[i][2])
	print(len(ans))
	print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
type1 = []
type2 = []
for i in range(n):
	(a, b) = ab[i]
	if a < b:
		type1.append([a, b, i + 1])
	elif a > b:
		type2.append([a, b, i + 1])
type1.sort(key=lambda x: x[0], reverse=True)
type2.sort(key=lambda x: x[1])
ans1 = [type1[i][2] for i in range(len(type1))]
ans2 = [type2[i][2] for i in range(len(type2))]
if len(ans1) > len(ans2):
	print(len(ans1))
	print(*ans1)
else:
	print(len(ans2))
	print(*ans2)


from operator import itemgetter
from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, pairs):
	for (i, item) in enumerate(pairs):
		item.append(i + 1)
	greater_than = list(filter(lambda x: x[0] < x[1], pairs))
	if len(greater_than) > n - len(greater_than):
		greater_than.sort(reverse=True, key=itemgetter(0))
		return list(map(lambda x: x[2], greater_than))
	else:
		less_than = list(filter(lambda x: x[0] > x[1], pairs))
		less_than.sort(key=itemgetter(0))
		return list(map(lambda x: x[2], less_than))
n = int_in()
pairs = mat_in(n)
result = solve(n, pairs)
out(len(result))
arr_out(result)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
(a, b) = ([], [])
for i in range(n):
	t = gil()
	t.append(i)
	(a if t[0] > t[1] else b).append(t)
a.sort(key=lambda x: x[1])
b.sort(key=lambda x: -x[1])

def sa(a):
	if len(a) == 0:
		return []
	cv = a[0][1]
	ans = [a[0][2] + 1]
	for i in range(1, len(a)):
		if a[i][0] > cv:
			cv = a[i][1]
			ans.append(a[i][2] + 1)
	return ans

def sb(b):
	if len(b) == 0:
		return []
	cv = b[0][1]
	ans = [b[0][2] + 1]
	for i in range(1, len(b)):
		if b[i][0] < cv:
			cv = b[i][1]
			ans.append(b[i][2] + 1)
	return ans
ans = max(sa(a), sb(b), key=len)
print(len(ans))
print(*ans)


n = int(input())
arr = []
ans1 = []
ans2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	arr.append([x, y])
	if x < y:
		ans1.append([x, y, i + 1])
	else:
		ans2.append([x, y, i + 1])
ans1 = sorted(ans1, key=lambda item: item[0], reverse=True)
ans2 = sorted(ans2, key=lambda item: item[1])
if len(ans1) > len(ans2):
	print(len(ans1))
	for i in range(len(ans1)):
		print(ans1[i][2], end=' ')
	print()
else:
	print(len(ans2))
	for i in range(len(ans2)):
		print(ans2[i][2], end=' ')
	print()