In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.

Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:   an introvert always chooses a row where both seats are empty. Among these rows he chooses the one with the smallest seats width and takes one of the seats in it;  an extrovert always chooses a row where exactly one seat is occupied (by an introvert). Among these rows he chooses the one with the largest seats width and takes the vacant place in it. 

You are given the seats width in each row and the order the passengers enter the bus. Determine which row each passenger will take.


-----Input-----

The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus.

The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.

The third line contains a string of length $2n$, consisting of digits '0' and '1' — the description of the order the passengers enter the bus. If the $j$-th character is '0', then the passenger that enters the bus on the $j$-th stop is an introvert. If the $j$-th character is '1', the the passenger that enters the bus on the $j$-th stop is an extrovert. It is guaranteed that the number of extroverts equals the number of introverts (i. e. both numbers equal $n$), and for each extrovert there always is a suitable row.


-----Output-----

Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input.


-----Examples-----
Input
2
3 1
0011

Output
2 1 1 2 

Input
6
10 8 9 11 13 5
010010011101

Output
6 6 2 3 3 1 4 4 1 2 5 5 



-----Note-----

In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat width is the largest among such rows. The fourth passenger (extrovert) chooses the row $2$, because it is the only row with an empty place.

Difficulty: EASY

Solutions:
n = int(input().strip())
arr = [int(i) for i in input().strip().split()]
for i in range(len(arr)):
	arr[i] = (arr[i], i + 1)
arr.sort(key=lambda x: x[0])
intro = 0
extro = []
inp = input().strip()
for i in inp:
	if i == '0':
		print(arr[intro][1], end=' ')
		extro.append(arr[intro][1])
		intro += 1
	else:
		print(extro.pop(), end=' ')


from heapq import heappop, heappush, heapify
n = int(input())
lis = list(map(int, input().split()))
s = list(input())
lis = [[lis[i], i + 1] for i in range(n)]
lis.sort()
has = [0] * (n + 1)
ans = [0] * (2 * n)
i = j = 0
heap = []
heapify(heap)
for _ in range(2 * n):
	if s[_] == '0':
		ans[_] = lis[i][1]
		heappush(heap, [-1 * lis[i][0], lis[i][1]])
		i += 1
	else:
		a = 1
		ele = heappop(heap)
		ans[_] = ele[1]
print(*ans)


from sys import stdin
import heapq

def solve(tc):
	n = int(stdin.readline())
	w = list(map(int, stdin.readline().split()))
	seq = stdin.readline()
	wi = []
	for i in range(n):
		wi.append((w[i], i + 1))
	heapq.heapify(wi)
	ans = []
	remained = []
	for c in seq:
		if c == '0':
			seat = heapq.heappop(wi)
			heapq.heappush(remained, (-seat[0], seat[1]))
			ans.append(str(seat[1]))
		if c == '1':
			seat = heapq.heappop(remained)
			ans.append(str(seat[1]))
	print(' '.join(ans))
	pass
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


n = int(input())
w = list(map(int, input().split()))
s = input()
for i in range(n):
	w[i] = [w[i], i]
w.sort(reverse=True)
exos = []
locs = [-1 for i in range(2 * n)]
for i in range(2 * n):
	if s[i] == '0':
		exos.append(w.pop())
		locs[i] = exos[-1][1] + 1
	else:
		temp = exos.pop()
		locs[i] = temp[1] + 1
print(*locs)


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().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] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)

def output(answer):
	stdout.write(str(answer))
num = int(z())
arr = zzz()
new_arr = [(i, j + 1) for (j, i) in enumerate(arr)]
new_arr = sorted(new_arr)
passenger = fast()
que = deque()
ans = [0] * 2 * num
left = 0
right = num - 1
le = 0
for i in range(2 * num):
	if passenger[i] == '0':
		ans[i] = new_arr[left][1]
		que.append(new_arr[left][1])
		left += 1
		le += 1
	elif le >= 1:
		ans[i] = que[-1]
		que.pop()
		le -= 1
	else:
		ans[i] = new_arr[right][1]
		que.append(new_arr[right][1])
		right -= 1
		le += 1
print(*ans)


n = int(input())
w = [(int(x), c + 1) for (c, x) in enumerate(input().split())]
b = sorted(w, reverse=True)
f = []
p = []
k = input()
for i in k:
	if i == '0':
		x = b.pop()
		f.append(x)
		p.append(x[1])
	else:
		y = f.pop()
		p.append(y[1])
print(*p)


n = int(input())
s = list(map(int, input().split()))
strr = input()
dic = {}
for i in range(0, n):
	dic[s[i]] = i + 1
list0 = s[:]
list1 = []
list2 = []
m = ''
k = 0
j = 0
list0.sort()
for i in strr:
	if i == '0':
		m += str(dic[list0[j]]) + ' '
		list1 += [list0[j]]
		k = k + 1
		j = j + 1
	else:
		m += str(dic[list1[k - 1]]) + ' '
		del list1[k - 1]
		k = k - 1
print(m)


from collections import deque

def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = input()
	b = []
	for i in range(n):
		b.append([a[i], i + 1])
	b.sort()
	ans = []
	(count1, count2) = (0, 0)
	c = deque([])
	for i in range(2 * n):
		if s[i] == '0':
			ans.append(b[count1][1])
			c.append(b[count1][1])
			count1 += 1
		else:
			ans.append(c[-1])
			c.pop()
			count2 += 1
	for i in range(2 * n):
		print(ans[i], end=' ')
main()


n = int(input())
l = list(map(int, input().split()))
a = {}
for t in range(n):
	a[l[t]] = t + 1
c = a.items()
b = sorted(c, reverse=True)
f = []
p = []
k = input()
for i in k:
	if i == '0':
		x = b.pop()
		f.append(x)
		p.append(x[1])
	else:
		y = f.pop()
		p.append(y[1])
print(*p)


n = int(input())
arr = sorted([(int(x), i + 1) for (i, x) in enumerate(input().split())])
ptr = 0
ind = 0
array = []
for i in input():
	if i == '0':
		print(arr[ptr][1], end=' ')
		array.append(arr[ptr][1])
		ptr += 1
	else:
		print(array.pop(), end=' ')


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a[i] = [a[i], i]
s = input()
ans = [0 for i in range(2 * n)]
ext = []
a.sort()
i = 0
for t in range(2 * n):
	if s[t] == '0':
		ans[t] = a[i][1] + 1
		ext.append(a[i][1] + 1)
		i += 1
	else:
		ans[t] = ext[-1]
		ext.pop()
print(*ans)


from collections import deque
n = int(input())
w = list(map(int, input().split()))
s = input()
avt = {el: i for (i, el) in enumerate(w, 1)}
w.sort()
ans = list()
st = deque()
ind = 0
for el_ in s:
	if el_ == '0':
		ans.append(avt[w[ind]])
		st.append(w[ind])
		ind += 1
	elif el_ == '1':
		ans.append(avt[st.pop()])
	else:
		exit(100500)
print(' '.join(map(str, ans)))


rows = int(input())
rows_width = list(map(int, input().split()))
passengers = input()
rows_order = {}
for i in range(len(rows_width)):
	rows_order[rows_width[i]] = i + 1
rows_width.sort()
seating_order = []
intake_queue = []
introverts = 0
for i in range(len(passengers)):
	if passengers[i] == '0':
		seating_order.append(rows_order[rows_width[introverts]])
		intake_queue.append(rows_order[rows_width[introverts]])
		introverts += 1
	else:
		seating_order.append(intake_queue.pop())
print(*seating_order, sep=' ')


n = int(input())
two_seats = []
one_seat = []
j = 1
for item in input().split():
	two_seats.append((int(item), j))
	j += 1
two_seats.sort(key=lambda x: -x[0])
for person in input():
	if person == '0':
		q = two_seats.pop()
		print(q[1], end=' ')
		one_seat.append(q)
	else:
		print(one_seat.pop()[1], end=' ')


n = int(input())
w = list(map(int, input().split()))
w = sorted(range(len(w)), key=w.__getitem__)
w = iter(w)
e = list(input())
from collections import deque
s = deque()
for e1 in e:
	if e1 == '0':
		x = next(w) + 1
		print(x, end=' ')
		s.append(x)
	else:
		print(s.pop(), end=' ')


n = int(input())
w = list(map(int, input().split()))
d = {}
for i in range(n):
	if str(w[i]) in d:
		d[str(w[i])].append(i)
	else:
		d[str(w[i])] = [i]
s = input()
w.sort()
l = []
result = []
k = 0
for i in range(2 * n):
	if s[i] == '0':
		for j in range(k, n):
			if d[str(w[j])] != []:
				result.append(d[str(w[j])][-1] + 1)
				l.append(d[str(w[j])][-1] + 1)
				d[str(w[j])].pop()
				break
			else:
				k += 1
	else:
		result.append(l[-1])
		l.pop()
print(*result)


n = int(input())
W = [int(x) for x in input().split()]
W = sorted(((w, i) for (i, w) in enumerate(W)))
P = input()
smallfree = 0
smallhalf = 0
highfree = n - 1
highasdk = n - 1
R = []
from collections import defaultdict as dd, deque
Q = deque()
for p in P:
	if p == '0':
		R.append(W[smallfree][1])
		Q.append(smallfree)
		smallfree += 1
	else:
		seat = Q.pop()
		R.append(W[seat][1])
print(*[r + 1 for r in R])


n = int(input())
a = list(map(int, input().split()))
b = input()
c = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
	for j in range(2):
		if j == 1:
			c[i][j] = i + 1
		else:
			c[i][j] = a[i]
c.sort()
result = []
j = 0
temp = []
for i in range(2 * n):
	if b[i] == '0':
		result.append(c[j][1])
		temp.append(c[j][1])
		j += 1
	else:
		z = temp.pop()
		result.append(z)
for x in range(len(result)):
	print(result[x], end=' ')


from sys import stdin
inp = stdin.readline
n = int(inp())
a = [(int(ele), i + 1) for (i, ele) in enumerate(inp().split())]
s = inp().strip()
ans = [0] * (2 * n)
partially_filled = []
a.sort()
start = 0
for j in range(2 * n):
	if s[j] == '0':
		partially_filled.append(a[start])
		ans[j] = a[start][1]
		start += 1
	else:
		ans[j] = partially_filled[-1][1]
		partially_filled.pop()
print(*ans)


n = int(input())
w = [int(k) for k in input().split()]
for i in range(n):
	w[i] = [i + 1, w[i], 0]
w.sort(key=lambda e: e[1])
nextIntro = 0
result = [0 for _ in range(2 * n)]
unfilled = []
for (index, v) in enumerate(input()[:2 * n]):
	if v == '0':
		result[index] = w[nextIntro][0]
		unfilled.append(nextIntro)
		nextIntro += 1
	elif v == '1':
		result[index] = w[unfilled.pop()][0]
print(*result)


from sys import stdin

def get_ints():
	return list(map(int, stdin.readline().strip().split()))
n = int(input())
ar = get_ints()
bus = sorted([(ar[i], i + 1) for i in range(n)])
pa = [int(x) for x in input()]
seq = []
tail = 0
for p in pa:
	if p == 0:
		print(bus[tail][1], end=' ')
		seq.append(tail)
		tail += 1
	else:
		v = seq.pop()
		print(bus[v][1], end=' ')


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().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] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
arr = zzz()
new_arr = sorted([(i, j) for (j, i) in enumerate(arr)])
lst = fast()
stack = []
ans = []
size = 0
left = 0
right = n - 1
for (i, j) in enumerate(lst):
	if j == '0':
		ans.append(new_arr[left][1] + 1)
		stack.append(new_arr[left][1] + 1)
		size += 1
		left += 1
	if j == '1':
		if size == 0:
			ans.append(new_arr[right][1] + 1)
			stack.append(new_arr[right][1] + 1)
			right -= 1
		if size > 0:
			ans.append(stack[-1])
			stack.pop()
			size -= 1
print(*ans)


import collections
n = int(input())
w = list(map(int, input().split(' ')))
a = []
s = input()
intro = 0
query = collections.deque()
for i in range(n):
	a.append((i, w[i]))
a.sort(key=lambda x: x[1])
for i in range(2 * n):
	if s[i] == '0':
		print(a[intro][0] + 1, end=' ')
		query.append(a[intro][0])
		intro += 1
	else:
		print(query[-1] + 1, end=' ')
		query.pop()


n = int(input())
seats = sorted(enumerate(map(int, input().split()), 1), key=lambda x: -x[1])
psngr = input()
extrovert = []
for i in range(2 * n):
	if psngr[i] == '0':
		print(seats[-1][0], end=' ')
		extrovert.append(seats.pop())
	else:
		print(extrovert.pop()[0], end=' ')


n = int(input())
w = [int(s) for s in input().split(' ')]
s = input()
a = []
for i in range(n):
	a.append((w[i], i + 1))
a.sort(key=lambda x: x[0])
intr_n = 0
res = []
intrs = []
for c in s:
	if c == '0':
		x = a[intr_n][1]
		res.append(x)
		intrs.append(x)
		intr_n = intr_n + 1
	else:
		extr = intrs.pop()
		res.append(extr)
print(' '.join([str(x) for x in res]))


N = int(input())
Width = [int(x) for x in input().split()]
Input_Order = [int(x) for x in list(input())]
Sorted_Width = sorted(Width)
Data = {Width[x]: x for x in range(0, N)}
A = []
B = []
position = 0
for x in range(0, 2 * N):
	if Input_Order[x] == 0:
		A.append(Data[Sorted_Width[position]] + 1)
		B.append(Data[Sorted_Width[position]] + 1)
		position += 1
	else:
		A.append(B[-1])
		B.pop()
for x in A:
	print(x, end=' ')


from heapq import heappop, heappush, heapify

def main():
	n = int(input())
	l = sorted(range(n), key=list(map(int, input().split())).__getitem__)
	i = 0
	(cc, res) = ([], [])
	for c in input():
		if c == '0':
			heappush(cc, i)
			res.append(l[-i] + 1)
			i -= 1
		else:
			res.append(l[-heappop(cc)] + 1)
	print(' '.join(map(str, res)))
main()


n = int(input())
ws = [(v, i) for (i, v) in enumerate(map(int, input().split(' ')))]
ws = sorted(ws)
ws = [i for (v, i) in ws]
s = input()
introI = 0
extraStack = []
res = []
for c in s:
	ex = c == '1'
	if not ex:
		row = ws[introI]
		extraStack += [row]
		introI += 1
	else:
		row = extraStack.pop()
	res += [row + 1]
print(*res)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	l = sorted(zip(lst(), range(n)))
	p = 0
	ans = [0] * (2 * n)
	st = [0] * n
	ln = 0
	s = input()
	for i in range(2 * n):
		ch = s[i]
		if ch == '0':
			st[ln] = p
			ans[i] = l[p][1] + 1
			ln += 1
			p += 1
		else:
			ans[i] = l[st[ln - 1]][1] + 1
			ln -= 1
	print(*ans)


n = int(input())
p = list(map(int, input().split()))
s = input()
k = []
final = []
for j in range(len(p)):
	p[j] = [p[j], j]
p.sort(reverse=True)
for c in s:
	if c == '0':
		print(p[len(p) - 1][1] + 1, end=' ')
		k.append(p.pop())
	else:
		print(k[len(k) - 1][1] + 1, end=' ')
		k.pop()
print()


n = int(input())
a = list(map(int, input().split()))
b = []
s = input()
d = dict()
for i in range(n):
	d[a[i]] = i
a.sort()
j = 0
for i in s:
	if i == '0':
		print(d[a[j]] + 1, end=' ')
		b.append(d[a[j]] + 1)
		j = j + 1
	else:
		print(b[len(b) - 1], end=' ')
		b.pop()


n = int(input())
w = [(int(wid), ind) for (ind, wid) in enumerate(input().split())]
w = sorted(w)
l = []
ind = 0
for pas in input():
	if pas == '0':
		print(w[ind][1] + 1, end=' ')
		l.append(w[ind][1] + 1)
		ind += 1
	else:
		print(l.pop(), end=' ')


n = int(input())
width = [(int(w), i) for (i, w) in enumerate(input().split(' '))]
order = input()
width = sorted(width, key=lambda x: x[0])
no_passengers = [w[1] for w in width]
one_passenger = []
i = 0
for person in order:
	if person == '0':
		print(no_passengers[i] + 1, end=' ')
		one_passenger.append(no_passengers[i])
		i += 1
	else:
		print(one_passenger.pop() + 1, end=' ')


n = int(input())
l = [int(i) for i in input().split()]
l = [[l[i], i] for i in range(n)]
l.sort()
empty = [[0 for j in range(2)] for i in range(n)]
st = 0
intr = 0
stk = []
end = n - 1
s = input()
ans = []
for i in s:
	if i == '0':
		ans.append(l[intr][1])
		stk.append(l[intr][1])
		intr += 1
	else:
		ans.append(stk.pop())
print(*(i + 1 for i in ans))


n = int(input())
(d, ans, m, id) = ([], [], [], 0)
for i in map(int, input().split()):
	d.append([i, id])
	id += 1
d = sorted(d)
id = 0
for i in input():
	if i == '0':
		ans.append(str(d[id][1] + 1))
		m.append(id)
		id += 1
	else:
		ans.append(str(d[m.pop()][1] + 1))
print(' '.join(ans))


def main():
	n = int(input())
	w = input().split()
	w = [[int(w[i]), i + 1] for i in range(n)]
	w.sort(key=lambda x: x[0])
	introindex = 0
	result = []
	introPlaces = []
	for passenger in input():
		if passenger == '0':
			result.append(str(w[introindex][1]))
			introPlaces.append(w[introindex][1])
			introindex += 1
		else:
			result.append(str(introPlaces.pop()))
	print(' '.join(result))
main()


n = int(input())
w = list(map(int, input().split()))
s = input()
for i in range(n):
	w[i] = [w[i], i]
w.sort(key=lambda x: x[0], reverse=1)
c = []
for i in range(2 * n):
	if s[i] == '0':
		c.append(w.pop()[1])
		print(c[-1] + 1, end=' ')
	else:
		print(c.pop() + 1, end=' ')


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
z = defaultdict(list)
temp1 = []
temp2 = []
for i in range(n):
	z[a[i]] = i + 1
	temp1.append(a[i])
s = input()
temp1.sort(reverse=True)
for i in s:
	if i == '0':
		x = temp1.pop()
		print(z[x], end=' ')
		temp2.append(x)
	else:
		print(z[temp2.pop()], end=' ')


n = int(input())
w = list(map(int, input().split()))
a = [(w[i], i + 1) for i in range(n)]
avail = []
a.sort()
s = input()
tail = 0
for x in s:
	if x == '0':
		print(a[tail][1], end=' ')
		avail.append(tail)
		tail += 1
	else:
		v = avail.pop()
		print(a[v][1], end=' ')


import queue
n = int(input())
w = [int(x) for x in input().split()]
seats = [(w[i], i + 1) for i in range(n)]
seats = sorted(seats, key=lambda x: x[0])
se = []
s = input()
i = 0
used = []
for p in s:
	if p == '0':
		print(seats[i][1], end=' ')
		se.append(seats[i])
		i += 1
	else:
		print(se[-1][1], end=' ')
		se.pop(-1)
print()


import heapq
row = int(input())
width = [int(x) for x in input().split()]
Introvert = []
Extrovert = []
for i in range(row):
	heapq.heappush(Introvert, (width[i], i + 1))
sequence = input()
Ans = []
for i in sequence:
	if i == '0':
		(x, y) = heapq.heappop(Introvert)
		heapq.heappush(Extrovert, (-x, y))
		Ans.append(y)
	else:
		(x, y) = heapq.heappop(Extrovert)
		Ans.append(y)
print(*Ans)


n = int(input())
num = list(map(int, input().split()))
s = input()
a = sorted(range(1, n + 1), key=lambda i: num[i - 1])
(i, inv, ext) = (0, [], [])
for c in s:
	if c == '0':
		ext.append(a[i])
		inv.append(a[i])
		i += 1
	else:
		ext.append(inv.pop())
print(*ext)


n = int(input())
ws = [(int(x), i + 1) for (i, x) in enumerate(input().split())]
log = input()
ws.sort()
stack = []
out = []
cur = 0
for ch in log:
	if ch == '0':
		r = ws[cur][1]
		stack.append(r)
		out.append(r)
		cur += 1
	else:
		out.append(stack.pop())
print(' '.join(map(str, out)))


from collections import deque
n = int(input())
orderedli = list(map(int, input().split(' ')))
indexof = {}
for (i, x) in enumerate(orderedli):
	indexof[x] = i + 1
sortedli = list(sorted(orderedli))
i = 0
s = input()
st = deque()
for x in s:
	if x == '0':
		st.append(sortedli[i])
		print(indexof[sortedli[i]], end=' ')
		i += 1
	else:
		temp = st.pop()
		print(indexof[temp], end=' ')


n = int(input())
a = list(map(int, input().split()))
b = range(1, n + 1)
za = [x for (x, y) in sorted(zip(a, b))]
zb = [y for (x, y) in sorted(zip(a, b))]
s = input()
a = []
j = 0
for i in range(2 * n):
	if s[i] == '0':
		a.append(zb[j])
		print(zb[j], end=' ')
		j += 1
	else:
		print(a.pop(), end=' ')


n = int(input())
i = iter(sorted(zip(map(int, input().split()), range(1, n + 1))))
(s, o) = ([], [])
for c in input():
	if c == '0':
		x = next(i)[1]
		o += [x]
		s += [x]
	else:
		o.append(s.pop())
print(*o)


from heapq import heappush, heappop, heapify
n = int(input())
W_I = [(int(w), i) for (i, w) in enumerate(input().split(' '))]
heapify(W_I)
W_E = []
passengers = input()
answer = []
for passenger in passengers:
	if passenger == '0':
		(w, i) = heappop(W_I)
		heappush(W_E, (-w, i))
		answer.append(i + 1)
	else:
		(w, i) = heappop(W_E)
		answer.append(i + 1)
print(' '.join([str(el) for el in answer]))


n = int(input())
i = 1
l = []
for j in input().split():
	l.append((i, int(j)))
	i += 1
st = input()
l.sort(key=lambda x: x[1])
stack = []
k = 0
for i in range(2 * n):
	if st[i] == '0':
		print(l[k][0], end=' ')
		stack.append(l[k][0])
		k += 1
	else:
		a = stack.pop()
		print(a, end=' ')


def solve(w, s):
	empty = sorted(enumerate(w), key=lambda x: x[1], reverse=True)
	non_empty = []
	result = []
	for p in s:
		if p == '0':
			row = empty.pop()
			non_empty.append(row)
		else:
			row = non_empty.pop()
		result.append(row[0] + 1)
	return result

def main():
	_ = input()
	w = [int(x) for x in input().strip().split()]
	s = input().strip()
	result = solve(w, s)
	print(' '.join(map(str, result)))
main()


N = int(input())
w = list(map(int, input().split(' ')))
key = [i + 1 for i in range(N)]
w_dict = dict(zip(key, w))
w_dict = sorted(w_dict.items(), key=lambda x: x[1])
number = [row[0] for row in w_dict]
passenger = input()
ans = []
gaikouteki = []
now = 0
for i in passenger:
	if i == '0':
		ans.append(number[now])
		gaikouteki.append(number[now])
		now += 1
	else:
		ans.append(gaikouteki[-1])
		gaikouteki.pop()
print(' '.join(map(str, ans)))


n = int(input())
w = list(map(int, input().split()))
a = sorted(list(range(1, n + 1)), key=lambda i: w[i - 1])
(i, s, o) = (0, [], [])
for c in input():
	if c == '0':
		o.append(a[i])
		s.append(a[i])
		i += 1
	else:
		o.append(s.pop())
print(*o)


def print_return(func):

	def wrapper(*args, **kwargs):
		retval = func(*args, **kwargs)
		print(retval)
		return retval
	return wrapper

class Solve:

	@staticmethod
	@print_return
	def solve_a(lines=None):
		if lines is None:
			n = int(input())
			row = input()
		else:
			lines = lines.split('\n')
			n = int(lines[0].strip())
			row = lines[1].strip()
		ans = 'Yes'

		def neighs(idx):
			ns = []

			def get_idxes(idx):
				return (idx - 1, idx + 1)
			for i in get_idxes(idx):
				if i > -1 and i < n:
					ns.append(row[i])
			return ns
		for idx in range(n):
			if row[idx] == '0' and all((x == '0' for x in neighs(idx))):
				ans = 'No'
				break
			elif row[idx] == '1' and any((x == '1' for x in neighs(idx))):
				ans = 'No'
				break
		return ans

	@staticmethod
	@print_return
	def solve_b(lines=None):
		if lines is None:
			n = int(input())
			idx___width = [int(x) for x in input().split()]
			stop_idx___char = input()
		else:
			lines = lines.split('\n')
			n = int(lines[0])
			idx___width = [int(x) for x in lines[1].split()]
			stop_idx___char = lines[2]
		bus = sorted(enumerate(idx___width), key=lambda x: x[1])
		queue = []
		ans = []
		curr_last = 0
		for person in stop_idx___char:
			if person == '0':
				queue.append(str(bus[curr_last][0] + 1))
				ans.append(queue[-1])
				curr_last += 1
			else:
				ans.append(queue.pop())
		ans = ' '.join(ans)
		return ans

	@staticmethod
	@print_return
	def solve_c(lines=None):
		pass

	@staticmethod
	@print_return
	def solve_d(lines=None):
		pass

	@staticmethod
	@print_return
	def solve_e(lines=None):
		pass

	@staticmethod
	@print_return
	def solve_f(lines=None):
		pass
Solve.solve_b()


from collections import deque
n = int(input())
w = list(map(int, input().split()))
d = {}
for i in range(n):
	d[w[i]] = i
w.sort()
stack = deque()
s = input()
ans = []
j = 0
for i in range(2 * n):
	if s[i] == '0':
		y = d[w[j]]
		stack.append(y)
		ans.append(y + 1)
		j += 1
	else:
		x = stack.pop()
		ans.append(x + 1)
print(*ans)


MyDict = {}
(N, Ans) = (int(input()), [])
Width = list(map(int, input().split()))
Passengers = input()
for i in range(N):
	MyDict[Width[i]] = i + 1
Keys = sorted(Width)
Now = []
Index = 0
for j in Passengers:
	if j == '0':
		Now.append(Keys[Index])
		print(MyDict[Keys[Index]], end=' ')
		Index += 1
	else:
		print(MyDict[Now.pop()], end=' ')


from collections import deque
n = int(input())
w = list(map(int, input().strip().split()))
pas = input().strip()
W = []
for i in range(n):
	W.append([w[i], str(i + 1), 2])
W.sort(key=lambda x: x[0])
stack = []
i = 0
j = -1
final = ''
for k in range(2 * n):
	if pas[k] == '0':
		final += W[i][1] + ' '
		stack.append(W[i])
		i += 1
		j = i - 1
	else:
		elem = stack.pop()
		final += elem[1] + ' '
print(final)


from _collections import deque
n = int(input())
m = list(map(int, input().split()))
a = []
b = deque()
i = 1
for x in m:
	a.append((x, i))
	i += 1
a.sort(key=lambda p: -p[0])
s = input()
ans = []
for x in s:
	if x == '1':
		v = b.pop()
		ans.append(v[1])
	else:
		v = a.pop()
		ans.append(v[1])
		b.append(v)
print(*ans)


n = int(input())
width = [int(x) for x in input().split()]
p = input()
w = []
for i in range(n):
	w.append((width[i], i))
w.sort(reverse=True)
intro = []
seat = []
for i in range(2 * n):
	if p[i] == '0':
		x = w.pop()
		seat.append(x[1] + 1)
		intro.append(x)
	elif p[i] == '1':
		x = intro.pop()
		seat.append(x[1] + 1)
for i in range(2 * n):
	print(seat[i], end=' ')


import math
import time
import bisect

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

def getTransIntList(n):
	first = getIntList()
	m = len(first)
	result = [[0] * n for _ in range(m)]
	for i in range(m):
		result[i][0] = first[i]
	for j in range(1, n):
		curr = getIntList()
		for i in range(m):
			result[i][j] = curr[i]
	return result
n = int(input())
w = getIntList()
s = input()
p = [int(s[i]) for i in range(2 * n)]
seatInt = [(w[i], i) for i in range(n)]
seatInt.sort()
currI = 0
seatExt = []
result = [0] * (2 * n)
for i in range(2 * n):
	if p[i] == 0:
		result[i] = seatInt[currI][1] + 1
		bisect.insort(seatExt, seatInt[currI])
		currI += 1
	else:
		result[i] = seatExt.pop()[1] + 1
print(' '.join(map(str, result)))


def main():
	n = int(input())
	j = list(map(int, input().split()))
	for i in range(n):
		j[i] = [j[i], i + 1]
	j.sort()
	j = j[::-1]
	e = []
	s = input()
	for i in range(2 * n):
		if s[i] == '0':
			print(j[-1][1], end=' ')
			e.append(j[-1])
			j.pop()
		else:
			print(e[-1][1], end=' ')
			e.pop()
main()


n = int(input())
cl = list(map(int, input().split()))
s = input()
dic = {}
for x in range(n):
	dic.update({cl[x]: x + 1})
cl = sorted(cl)
pl = []
res = ''
pos1 = 0
for c in s:
	if c == '0':
		pl.append(cl[pos1])
		res += str(dic[cl[pos1]]) + ' '
		pos1 += 1
	if c == '1':
		mx = pl[-1]
		res += str(dic[mx]) + ' '
		pl.pop(-1)
print(res)


from collections import deque
n = int(input().strip())
wis = list(map(int, input().strip().split()))
cs = input().strip()
pl = list(range(1, n + 1))
pl.sort(key=lambda p: wis[p - 1])
i = 0
stack = deque()
res = []
for c in cs:
	if c == '0':
		stack.append(pl[i])
		res.append(pl[i])
		i += 1
	else:
		res.append(stack.pop())
print(' '.join(map(str, res)))


n = int(input())
w = [(int(x), i + 1) for (i, x) in enumerate(input().split())]
s = input()
w.sort()
stack = []
ans = []
cur = 0
for c in s:
	if c == '0':
		stack.append(w[cur][1])
		ans.append(w[cur][1])
		cur += 1
	else:
		ans.append(stack.pop())
print(' '.join(map(str, ans)))


import sys

def main():
	n = int(sys.stdin.readline())
	w = sys.stdin.readline().split()
	w = [(int(w[i]), i) for i in range(n)]
	p = [i for i in sys.stdin.readline().strip()]
	w.sort()
	res = []
	(intro, extro) = (0, [])
	for pa in p:
		if pa == '0':
			extro.append(w[intro][1])
			res.append(str(w[intro][1] + 1))
			intro += 1
		else:
			s = extro.pop()
			res.append(str(s + 1))
	print(' '.join(res))
main()


import sys
import math

def fun():
	n = int(input())
	arr = list(map(int, input().split()))
	enter_list = input()
	width_list = [[i + 1, arr[i]] for i in range(n)]
	width_list.sort(key=lambda x: x[-1])
	j = 0
	seated_list = [width_list[0]]
	all_list = [width_list[0][0]]
	j += 1
	for c in enter_list[1:]:
		if c == '0':
			seated_list.append(width_list[j])
			all_list.append(width_list[j][0])
			j += 1
		else:
			all_list.append(seated_list[-1][0])
			seated_list.pop()
	all_list = [str(i) for i in all_list]
	print(' '.join(all_list))

def __starting_point():
	fun()
__starting_point()


from array import array
n = int(input())
ws = array('i', [0] + [int(x) for x in input().split()])
ins = array('i', range(1, n + 1))
prevs = array('i', range(-1, n))
ps = input()

def I(i):
	return ins[i]

def W(i):
	return ws[ins[i]]
ins = sorted(ins, key=lambda i: ws[i])
vacant = 0
for p in ps:
	if p == '0':
		iw = ins[vacant]
		print(iw, end=' ')
		vacant += 1
	else:
		iw = ins[prevs[vacant]]
		print(iw, end=' ')
		prevs[vacant] = prevs[prevs[vacant]]


n = int(input())
line = input().split()
w = []
for i in range(n):
	w.append((int(line[i]), i + 1))
w = sorted(tuple(w))
cur = 0
st = []
res = []
for ch in input():
	if ch == '0':
		st.append(w[cur][1])
		res.append(w[cur][1])
		cur += 1
	else:
		res.append(st[-1])
		st.pop()
print(' '.join((str(item) for item in res)))


from collections import deque
from operator import itemgetter

class CodeforcesTask982BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.seats = []
		self.passengers = ''

	def read_input(self):
		self.n = int(input())
		self.seats = [int(x) for x in input().split(' ')]
		self.passengers = input()

	def process_task(self):
		results = []
		numbered_seats = [(x + 1, self.seats[x]) for x in range(self.n)]
		numbered_seats.sort(key=itemgetter(1), reverse=True)
		intro = deque()
		for passenger in self.passengers:
			if passenger == '0':
				seat = numbered_seats.pop(-1)
				results.append(seat[0])
				intro.append(seat[0])
			else:
				seat = intro.pop()
				results.append(seat)
		self.result = ' '.join([str(x) for x in results])

	def get_result(self):
		return self.result
Solution = CodeforcesTask982BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
w = list(map(int, input().split()))
s = input()
(mn, mx) = (min(w), max(w))
mnd = {}
for i in range(n):
	if w[i] not in mnd:
		mnd[w[i]] = i
w.sort()
ans = []
j = 0
temp = []
for i in range(2 * n):
	if s[i] == '0':
		ans.append(mnd[w[j]] + 1)
		temp.append(w[j])
		j += 1
	else:
		ans.append(mnd[temp[len(temp) - 1]] + 1)
		temp.pop()
print(*ans)


import heapq
N = int(input())
w = list(map(int, input().split()))
s = input()
P = []
for i in range(N):
	P.append((w[i], i))
P = sorted(P)
empty = 0
occupied = []
rec = [None] * (2 * N)
hq = heapq
for i in range(len(s)):
	if s[i] == '0':
		rec[i] = P[empty][1] + 1
		empty += 1
		hq.heappush(occupied, -empty)
	else:
		q = -hq.heappop(occupied)
		rec[i] = P[q - 1][1] + 1
print(' '.join(map(str, rec)))


def main():
	t = 1
	for _ in range(t):
		n = int(input())
		tab = list(map(int, input().split()))
		s = input()
		for x in range(n):
			tab[x] = (tab[x], x + 1)
		tab.sort()
		cur = 0
		q = []
		for x in range(2 * n):
			if s[x] == '0':
				q.append(tab[cur][1])
				print(tab[cur][1], end=' ')
				cur += 1
			else:
				print(q.pop(-1), end=' ')
main()


import heapq
n = int(input())
w = [int(x) for x in input().split()]
us = {w[i]: i + 1 for i in range(n)}
w.sort()
p = input()
order = ''
i = 0
seats = []
for x in p:
	if x == '0':
		y = w[i]
		order += str(us[y]) + ' '
		heapq.heappush(seats, -y)
		i += 1
	else:
		m = heapq.heappop(seats)
		order += str(us[-m]) + ' '
print(order)


import sys
from math import gcd, sqrt
from typing import Deque
sys.setrecursionlimit(10 ** 5)
inf = float('inf')
en = lambda x: list(enumerate(x))
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = rr()
arr = en(arr)
arr.sort(key=lambda x: x[1])
i = 0
brr = []
for j in input():
	if j == '0':
		brr.append(arr[i])
		print(arr[i][0] + 1, end=' ')
		i += 1
	else:
		x = brr.pop()
		print(x[0] + 1, end=' ')


n = int(input())
u = list(map(int, input().split()))
for i in range(n):
	u[i] = (u[i], i)
h = list(map(int, list(input())))

def f(t):
	return t[0]
k = 2 * n
p = [0] * k
ex = []
it = u[:]
it.sort(key=f)
ind = 0
for i in range(k):
	if not h[i]:
		p[i] = it[ind][1] + 1
		ex.append(p[i])
		ind += 1
	else:
		p[i] = ex[-1]
		ex.pop()
for i in range(k):
	print(p[i], end=' ')


n = int(input())
(li1, li2, a) = ([], [], 0)
(li3, li4, b, c) = ([], [], 0, 0)
for i in map(int, input().split()):
	li1.append([i, a])
	a += 1
a = 0
li1.sort()
for i in input():
	if i == '0':
		li3.append(str(li1[a][1] + 1))
		li2.append(a)
		a += 1
	else:
		li3.append(str(li1[li2.pop()][1] + 1))
out = ' '.join(li3)
print(out)


def main():
	n = int(input())
	w = input().split()
	w = sorted([[int(w[i]), i + 1] for i in range(n)])
	introindex = 0
	result = []
	introPlaces = []
	for passenger in input():
		if passenger == '0':
			result.append(str(w[introindex][1]))
			introPlaces.append(w[introindex][1])
			introindex += 1
		else:
			result.append(str(introPlaces.pop()))
	print(' '.join(result))
main()


from heapq import heappop, heappush
n = int(input())
c = 1
w = {}
wh = []
for i in input().split():
	i = int(i)
	w[i] = c
	c += 1
	heappush(wh, i)
o = ''
ss = []
for i in input():
	if i == '0':
		ss += [str(w[heappop(wh)])]
		o += ss[-1] + ' '
	else:
		o += ss[-1] + ' '
		ss.pop(-1)
print(o)


n = int(input())
w = list(map(int, input().split()))
pos_w = {}
for i in range(len(w)):
	pos_w[w[i]] = i + 1
w.sort()
s = input()
stack = []
count = 0
for i in range(len(s)):
	if s[i] == '0':
		stack.append(pos_w[w[count]])
		print(pos_w[w[count]], end=' ')
		count += 1
	else:
		print(stack[-1], end=' ')
		stack.pop()


n = int(input())
w = input().split(' ')
w = [(int(w[i]), i + 1) for i in range(n)]
w.sort()
(stack, output) = ([], [])
pos = 0
for c in input():
	if c == '0':
		stack.append(w[pos][1])
		output.append(w[pos][1])
		pos += 1
	else:
		output.append(stack.pop())
print(*output)


import sys
INTROVERT = '0'
EXTROVERT = '1'

def solve(row_width, passengers):
	rows = [(i + 1, width) for (i, width) in enumerate(row_width)]
	rows = sorted(rows, key=lambda x: x[1])
	seats = [x[0] for x in rows]
	iptr = 0
	solution = []
	available_seats = []
	for p in passengers:
		if p == INTROVERT:
			solution.append(seats[iptr])
			available_seats.append(seats[iptr])
			iptr += 1
		if p == EXTROVERT:
			solution.append(available_seats.pop())
	return solution
row_number = int(sys.stdin.readline())
row_width = map(int, sys.stdin.readline().split(' '))
passengers = sys.stdin.readline()
solution = solve(row_width, passengers)
print(' '.join(map(str, solution)))


import heapq
n = int(input())
w0 = [(int(wi), i + 1) for (i, wi) in enumerate(input().split())]
w1 = []
p = input()
ans = []
w0.sort()
i = 0
for j in p:
	if j == '0':
		ans.append(w0[i][1])
		w1.append(w0[i])
		i += 1
	else:
		(w, ix) = w1.pop()
		ans.append(ix)
print(*ans)


n = int(input())
a = [int(i) for i in input().split()]
s = input()
mp = {}
for i in range(n):
	mp[a[i]] = i + 1
a.sort()
intr = 0
extr = 0
first = mp[a[0]]
st = []
ans = []
for i in range(len(s)):
	if s[i] == '0':
		ans += [mp[a[intr]]]
		st.append(mp[a[intr]])
		intr += 1
	else:
		ans += [st.pop()]
print(*ans)


n = int(input())
p = list(map(int, input().split()))
s = input()
k = []
final = []
for j in range(len(p)):
	p[j] = [p[j], j]

def myfunc(c):
	return c[0]
p = sorted(p, key=myfunc, reverse=True)
for c in s:
	if c == '0':
		final.append(p[len(p) - 1])
		k.append(p[len(p) - 1])
		p.pop()
	else:
		final.append(k[len(k) - 1])
		k.pop()
for i in final:
	print(i[1] + 1, end=' ')
print()


n = int(input().strip())
temp = input().strip().split()
w = []
for j in range(len(temp)):
	w.append([int(temp[j]), j])
w.sort()
passenger = input().strip()
biggest_intro = []
smallest_index = 0
for i in range(2 * n):
	if passenger[i] == '0':
		print(w[smallest_index][1] + 1, end=' ')
		biggest_intro.append(smallest_index)
		smallest_index += 1
	elif passenger[i] == '1':
		b = biggest_intro.pop()
		print(w[b][1] + 1, end=' ')
print()


n = int(input())
w = list(map(int, input().split()))
intro = [[v, i] for (i, v) in enumerate(w, 1)]
intro.sort(key=lambda x: x[0])
s = input()
i = -1
li = []
ans = []
for j in s:
	if j == '0':
		i += 1
		ans.append(intro[i][1])
		li.append(intro[i][1])
	else:
		ans.append(li.pop(-1))
print(' '.join(map(str, ans)))


n = int(input())
seats = list(map(int, input().split()))
sarr = list(zip(seats, range(1, n + 1)))
sarr.sort()
sarr = [i[1] for i in sarr]
ans = []
k = 0
for i in input():
	if i == '0':
		print(sarr[k], end=' ')
		ans.append(sarr[k])
		k += 1
	if i == '1':
		print(ans[-1], end=' ')
		ans.pop()


n = int(input())
w = [[-int(x), i + 1] for (i, x) in enumerate(input().split(' '))]
w.sort(key=lambda x: x[0])
m = input()
e = []
res = []
for x in m:
	if x == '0':
		res.append(w[len(w) - 1][1])
		e.append(w.pop()[1])
	else:
		res.append(e.pop())
print(' '.join(map(str, res)))


class heap:

	def __init__(self, maxn):
		self.a = [0] * maxn
		self.size = 0

	def shift_down(self, i):
		while 2 * i + 1 < self.size:
			l = 2 * i + 1
			r = 2 * i + 2
			j = l
			if r < self.size and self.a[r] < self.a[l]:
				j = r
			if self.a[i] <= self.a[j]:
				break
			(self.a[i], self.a[j]) = (self.a[j], self.a[i])
			i = j

	def shift_up(self, i):
		while i and self.a[i] < self.a[(i - 1) // 2]:
			(self.a[i], self.a[(i - 1) // 2]) = (self.a[(i - 1) // 2], self.a[i])
			i = (i - 1) // 2

	def erase_min(self):
		mn = self.a[0]
		self.a[0] = self.a[self.size - 1]
		self.size -= 1
		self.shift_down(0)
		return mn

	def insert(self, val):
		self.size += 1
		self.a[self.size - 1] = val
		self.shift_up(self.size - 1)
n = int(input())
ar = [int(j) for j in input().split()]
s0 = heap(400000 + 100)
s1 = heap(400000 + 100)
for i in range(n):
	s0.insert((ar[i], i + 1))
for c in input():
	if c == '0':
		v = s0.erase_min()
		print(v[1], end=' ')
		s1.insert((-v[0], v[1]))
	else:
		print(s1.erase_min()[1], end=' ')


n = int(input())
l = 2 * n
w = [int(i) for i in input().split()]
pas = input()
seat = [i for i in w]
seat.sort()
d = {}
for i in range(len(w)):
	d[w[i]] = i
i = 0
w1 = [0] * l
j = 0
wkend = ' '
for k in range(l):
	if k == l - 1:
		wkend = '\n'
	if pas[k] == '0':
		wkindex = d[seat[i]] + 1
		print(wkindex, end=wkend)
		j += 1
		w1[j] = wkindex
		i += 1
	else:
		print(w1[j], end=wkend)
		j -= 1


from collections import deque
n = int(input())
arr = [int(p) for p in input().split()]
pas = input()
stack = deque()
patt = []
j = 0
index = {}
for i in range(len(arr)):
	index[arr[i]] = i
arr.sort()
for i in range(len(pas)):
	if pas[i] == '0':
		stack.append(arr[j])
		patt.append(index[arr[j]] + 1)
		j += 1
	else:
		ele = stack.pop()
		patt.append(index[ele] + 1)
print(*patt)


n = int(input())
a = [int(a) for a in input().split()]
code = []
for i in range(1, n + 1):
	d = dict(x=a[i - 1], y=i)
	code.append(d)
code = sorted(code, key=lambda i: i['x'], reverse=True)
intro = []
extro = []
for i in range(1, n + 1):
	intro.append(code[i - 1]['y'])
inp = input()
for i in inp:
	if i == '0':
		intro_seat = intro.pop()
		print(intro_seat, end=' ')
		extro.append(intro_seat)
	else:
		print(extro.pop(), end=' ')
print()


import heapq
n = int(input())
i = [int(x) for x in input().split(' ')]
i = [(x, i) for (i, x) in enumerate(i)]
e = []
s = input()
heapq.heapify(i)
heapq.heapify(e)
ans = []
for c in s:
	if c == '0':
		r = heapq.heappop(i)
		heapq.heappush(e, (-r[0], r[1]))
	else:
		r = heapq.heappop(e)
	ans.append(r[1] + 1)
print(*ans)


def main():
	l = sorted(range(int(input())), key=list(map(int, input().split())).__getitem__)
	(i, st, res) = (0, [], [])
	for c in input():
		if c == '0':
			st.append(i)
			res.append(l[i] + 1)
			i += 1
		else:
			res.append(l[st.pop()] + 1)
	print(' '.join(map(str, res)))
main()


input()
intro = sorted([(-x, i + 1) for (i, x) in enumerate(map(int, input().split()))])
extro = []
line = input()
sol = []
for c in line:
	if c == '0':
		(w, r) = intro.pop()
		extro.append((w, r))
		sol.append(str(r))
	else:
		(w, r) = extro.pop()
		sol.append(str(r))
print(' '.join(sol))


from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
s = input()
ans = [0] * 2 * n
for i in range(n):
	a[i] = (a[i], i + 1)
a.sort()
stack = deque()
index = 0
for i in range(2 * n):
	if s[i] == '0':
		stack.appendleft((i, a[index][1]))
		index += 1
	else:
		now = stack.popleft()
		ans[i] = now[1]
		ans[now[0]] = now[1]
print(*ans)


n = int(input())
x = [int(i) for i in input().split(' ')]
s = input()
stack = []
ele = [i[0] + 1 for i in sorted(enumerate(x), key=lambda x: x[1])]
j = 0
for c in s:
	if c == '0':
		print(ele[j], end=' ')
		stack.append(ele[j])
		j += 1
	else:
		print(stack.pop(), end=' ')


import sys
n = int(sys.stdin.readline().lstrip().rstrip())
w = list(map(int, sys.stdin.readline().lstrip().rstrip().split()))
word = sys.stdin.readline().lstrip().rstrip()
seat = []
for i in range(n):
	seat.append([w[i], i])
seat.sort()
visited = [False for i in range(n)]
stack = []
(intro, extro) = (0, 0)
for i in word:
	if i == '0':
		x = seat[intro]
		sys.stdout.write(str(x[1] + 1) + ' ')
		stack.append(x[1] + 1)
		intro += 1
	else:
		sys.stdout.write(str(stack[-1]) + ' ')
		stack.pop()


n = int(input())
w = list(map(int, input().split()))
for (i, ww) in enumerate(w):
	w[i] = (ww, i + 1)
p = input()
w = sorted(w)
import heapq
que = []
t = 0
ans = []
for s in p:
	if s == '0':
		heapq.heappush(que, w[t])
		ans.append(w[t][1])
		t += 1
	else:
		head = que.pop()
		ans.append(head[1])
print(*ans)


n = int(input())
w = list(map(int, input().split()))
s = input()
ind = {}
for i in range(n):
	ind[w[i]] = i + 1
w.sort()
l = 0
arr = []
for i in range(2 * n):
	if s[i] == '0':
		print(ind[w[l]], end=' ')
		arr.append(w[l])
		l += 1
	else:
		print(ind[arr[-1]], end=' ')
		arr.pop()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
from collections import Counter
n = int(input())
arr = sorted([(int(x), i + 1) for (i, x) in enumerate(input().split())])
ptr = 0
ind = 0
array = []
for i in input():
	if i == '0':
		print(arr[ptr][1], end=' ')
		array.append(arr[ptr][1])
		ptr += 1
	else:
		print(array.pop(), end=' ')


def merge(arr, temp, l, m, r):
	n1 = m - l + 1
	n2 = r - m
	L1 = [0] * n1
	L2 = [0] * n1
	R1 = [0] * n2
	R2 = [0] * n2
	for i in range(0, n1):
		L1[i] = arr[l + i]
		L2[i] = temp[l + i]
	for j in range(0, n2):
		R1[j] = arr[m + 1 + j]
		R2[j] = temp[m + 1 + j]
	i = 0
	j = 0
	k = l
	while i < n1 and j < n2:
		if L1[i] <= R1[j]:
			arr[k] = L1[i]
			temp[k] = L2[i]
			i += 1
		else:
			arr[k] = R1[j]
			temp[k] = R2[j]
			j += 1
		k += 1
	while i < n1:
		arr[k] = L1[i]
		temp[k] = L2[i]
		i += 1
		k += 1
	while j < n2:
		arr[k] = R1[j]
		temp[k] = R2[j]
		j += 1
		k += 1

def mergeSort(arr, temp, l, r):
	if l < r:
		m = (l + (r - 1)) // 2
		mergeSort(arr, temp, l, m)
		mergeSort(arr, temp, m + 1, r)
		merge(arr, temp, l, m, r)
n = int(input())
arr = list(map(int, input().split()))
temp = []
for i in range(n):
	temp.append(i + 1)
j = 0
k = -1
arrx = [0] * n
mergeSort(arr, temp, 0, n - 1)
s = str(input())
arry = [0] * len(s)
arrn = [0]
for i in range(len(s)):
	if s[i] == '0':
		arry[i] = temp[j]
		arrx[temp[j] - 1] += 1
		arrn.append(temp[j])
		j += 1
	if s[i] == '1':
		arry[i] = arrn[-1]
		del arrn[-1]
print(' '.join(map(str, arry)))


from sys import stdin, stdout
a = stdin.readline()
z1 = []
k = ''
o = -1
z = sorted(((j, i) for (i, j) in enumerate(map(int, input().split()))))
for i in input():
	if i == '0':
		o += 1
		k += str(z[o][1] + 1) + ' '
		z1 += [z[o][1] + 1]
	else:
		k += str(z1.pop()) + ' '
stdout.write(k)


n = int(input())
w = list(map(int, input().split(' ')))
s = input()
h = dict()
for i in range(len(w)):
	h[w[i]] = i
w.sort()
st = []
pos = 0
for i in s:
	if i == '0':
		point = h[w[pos]]
		st.append(point)
		print(point + 1, end=' ')
		pos = pos + 1
	else:
		val = st.pop()
		print(val + 1, end=' ')


import sys
from heapq import heappush, heappop
n = int(sys.stdin.readline())
ws = sys.stdin.readline().split()
passengers = sys.stdin.readline().strip()
assert n == len(ws)
assert 2 * n == len(passengers)
h0 = []
h1 = []
for i in range(len(ws)):
	w = int(ws[i])
	heappush(h0, (w, i + 1))
res = []
for p in passengers:
	if p == '0':
		p0 = heappop(h0)
		p1 = (-p0[0], p0[1])
		heappush(h1, p1)
		res.append(str(p0[1]))
	elif p == '1':
		p1 = heappop(h1)
		res.append(str(p1[1]))
print(' '.join(res))


n = int(input())
widths = [(int(x), c) for (c, x) in enumerate(input().split())]
widths.sort()
passengers = input()
seating = ''
stack = []
i = 0
for pi in passengers:
	if pi == '1':
		seating += str(stack[-1][1] + 1) + ' '
		stack.pop()
	else:
		stack.append(widths[i])
		seating += str(stack[-1][1] + 1) + ' '
		i += 1
print(seating[:-1])


import logging
import collections
fmt = '%(levelname)s - %(name)s (line:%(lineno)s) - %(message)s'
formatter = logging.Formatter(fmt)
ch = logging.StreamHandler()
ch.setLevel(logging.NOTSET)
ch.setFormatter(formatter)
logger = logging.getLogger('bus_of_characters')
logger.setLevel(logging.NOTSET)
logger.addHandler(ch)

def solve(w, s):
	free = collections.deque()
	used = collections.deque()
	for w in sorted(enumerate(w), key=lambda x: x[1]):
		free.append([w[0] + 1, w[1]])
	ids = [-1] * len(s)
	order = []
	for (pid, p) in enumerate(s):
		logger.debug('pid: %s', pid)
		if p == '0':
			taken = (free.popleft(),)
			used.appendleft(taken)
		else:
			logger.debug('used %s', used)
			taken = used.popleft()
		ids[pid] = taken[0]
	return [x for (x, y) in ids]

def main():
	n = int(input().strip())
	w = [int(x) for x in input().strip().split()]
	s = input().strip()
	result = solve(w, s)
	print(' '.join(map(str, result)))

def __starting_point():
	main()
__starting_point()


n = int(input())
temp = list(zip([int(x) for x in input().split()], range(1, n + 1)))
temp.sort(key=lambda x: x[0], reverse=True)
type1 = [int(x) for x in list(input())]
a = []
ans = []
for i in type1:
	if i == 0:
		a.append(temp.pop())
		ans.append(a[-1][1])
	else:
		ans.append(a.pop()[1])
print(*ans)


n = input()
seat_rows = [int(x) for x in input().strip().split()]
aliens = input().strip()
eldian = '0'
marleyan = '1'
empty = sorted(enumerate(seat_rows), key=lambda x: x[1], reverse=True)
non_empty = []
result = []
for alien in aliens:
	if alien == eldian:
		row = empty.pop()
		non_empty.append(row)
	else:
		row = non_empty.pop()
	result.append(row[0] + 1)
print(' '.join(map(str, result)))


n = int(input())
a = []
for (i, w) in enumerate(input().split()):
	a.append((int(w), i + 1))
a.sort()
(i, ans, pls1) = (0, [], [])
for x in input():
	if x == '0':
		ans.append(a[i][1])
		pls1.append(a[i])
		i += 1
	else:
		ans.append(pls1.pop()[1])
print(*ans)