You are given an integer array of length $n$.

You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to $[x, x + 1, \dots, x + k - 1]$ for some value $x$ and length $k$.

Subsequence of an array can be obtained by erasing some (possibly zero) elements from the array. You can erase any elements, not necessarily going successively. The remaining elements preserve their order. For example, for the array $[5, 3, 1, 2, 4]$ the following arrays are subsequences: $[3]$, $[5, 3, 1, 2, 4]$, $[5, 1, 4]$, but the array $[1, 3]$ is not.


-----Input-----

The first line of the input containing integer number $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array. The second line of the input containing $n$ integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the array itself.


-----Output-----

On the first line print $k$ — the maximum length of the subsequence of the given array that forms an increasing sequence of consecutive integers.

On the second line print the sequence of the indices of the any maximum length subsequence of the given array that forms an increasing sequence of consecutive integers.


-----Examples-----
Input
7
3 3 4 7 5 6 8

Output
4
2 3 5 6 

Input
6
1 3 5 2 4 6

Output
2
1 4 

Input
4
10 9 8 7

Output
1
1 

Input
9
6 7 8 3 4 5 9 10 11

Output
6
1 2 3 7 8 9 



-----Note-----

All valid answers for the first example (as sequences of indices):   $[1, 3, 5, 6]$  $[2, 3, 5, 6]$ 

All valid answers for the second example:   $[1, 4]$  $[2, 5]$  $[3, 6]$ 

All valid answers for the third example:   $[1]$  $[2]$  $[3]$  $[4]$ 

All valid answers for the fourth example:   $[1, 2, 3, 7, 8, 9]$

Difficulty: MEDIUM_HARD
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
d = dict()
opt = []
m = -1
for i in range(n):
	t = a[i]
	p = t - 1
	if p in d:
		if t not in d or p - d[p] >= t - d[t]:
			d[t] = d[p]
			k = t - d[t]
			if k > m:
				m = k
				opt = d[t]
	elif t not in d:
		d[t] = t
		if m == -1:
			opt = t
			m = 0
print(m + 1)
r = []
for i in range(n):
	if a[i] == opt:
		r += [i + 1]
		opt += 1
print(*r)


import sys
input = sys.stdin.readline
out = sys.stdout

def main():
	n = int(input())
	a = list(map(int, input().split()))
	dp = {a[i]: 0 for i in range(n)}
	(ans, lst) = (0, 0)
	for i in range(n):
		x = a[i]
		if x - 1 in dp:
			dp[x] = dp[x - 1] + 1
		else:
			dp[x] = 1
		if ans < dp[x]:
			ans = dp[x]
			lst = x
	res = []
	for i in range(n - 1, -1, -1):
		if a[i] == lst:
			res.append(i)
			lst -= 1
	res.sort()
	print(ans)
	for k in res:
		out.write(str(k + 1) + ' ')
	return
main()


import sys
from math import *

def input():
	return sys.stdin.readline().strip()

def input_line():
	return map(int, input().split())
n = int(input())
a = list(input_line())
d = dict()
p = dict()
o = [0] * n
q = [0] * n
r = (0, 0)
for i in range(n):
	x = a[i]
	v = d.get(x - 1, 0) + 1
	r = max(r, (v, i))
	o[i] = v
	q[i] = p.get(x - 1, -1)
	d[x] = o[i]
	p[x] = i
print(r[0])
z = []
x = r[1]
while len(z) < r[0]:
	z.append(x + 1)
	x = q[x]
print(*z[::-1])


n = int(input())
d = {}
l = list(map(int, input().split()))
val = 0
ma = 0
for i in range(n):
	d[l[i]] = 1 + d.get(l[i] - 1, 0)
	if d[l[i]] > ma:
		ma = d[l[i]]
		val = l[i]
print(ma)
ans = []
for i in range(n - 1, -1, -1):
	if l[i] == val:
		ans.append(i + 1)
		val -= 1
ans = ans[::-1]
print(' '.join(map(str, ans)))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		a = [0] + ria()
		posn = {}
		d = [[-1, -1] for i in range(n + 1)]
		for i in range(1, n + 1):
			if a[i] in posn:
				posn[a[i]].append(i)
			else:
				posn[a[i]] = [i]
			if a[i] - 1 in posn:
				d[i] = [1 + d[posn[a[i] - 1][-1]][0], posn[a[i] - 1][-1]]
			else:
				d[i] = [1, -1]
		maxd = -1
		start = -1
		for i in range(1, n + 1):
			(x, y) = d[i]
			if x > maxd:
				maxd = x
				start = i
		ans = []
		while True:
			ans.append(start)
			(x, y) = d[start]
			if y == -1:
				break
			else:
				start = y
		wi(len(ans))
		wia(ans[::-1])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
mod2 = 998244353
t = 1
for i in range(t):
	n = read_int()
	a = read_int_line()
	d = {}
	for i in range(n):
		if a[i] in d:
			d[a[i]].append(i)
		else:
			d[a[i]] = [i]
	dp = [0] * n
	dp[0] = 1
	for i in range(1, n):
		ind = -1
		if a[i] - 1 in d:
			ind = d[a[i] - 1][bisect_right(d[a[i] - 1], i) - 1]
		dp[i] = 1
		if ind != -1:
			dp[i] += dp[ind]
	m = max(dp)
	ind = dp.index(m)
	ans = []
	prev = ind
	while ind != -1 and len(ans) < m:
		ans.append(ind + 1)
		prev = ind
		if a[ind] - 1 in d:
			ind = d[a[ind] - 1][bisect_right(d[a[ind] - 1], ind) - 1]
		else:
			ind = -1
		if ind == prev:
			break
	ans = ans[::-1]
	print(m)
	print(*ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	d[i] = d.get(i - 1, 0) + 1
maxi = max(d, key=d.get)
print(d[maxi])
p = 0
for i in range(maxi - d[maxi], maxi):
	p = a.index(i + 1, p)
	print(p + 1, end=' ')


n = int(input())
lis = list(map(int, input().split()))
from collections import defaultdict
dp = defaultdict(int)
mx = float('-inf')
val = None
for i in range(n):
	cur = lis[i]
	dp[cur] = dp[cur - 1] + 1
	if mx < dp[cur]:
		mx = dp[cur]
		val = cur
new = []
for i in range(n - 1, -1, -1):
	if lis[i] == val:
		new.append(i + 1)
		val -= 1
print(mx)
print(*new[::-1])


input()
arr = list(map(int, input().split()))
m = {}
for e in arr:
	if e - 1 not in m:
		m[e] = 1
	else:
		m[e] = m[e - 1] + 1
best = 0
bk = 0
for k in m:
	if m[k] > best:
		best = m[k]
		bk = k
last = bk
indices = []
for i in range(len(arr) - 1, -1, -1):
	if arr[i] == last:
		indices.append(i + 1)
		last -= 1
print(len(indices))
print(' '.join(map(str, reversed(indices))))


import sys
from array import array
import typing as Tp

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

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	from collections import defaultdict
	from operator import itemgetter
	n = int(input())
	a = list(map(int, input().split()))
	dp = defaultdict(int)
	for v in a:
		dp[v] = max(dp[v], dp[v - 1] + 1)
	last_num = max(dp.items(), key=itemgetter(1))[0]
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] == last_num:
			ans.append(i + 1)
			last_num -= 1
	output(len(ans), ' '.join(map(str, reversed(ans))))
main()


n = int(input())
arr = list(map(int, input().split()))
prev = [-1] * (n + 1)
d = dict()
mp = dict()
best = int(0)
index = 0
for i in range(0, n):
	if arr[i] - 1 in d:
		d[arr[i]] = d[arr[i] - 1] + 1
		prev[i] = mp[arr[i] - 1]
	else:
		d[arr[i]] = int(1)
		prev[i] = int(-1)
	if d[arr[i]] > best:
		best = d[arr[i]]
		index = i
	mp[arr[i]] = i
print(best)
seq = [0] * best
for i in range(0, best):
	seq[best - i - 1] = index + 1
	index = prev[index]
print(*seq)


from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
n = int(input())
a = list(map(int, input().split()))
dp = {}
maxind = 0
ans = 0
for i in range(n):
	dp[a[i]] = 1 + dp.get(a[i] - 1, 0)
	if dp[a[i]] > ans:
		ans = dp[a[i]]
		maxind = i
res = [maxind + 1]
curr_max = a[maxind]
for i in range(maxind - 1, -1, -1):
	if a[i] == curr_max - 1:
		res.append(i + 1)
		curr_max -= 1
print(ans)
print(*res[::-1])


n = int(input())
l = list(map(int, input().split()))
dp = [0] * n
prev = [-1] * n
d = dict()
for i in range(n):
	if l[i] in d:
		d[l[i]].append(i)
	else:
		d.update({l[i]: [i]})
	if l[i] - 1 in d:
		dp[i] = dp[d[l[i] - 1][-1]] + 1
		prev[i] = d[l[i] - 1][-1]
	else:
		dp[i] = 1
e = max(dp)
print(e)
ans = []
ind = dp.index(e)
while ind != -1:
	ans.append(ind + 1)
	ind = prev[ind]
print(*ans[::-1], sep=' ')


n = int(input())
arr = [int(x) for x in input().split()]
dp = {}
dp = dp.fromkeys(arr, 0)
(ans, ind) = (0, 0)
for i in range(n):
	x = arr[i]
	if x - 1 not in dp:
		dp[x - 1] = 0
	dp[x] = dp[x - 1] + 1
	if ans < dp[x]:
		ans = dp[x]
		ind = x
indices = []
for j in range(n - 1, -1, -1):
	if arr[j] == ind:
		indices.append(j)
		ind -= 1
indices.reverse()
print(ans)
for num in indices:
	print(num + 1, end=' ')


input()
arr = [int(x) for x in input().split()]
import collections
his = collections.defaultdict(int)
his[arr[0]] = 1
for i in arr:
	if his[i - 1] > 0:
		his[i] = his[i - 1] + 1
	else:
		his[i] = 1
imax = 0
vmax = 0
for i in his.keys():
	if his[i] > vmax:
		imax = i - his[i] + 1
		vmax = his[i]
res = []
for i in range(len(arr)):
	if arr[i] == imax:
		res.append(str(i + 1))
		imax += 1
print(len(res))
print(' '.join(res))


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	d[i] = d.get(i - 1, 0) + 1
e = max(d, key=d.get)
m = []
while n:
	if a[n - 1] == e:
		m.append(n)
		e -= 1
	n -= 1
print(len(m))
print(*m[::-1])


import sys
input()
arr = list(map(int, sys.stdin.readline().split()))
n = len(arr)
dp = {}
ans = 0
lst = -1
for i in range(n):
	x = arr[i]
	if x - 1 in dp:
		dp[x] = dp[x - 1] + 1
	else:
		dp[x] = 1
	if ans < dp[x]:
		ans = dp[x]
		lst = x
ans_list = []
for (idx, x) in enumerate(reversed(arr)):
	if x == lst:
		ans_list.append(n - idx)
		lst -= 1
print(len(ans_list))
print(' '.join(map(str, reversed(ans_list))))


input()
arr = [int(i) for i in input().strip().split()]
d = {}
for i in arr:
	if d.get(i, 0) + 1 > d.get(i + 1, 0):
		d[i + 1] = d.get(i, 0) + 1
best = -1
length = 0
for key in d:
	if d[key] > length:
		best = key
		length = d[key]
lf = best - length
print(length)
for i in range(len(arr)):
	if arr[i] == lf:
		print(i + 1, end=' ')
		length -= 1
		lf += 1
	if length == 0:
		break
print()


n = int(input())
a = list(map(int, input().split()))
d = {}
maior = -1
imaior = 0
for x in a:
	d[x] = d.get(x - 1, 0) + 1
	if d[x] > maior:
		maior = d[x]
		imaior = x
print(maior)
cont = imaior - (maior - 1)
resp = []
for i in range(n):
	if a[i] == cont:
		cont += 1
		resp.append(i + 1)
print(*resp)


n = int(input())
g = {}
s = [*map(int, input().split())]
for i in s:
	g[i] = g.get(i - 1, 0) + 1
e = max(g, key=g.get)
m = g[e]
a = []
while n:
	if s[n - 1] == e:
		a += (n,)
		e -= 1
	n -= 1
print(m, *a[::-1])


n = int(input())
arr = [int(var) for var in input().split()]
(lis, maxLis, default) = ({}, None, [0])
for i in range(len(arr)):
	lis[arr[i]] = [lis.get(arr[i] - 1, default)[0] + 1, i + 1]
	maxLis = max(maxLis, arr[i], key=lambda x: lis.get(x, default)[0])
(next, pos) = (maxLis - lis[maxLis][0] + 1, 0)
print(lis[maxLis][0])
while next <= maxLis:
	if arr[pos] == next:
		next += 1
		print(pos + 1, end=' ')
	pos += 1
print()


from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
(mv, ml, l) = (0, 0, [])
for i in range(n):
	d[a[i]] = d[a[i] - 1] + 1
	if ml < d[a[i]]:
		ml = d[a[i]]
		mv = a[i]
for i in range(n - 1, -1, -1):
	if a[i] == mv:
		l.append(i + 1)
		mv -= 1
print(ml)
print(*l[::-1])


n = int(input())
arr = list(map(int, input().split()))
H = {}
prev = [-1 for i in range(n)]
for i in range(n):
	H[arr[i]] = i
	if arr[i] - 1 in H:
		prev[i] = H[arr[i] - 1]
(Max, pos) = (0, 0)
dp = [0 for i in range(n)]
for i in range(n):
	if prev[i] == -1:
		dp[i] = 1
	else:
		dp[i] = 1 + dp[prev[i]]
	if dp[i] > Max:
		(Max, pos) = (dp[i], i)
print(Max)
sequence = []
while Max > 0:
	sequence.append(pos + 1)
	pos = prev[pos]
	Max -= 1
sequence.reverse()
print(*sequence)


import collections
n = int(input())
q = list(map(int, input().split()))
w = collections.defaultdict(int)
for i in q:
	w[i] = max(w[i - 1] + 1, w[i])
m = max(w.values())
ans = 0
for i in w:
	ans = i * (w[i] == m) + ans * (not w[i] == m)
z = []
for i in range(n - 1, -1, -1):
	if q[i] == ans:
		ans -= 1
		z.append(i + 1)
print(len(z))
print(*list(reversed(z)))


n = int(input())
a = list(map(int, input().split()))
h = {}
for i in a:
	h[i - 1] = 0
tb = 0
end = -1
for i in a:
	h[i] = h[i - 1] + 1
	if tb < h[i]:
		tb = h[i]
		end = i
arr = []
start = end - tb + 1
for i in range(n):
	if a[i] == start:
		arr.append(i + 1)
		start += 1
print(tb)
print(*arr)


n = int(input())
G = list(map(int, input().split()))
D = {}
M = 0
for i in G:
	if i - 1 in D:
		D[i] = D[i - 1] + 1
	else:
		D[i] = 1
	if D[i] > M:
		M = D[i]
		Mi = i
R = []
A = Mi
for i in range(len(G) - 1, -1, -1):
	if G[i] == A:
		R.append(i + 1)
		A -= 1
print(M)
print(*R[::-1])


n = int(input())
L = map(int, input().split())
d = dict()
for (i, x) in enumerate(L):
	if x in d:
		T = d.pop(x)
		T.append(i + 1)
	else:
		T = [i + 1]
	if x + 1 not in d or len(T) > len(d[x + 1]):
		d[x + 1] = T
M = max(map(len, d.values()))
S = next(filter(lambda a: len(a) == M, d.values()))
print(M)
print(' '.join(map(str, S)))


from bisect import *
a = int(input())
z = list(map(int, input().split()))
from collections import defaultdict
al = defaultdict(list)
for i in range(len(z)):
	al[z[i]].append(i)
inc = [0 for i in range(len(z))]
index = [0 for i in range(len(z))]
for i in range(len(z)):
	if len(al[z[i]]):
		m = bisect_left(al[z[i] - 1], i)
		if m == 0:
			inc[i] = 1
			index[i] = i
		else:
			m -= 1
			inc[i] = inc[al[z[i] - 1][m]] + 1
			index[i] = al[z[i] - 1][m]
y = inc.index(max(inc))
ans = []
while index[y] != y:
	ans.append(y + 1)
	y = index[y]
ans.append(y + 1)
print(len(ans))
print(*ans[::-1])


from collections import defaultdict
n = int(input())
arr = [int(x) for x in input().split()]
d = defaultdict(int)
for i in range(n):
	if d[arr[i] - 1]:
		d[arr[i]] = d[arr[i] - 1] + 1
	else:
		d[arr[i]] = 1
key = -1
MAX = 0
for i in d.keys():
	if d[i] > MAX:
		key = i
		MAX = d[i]
print(MAX)
j = key - MAX + 1
ans = []
for i in range(n):
	if arr[i] == j:
		ans.append(i + 1)
		j += 1
print(*ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
lst = zzz()
cnt = {}
for i in lst:
	try:
		cnt[i] = cnt[i - 1] + 1
	except:
		cnt[i] = 1
m = max(cnt, key=cnt.get)
t = cnt[m]
print(t)
x = m - t + 1
p = 0
for i in range(x, m + 1):
	p = lst.index(i, p)
	print(p + 1)
exit()
(n, k) = zz()
l = [1] + szzz()
if k >= n:
	print(-1)
	exit()
p = l[k]
print(p if l[k + 1] - p else -1)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	dp = dict()
	dp[a[0]] = 1
	for i in range(1, n):
		if not a[i] in dp:
			dp[a[i]] = 1
		if a[i] - 1 in dp:
			dp[a[i]] = dp[a[i] - 1] + 1
	lst = a[0]
	for x in dp:
		if dp[lst] < dp[x]:
			lst = x
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] == lst:
			ans.append(i + 1)
			lst -= 1
	print(len(ans))
	print(*ans[::-1])
main()


from sys import stdin
from collections import *

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, a, mem) = (int(input()), arr_inp(1), defaultdict(int))
for i in range(n):
	if mem[a[i] - 1]:
		mem[a[i]] = mem[a[i] - 1] + 1
	else:
		mem[a[i]] = 1
(ma, ans) = (max(mem, key=mem.get), deque())
c = ma - mem[ma]
for i in range(n - 1, -1, -1):
	if ma == c:
		break
	if a[i] == ma:
		ans.appendleft(i + 1)
		ma -= 1
print(len(ans))
print(*ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(n):
	if not d.get(l[i]) and (not d.get(l[i] + 1)):
		d[l[i] + 1] = 1
	elif d.get(l[i]):
		tmp = d[l[i]]
		d.pop(l[i])
		if not d.get(l[i] + 1) or (d.get(l[i] + 1) and d[l[i] + 1] < tmp + 1):
			d[l[i] + 1] = tmp + 1
mkey = 0
m = 0
for (key, value) in d.items():
	if value > m:
		mkey = key
		m = value
mkey -= m
ans = []
for i in range(n):
	if l[i] == mkey:
		ans.append(i + 1)
		mkey += 1
print(len(ans))
for x in ans:
	print(x, end=' ')


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = list(mints())
d = dict()
p = dict()
dp = [0] * n
pd = [0] * n
r = (0, 0)
for i in range(n):
	x = a[i]
	v = d.get(x - 1, 0) + 1
	r = max(r, (v, i))
	dp[i] = v
	pd[i] = p.get(x - 1, -1)
	d[x] = dp[i]
	p[x] = i
print(r[0])
res = []
x = r[1]
while len(res) < r[0]:
	res.append(x + 1)
	x = pd[x]
print(*res[::-1])


from collections import defaultdict

def solve(a):
	cnt = defaultdict(int)
	for el in a:
		c1 = 1 + cnt[el - 1]
		cnt[el] = max(cnt[el], c1)
	(max_cnt, last_el) = max(((v, k) for (k, v) in cnt.items()))
	res = []
	for (i, el) in reversed(list(enumerate(a, 1))):
		if el == last_el:
			res.append(i)
			last_el -= 1
	res.reverse()
	return res
n_str = input()
a = [int(x) for x in input().split()]
res = solve(a)
print(len(res))
print(' '.join((str(x) for x in res)))


n = int(input())
a = [int(x) for x in input().split()]
b = [-1 for _ in range(n)]
dp = {}
best = -1
best2 = -1
for (i, x) in enumerate(a):
	(p, q) = dp.get(x, (1, i))
	(r, t) = dp.get(x - 1, (0, 0))
	if r + 1 > p:
		(p, q) = (r + 1, i)
	else:
		t = i
	dp[x] = (p, q)
	b[i] = t
	if best < 0 or dp[best][0] < p:
		best = x
		best2 = i
ans = []
m = dp[best][0]
for _ in range(m):
	ans.append(best2)
	best2 = b[best2]
ans.reverse()
print(len(ans))
print(' '.join([str(x + 1) for x in ans]))


a = int(input())
b = [int(i) for i in input().split()]
d = {i: 0 for i in b}
lst = 0
ans = 0
for i in b:
	if i - 1 not in d:
		d[i] = 1
	else:
		d[i] = d[i - 1] + 1
	if ans < d[i]:
		ans = d[i]
		lst = i
anss = []
for i in range(len(b) - 1, -1, -1):
	if b[i] == lst:
		anss.append(i + 1)
		lst -= 1
print(len(anss))
anss = [str(i) for i in anss[::-1]]
print(' '.join(anss))


input()
a = list(map(int, input().split()))
dp = {}
for x in a:
	dp[x] = dp.get(x - 1, 0) + 1
r = max(dp, key=dp.get)
s = r - dp[r] + 1
print(dp[r])
r = []
for (i, x) in enumerate(a):
	if x == s:
		r.append(i + 1)
		s += 1
print(*r)


import bisect
import sys
import math
input = sys.stdin.readline
t = 1
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	dp = {}
	dp[l[0]] = 1
	for i in range(1, n):
		dp[l[i]] = max(dp.get(l[i] - 1, 0) + 1, dp.get(l[i], 0))
	(maxi, ind) = (1, 1)
	for i in dp:
		if maxi < dp[i]:
			maxi = dp[i]
			ind = i
	if maxi == 1:
		print(1)
		print(1)
	else:
		print(maxi)
		ans = []
		for i in range(n - 1, -1, -1):
			if l[i] == ind:
				ans.append(i + 1)
				ind = l[i] - 1
		print(*ans[::-1])


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = {}
maxi = 0
for i in range(n):
	if a[i] not in b.keys():
		b[a[i]] = 1
	if a[i] - 1 in b.keys():
		b[a[i]] = max(b[a[i]], b[a[i] - 1] + 1)
	if b[a[i]] > maxi:
		maxi = b[a[i]]
		pos = i
print(maxi)
res = [pos + 1]
target = a[pos] - 1
for i in range(pos, -1, -1):
	if target <= 0:
		break
	if a[i] == target:
		res.append(i + 1)
		target -= 1
for i in range(maxi - 1, -1, -1):
	print(res[i], end=' ')


n = int(input())
data = list(map(int, input().split()))
best = [(1, None) for _ in range(n)]
idx = {}
idx[data[-1]] = n - 1
for i in range(n - 2, -1, -1):
	if data[i] + 1 in idx:
		best[i] = (1 + best[idx[data[i] + 1]][0], idx[data[i] + 1])
	if data[i] in idx:
		if best[i][0] > best[idx[data[i]]][0]:
			idx[data[i]] = i
	else:
		idx[data[i]] = i
best_idx = 0
k = best[0][0]
for i in range(1, n):
	if k < best[i][0]:
		k = best[i][0]
		best_idx = i
print(k)
output = []
for i in range(k - 1):
	output.append(str(best_idx + 1))
	best_idx = best[best_idx][1]
output.append(str(best_idx + 1))
print(' '.join(output))


n = int(input())
nums = list(map(int, input().split()))
num2len = dict()
for num in nums:
	num2len[num] = num2len.get(num - 1, 0) + 1
(max_num, max_len) = max(num2len.items(), key=lambda x: x[1])
print(max_len)
cur = max_num - max_len + 1
idxs = []
for (i, num) in enumerate(nums):
	if num == cur:
		idxs.append(str(i + 1))
		cur += 1
		if cur == max_num + 1:
			break
print(' '.join(idxs))


n = int(input())
a = [int(i) for i in input().split()]
dp = [1] * n
p = [-1] * n
m = {}
for i in range(n):
	m[a[i]] = i
	try:
		dp[i] = dp[m[a[i] - 1]] + 1
		p[i] = m[a[i] - 1]
	except:
		dp[i] = 1
ans = [0] * max(dp)
c = dp.index(max(dp))
ans[0] = c + 1
k = 1
while ans[len(ans) - 1] == 0:
	c = p[c]
	ans[k] = c + 1
	k += 1
	if p[c] == -1:
		break
print(max(dp))
ans.reverse()
print(*ans)


k = int(input())
arr = input().split(' ')
arr = [int(x) for x in arr]
d = {}
for i in range(k):
	if arr[i] - 1 in d.keys():
		d[arr[i]] = d[arr[i] - 1] + 1
	else:
		d[arr[i]] = 1
longest = max(d.values())
print(longest)
largest = 0
for j in d.keys():
	if d[j] == longest:
		largest = j
		break
length = largest - longest + 1
answer = []
for r in range(k):
	if arr[r] == length:
		answer.append(str(r + 1))
		length += 1
	if length == largest + 1:
		break
print(' '.join(answer))


n = int(input())
a = list(map(int, input().split()))
fr = {}
for i in range(n):
	if a[i] - 1 in fr:
		if a[i] in fr:
			fr[a[i]] = max(fr[a[i] - 1] + 1, fr[a[i]])
		else:
			fr[a[i]] = fr[a[i] - 1] + 1
	else:
		fr[a[i]] = 1
ans = max(fr.values())
for i in fr.keys():
	if fr[i] == ans:
		db = i
		break
ansl = []
c = 0
j = n - 1
while j > -1 and c < ans:
	if a[j] == i:
		ansl.append(j + 1)
		i = i - 1
	j = j - 1
print(ans)
print(*ansl[::-1])


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {}
	for i in range(n):
		if a[i] - 1 not in d:
			d[a[i]] = 1
		else:
			d[a[i]] = d[a[i] - 1] + 1
	mx = -1
	ans = 0
	for k in d:
		if d[k] > mx:
			mx = d[k]
			ans = k
	ix = -1
	for i in range(n - 1, -1, -1):
		if a[i] == ans:
			ix = i
			break
	ai = [ix + 1]
	print(mx)
	for i in range(ix, -1, -1):
		if a[i] == ans - 1 and mx > 0:
			ans -= 1
			mx -= 1
			ai.append(i + 1)
	ai.reverse()
	print(*ai)


from collections import defaultdict

def find(a, i, dic):
	if dic[a] == [] or dic[a][-1] < i:
		return -1
	left = 0
	right = len(dic[a]) - 1
	while left <= right:
		mid = (left + right) // 2
		if dic[a][mid] == i + 1:
			return i + 1
		elif dic[a][mid] > i:
			right = mid - 1
		else:
			left = mid + 1
	if dic[a][mid] > i:
		return dic[a][mid]
	return dic[a][mid + 1]

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	dic = defaultdict(list)
	for i in range(n):
		dic[a[i]].append(i)
	darray = [-1] * n
	for i in range(n - 1, -1, -1):
		idx = find(a[i] + 1, i, dic)
		if idx == -1:
			darray[i] = 1
		else:
			darray[i] = darray[idx] + 1
	cm = 0
	idx = 0
	for i in range(n):
		if darray[i] > cm:
			cm = darray[i]
			idx = i
	print(cm)
	cm = a[idx]
	for i in range(n):
		if a[i] == cm:
			print(i + 1, end=' ')
			cm += 1
main()


from collections import defaultdict
n = int(input())
A = list(map(int, input().split()))
last = defaultdict(int)
D = {0: (0, 0)}
best = (0, 0)
for (i, a) in enumerate(A, start=1):
	last[a] = i
	last_a1 = last[a - 1]
	(best_a1, _) = D[last_a1]
	D[i] = (1 + best_a1, last_a1)
	best = max(best, (1 + best_a1, i))
print(best[0])
rsseq = []
i = best[1]
while i != 0:
	rsseq.append(i)
	i = D[i][1]
print(' '.join(map(str, reversed(rsseq))))


N = int(input())
D = {}
L = list(map(int, input().split()))[::-1]
for i in L:
	D[i] = max(D.get(i, 0), D.get(i + 1, 0) + 1)
M = max([(i[1], -i[0]) for i in D.items()])
L.reverse()
print(M[0])
M = -M[1]
for i in range(N):
	if L[i] == M:
		print(i + 1, end=' ')
		M += 1


import bisect

def main():
	n = int(input())
	dp = {}
	indices = {}
	arr = list(map(int, input().split()))
	for i in range(n - 1, -1, -1):
		x = arr[i]
		if x not in indices.keys():
			indices[x] = []
		indices[x].append(i)
		if x not in dp.keys():
			dp[x] = 1
		if x + 1 in dp.keys():
			dp[x] = max(dp[x], dp[x + 1] + 1)
	for i in indices.keys():
		indices[i].reverse()
	start = -1
	k = 0
	for i in dp.keys():
		if dp[i] > k:
			k = dp[i]
			start = i
	index = -1
	ans = []
	while k > 0:
		index = bisect.bisect(indices[start], index)
		index = indices[start][index]
		ans.append(index + 1)
		start = arr[index] + 1
		k -= 1
	print(len(ans))
	for i in ans:
		print(i, end=' ')
main()


from collections import *
import sys
input = lambda : sys.stdin.readline().strip()
orddict = OrderedDict
defdict = defaultdict
counter = Counter

def nextint():
	return int(input())

def snexts():
	return input().split(' ')

def snextint():
	return map(int, snexts())
n = nextint()
lis = [0] + list(map(int, input().split()))
dic = {}
for i in range(1, n + 1):
	if lis[i] in dic:
		dic[lis[i]] = min(dic[lis[i]], i)
	else:
		dic[lis[i]] = i
dp = [0] * (n + 1)
par = [-1] * (n + 1)
for i in range(1, n + 1):
	lastv = lis[i] - 1
	if lastv in dic and dic[lastv] < i:
		lastind = dic[lastv]
		dp[i] = dp[lastind] + 1
		par[i] = lastind
	dic[lis[i]] = i
best = -100
bestind = -1
for i in range(1, n + 1):
	if dp[i] > best:
		best = dp[i]
		bestind = i
outputs = []
while bestind != -1:
	outputs.append(bestind)
	bestind = par[bestind]
print(best + 1)
print(' '.join(reversed(list(map(str, outputs)))))


n = int(input().strip())
ais = list(map(int, input().strip().split()))
dp = {}
for a in ais:
	dp[a] = dp.get(a - 1, 0) + 1
(_, amax) = max(((v, k) for (k, v) in dp.items()))
res = []
for i in reversed(range(n)):
	if ais[i] == amax:
		res.append(i + 1)
		amax -= 1
print(len(res))
print(' '.join(map(str, reversed(res))))


from sys import stdin, stdout
from collections import defaultdict
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
dp = defaultdict(list)
last = 0
for i in range(n):
	if a[i] - 1 not in dp:
		dp[a[i]] = 1
	else:
		dp[a[i]] = dp[a[i] - 1] + 1
(m, last) = (0, 0)
for (k, v) in zip(dp.keys(), dp.values()):
	if v > m:
		m = v
		last = k
seq = []
for i in range(n - 1, -1, -1):
	if a[i] == last:
		seq.append(i)
		last -= 1
seq = seq[::-1]
stdout.write('{}\n'.format(len(seq)))
for i in range(len(seq)):
	stdout.write('{} '.format(seq[i] + 1))
stdout.write('\n')


n = int(input())
a = list(map(int, input().split()))
di = {}
for i in range(n):
	if a[i] not in di:
		di[a[i]] = 0
	if a[i] + 1 not in di:
		di[a[i] + 1] = 0
	di[a[i] + 1] = max(di[a[i] + 1], di[a[i]] + 1)
mx = 0
for (k, v) in di.items():
	if mx < v:
		mx = v
		now = k - v
print(mx)
ans = []
for i in range(n):
	if a[i] != now:
		continue
	ans.append(i + 1)
	now += 1
print(*ans)


import sys
from collections import defaultdict

def solve(io):
	N = io.readInt()
	A = io.readIntArray(N)
	prev = [-1] * N
	size = [1] * N
	last = defaultdict(lambda : -1)
	for i in range(0, N):
		idx = last[A[i] - 1]
		if idx >= 0:
			prev[i] = idx
			size[i] = 1 + size[idx]
		last[A[i]] = i
	bestIdx = 0
	for i in range(1, N):
		if size[i] > size[bestIdx]:
			bestIdx = i
	path = []
	curr = bestIdx
	while curr >= 0:
		path.append(curr)
		curr = prev[curr]
	io.println(len(path))
	io.println(' '.join((str(x + 1) for x in reversed(path))))

class IO:
	input = None
	output = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, inputStream, outputStream):
		self.input = inputStream
		self.output = outputStream

	def readToBuffer(self):
		self.raw = self.input.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def readString(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def readInt(self):
		return int(self.readString())

	def readFloat(self):
		return float(self.readString())

	def readStringArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readString())
		return arr

	def readIntArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readInt())
		return arr

	def readFloatArray(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.readFloat())
		return arr

	def readLine(self):
		while self.pos == len(self.buf):
			self.readToBuffer()
		if self.pos > 0:
			raise ValueError('Cannot call readline in the middle of a line.')
		return self.raw

	def print(self, s):
		self.output.write(str(s))

	def println(self, s):
		self.print(s)
		self.print('\n')

	def flushOutput(self):
		self.output.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flushOutput()


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
dp = defaultdict(int)
for v in a:
	dp[v] = dp[v - 1] + 1
(cur, _) = max(dp.items(), key=lambda x: x[1])
ret = []
for i in range(n - 1, -1, -1):
	if a[i] == cur:
		ret.append(i + 1)
		cur -= 1
print('%d\n%s' % (len(ret), ' '.join(map(str, ret[::-1]))))


import sys
from collections import defaultdict
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	dp = defaultdict(lambda : 0)
	best = 0
	nd = 0
	for x in a:
		dp[x] = dp[x - 1] + 1
		if dp[x] > best:
			best = dp[x]
			nd = x
	ans = []
	while best > 0:
		ans.append(nd)
		nd -= 1
		best -= 1
	ans = list(reversed(ans))
	idxs = []
	j = 0
	for (i, x) in enumerate(a):
		if x == ans[j]:
			idxs.append(i + 1)
			j += 1
			if j == len(ans):
				break
	print(len(ans))
	print(' '.join(map(str, idxs)))
main()


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = {}
length = -1
for i in range(n):
	try:
		d[a[i]] = d[a[i] - 1] + 1
	except KeyError:
		d[a[i]] = 1
	if length < d[a[i]]:
		length = d[a[i]]
		lp = i
print(length)
target = a[lp] - length + 1
cnt = 0
i = 0
while cnt < n and i < n:
	if a[i] == target:
		print(i + 1, end=' ')
		target += 1
		cnt += 1
	i += 1
print()


n = int(input())
arr = list(map(int, input().split()))
dp = [0 for i in range(n)]
dic = {}
for i in range(1, n + 1):
	num = arr[-i]
	if num + 1 in dic:
		dp[-i] = dp[dic[num + 1]] + 1
	else:
		dp[-i] = 1
	dic[num] = -i
ans = max(dp)
print(ans)
final = []
init = float('inf')
for i in range(n):
	if dp[i] == ans:
		init = arr[i]
		ans = 0
	if arr[i] == init:
		final += [i + 1]
		init += 1
print(' '.join(list(map(str, final))))


n = int(input())
nums = [int(x) for x in input().split()]
didi = {}
madidi = 0
ididi = -1
for nu in nums:
	if didi.get(nu - 1, 0) + 1 > didi.get(nu, 0):
		didi[nu] = didi.get(nu - 1, 0) + 1
		didi[nu - 1] = 0
		if didi[nu] > madidi:
			madidi = didi[nu]
			ididi = nu
print(madidi)
res = []
for (i, v) in reversed(list(enumerate(nums, 1))):
	if v == ididi:
		res.append(i)
		ididi -= 1
print(' '.join(map(str, reversed(res))))


from collections import defaultdict, deque
from heapq import heappush, heappop
from math import inf
ri = lambda : map(int, input().split())

def solve():
	n = int(input())
	A = list(ri())
	dp = defaultdict(int)
	for x in A:
		if dp[x - 1] == 0:
			dp[x] = 1
		else:
			dp[x] = dp[x - 1] + 1
	mx = max(dp.values())
	start = -1
	for x in dp:
		if dp[x] == mx:
			start = x - mx + 1
	print(mx)
	have = 0
	for i in range(n):
		if have == mx:
			break
		if A[i] == start:
			start += 1
			print(i + 1, end=' ')
			have += 1
	print()
t = 1
while t:
	t -= 1
	solve()


n = int(input())
lst = list(map(int, input().split()))
(d, res) = ({}, [0] * n)
for (i, x) in enumerate(lst):
	if d.get(x - 1) == None:
		res[i] = 1
	else:
		res[i] = res[d[x - 1]] + 1
	d[x] = i
x = max(res)
print(x)
result = []
for i in range(n - 1, -1, -1):
	if res[i] == x:
		a = lst[i]
		break
for j in range(i, -1, -1):
	if lst[j] == a and res[j] == x:
		a -= 1
		x -= 1
		result.append(j + 1)
result.reverse()
print(*result)


n = int(input())
a = list(map(int, input().split()))
d = {}
prv = [-1] * n
(mx, idx) = (0, -1)
for (i, x) in enumerate(a):
	if x - 1 in d:
		d[x] = (d[x - 1][0] + 1, i)
		prv[i] = d[x - 1][1]
	else:
		d[x] = (1, i)
	if d[x][0] > mx:
		mx = d[x][0]
		idx = i
L = []
for i in range(mx):
	L.append(idx + 1)
	idx = prv[idx]
print(mx)
print(*L[::-1])


def reconst(x):
	out = []
	while x:
		out.append(x)
		x = prev[x - 1]
	for i in range(0, len(out)):
		print(out[len(out) - i - 1], end=' ')
n = int(input())
numbers = input().split()
v = []
for i in numbers:
	v.append(int(i))
dp = {}
where = {}
prev = []
ans = 0
for i in v:
	if i - 1 in dp:
		x = dp[i - 1] + 1
		pos = where[i - 1]
	else:
		x = 1
		pos = 0
	if i in dp:
		dp[i] = max(dp[i], x)
	else:
		dp[i] = x
	prev.append(pos)
	where[i] = len(prev)
	if ans < x:
		ans = x
		finalPos = len(prev)
print(ans)
reconst(finalPos)


n = int(input())
arr = [int(x) for x in input().split()]
d = {}
for i in arr:
	d[i] = d.get(i - 1, 0) + 1
m = 0
x = 0
for ele in d.keys():
	if d[ele] > m:
		x = ele
		m = d[ele]
i = n - 1
l = []
while i >= 0:
	if arr[i] == x:
		l.append(i + 1)
		x = x - 1
	i = i - 1
print(len(l))
print(*l[::-1])


n = int(input())
arr = list(map(int, input().split()))
dp = {}
maxn = 0
max_ind = 0
for i in arr:
	dp[i] = dp.get(i - 1, 0) + 1
for i in dp.keys():
	if dp[i] > maxn:
		maxn = dp[i]
		max_ind = i
start = max_ind - maxn + 1
print(maxn)
count = 0
for i in arr:
	count += 1
	if i == start:
		print(count, end=' ')
		start += 1
print()


n = int(input())
nums = [int(num) for num in input().split()]
num2len = {}
num2idx = {}
for i in range(n):
	num = nums[i]
	num2idx[num] = i
	if i == 0:
		num2len[num] = 1
		continue
	num2len[num] = num2len[num - 1] + 1 if num - 1 in num2len else 1
max_num = None
max_len = 0
for num in num2len:
	if num2len[num] > max_len:
		max_num = num
		max_len = num2len[num]
print(max_len)
cur = max_num - max_len + 1
idxs = []
for i in range(n):
	if nums[i] == cur:
		idxs.append(str(i + 1))
		cur += 1
		if cur == max_num + 1:
			break
print(' '.join(idxs))


n = int(input())
a = list(map(int, input().split()))
d = dict()
for i in range(n):
	if a[i] - 1 not in d:
		if a[i] not in d:
			d[a[i]] = 1
	elif a[i] in d:
		if d[a[i]] < d[a[i] - 1] + 1:
			d[a[i]] = d[a[i] - 1] + 1
	else:
		d[a[i]] = d[a[i] - 1] + 1
pos = -1
val = -1
for i in d.keys():
	if d[i] > val:
		val = d[i]
		pos = i
print(val)
ans = []
for i in range(n - 1, -1, -1):
	if a[i] == pos - len(ans):
		ans.append(i + 1)
print(*reversed(ans))


from collections import defaultdict
n = int(input())
li = [int(k) for k in input().split()]
dic = defaultdict(int)
ans = 0
id = 0
for i in li:
	if i - 1 in dic:
		dic[i] = max(dic[i], dic[i - 1] + 1)
	else:
		dic[i] = 1
	ans = max(ans, dic[i])
	if ans == dic[i]:
		id = i
print(ans)
res = []
for j in range(n - 1, -1, -1):
	if li[j] == id:
		res.append(j + 1)
		id -= 1
print(*res[::-1])


from sys import stdin as si
from sys import maxsize as m
from collections import Counter as C
from operator import itemgetter as ig
from functools import reduce

class Solution:

	def bazinga1(self, k, t):
		st = sorted(list(enumerate(t)), key=ig(1))
		stack = []
		temp = [st[0][0]]
		print(st)
		for i in range(1, len(st)):
			print(temp)
			if st[i][1] == t[temp[-1]]:
				temp.append(min(st[i][0], temp[-1]))
				temp.pop(-2)
				continue
			if st[i][0] > temp[-1] and st[i][1] == t[temp[-1]] + 1:
				temp.append(st[i][0])
			else:
				if len(temp) >= len(stack):
					stack = temp[:]
				temp = [st[i][0]]
		if len(temp) >= len(stack):
			stack = temp[:]
		print(len(stack))
		stack = [1 + x for x in stack]
		print(*stack)

	def bazinga2(self, k, t):
		d = {}
		for i in range(len(t)):
			d[t[i]] = d.get(t[i], []) + [i]
		self.sd = sorted(d.items())
		del d
		self.g = t
		l = len(self.sd)
		self.temp = []
		self.bazinga2(0, l)
		stack = reduce(lambda x, y: x if len(x) > len(y) else y, self.temp)
		print(len(stack))
		stack = [1 + x for x in stack]
		print(*stack)

	def bazinga21(self, i, l, sdi=None):
		t = []
		if i == l - 1:
			for j in self.sd[l - 1][1]:
				if self.g[sdi] + 1 == self.g[j]:
					t.append([j])
			if t != []:
				self.temp.extend(t)
		else:
			b = []
			for j in self.sd[i][1]:
				self.bazinga2(i + 1, l, j)
				for t in self.temp:
					if self.g[t[0]] == 1 + self.g[j] and t[0] > j:
						t.insert(0, j)
				b.append([j])
			self.temp.extend(b)

	def bazinga(self, n, l):
		(lnt, lst_elmnt) = (0, 0)
		dp = {}
		for i in range(n):
			dp[l[i]] = dp.get(l[i] - 1, 0) + 1
			if lnt < dp[l[i]]:
				lnt = dp[l[i]]
				lst_elmnt = l[i]
		ans = []
		for i in range(n - 1, -1, -1):
			if l[i] == lst_elmnt:
				ans.append(i)
				lst_elmnt -= 1
		print(lnt)
		ans = [1 + j for j in ans[::-1]]
		print(*ans)
n = int(si.readline().strip())
l = list(map(int, si.readline().strip().split()))
S = Solution()
S.bazinga(n, l)


n = int(input())
mp = {}
values = [0 for i in range(0, n)]
lastV = -1
maxLen = 0
values = list(map(int, input().split(' ')))
for i in range(0, n):
	if values[i] - 1 in mp:
		mp[values[i]] = mp[values[i] - 1] + 1
	else:
		mp[values[i]] = 1
	if mp[values[i]] > maxLen:
		maxLen = mp[values[i]]
		lastV = values[i]
currentValue = lastV - maxLen + 1
print(maxLen)
s = ''
for i in range(0, len(values)):
	if values[i] == currentValue:
		i2 = str(i + 1) + ' '
		s += i2
		currentValue += 1
print(s)


n = int(input())
a = [*map(int, input().split())]
c = [None] * n
whereIs = [None] * n
for i in range(0, n):
	c[i] = i
c.sort(key=lambda value: a[value])
tot = 0
for i in range(0, n):
	if i == 0 or a[c[i]] != a[c[i - 1]]:
		whereIs[c[i]] = tot
		tot += 1
	else:
		whereIs[c[i]] = whereIs[c[i - 1]]
dp = [0] * n
preState = [None] * n
lst = [-1] * n
res = 0
ptr = -1
for i in range(0, n):
	if whereIs[i] == 0:
		preState[i] = -1
		dp[i] = 1
	else:
		preState[i] = lst[whereIs[i] - 1]
		if a[preState[i]] != a[i] - 1:
			preState[i] = -1
		if preState[i] != -1:
			dp[i] = dp[preState[i]] + 1
		else:
			dp[i] = 1
	lst[whereIs[i]] = i
	res = max(res, dp[i])
	if res == dp[i]:
		ptr = i
print(res)
resArr = [-1] * res
while res > 0:
	resArr[res - 1] = ptr + 1
	ptr = preState[ptr]
	res -= 1
print(' '.join(map(str, resArr)))


from collections import Counter

def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n,) = read_nums()
	nums = read_nums()
	dp = Counter()
	for i in range(n):
		dp[nums[i]] = dp[nums[i] - 1] + 1
	indexes = {}
	for i in range(n):
		indexes[nums[i]] = i
	last_num = max(list(dp.items()), key=lambda x: x[1])[0]
	result = []
	for i in range(n - 1, -1, -1):
		if nums[i] == last_num:
			result.append(i)
			last_num -= 1
	result.reverse()
	print(len(result))
	print(' '.join([str(x + 1) for x in result]))

def __starting_point():
	main()
__starting_point()


n = int(input())
numbers = [int(s) for s in input().split(' ') if s != '']
sequences = {}
for (i, m) in enumerate(numbers):
	if m - 1 in sequences.keys():
		new_seq = sequences[m - 1][:]
		if m not in sequences.keys() or new_seq[1] - new_seq[0] + 1 > sequences[m][1] - sequences[m][0]:
			new_seq[1] = m
			sequences[m] = new_seq
	elif m not in sequences.keys():
		sequences[m] = [m, m]
longest = None
for s in sequences.values():
	if longest == None or s[1] - s[0] > longest[1] - longest[0]:
		longest = s
print(longest[1] - longest[0] + 1)
m = longest[0]
for i in range(n):
	if numbers[i] == m:
		m += 1
		print(i + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
d = {}
l = {'value': -1, 'index': 0}
for i in a:
	d[i] = d.get(i - 1, 0) + 1
	if d[i] > l['value']:
		l['value'] = d[i]
		l['index'] = i
print(l['value'])
counter = l['index'] - l['value'] + 1
answer = []
for i in range(n):
	if a[i] == counter:
		counter += 1
		answer.append(str(i + 1))
print(' '.join(answer))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
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(map(int, input().split()))
dp = [1] * n
prev = [-1] * n
d = dict()
for i in range(n):
	d[a[i]] = i
	if a[i] - 1 in d:
		dp[i] = dp[d[a[i] - 1]] + 1
		prev[i] = d[a[i] - 1]
mx = 1
ind = 0
for i in range(n):
	if dp[i] > mx:
		mx = dp[i]
		ind = i
print(mx)
res = list()
while ind != -1:
	res.append(ind + 1)
	ind = prev[ind]
print(*res[::-1])


from collections import defaultdict
n = int(input())
lst = list(map(int, input().split()))
dp = defaultdict(int)
max_c = 0
max_n = 0
for i in range(len(lst)):
	dp[lst[i]] = dp[lst[i] - 1] + 1
	if dp[lst[i]] > max_c:
		max_c = dp[lst[i]]
		max_n = lst[i]
ans = []
for i in range(len(lst) - 1, -1, -1):
	if lst[i] == max_n:
		ans.append(i + 1)
		max_n -= 1
print(max_c)
print(' '.join(map(str, list(reversed(ans)))))


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import *

def main():
	n = int(input())
	nums = list(map(int, input().split(' ')))
	dic = {}
	indx = defaultdict(lambda : [])
	for x in range(len(nums)):
		indx[nums[x]].append(x)
		dic[nums[x]] = 1
		if nums[x] - 1 in dic:
			dic[nums[x]] = max(dic[nums[x] - 1] + 1, dic[nums[x]])
	print(max(dic.values()))
	here = max(dic.values())
	for (x, y) in dic.items():
		if y == here:
			start = indx[x][-1] + 1
			ans = []
			for z in range(x, x - y, -1):
				ans.append(indx[z][bl(indx[z], start) - 1] + 1)
				start = ans[-1]
			ans.reverse()
			print(*ans)
			return 0
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()


n = int(input())
a = [int(x) for x in input().split()]
l = len(a)
f = [0] * l
fa = [-1] * l
d = dict()
mlen = 0
mlenp = -1
for (i, num) in enumerate(a):
	p = -1
	if num - 1 in d:
		p = d[num - 1]
	if p == -1:
		f[i] = 1
	else:
		f[i] = f[p] + 1
		fa[i] = p
	if num in d:
		if f[i] > f[d[num]]:
			d[num] = i
	else:
		d[num] = i
	if f[i] > mlen:
		mlen = f[i]
		mlenp = i
ans = list()
cur = mlenp
while cur != -1:
	ans.append(cur)
	cur = fa[cur]
ans.reverse()
print(len(ans))
for num in ans:
	print(num + 1, sep=' ')


def position_zip(a, flag):
	j = 0
	d = {}
	for i in sorted(a):
		if i in d:
			continue
		d[i] = j
		j += 1
	if flag == 1:
		return d
	return [d[i] for i in a]
n = int(input())
a = list(map(int, input().split()))
b = []
for i in a:
	b.append(i - 1)
	b.append(i)
	b.append(i + 1)
d = position_zip(b, 1)
l = len(d)
ans = [[] for _ in range(l)]
dp = list(range(l))
ma = 0
ansi = 0
for i in range(n):
	x = dp[d[a[i] - 1]]
	y = dp[d[a[i]]]
	if len(ans[x]) != 0 and x != y:
		y = dp[d[a[i]]] = x
		ans[y].append(i + 1)
	elif len(ans[y]) == 0:
		ans[y].append(i + 1)
	if len(ans[y]) > ma:
		ma = len(ans[y])
		ansi = y
print(ma)
print(*ans[ansi])


input()
s = list(map(int, input().split()))
d = {}
for a in s:
	d[a] = d.get(a - 1, 0) + 1
a = max(d, key=d.get)
print(d[a])
p = 0
for b in range(a - d[a], a):
	p = s.index(b + 1, p)
	print(p + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
dp = dict()
for ai in a:
	if ai not in dp:
		dp[ai] = 0
	if ai - 1 in dp:
		dp[ai] = max(dp[ai], 1 + dp[ai - 1])
k = max(dp.values())
print(k + 1)
pos = -1
for ai in a:
	if dp[ai] == k:
		pos = ai
idx = []
for i in range(n - 1, -1, -1):
	if a[i] == pos:
		idx.append(i + 1)
		pos -= 1
print(*idx[::-1])


n = int(input())
l = list(map(int, input().split()))
d = {}
dp = [0 for i in range(n)]
ind = dp[:]
dp[0] = 1
d[l[0]] = 0
for i in range(1, len(l)):
	if l[i] - 1 in d:
		dp[i] = 1 + dp[d[l[i] - 1]]
		ind[i] = d[l[i] - 1]
	else:
		dp[i] = 1
	d[l[i]] = i
print(max(dp))
i = dp.index(max(dp))
mx = max(dp)
ans = []
while mx:
	ans.append(i + 1)
	i = ind[i]
	mx -= 1
print(*ans[::-1])


def reconst(pos):
	if pos == 0:
		return
	reconst(prev[pos - 1])
	print(pos, end=' ')
n = int(input())
v = [int(x) for x in input().split()]
dp = {}
res = []
sol = 0
for val in v:
	if val - 1 in dp:
		dp[val] = dp[val - 1] + 1
	else:
		dp[val] = 1
	if sol < dp[val]:
		sol = dp[val]
		lst = val
for i in range(n - 1, -1, -1):
	if v[i] == lst:
		res.append(i)
		lst -= 1
res.reverse()
print(sol)
for i in res:
	print(i + 1, end=' ')


import math, sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
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 minp():
	return map(int, sys.stdin.readline().rstrip().split())

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

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

def print_list(l):
	print(' '.join(map(str, l)))

def lis(a, n):
	dp = {}
	for x in a:
		dp[x] = 0
	max_seq = 0
	end = 0
	for x in a:
		try:
			dp[x] = dp[x - 1] + 1
		except:
			dp[x] = 1
		if dp[x] > max_seq:
			max_seq = dp[x]
			end = x
	print(max_seq)
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] == end:
			ans.append(i + 1)
			end -= 1
	ans.reverse()
	print_list(ans)
n = inp()
a = linp()
lis(a, n)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	d[i] = d.get(i - 1, 0) + 1
k = max(d, key=d.get)
print(d[k])
r = 0
for i in range(k - d[k], k):
	r = a.index(i + 1, r)
	print(r + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
d = {}
for ai in a:
	if ai - 1 in d:
		d[ai] = min(d.get(ai, float('inf')), d[ai - 1])
	elif ai not in d:
		d[ai] = ai
ans = (0, -1)
for (k, v) in d.items():
	if ans[1] - ans[0] < k - v:
		ans = (v, k)
al = []
now = ans[0]
for (i, ai) in enumerate(a):
	if ai == now:
		al.append(i + 1)
		now += 1
print(len(al))
print(' '.join(map(str, al)))


(dp, last, prev) = ({}, {}, [])
input()
for (idx, a) in enumerate(map(int, input().split())):
	dp[a] = dp.get(a - 1, 0) + 1
	last[a] = idx
	prev.append(last.get(a - 1, None))
(a, l) = max(dp.items(), key=lambda x: x[1])
print(l)
(p, ss) = (last[a], [])
while p is not None:
	ss.append(p + 1)
	p = prev[p]
print(*reversed(ss))


n = int(input())
a = list(map(int, input().split()))
d = {}
for c in a:
	d[c] = 0
ans = 0
maxi = 0
for c in a:
	try:
		d[c] = d[c - 1] + 1
		if ans < d[c]:
			ans = d[c]
			maxi = c
	except:
		d[c] = 1
		if ans < d[c]:
			ans = d[c]
			maxi = c
f = []
for i in range(n - 1, -1, -1):
	if a[i] == maxi:
		f.append(i + 1)
		maxi -= 1
f.sort()
print(len(f))
for c in f:
	print(c, end=' ')


n = int(input())
a = list(map(int, input().split()))
d = {}
for ai in a:
	d[ai] = d.get(ai - 1, 0) + 1
maxRange = 0
endVal = 0
for key in d.keys():
	if d[key] > maxRange:
		maxRange = d[key]
		endVal = key
startVal = endVal - maxRange + 1
print(maxRange)
for (i, val) in enumerate(a):
	if val == startVal:
		print(i + 1, end=' ')
		startVal += 1


def lics(array):
	n = len(array)
	index = {}
	dp = [0] * (n + 1)
	for i in range(n):
		if a[i] - 1 in index:
			ind = index[a[i] - 1]
			dp[i + 1] = dp[ind] + 1
		else:
			dp[i + 1] = 1
		index[a[i]] = i + 1
	max_dp = max(dp)
	max_ind = dp.index(max_dp) - 1
	ans = [max_ind]
	num = a[max_ind]
	for i in range(max_ind)[::-1]:
		if a[i] + 1 == num:
			ans.append(i)
			num = a[i]
	return reversed(ans)
n = int(input())
a = list(map(int, input().split()))
ans = lics(a)
ans = [num + 1 for num in ans]
print(len(ans))
print(*ans)


n = int(input())
a = [int(x) for x in input().split()]
dic = {}
f = []
for i in range(n):
	if a[i] - 1 in dic:
		f.append(dic[a[i] - 1] + 1)
	else:
		f.append(1)
	if a[i] in dic:
		dic[a[i]] = max(dic[a[i]], f[i])
	else:
		dic[a[i]] = f[i]
ans = max(f)
print(ans)
index = f.index(ans)
now = a[index] - ans + 1
lis = []
for i in range(n):
	if a[i] == now:
		lis.append(i + 1)
		now = now + 1
print(*lis)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

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

def solve():
	n = N()
	ar = [0] + lis()
	d = defaultdict(int)
	dp = [(0, 0)] * (n + 1)
	for i in range(1, n + 1):
		if dp[d[ar[i]]][0] > dp[d[ar[i] - 1]][0] + 1:
			dp[i] = (dp[d[ar[i]]][0], dp[d[ar[i]]][1])
		else:
			dp[i] = (dp[d[ar[i] - 1]][0] + 1, d[ar[i] - 1])
		d[ar[i]] = i
	ans = []
	curr = max(dp)
	curri = dp.index(curr)
	ans.append(curri)
	while curr[0] > 0:
		ans.append(curr[1])
		curr = dp[curr[1]]
	ans = ans[:-1][::-1]
	print(len(ans))
	print(*ans)
solve()


n = int(input())
vt = list(map(int, input().split()))
dp = [1 for i in range(n)]
mp = {vt[0]: 1}
for i in range(1, n):
	dp[i] = 1 + mp.get(vt[i] - 1, 0)
	mp[vt[i]] = dp[i]
sol = max(dp)
start = vt[dp.index(sol)] - sol + 1
print(sol)
for i in range(n):
	if vt[i] == start:
		print(i + 1, end=' ')
		start += 1


n = int(input())
l = list(map(int, input().split()))
x = {}
for i in range(n):
	x[l[i]] = x.get(l[i] - 1, 0) + 1
(p, j) = (0, 0)
for i in x:
	if x[i] > p:
		p = x[i]
		j = i
ans = []
for i in range(n - 1, -1, -1):
	if l[i] == j:
		ans.append(i + 1)
		j = j - 1
ans = ans[::-1]
print(len(ans))
print(*ans)


from sys import stdin
import sys
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
ans = 0
dp = {}
for i in range(n):
	if arr[i] - 1 not in dp:
		dp[arr[i]] = 1
	else:
		dp[arr[i]] = dp[arr[i] - 1] + 1
	if dp[arr[i]] > ans:
		ans = dp[arr[i]]
		idx = arr[i]
st = []
for i in range(n - 1, -1, -1):
	if arr[i] == idx:
		idx -= 1
		st.append(i + 1)
st.reverse()
print(ans)
print(*st)


from collections import defaultdict
from math import sqrt, factorial, gcd, log2
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
l = list(map(int, input().split()))
s = sorted(set(l))
hash = defaultdict(int)
cnt = 1
la = [i for i in l]
dp = defaultdict(int)
maxi = 0
for i in la:
	dp[i] = dp[i - 1] + 1
	maxi = max(maxi, dp[i])
ans = []
z = maxi
yo = -1
for i in dp:
	if dp[i] == z:
		yo = i
		break
cnt = yo - (z - 1)
leni = 0
for (j, i) in enumerate(la):
	if i == cnt and leni < z:
		ans.append(j + 1)
		leni += 1
		cnt += 1
print(len(ans))
print(*ans)


z = input
n = int(z())
l = list(map(int, z().split()))
ans = {}
for i in l:
	try:
		ans[i] = ans[i - 1] + 1
	except:
		ans[i] = 1
mx = max(ans, key=ans.get)
print(ans[mx])
x = 0
for i in range(mx - ans[mx], mx):
	x = l.index(i + 1, x)
	print(x + 1, end=' ')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
d = defaultdict(int)
for i in l:
	d[i] = 1 + d[i - 1]
m = 0
key = 0
for i in d.keys():
	if m <= d[i]:
		m = d[i]
		key = i
x = key - m + 1
w = []
for i in range(n):
	if l[i] == x:
		w.append(i + 1)
		x += 1
print(m)
print(*w)


n = int(input())
a = list(map(int, input().split()))
s = dict()
for i in range(n):
	if a[i] - 1 in s:
		s[a[i]] = s[a[i] - 1] + 1
	else:
		s[a[i]] = 1
ans = [-1, -1]
for i in s:
	if ans[1] < s[i]:
		ans = [i, s[i]]
ans_ = []
for i in range(n - 1, -1, -1):
	if ans[0] == a[i]:
		ans[0] -= 1
		ans[1] -= 1
		ans_.append(i + 1)
		if ans[1] == 0:
			break
print(len(ans_))
print(' '.join(map(str, ans_[::-1])))


from typing import List

def longestConsecutiveIntegerSubsequence(a: List[int]) -> List[int]:
	n = len(a)
	indexes = {}
	lenLCISubseq = [1] * n
	parent = [-1] * n
	(maxLen, maxSubseqEndIndex) = (0, 0)
	for (i, v) in enumerate(a):
		prevIndex = indexes.get(v - 1, -1)
		if prevIndex >= 0:
			lenLCISubseq[i] = lenLCISubseq[prevIndex] + 1
			parent[i] = prevIndex
		if lenLCISubseq[i] > maxLen:
			maxLen = lenLCISubseq[i]
			maxSubseqEndIndex = i
		prevOccurence = indexes.get(v, -1)
		if prevOccurence < 0 or lenLCISubseq[prevOccurence] < lenLCISubseq[i]:
			indexes[v] = i
	result = [0] * maxLen
	for i in reversed(range(maxLen)):
		result[i] = maxSubseqEndIndex + 1
		maxSubseqEndIndex = parent[maxSubseqEndIndex]
	return result
n = int(input())
a = list(map(int, input().strip().split()))
result = longestConsecutiveIntegerSubsequence(a)
print(len(result))
print(' '.join(map(str, result)))


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
mp = defaultdict(list)
for i in range(n):
	mp[a[i]].append(i)
dp = [1] * n
p = [i for i in range(n)]
for i in range(n):
	best = -1
	mx = 0
	j = -1
	l = 0
	r = len(mp[a[i] - 1]) - 1
	while l <= r:
		m = (l + r) // 2
		if mp[a[i] - 1][m] < i:
			j = mp[a[i] - 1][m]
			l = m + 1
		else:
			r = m - 1
	if j == -1:
		continue
	p[i] = j
	dp[i] += dp[j]
best = 0
mx = 0
for i in range(n):
	if mx < dp[i]:
		mx = dp[i]
		best = i
ans = []
while best != p[best]:
	ans.append(best + 1)
	best = p[best]
ans.append(best + 1)
ans = ans[::-1]
print(len(ans))
print(*ans)


import sys
from typing import List, Tuple
input = sys.stdin.readline

def solve(n: int, a: List[int]) -> Tuple[int, List[int]]:
	t = {}
	p = {}
	maxi_len = 0
	maxi_val = None
	for i in range(n):
		v = a[i]
		if v - 1 in t:
			t[v] = (t[v - 1][0] + 1, i)
			p[i] = t[v - 1][1]
		else:
			t[v] = (1, i, None)
		if t[v][0] > maxi_len:
			maxi_len = t[v][0]
			maxi_val = v
	i = t[maxi_val][1]
	indice = []
	while i in p:
		indice.append(i + 1)
		i = p[i]
	indice.append(i + 1)
	return (maxi_len, indice[::-1])
n = int(input())
a = list(map(int, input().split()))
(maxi_val, indices) = solve(n, a)
print(maxi_val)
print(' '.join(map(str, indices)))


import sys
from array import array
from collections import Counter, defaultdict

def input():
	return sys.stdin.buffer.readline().decode('utf-8')
n = int(input())
a = list(map(int, input().split()))
(dp, dp_index) = (Counter(), {})
dp_prev = defaultdict(lambda : -1)
for (i, x) in enumerate(a, start=1):
	if dp[x] < dp[x - 1] + 1:
		dp[x] = dp[x - 1] + 1
		dp_index[x] = i
		if dp[x] > 1:
			dp_prev[i] = dp_index[x - 1]
ans = []
(x, cnt) = dp.most_common(1)[0]
index = dp_index[x]
for _ in range(cnt):
	ans.append(index)
	index = dp_prev[index]
print(len(ans))
print(*reversed(ans))


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
positions = defaultdict(int)
for i in range(n):
	positions[a[i]] = 1 + positions[a[i] - 1]
max_num = 1
max_val = a[0]
for (k, v) in positions.items():
	if v >= max_num:
		max_num = v
		max_val = k
ans = []
for i in range(n - 1, -1, -1):
	if a[i] == max_val:
		ans.append(i + 1)
		max_val -= 1
ans.sort()
print(max_num)
print(*ans)


n = int(input())
s = list(map(int, input().split()))
rl = {}
best_range = range(0)
for x in s:
	run = rl[x] = rl.get(x - 1, 0) + 1
	r = range(x - run + 1, x + 1)
	if len(r) > len(best_range):
		best_range = r
res = list(best_range)
size = len(res)
output = []
pointer = 0
for (i, c) in enumerate(s):
	if res[pointer] == c:
		output.append(str(i + 1))
		pointer += 1
	if pointer >= size:
		break
print(size)
print(' '.join(output))


from collections import defaultdict
from math import inf
n = int(input())
a = [int(x) for x in input().split()]
z = defaultdict(lambda : -1)
dp = [1 for i in range(n)]
m = -inf
for j in range(n - 1, -1, -1):
	if z[a[j]] != -1:
		dp[j] = max(dp[j], dp[z[a[j]]])
	if z[a[j] + 1] != -1:
		dp[j] = max(dp[j], dp[z[a[j] + 1]] + 1)
	z[a[j]] = j
	if m < dp[j]:
		m = dp[j]
		an = j
if m < dp[j]:
	m = dp[j]
	an = j
c = a[an]
x = []
for i in range(n):
	if a[i] == c:
		c += 1
		x.append(i + 1)
print(len(x))
print(*x)


n = int(input())
inp = [int(var) for var in input().split()]
dp = {}
ans = 0
last = 0
for i in inp:
	dp[i] = max(dp.get(i - 1, 0) + 1, dp.get(i, 0))
	if dp[i] > ans:
		ans = dp[i]
		last = i
print(ans)
for i in range(n):
	if inp[i] == last - ans + 1:
		print(i + 1, end=' ')
		ans -= 1


n = int(input())
lis = [int(l) for l in input().split()]
dp = {}
(mv, ml) = (0, 0)
i = 1
while i <= n:
	cur = lis[i - 1]
	dp[cur] = dp.get(cur - 1, 0) + 1
	if dp[cur] > mv:
		mv = dp[cur]
		ml = cur
	i += 1
res = []
i = len(lis) - 1
while i >= 0:
	if lis[i] == ml:
		res += [str(i + 1)]
		ml -= 1
	i -= 1
print(len(res))
print(' '.join(res[::-1]))


from collections import *
import bisect
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
maxx = -1
for i in a:
	dic[i] = max(dic[i], 1 + dic[i - 1])
	maxx = max(maxx, dic[i])
store = -1
for i in dic:
	if dic[i] == maxx:
		store = i
ans = []
for i in range(n - 1, -1, -1):
	if store == 0:
		break
	if a[i] == store:
		ans.append(i + 1)
		store -= 1
print(maxx)
print(*ans[::-1])


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

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

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	dp = [0] * len(arr)
	s = dict()
	maxIdx = 0
	for i in range(len(arr)):
		if arr[i] - 1 in s:
			dp[i] = s[arr[i] - 1] + 1
			s[arr[i]] = dp[i]
		else:
			dp[i] = 1
			s[arr[i]] = 1
		if dp[maxIdx] <= dp[i]:
			maxIdx = i
	entry = arr[maxIdx] - dp[maxIdx] + 1
	print(dp[maxIdx])
	res = []
	for i in range(len(arr)):
		if arr[i] == entry:
			res.append(i + 1)
			entry += 1
	print(' '.join(map(str, res)))
main()


n = int(input())
arr_a = input().split()
arr_a = [int(a) for a in arr_a]
dicionario = dict()
for a in arr_a:
	dicionario[a] = dicionario.get(a - 1, 0) + 1
comeco = 0
final = 0
result = 0
for k in dicionario.keys():
	if dicionario[k] > result:
		result = dicionario[k]
		final = k
		comeco = k - dicionario[k] + 1
print(result)
atual = comeco
for (i, x) in enumerate(arr_a):
	if atual == x:
		print(i + 1, end=' ')
		atual += 1


import sys
line = lambda : sys.stdin.buffer.readline()
n = int(line())
a = [*map(int, line().split())]
pre = [0] * n
res = 0
ans = 0
c = {}
p = {}
for i in range(n):
	if a[i] - 1 not in c:
		c[a[i]] = 1
		pre[i] = -1
		p[a[i]] = i
	else:
		c[a[i]] = c[a[i] - 1] + 1
		pre[i] = p[a[i] - 1]
		p[a[i]] = i
	if c[a[i]] > ans:
		res = i
		ans = c[a[i]]
print(ans)
r = [res]
while pre[r[-1]] >= 0:
	r.append(pre[r[-1]])
r.reverse()
print(*(x + 1 for x in r))


import collections
n = int(input(''))
nums = list(map(int, input('').split(' ')))
dp = collections.defaultdict(int)
for i in range(n):
	dp[nums[i]] = max(dp[nums[i] - 1] + 1, dp[nums[i]])
mx = max(dp.values())
ans = None
for i in dp:
	if dp[i] == mx:
		ans = i
output = []
for i in range(n)[::-1]:
	if nums[i] == ans:
		ans -= 1
		output.append(i + 1)
print(len(output))
print(*output[::-1])


from sys import stdin, stdout
input = lambda : stdin.readline().rstrip('\r\n')
from collections import deque as que, defaultdict as vector
from heapq import *
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
Testcase = 1
for Casenumber in range(Testcase):
	n = inin()
	a = inar()
	dp = vector(int)
	for i in a:
		dp[i] = max(dp[i], dp[i - 1] + 1)
	ans = 0
	for i in dp:
		ans = max(ans, dp[i])
	ele = 0
	for i in a:
		if dp[i] == ans:
			ele = i
			break
	ff = []
	for i in range(n - 1, -1, -1):
		if a[i] == ele:
			ff.append(i + 1)
			ele -= 1
	ff.reverse()
	print(len(ff))
	print(*ff)


n = int(input())
a = list(map(int, input().split()))
d = {}
for x in a:
	d[x] = max(d.get(x - 1, 0) + 1, d.get(x, 0))
(value, length) = max(d.items(), key=lambda x: x[1])
seq = []
print(length)
for i in range(len(a) - 1, -1, -1):
	if a[i] == value:
		seq.append(i + 1)
		value -= 1
print(' '.join(map(str, seq[::-1])))


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
n = ri()
a = ris()
mp = ddict(int)
best = 0
for i in range(n - 1, -1, -1):
	x = a[i]
	mp[x] = max(mp[x], 1 + mp[x + 1])
	if mp[x] >= mp[a[best]]:
		best = i
i = j = best
k = mp[a[i]] - 1
ans = [i + 1]
while k > 0:
	if a[i] == a[j] - 1:
		ans.append(j + 1)
		k -= 1
		i = j
	j += 1
print(len(ans))
print(*ans)


n = int(input())
a = list(map(int, input().split()))
arr = {}
k = -1
indx = 0
for i in a:
	arr[i] = arr.get(i - 1, 0) + 1
	if arr[i] > k:
		k = arr[i]
		indx = i
print(k)
tmp = indx - (k - 1)
subsequence = []
for i in range(n):
	if a[i] == tmp:
		tmp += 1
		subsequence.append(i + 1)
print(*subsequence)


n = int(input())
l = list(map(int, input().split()))
d = {}
back = [None] * n
res = [0] * n
for (i, num) in enumerate(l):
	if num - 1 in d:
		back[i] = d[num - 1]
		res[i] = res[back[i]] + 1
	else:
		res[i] = 1
	d[num] = i
(pos, num) = max(enumerate(res), key=lambda k: (k[1], k[0]))
out = []
out.append(pos)
while back[pos] is not None:
	out.append(back[pos])
	pos = back[pos]
out.reverse()
print(num)
print(*[i + 1 for i in out])


n = int(input())
a = list(map(int, input().split()))
d = [1 for i in range(n)]
p = [-1 for i in range(n)]
last_pos = dict()
maxi = 0
for i in range(n):
	cur = a[i]
	prev = cur - 1
	if prev in last_pos:
		prev_pos = last_pos[prev]
		d[i] = d[prev_pos] + 1
		p[i] = prev_pos
	if d[maxi] < d[i]:
		maxi = i
	last_pos[cur] = i
subseq = []
i = maxi
while i >= 0:
	subseq.append(i + 1)
	i = p[i]
print(len(subseq))
print(' '.join([str(x) for x in subseq[::-1]]))


n = int(input())
nums = list(map(int, input().strip().split()))
d = {}
pre = {}
loc = {}
for i in range(n):
	cur = nums[i]
	loc[cur] = i + 1
	if cur - 1 in d:
		d[cur] = d[cur - 1] + 1
		pre[i + 1] = loc[cur - 1]
	else:
		d[cur] = 1
mmax = 0
mmax_val = 0
for (key, val) in d.items():
	if val > mmax:
		mmax = val
		mmax_val = key
print(mmax)
i = loc[mmax_val]
res = [str(i)]
while i in pre:
	j = pre[i]
	res.append(str(j))
	i = j
res.reverse()
print(' '.join(res))


N = int(input())
array = list(map(int, input().split()))
mp = {}
maxi = 0
cnt = 0
for i in range(0, N):
	x = array[i]
	if mp.get(x - 1) == None:
		mp[x] = 1
	if mp.get(x - 1) != None:
		mp[x] = 1 + mp[x - 1]
	if maxi < mp[x]:
		maxi = mp[x]
		cnt = x
print(maxi)
ans = cnt - maxi + 1
for i in range(0, N):
	if array[i] == ans:
		print(i + 1, end=' ')
		ans += 1


n = int(input())
a = list(map(int, input().strip().split()))
l = dict()
for i in range(n):
	l[a[i]] = l.get(a[i] - 1, 0) + 1
maxi = max(l, key=lambda x: l[x])
maxx = l[maxi]
print(maxx)
aa = maxi - maxx + 1
for i in range(n):
	if a[i] == aa:
		print(i + 1, end=' ')
		aa += 1


total = int(input())
array = [int(z) for z in input().split()]
dp = {}
(tamF, ultimo) = (0, 0)
for i in range(total):
	temp = array[i]
	if temp - 1 not in dp:
		dp[temp - 1] = 0
	dp[temp] = dp[temp - 1] + 1
	if tamF < dp[temp]:
		tamF = dp[temp]
		ultimo = temp
final = []
for i in range(total - 1, -1, -1):
	if array[i] == ultimo:
		final.append(i)
		ultimo -= 1
print(tamF)
final = list(reversed(final))
for i in range(len(final)):
	print(final[i] + 1, end=' ')


from collections import defaultdict
n = int(input())
l = [int(i) for i in input().split()]
dic = defaultdict()
end = 0
ans = 0
for i in l:
	if i not in dic:
		dic[i] = 1
	if i - 1 in dic:
		dic[i] = max(dic[i], dic[i - 1] + 1)
	if ans < dic[i]:
		ans = dic[i]
		end = i
curr = end - ans + 1
r = []
for i in range(n):
	if curr == l[i]:
		r.append(i + 1)
		curr += 1
	if curr == end + 1:
		break
print(ans)
print(*r)


import sys
sys.setrecursionlimit(10 ** 6)
debug_mode = True if len(sys.argv) > 1 and sys.argv[1] == '-d' else False
if debug_mode:
	import os
	inf = open(os.path.abspath(__file__).replace('.py', '.in'))

	def input():
		return inf.readline()
from collections import defaultdict

def main():
	_n = int(input().strip())
	A = list(map(int, input().strip().split()))
	d = defaultdict(int)
	for a in A:
		d[a] = d[a - 1] + 1
	last_num = max(d, key=lambda k: d[k])
	print(d[last_num])
	res = []
	curr = last_num - d[last_num] + 1
	for (i, a) in enumerate(A):
		if a == curr:
			res.append(i + 1)
			curr += 1
	print(' '.join((str(x) for x in res)))
main()
if debug_mode:
	inf.close()


from collections import defaultdict

def compute(arr, n):
	dic = defaultdict(lambda : 0)
	max_index = [0, 0]
	for i in range(n):
		if arr[i] - 1 in dic:
			dic[arr[i]] = dic[arr[i] - 1] + 1
		else:
			dic[arr[i]] = 1
		if dic[arr[i]] > max_index[0]:
			max_index = (dic[arr[i]], arr[i])
	starting = max_index[1] - max_index[0] + 1
	print(max_index[0])
	for i in range(n):
		if arr[i] == starting:
			print(i + 1, end=' ')
			starting += 1
n = int(input())
arr = list(map(int, input().split()))
compute(arr, n)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
arr = iia()
d = {}
for i in range(n):
	d[arr[i]] = d.get(arr[i] - 1, 0) + 1
num = max(d, key=d.get)
index = len(arr) - arr[::-1].index(num) - 1
cur = num
ans = [index + 1]
for i in range(0, index)[::-1]:
	if arr[i] == cur - 1:
		ans.append(i + 1)
		cur -= 1
print(d[num])
print(*ans[::-1])


from sys import stdin, stdout, stderr
import time, math
from collections import defaultdict as dd

def pn(ob):
	stdout.write(str(ob))

def inp():
	return stdin.readline()

def main():
	n = int(inp())
	arr = list(map(int, inp().split()))
	li = []
	dp = dd(lambda : 0)
	for i in arr:
		dp[i] = max(dp[i - 1] + 1, dp[i])
	mx = max(dp.keys(), key=dp.get)
	for i in range(n - 1, -1, -1):
		if arr[i] == mx:
			li.append(i + 1)
			mx -= 1
	li.reverse()
	print(len(li))
	print(*li)
main()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
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')
import time
start_time = time.time()
import collections as col
import math
from functools import reduce

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())

def solve():
	N = getInt()
	A = getInts()
	dp = col.defaultdict(int)
	left_most_ind = col.defaultdict(int)
	best = 0
	curr = -1
	for j in range(N - 1, -1, -1):
		el = A[j]
		left_most_ind[el] = j
		if not left_most_ind[el + 1]:
			dp[j] = 1
		else:
			dp[j] = dp[left_most_ind[el + 1]] + 1
		if best < dp[j]:
			curr = j
			best = dp[j]
	seq = [curr + 1]
	while len(seq) < best:
		while A[curr] != A[seq[-1] - 1] + 1:
			curr += 1
		seq.append(curr + 1)
	print(best)
	print(*seq)
	return
solve()


n = int(input())
T = input().split(' ')
for i in range(n):
	T[i] = int(T[i])
D = {}
for i in range(n):
	D[T[i]] = 0
for i in range(n):
	if T[i] - 1 not in D:
		D[T[i]] = 1
	else:
		D[T[i]] = D[T[i] - 1] + 1
m = -1
j = -1
for i in D:
	if D[i] > m:
		m = D[i]
		j = i
L = []
for i in range(n - 1, -1, -1):
	if T[i] == j:
		L.append(i)
		j -= 1
print(m)
for i in range(m - 1):
	print(L[m - 1 - i] + 1, end=' ')
print(L[0] + 1)


from sys import stdin, stdout
from collections import defaultdict
import math
I = stdin.readline
P = stdout.write
n = int(I())
arr = [int(x) for x in I().split()]
num = defaultdict(lambda : 0)
ans = 0
count = 0
for i in range(n):
	num[arr[i]] = 1 + num[arr[i] - 1]
	if num[arr[i]] > count:
		ans = arr[i]
		count += 1
print(num[ans])
st = ans - num[ans] + 1
for i in range(n):
	if arr[i] == st:
		print(i + 1, end=' ')
		st += 1
	if st == ans + 1:
		break
print(' ')


n = int(input())
li = list(map(int, input().split()))
from collections import defaultdict
dp = defaultdict(int)
for i in li:
	dp[i] = dp[i - 1] + 1
max_val = -1
max_idx = 0
for (k, v) in dp.items():
	if v > max_val:
		max_idx = k
		max_val = v
print(max_val)
idx = len(li) - 1
ans = []
while idx >= 0 and max_val > 0:
	if li[idx] == max_idx:
		ans.append(idx + 1)
		max_val -= 1
		max_idx -= 1
	idx -= 1
ans.reverse()
print(*ans)


from collections import *
n = int(input())
l = list(map(int, input().split()))
d = defaultdict(lambda : 0)
(maxi, val) = (0, 0)
for i in range(n - 1, -1, -1):
	d[l[i]] = max(d[l[i] + 1] + 1, d[l[i]])
	if d[l[i]] > maxi:
		maxi = d[l[i]]
		val = l[i]
cnt = 0
fin = []
for i in range(n):
	if val == l[i]:
		fin.append(i + 1)
		val += 1
		cnt += 1
	if cnt == maxi:
		break
print(maxi)
print(*fin)


from collections import defaultdict
n = int(input())
As = list(map(int, input().split()))
d = defaultdict(list)
for (i, a) in enumerate(As, 1):
	v = d[a - 1]
	v.append(i)
	if len(v) > len(d[a]):
		d[a] = v
	del d[a - 1]
m = max(d.values(), key=len)
print(len(m))
print(*m, sep=' ')


n = int(input())
temp = input()
a = [int(x) for x in temp.split()]
best = dict()
best.update({a[0]: 1})
for i in range(1, n):
	if a[i] - 1 in best:
		best.update({a[i]: best[a[i] - 1] + 1})
	else:
		best.update({a[i]: 1})
ind = 0
val = 0
for (key, value) in best.items():
	if value > val:
		ind = key
		val = value
print(val)
seq = []
for i in range(len(a) - 1, -1, -1):
	if a[i] == ind:
		seq.append(i + 1)
		ind -= 1
		if ind == 0:
			break
seq.reverse()
seq = list(map(str, seq))
print(' '.join(seq))


n = int(input())
arr = list(map(int, input().split()))
dc = dict()
for x in arr:
	dc[x] = max(dc.get(x, 0), dc.get(x - 1, 0) + 1)
mx = dc[arr[0]]
p = arr[0]
for x in dc.keys():
	if dc[x] > mx:
		mx = dc[x]
		p = x
print(mx)
s = []
for i in range(n - 1, -1, -1):
	if arr[i] == p:
		s.append(i + 1)
		p -= 1
print(*s[::-1])


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
dp = {}
for i in range(n):
	if a[i] not in dp:
		dp[a[i]] = 1
	dp[a[i]] = dp[a[i] - 1] + 1 if a[i] - 1 in dp else dp[a[i]]
(k, v) = max(dp.items(), key=lambda x: x[1])
print(v)
c = k - v + 1
for i in range(n):
	if a[i] == c:
		print(i + 1, end=' ')
		c += 1


n = input()
n = int(n)
s = input()
a = s.split()
for i in range(n):
	a[i] = int(a[i])
dp = []
pre = []
pos = {}
(ans, p) = (0, 0)
w = []
for i in range(n):
	pos[a[i]] = i
	if a[i] - 1 in pos.keys():
		dp.append(dp[pos[a[i] - 1]] + 1)
		pre.append(pos[a[i] - 1])
	else:
		dp.append(1)
		pre.append(-1)
for i in range(n):
	if ans < dp[i]:
		ans = dp[i]
		p = i
print(ans)
i = p
while i >= 0:
	w.append(i)
	i = pre[i]
w.reverse()
for i in range(ans):
	print(w[i] + 1, end=' ')


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
dp = defaultdict(int)
res = 0
st = 0
for i in range(n):
	x = arr[i]
	dp[x] = max(dp[x], dp[x - 1] + 1)
	if dp[x] > res:
		res = dp[x]
		st = x - dp[x] + 1
ed = st + res
res_ind = []
for i in range(n):
	if arr[i] == st:
		res_ind.append(str(i + 1))
		st += 1
	if st == ed:
		break
print(res)
print(' '.join(res_ind))


n = int(input())
f = input().split(' ')
v = list()
max = 0
for i in range(0, n):
	if int(f[i]) > max:
		max = int(f[i])
	v.append(int(f[i]))
ans = 0
dp = dict()
for el in v:
	if el - 1 not in dp:
		dp[el - 1] = 0
	dp[el] = dp[el - 1] + 1
	if dp[el] > ans:
		ans = dp[el]
		pred = el
sol = list()
i = n - 1
for el in v[::-1]:
	if el == pred:
		sol.append(i + 1)
		pred -= 1
	i -= 1
print(ans)
for i in sol[::-1]:
	print(i, end=' ')


import sys
import math
from collections import defaultdict, deque
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
dic = defaultdict(int)
dic[arr[-1]] = 1
ans = 1
st = arr[-1]
for i in range(n - 1, -1, -1):
	dic[arr[i]] = max(dic[arr[i]], dic[arr[i] + 1] + 1)
	if dic[arr[i]] > ans:
		ans = dic[arr[i]]
		st = arr[i]
print(ans)
res = []
for i in range(n):
	if arr[i] == st:
		res.append(i + 1)
		st += 1
print(*res)


import sys
next(sys.stdin)
xs = list(map(int, next(sys.stdin).rstrip().split()))
candidates = [[(xs[0], 1)]]
last2candidates_id = {xs[0]: 0}
for (id_, x) in enumerate(xs[1:], 2):
	if x - 1 in last2candidates_id:
		candidates_id = last2candidates_id[x - 1]
		candidate = candidates[candidates_id]
		if x in last2candidates_id:
			competitor_id = last2candidates_id[x]
			competitor = candidates[competitor_id]
			if len(competitor) > len(candidate) + 1:
				continue
		candidate.append((x, id_))
		last2candidates_id.pop(x - 1, None)
		last2candidates_id[x] = candidates_id
	elif x not in last2candidates_id:
		candidates.append([(x, id_)])
		last2candidates_id[x] = len(candidates) - 1
longest_sequence = max(candidates, key=len)
print(len(longest_sequence))
print(' '.join((str(x[1]) for x in longest_sequence)))


n = int(input())
arr = list(map(int, input().split()))
d = {}
ans = 0
for i in range(len(arr)):
	d[arr[i]] = d.get(arr[i] - 1, 0) + 1
	if d[arr[i]] > ans:
		ind = i
		ans = d[arr[i]]
l = []
num = arr[ind]
for i in range(ind, -1, -1):
	if arr[i] == num:
		num -= 1
		l.append(i + 1)
l.reverse()
print(ans)
print(*l)


def solve(ls):
	dp = {ls[0]: 1}
	for i in range(1, len(ls)):
		v = ls[i] - 1
		if v in dp:
			if ls[i] in dp:
				dp[ls[i]] = max(dp[ls[i]], dp[v] + 1)
			else:
				dp[ls[i]] = dp[v] + 1
		else:
			dp[ls[i]] = 1
	maxi = -1
	keys = -1
	for k in dp:
		if dp[k] > maxi:
			maxi = dp[k]
			keys = k
	ans = []
	for j in range(len(ls) - 1, -1, -1):
		if ls[j] == keys:
			ans.append(j)
			keys -= 1
	print(maxi)
	for t in range(len(ans) - 1, -1, -1):
		print(ans[t] + 1, end=' ')
v = int(input())
inp = list(map(int, input().strip().split(' ')))
solve(inp)


n = int(input())
a = list(map(int, input().split()))
d = dict()
for x in a:
	d[x] = d.get(x - 1, 0) + 1
start = 0
finish = 0
result = 0
for key in d.keys():
	if d[key] > result:
		result = d[key]
		finish = key
		start = key - d[key] + 1
print(result)
curr = start
for (i, x) in enumerate(a):
	if curr == x:
		print(i + 1, end=' ')
		curr += 1


from sys import stdin

def main():
	n = int(stdin.readline())
	ar = list(map(int, stdin.readline().split()))
	dp = {}
	prev = {}
	index = {}
	for i in range(n):
		if ar[i] - 1 in dp:
			dp[ar[i]] = dp[ar[i] - 1] + 1
			prev[ar[i]] = index[ar[i] - 1]
		else:
			if ar[i] in dp:
				continue
			dp[ar[i]] = 1
			prev[ar[i]] = -1
		index[ar[i]] = i
	ans = -1
	max_key = -1
	for key in dp:
		if ans < dp[key]:
			ans = dp[key]
			max_key = key
	curr = max_key
	res = []
	for i in range(n - 1, -1, -1):
		if curr == ar[i] and curr > max_key - ans:
			res.append(i + 1)
			curr -= 1
	res.reverse()
	print(ans)
	print(*res)
main()


from sys import stdin, stdout
import math
N = int(input())
arr = [int(x) for x in stdin.readline().split()]
res = 0
record = {}
record[arr[0]] = 1
for i in range(1, N):
	num = arr[i]
	if num - 1 in record:
		if num not in record:
			record[num] = record[num - 1] + 1
		else:
			record[num] = max(record[num - 1] + 1, record[num])
	elif num not in record:
		record[num] = 1
res = 0
max_end = -1
for num in record:
	res = max(res, record[num])
	if record[num] == res:
		max_end = num
print(res)
tmp = [0] * res
k = max_end
j = 0
for i in range(N - 1, -1, -1):
	if arr[i] == k:
		k -= 1
		tmp[j] = i + 1
		j += 1
	if j == res:
		break
tmp = tmp[::-1]
print(*tmp)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
arr = list(map(int, input().split()))
dict1 = {}
ans = 0
for i in range(n):
	if arr[i] not in dict1.keys():
		if arr[i] + 1 not in dict1.keys():
			dict1[arr[i] + 1] = 1
			ans = max(ans, 1)
		else:
			dict1[arr[i] + 1] = max(1, dict1[arr[i] + 1])
			ans = max(ans, 1)
	else:
		if arr[i] + 1 not in dict1.keys():
			dict1[arr[i] + 1] = dict1[arr[i]] + 1
			ans = max(ans, dict1[arr[i] + 1])
		else:
			dict1[arr[i] + 1] = max(dict1[arr[i]] + 1, dict1[arr[i] + 1])
			ans = max(ans, dict1[arr[i] + 1])
		del dict1[arr[i]]
keyList = list(dict1.keys())
valList = list(dict1.values())
a = keyList[valList.index(ans)]
lis = []
b = a - ans
for i in range(n):
	if arr[i] == b:
		lis.append(i + 1)
		b += 1
print(ans)
print(' '.join((str(x) for x in lis)))


n = int(input())
s = list(map(int, input().split(' ')))
d = {}
for (i, x) in enumerate(s):
	if x - 1 not in d:
		d[x] = 1
	else:
		d[x] = 1 + d[x - 1]
(i, v) = max(d.items(), key=lambda p: p[1])
print(v)
out = []
start = i - v + 1
for (i, x) in enumerate(s):
	if x == start:
		out += [i + 1]
		start += 1
print(' '.join(map(str, out)))


from collections import *
input()
a = list(map(int, input().split()))
m = defaultdict(int)
for x in reversed(a):
	m[x] = m[x + 1] + 1
v = max(list(m.keys()), key=m.get)
seq = []
for (i, x) in enumerate(a):
	if v == x:
		seq.append(i + 1)
		v += 1
print(len(seq))
print(*seq)


n = int(input())
a = list(map(int, input().split()))
dp = {}
for i in a:
	dp[i] = dp.get(i - 1, 0) + 1
maxi = max(dp, key=dp.get)
print(dp[maxi])
seq = 0
for j in range(maxi - dp[maxi], maxi):
	seq = a.index(j + 1, seq) + 1
	print(seq, end=' ')


n = int(input())
a = list(map(int, input().split()))
mp = {}
for i in a:
	mp[i] = mp.get(i - 1, 0) + 1
ans = max(mp, key=mp.get)
print(mp[ans])
r = 0
for i in range(ans - mp[ans] + 1, ans + 1):
	r = a.index(i, r)
	print(r + 1, end=' ')


import sys
input = sys.stdin.readline
from math import ceil, floor

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(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
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
dp = [1] * n
hsh = {}
for i in range(n):
	j = a[i]
	if j not in hsh:
		hsh[j] = 1
	if j - 1 in hsh:
		x = hsh[j - 1]
		dp[i] = x + 1
		hsh[j] = dp[i]
k = max(dp)
ans = []
for i in range(n):
	if dp[i] == k:
		kth = a[i]
		break
start = kth - k + 1
for i in range(n):
	if len(ans) == k:
		break
	if a[i] == start:
		ans.append(i + 1)
		start += 1
print(k)
print(*ans)


n = int(input())
a = list(map(int, input().split()))
dc = dict()
for x in a:
	dc[x] = max(dc.get(x, 0), dc.get(x - 1, 0) + 1)
ans = 0
mx = 0
for x in dc.keys():
	if dc[x] > mx:
		mx = dc[x]
		ans = x
arr = []
for i in range(n - 1, -1, -1):
	if a[i] == ans:
		ans -= 1
		arr.append(i + 1)
print(len(arr))
print(*arr[::-1])


from collections import Counter
(n,) = map(int, input().split())
a = list(map(int, input().split()))
index = {}
dp = [-1] * n
prev = [-1] * n
for i in range(n):
	if a[i] - 1 in index:
		j = index[a[i] - 1]
		prev[i] = j
		dp[i] = dp[j] + 1
	else:
		prev[i] = -1
		dp[i] = 1
	index[a[i]] = i
i = 0
for j in range(n):
	if dp[i] < dp[j]:
		i = j
res = []
while i != -1:
	res.append(i + 1)
	i = prev[i]
print(len(res))
print(*res[::-1])


input()
a = list(map(int, input().split()))
b = {i: 0 for i in set(a)}
ans = 0
ans_ind = 0
for i in range(len(a)):
	if a[i] - 1 in b.keys():
		b[a[i]] = b[a[i] - 1] + 1
	else:
		b[a[i]] = 1
	if b[a[i]] > ans:
		ans = b[a[i]]
		ans_ind = i
print(ans)
s = ''
aans = []
aans.append(ans_ind + 1)
x = a[ans_ind]
for i in range(ans - 1):
	while a[ans_ind] != x - 1:
		ans_ind -= 1
	x = a[ans_ind]
	aans.append(ans_ind + 1)
for i in aans[::-1]:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
e = {}
dp = [0] * n
for i in range(n - 1, -1, -1):
	try:
		dp[i] = dp[e[l[i] + 1]] + 1
	except:
		dp[i] = 1
	e[l[i]] = i
ans = max(dp)
c = [dp.index(ans) + 1]
m = l[c[-1] - 1] + 1
for i in range(c[-1], n):
	if l[i] == m:
		c.append(i + 1)
		m += 1
print(ans)
print(*c)


n = int(input())
l = input().split()
li = [int(i) for i in l]
hashi = dict()
for i in li:
	if i - 1 not in hashi:
		hashi[i] = 1
	else:
		hashi[i] = hashi[i - 1] + 1
maxa = 0
ans = 0
for i in hashi:
	if hashi[i] > maxa:
		ans = i
	maxa = max(maxa, hashi[i])
curr = ans - maxa + 1
print(maxa)
for i in range(n):
	if li[i] == curr:
		print(i + 1, end=' ')
		curr += 1


from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in a:
	dic[i] = max(dic[i], dic[i - 1] + 1)
maxx = -1
ind = -1
for i in dic:
	if dic[i] > maxx:
		maxx = dic[i]
		ind = i
print(maxx)
cnt = ind
ans = []
for i in range(n - 1, -1, -1):
	if a[i] == cnt:
		ans.append(i + 1)
		cnt -= 1
print(*ans[::-1])


n = int(input())
arr_a = input().split()
arr_a = [int(a) for a in arr_a]
dicionarioo = dict()
for a in arr_a:
	dicionarioo[a] = dicionarioo.get(a - 1, 0) + 1
comeco = 0
final = 0
result = 0
for k in dicionarioo.keys():
	if dicionarioo[k] > result:
		result = dicionarioo[k]
		final = k
		comeco = k - dicionarioo[k] + 1
print(result)
atual = comeco
arr_result = []
for (i, x) in enumerate(arr_a):
	if atual == x:
		arr_result.append(i + 1)
		atual += 1
for i in range(0, len(arr_result)):
	if i == len(arr_result) - 1:
		print(arr_result[i])
	else:
		print(arr_result[i], end=' ')


n = int(input())
a = [int(x) for x in input().split()]
dp = [1] * n
prev = [-1] * n
m = dict()
for i in range(n):
	last = m.get(a[i] - 1)
	if last is not None:
		dp[i] = dp[last] + 1
		prev[i] = last
	m[a[i]] = i
ans = max(dp)
print(ans)
seq = []
for i in range(n):
	if dp[i] == ans:
		j = i
		while j >= 0:
			seq.append(j + 1)
			j = prev[j]
		print(*seq[::-1])
		break


n = int(input())
inp = list(map(int, input().split()))
dp = {}
m = 0
num = 0
for i in range(n):
	(a, b) = (str(inp[i]), str(inp[i] - 1))
	if a not in dp:
		dp.update({a: 0})
	if b not in dp:
		dp.update({b: 0})
	dp[a] = dp[b] + 1
	if m < dp[a]:
		m = dp[a]
		num = int(a)
		ind = [i + 1]
for i in range(ind[-1] - 1, -1, -1):
	if num - inp[i] == 1:
		num = inp[i]
		ind.append(i + 1)
print(m)
print(*ind[::-1])


n = int(input())
a = [int(i) for i in input().split()]
last = {}
pred = {}
dp = [0] * n
dp[0] = 1
last[a[0]] = 0
pred[0] = -1
for i in range(1, n):
	now = a[i]
	if now - 1 in last.keys():
		dp[i] = dp[last[now - 1]] + 1
		pred[i] = last[now - 1]
	else:
		dp[i] = 1
		pred[i] = -1
	last[now] = i
mx = -1
index = -1
for i in range(len(dp)):
	if dp[i] > mx:
		mx = dp[i]
		index = i
print(mx)
ans = []
while index != -1:
	ans.append(index + 1)
	index = pred[index]
ans = ans[::-1]
print(*ans)


n = int(input())
a = list(map(int, input().split()))
d = {}
maxn = 0
max_ind = 0
for ai in a:
	d[ai] = d.get(ai - 1, 0) + 1
for key in d.keys():
	if d[key] > maxn:
		maxn = d[key]
		max_ind = key
start = max_ind - maxn + 1
print(maxn)
i = 0
for ai in a:
	i += 1
	if ai == start:
		print(i, end=' ')
		start += 1


n = int(input())
a = [int(s) for s in input().split()]
lens = {}
maxlen = 1
maxlast = a[0]
for i in range(n):
	lens[a[i]] = lens.get(a[i] - 1, 0) + 1
	if lens[a[i]] > maxlen:
		maxlen = lens[a[i]]
		maxlast = a[i]
print(maxlen)
subs = []
si = maxlast - maxlen + 1
for i in range(n):
	if a[i] == si:
		subs.append(i + 1)
		si += 1
print(*subs, sep=' ')


n = int(input())
a = list(map(int, input().split()))
dp = [1 for i in range(n)]
pos = [i for i in range(n)]
r = {}
ans = 1
for i in range(n):
	if r.get(a[i] - 1, -1) != -1:
		dp[i] += dp[r[a[i] - 1]]
		pos[i] = r[a[i] - 1]
	r[a[i]] = i
	ans = max(ans, dp[i])
i = n - 1
while i >= 0:
	if dp[i] == ans:
		break
	i -= 1
t = []
for j in range(ans):
	t.append(i + 1)
	if j < ans - 1:
		i = pos[i]
print(ans)
t.reverse()
for i in t:
	print(i, end=' ')
print('')


n = int(input())
a = list(map(int, input().split(' ')))
dp = {}
for k in range(n):
	if a[k] not in dp:
		dp[a[k]] = 1
		if a[k] - 1 in dp:
			dp[a[k]] = 1 + dp[a[k] - 1]
	elif a[k] - 1 in dp:
		dp[a[k]] = max(1 + dp[a[k] - 1], dp[a[k]])
ans = 0
val = -1
for pro in dp:
	ans = max(ans, dp[pro])
	if ans == dp[pro]:
		val = pro
inds = []
vv = val - ans + 1
for k in range(n):
	if a[k] == vv:
		vv += 1
		inds.append(k + 1)
print(ans)
for k in range(len(inds)):
	print(inds[k], end=' ')


n = int(input())
d = dict()
m = 0
val = 0
a = list(map(int, input().split()))
s = set()
aps = s.add
for i in a:
	d[i] = d.get(i - 1, 0) + 1
	if d[i] > m:
		m = d[i]
		val = int(i)
ans = []
ap = ans.append
for i in range(n - 1, -1, -1):
	if a[i] == val:
		val -= 1
		ap(i + 1)
print(m)
print(*ans[::-1])


n = int(input())
arr = list(map(int, input().strip().split()))
dicti = {}
maxi = [-1, -1]
for i in range(len(arr)):
	if arr[i] - 1 in dicti:
		prev = dicti[arr[i] - 1]
		dicti[arr[i]] = [prev[0] + 1, arr[i]]
	else:
		dicti[arr[i]] = [1, arr[i]]
	if dicti[arr[i]][0] > maxi[0]:
		maxi = dicti[arr[i]]
ans = []
print(maxi[0])
targets = [maxi[1] - maxi[0] + 1 + i for i in range(maxi[0])]
j = 0
for i in range(len(arr)):
	if targets[j] == arr[i]:
		ans.append(i + 1)
		j += 1
	if j == maxi[0]:
		break
print(*ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
d.setdefault(l[0], 1)
for i in range(1, n):
	if l[i] in d.keys():
		if l[i] - 1 in d.keys():
			d[l[i]] = max(d[l[i] - 1] + 1, d[l[i]])
		else:
			d[l[i]] = 1
	elif l[i] - 1 in d.keys():
		d[l[i]] = d[l[i] - 1] + 1
	else:
		d[l[i]] = 1
a = 0
b = 0
for (i, j) in d.items():
	if b < j:
		b = j
		a = i
print(b)
temp = a - b + 1
for i in range(n):
	if l[i] == temp:
		print(i + 1, end=' ')
		temp += 1
	if temp == a + 1:
		break
print()


import sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mx = -float('inf')
curr = 1
mp = defaultdict(lambda : 0)
dp = [0 for i in range(n)]
mx = -sys.maxsize
for i in range(n):
	if a[i] - 1 in mp:
		lastIndex = mp[a[i] - 1] - 1
		dp[i] = 1 + dp[lastIndex]
	else:
		dp[i] = 1
	mp[a[i]] = i + 1
	if dp[i] > mx:
		mx = dp[i]
		curr = a[i]
b = []
for i in range(-1, -n - 1, -1):
	if a[i] == curr:
		b.append(n + i + 1)
		curr -= 1
print(mx)
print(*b[::-1])


n = int(input())
a = list(map(int, input().split()))
d = {}
k = 1
ansnum = a[0]
for i in range(n):
	if a[i] - 1 in d:
		d[a[i]] = d[a[i] - 1] + 1
		if k < d[a[i]]:
			k = d[a[i]]
			ansnum = a[i]
	else:
		d[a[i]] = 1
ans = [0] * k
j = -1
for i in range(n - 1, -1, -1):
	if j < -k:
		break
	if a[i] == ansnum:
		ans[j] = i + 1
		ansnum -= 1
		j -= 1
print(k)
print(*ans)


from collections import *
n = int(input())
l = [int(x) for x in input().split()]
h = Counter()
for i in l:
	h[i] = max(h[i], h[i - 1] + 1)
max_value = h.most_common(1)[0][1]
print(max_value)
queue = deque()
l = l[::-1]
for i in range(n):
	if h[l[i]] == max_value:
		queue.append(n - i)
		ele = l[i]
		break
max_value -= 1
i = n - i - 2
ele -= 1
l = l[::-1]
while max_value > 0 and i >= 0:
	if l[i] == ele:
		queue.appendleft(i + 1)
		max_value -= 1
		ele -= 1
	i -= 1
for i in queue:
	print(i, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.reverse()
dic = {}
for i in range(n):
	dic[arr[i]] = dic[arr[i] + 1] + 1 if arr[i] + 1 in dic.keys() else 1
mx = 0
num = 0
for i in dic.keys():
	if dic[i] > mx:
		mx = dic[i]
		num = i
print(mx)
arr.reverse()
for i in range(n):
	if arr[i] == num:
		print(i + 1, end=' ')
		num += 1


n = int(input())
a = list(map(int, input().split()))
index = {}
dp = [0] * (n + 1)
for i in range(n):
	if a[i] - 1 in index:
		ind = index[a[i] - 1]
		dp[i + 1] = dp[ind] + 1
	else:
		dp[i + 1] = 1
	index[a[i]] = i + 1
tmp = 0
for i in range(n):
	if tmp < dp[i + 1]:
		ind = i
		tmp = dp[i + 1]
ans = [(ind, a[ind])]
tmp_num = a[ind]
for i in range(ind)[::-1]:
	if a[i] + 1 == tmp_num:
		ans.append((i, a[i]))
		tmp_num = a[i]
ans = [ans[i][0] + 1 for i in range(len(ans))][::-1]
print(len(ans))
print(*ans)


def readline():
	return tuple(map(int, input().split()))

def main():
	n = int(input())
	seq = readline()
	values = set()
	subsequences = dict()
	for a in seq:
		new = subsequences.get(a - 1, 0) + 1
		if new > subsequences.setdefault(a, 1):
			subsequences[a] = new
			subsequences.pop(a - 1)
	(last, length) = max(subsequences.items(), key=lambda x: x[1])
	print(length)
	first = last - length + 1
	for (idx, a) in enumerate(seq, start=1):
		if a == first:
			print(idx, end=' ')
			first += 1
main()


n = int(input())
a = [int(c) for c in input().split()]
from collections import defaultdict as dd
d = dd(int)
for i in range(n):
	d[a[i]] = d[a[i] - 1] + 1
(val, mx) = (0, 0)
for i in d.keys():
	if d[i] > mx:
		val = i
		mx = d[i]
idx = n - a[::-1].index(val) - 1
ans = [idx + 1]
for i in range(idx - 1, -1, -1):
	if a[i] == val - 1:
		ans.append(i + 1)
		val -= 1
print(len(ans))
print(*ans[::-1])


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
n = int(input())
l = list(map(int, input().split()))
d = {i: -1 for i in l}
z = 0
x = 0
for i in range(n):
	if l[i] - 1 in d and d[l[i] - 1] != -1:
		d[l[i]] = d[l[i] - 1] + 1
	else:
		d[l[i]] = 1
	if d[l[i]] > z:
		z = d[l[i]]
		x = l[i]
ans = []
t = x
for i in range(n - 1, -1, -1):
	if l[i] == t:
		ans.append(i + 1)
		t -= 1
ans.reverse()
print(len(ans))
print(*ans)


n = int(input())
a = input().split()
for (i, x) in enumerate(a):
	a[i] = int(x)
d = [float('inf')] * (n + 1)
d[0] = 0
length = 0
value = 0
s = dict()
for i in range(0, n):
	if a[i] - 1 in s:
		if a[i] is s:
			s[a[i]] = max(s[a[i]], s[a[i - 1]] + 1)
		else:
			s[a[i]] = s[a[i] - 1] + 1
	else:
		s[a[i]] = 1
	if s[a[i]] > length:
		length = s[a[i]]
		value = a[i]
ans = []
value0 = value - length + 1
for (i, x) in enumerate(a):
	if x == value0:
		ans.append(i + 1)
		value0 = value0 + 1
		if value0 > value:
			break
print(length)
print(' '.join((str(i) for i in ans)))


n = int(input())
from collections import defaultdict
d = defaultdict(int)
l = [int(i) for i in input().split()]
for i in l:
	if d[i - 1] > 0:
		d[i] = d[i - 1] + 1
	else:
		d[i] = 1
maxi = -1
for i in d:
	if d[i] > maxi:
		maxi = d[i]
		ans = i
res = [i for i in range(ans - maxi + 1, ans + 1)]
j = 0
print(maxi)
for i in range(n):
	if l[i] == res[j]:
		print(i + 1, end=' ')
		j += 1
		if j == len(res):
			break


import sys
import io, os
import bisect
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(i) for i in input().split() if i != '\n']
index = dict()
for i in range(n):
	if a[i] in index:
		index[a[i]].append(i + 1)
	else:
		index[a[i]] = [i + 1]
x = min(a)
ans = []
(count, ind) = (1, 0)
(store, ind2) = ([], [])
for i in range(n):
	if a[i] - 1 in index:
		pq = bisect.bisect(index[a[i] - 1], i + 1)
		if pq > 0:
			count = ans[index[a[i] - 1][pq - 1] - 1] + 1
			ans.append(count)
		else:
			count = 1
			ans.append(count)
	else:
		count = 1
		ans.append(count)
ans1 = max(ans)
indu = ans.index(ans1)
store = [indu + 1]
for i in range(a[indu] - 1, 0, -1):
	if i in index:
		for j in reversed(index[i]):
			if j < store[-1]:
				store.append(j)
				break
		else:
			break
	else:
		break
store.reverse()
sys.stdout.write(str(ans1) + '\n')
store = ' '.join(map(str, store))
sys.stdout.write(store + '\n')


import sys, math
input = lambda : sys.stdin.readline().rstrip()
I = lambda : [*map(int, input().split())]
(n,) = I()
lis = I()
from collections import defaultdict
dp = defaultdict(int)
mx = None
mxcnt = -1 << 64
ind = defaultdict(int)
for i in range(n):
	dp[lis[i]] = dp[lis[i] - 1] + 1
	ind[lis[i]] = i
	if dp[lis[i]] > mxcnt:
		mxcnt = dp[lis[i]]
		mx = lis[i]
req = mx
nls = []
for i in range(ind[mx], -1, -1):
	if lis[i] == req:
		nls.append(i + 1)
		req -= 1
print(mxcnt)
print(*nls[::-1])


import sys, math
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
seen = [0] * n
d = defaultdict(list)
for (i, x) in enumerate(a):
	d[x].append(i)
for i in range(n):
	if seen[i]:
		continue
	now = a[i]
	cnt = 0
	ind = i
	inds = [i]
	while True:
		cnt += 1
		if d[now + cnt] == []:
			break
		tmp = bisect_left(d[now + cnt], ind + 1)
		if tmp >= len(d[now + cnt]):
			break
		nx_ind = d[now + cnt][tmp]
		if nx_ind < ind:
			break
		if seen[nx_ind]:
			cnt += seen[nx_ind]
			break
		inds.append(nx_ind)
		ind = nx_ind
	for v in inds:
		seen[v] = cnt
		cnt -= 1
mx = 0
ind = -1
for (i, x) in enumerate(seen):
	if x > mx:
		ind = i
		mx = x
res = [ind + 1]
now = a[ind]
for i in range(ind + 1, n):
	if a[i] == now + 1:
		now += 1
		res.append(i + 1)
print(mx)
print(*res)


import sys
input = sys.stdin.buffer.readline

def solution():
	n = int(input())
	maxn = 200004
	l = list(map(int, input().split()))
	dp = [0] * maxn
	d = {}
	for i in range(n):
		dp[i] = max(dp[i], d.get(l[i] - 1, 0) + 1)
		d[l[i]] = dp[i]
	m = max(dp)
	ans = []
	for i in range(n + 1):
		if dp[i] == m:
			ans.append(i + 1)
			break
	i = ans[0] - 1
	x = l[i]
	i -= 1
	while i >= 0:
		if x - 1 == l[i]:
			ans.append(i + 1)
			x = l[i]
		i -= 1
	ans.reverse()
	print(m)
	print(*ans)
t = 1
for _ in range(t):
	solution()


import bisect
import sys
from collections import deque
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	start = {}

	def valPrev(x):
		return d[x - 1] if x - 1 in d else 0

	def startPrev(x):
		return start[x - 1] if x - 1 in d else x
	for val in a:
		vp = valPrev(val)
		if val in d:
			if vp + 1 > d[val]:
				d[val] = vp + 1
				start[val] = startPrev(val)
		else:
			d[val] = vp + 1
			start[val] = startPrev(val)
	_max_len = -1
	_max_val = -1
	for (k, v) in d.items():
		if v > _max_len:
			_max_len = v
			_max_val = k
	curr = start[_max_val]
	res_a = []
	for i in range(n):
		if a[i] == curr:
			res_a.append(i + 1)
			curr += 1
	print(len(res_a))
	print(*res_a)
main()


n = int(input())
arr = list(map(int, input().split()))
arr.reverse()
d = {}
for i in range(len(arr)):
	if arr[i] + 1 in d.keys():
		d[arr[i]] = d[arr[i] + 1] + 1
	else:
		d[arr[i]] = 1
maxx = 0
number = 0
for i in d.keys():
	if d[i] > maxx:
		maxx = d[i]
		number = i
arr.reverse()
curr = number
print(maxx)
for i in range(n):
	if arr[i] == curr:
		print(i + 1, end=' ')
		curr += 1


import sys
input = sys.stdin.readline
from collections import defaultdict
from bisect import *
n = int(input())
a = list(map(int, input().split()))
idx = defaultdict(list)
d = defaultdict(int)
for i in range(n):
	idx[a[i]].append(i)
	d[a[i]] = max(d[a[i]], d[a[i] - 1] + 1)
M = max(list(d.values()))
ans = []
for k in d.keys():
	if d[k] == M:
		K = k
		ans.append(idx[k][-1])
		break
for i in range(M - 1):
	mark = bisect_left(idx[K - i - 1], ans[-1])
	ans.append(idx[K - i - 1][mark - 1])
ans = ans[::-1]
ans = list(map(lambda x: x + 1, ans))
print(M)
print(*ans)


import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def main():
	n = int(input())
	arr = read()
	dic = Counter()
	for i in arr:
		dic[i] = max(dic[i], 1 + dic[i - 1])
	elem = dic.most_common()[0][0]
	i = n - 1
	ans = deque()
	while i > -1 and elem > 0:
		if elem == arr[i]:
			ans.appendleft(i + 1)
			elem -= 1
		i -= 1
	print(len(ans))
	print(*ans)
main()


from collections import defaultdict

def solve(a):
	cnt = defaultdict(int)
	for el in a:
		c1 = 1 + cnt[el - 1]
		cnt[el] = max(cnt[el], c1)
	(max_cnt, last_el) = max(((v, k) for (k, v) in cnt.items()))
	res = []
	for i in range(n - 1, -1, -1):
		if a[i] == last_el:
			last_el -= 1
			res.append(i + 1)
	res.reverse()
	return res
n = int(input())
a = [int(x) for x in input().split()]
res = solve(a)
print(len(res))
print(' '.join((str(x) for x in res)))


from collections import *
n = int(input())
a = list(map(int, input().split()))
dp = defaultdict(int)
(ans, res) = (0, 0)
for i in range(n):
	dp[a[i]] = max(dp[a[i]], dp[a[i] - 1] + 1)
	if dp[a[i]] > ans:
		ans = dp[a[i]]
		res = a[i]
print(ans)
x = res - ans + 1
b = []
for i in range(n):
	if a[i] == x:
		b.append(i + 1)
		x += 1
print(*b)


n = int(input())
t = list(map(int, input().split()))
dict = {}
for i in t:
	if i - 1 not in dict:
		dict[i] = 1
	else:
		dict[i] = dict[i - 1] + 1
m = 0
an = 0
for i in dict.keys():
	if dict[i] > m:
		m = dict[i]
		an = i
start = an - m + 1
print(m)
for i in range(n):
	if t[i] == start:
		print(i + 1, end=' ')
		start += 1


n = int(input())
a = map(int, input().split())

def seqlen(di):
	return max(di.keys())
d = {}
for (i0, y) in enumerate(a):
	x = y - 1
	i = i0 + 1
	if y not in d:
		d[y] = {1: i}
	if x in d and seqlen(d[x]) >= seqlen(d[y]):
		d[y][seqlen(d[x]) + 1] = i
y = max(d.items(), key=lambda x: seqlen(x[1]))[0]
s = seqlen(d[y])
answer = []
for i in range(s, 0, -1):
	answer.append(d[y][i])
	y -= 1
print(len(answer))
print(' '.join(map(str, answer[::-1])))


from collections import defaultdict
n = int(input())
arr = list(map(int, input().split()))
d = defaultdict(lambda : 0)
last = 0
m = 0
for i in range(n):
	x = arr[i]
	d[x] = d[x - 1] + 1
	if d[x] > m:
		m = d[x]
		last = x
sol = []
for i in range(n - 1, -1, -1):
	if arr[i] == last:
		sol.append(i + 1)
		last -= 1
print(m)
print(*sol[::-1])


last_occur = {}
n = int(input())
bk = []
arr = []
max_at = []
res = (0, -1)
for (i, v) in enumerate(map(int, input().split())):
	arr.append(v)
	ibk = i
	mx = 1
	if v - 1 in last_occur:
		ibk = last_occur[v - 1]
		mx = max_at[ibk] + 1
	bk.append(ibk)
	max_at.append(mx)
	res = max(res, (mx, i))
	last_occur[v] = i
i = res[1]
res = []
while True:
	res.append(i + 1)
	if bk[i] == i:
		break
	i = bk[i]
print(len(res))
print(*reversed(res))


n = int(input())
a = list(map(int, input().split()))
dp = {}
m = -1
an1 = []
for i in range(n):
	try:
		p = dp[a[i] - 1]
	except:
		p = 0
	dp[a[i]] = p + 1
	if dp[a[i]] > m:
		m = dp[a[i]]
		an = a[i]
ans = []
for i in range(n - 1, -1, -1):
	if a[i] == an:
		ans.append(i)
		an -= 1
print(len(ans))
for i in range(len(ans) - 1, -1, -1):
	print(ans[i] + 1, end=' ')


n = int(input())
a = [*map(int, input().split())]
f = {}
anslist = [0] * n
for i in range(n):
	try:
		f[a[i]] = f[a[i] - 1] + 1
	except:
		f[a[i]] = 1
ans = 0
for i in f:
	if ans < f[i]:
		ans = f[i]
		wk1 = i
print(ans)
wk1 -= ans - 1
for i in range(n):
	if a[i] == wk1:
		print(i + 1, end=' ')
		wk1 += 1
print()


import bisect
n = int(input())
a = list(map(int, input().split()))
d1 = {}
d2 = {}
dp = [0] * n
for i in range(n):
	if a[i] - 1 in d1:
		d1[a[i]] = i
		d2[a[i]] = d1[a[i] - 1]
		dp[i] = dp[d1[a[i] - 1]] + 1
	else:
		d1[a[i]] = i
		d2[a[i]] = -1
		dp[i] = 1
(el, ind) = max(((j, i) for (i, j) in enumerate(dp)))
lis = []
print(el)
temp = [a[ind]]
for i in range(max(dp) - 1):
	temp.append(temp[-1] - 1)
i = n - 1
end = 0
while end < len(temp) and i >= 0:
	if a[i] == temp[end]:
		lis.append(i + 1)
		end += 1
	i -= 1
print(*lis[::-1])


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
N = 5 * 10 ** 6
n = int(ri())
a = Ri()
dp = [1] * n
dic = {}
dic[a[0]] = 1
for i in range(1, len(a)):
	dic[a[i]] = dic.get(a[i] - 1, 0) + 1
no = -1
maxx = -1
for i in dic:
	if dic[i] > maxx:
		maxx = dic[i]
		no = i
ind = -1
for i in range(len(a) - 1, -1, -1):
	if a[i] == no:
		ind = i
		break
ans = []
for i in range(ind, -1, -1):
	if a[i] == no:
		ans.append(i + 1)
		no -= 1
		maxx -= 1
		if maxx == 0:
			break
print(len(ans))
print(*ans[::-1])


n = int(input())
s = list(map(int, input().split()))
d = dict()
for i in range(n):
	try:
		d[s[i]]
	except:
		d.update({s[i]: 1})
	try:
		d[s[i]] = max(d[s[i]], d[s[i] - 1] + 1)
	except:
		True
m = -1
ans = -1
for i in d:
	if d[i] > m:
		m = d[i]
		ans = i
print(m)
ans = ans - m + 1
for i in range(n):
	if s[i] == ans:
		print(i + 1, end=' ')
		ans += 1


from sys import stdin

def read_input():
	n = int(stdin.readline())
	sequence = [int(a) for a in stdin.readline().split()]
	return (n, sequence)

def find_longest_subsequence(n, sequence):
	longest_so_far = index_of_longest = 0
	longest_ending_on = {}
	for (i, el) in enumerate(sequence):
		longest_ending_on[el] = longest_ending_on.get(el - 1, 0) + 1
		if longest_ending_on[el] > longest_so_far:
			(longest_so_far, index_of_longest) = (longest_ending_on[el], i)
	return (longest_so_far, index_of_longest)
(n, sequence) = read_input()
(longest, index_of_longest) = find_longest_subsequence(n, sequence)
print(longest)
(cur_el, cur_ind) = (sequence[index_of_longest], 0)
for el in range(cur_el - longest, cur_el):
	cur_ind = sequence.index(el + 1, cur_ind)
	print(cur_ind + 1, end=' ')


n = int(input())
a = list(map(int, input().split()))
d = dict()
prev = [-1 for i in range(n + 1)]
res = [0, -1]
for i in range(n):
	cur = [1, i]
	x = a[i]
	if x - 1 in d:
		cur[0] = d[x - 1][0] + 1
		prev[i] = d[x - 1][1]
	if x in d:
		if d[x][0] < cur[0]:
			d[x] = cur
		else:
			cur = d[x]
	else:
		d[x] = cur
	if cur[0] > res[0]:
		res = [cur[0], i]
print(res[0])
f = []
cur = res[1]
while cur != -1:
	f.append(cur + 1)
	cur = prev[cur]
for x in reversed(f):
	print(x, end=' ')


n = int(input())
nums = list(map(int, input().split()))
scores = []
links = []
d = {}
maxscore = -1
maxloc = -1
for i in range(n):
	d[nums[i]] = i
	if nums[i] - 1 in d.keys():
		link = d[nums[i] - 1]
		score = scores[link] + 1
	else:
		link = -1
		score = 1
	scores.append(score)
	links.append(link)
	if score > maxscore:
		maxscore = score
		maxloc = i
answer = []
cur = maxloc
while cur != -1:
	answer.append(str(cur + 1))
	cur = links[cur]
answer.reverse()
print(maxscore)
print(' '.join(answer))


import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
d = {}
for i in range(n):
	if a[i] - 1 in d:
		d[a[i]] = d[a[i] - 1] + 1
	else:
		d[a[i]] = 1
maxi = 1
z = a[0]
for i in d:
	if d[i] > maxi:
		maxi = d[i]
		z = i
c = []
for i in range(n - 1, -1, -1):
	if a[i] == z:
		c.append(i + 1)
		break
zp = c[0]
z -= 1
for i in range(zp - 1, -1, -1):
	if a[i] == z:
		c.append(i + 1)
		z -= 1
print(maxi)
print(*c[::-1])