Polycarp studies at the university in the group which consists of n students (including himself). All they are registrated in the social net "TheContacnt!".

Not all students are equally sociable. About each student you know the value a_{i} — the maximum number of messages which the i-th student is agree to send per day. The student can't send messages to himself. 

In early morning Polycarp knew important news that the programming credit will be tomorrow. For this reason it is necessary to urgently inform all groupmates about this news using private messages. 

Your task is to make a plan of using private messages, so that:

  the student i sends no more than a_{i} messages (for all i from 1 to n);  all students knew the news about the credit (initially only Polycarp knew it);  the student can inform the other student only if he knows it himself. 

Let's consider that all students are numerated by distinct numbers from 1 to n, and Polycarp always has the number 1.

In that task you shouldn't minimize the number of messages, the moment of time, when all knew about credit or some other parameters. Find any way how to use private messages which satisfies requirements above. 


-----Input-----

The first line contains the positive integer n (2 ≤ n ≤ 100) — the number of students. 

The second line contains the sequence a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 100), where a_{i} equals to the maximum number of messages which can the i-th student agree to send. Consider that Polycarp always has the number 1.


-----Output-----

Print -1 to the first line if it is impossible to inform all students about credit. 

Otherwise, in the first line print the integer k — the number of messages which will be sent. In each of the next k lines print two distinct integers f and t, meaning that the student number f sent the message with news to the student number t. All messages should be printed in chronological order. It means that the student, who is sending the message, must already know this news. It is assumed that students can receive repeated messages with news of the credit. 

If there are several answers, it is acceptable to print any of them. 


-----Examples-----
Input
4
1 2 1 0

Output
3
1 2
2 4
2 3

Input
6
2 0 1 3 2 0

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

Input
3
0 2 2

Output
-1



-----Note-----

In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit.

Difficulty: EASY
Tags: Amortized analysis

Greedy algorithms
Skill types: Amortized analysis

Greedy algorithms

Starter code:

Solutions:
def main():
	students = int(input())
	msgs = [int(x) for x in input().split()]
	if msgs[0] == 0:
		print('-1')
	elif students - 1 > sum(msgs):
		print('-1')
	else:
		result = []
		no_info = [x for x in range(1, students)]
		sort_dict = {str(x): msgs[x] for x in no_info}
		sort_dict = sorted(sort_dict, key=sort_dict.__getitem__, reverse=True)
		no_info = [int(x) for x in sort_dict]
		has_info = [0]
		for target in no_info:
			if msgs[0] == 0:
				break
			if msgs[target] == 0:
				continue
			else:
				has_info.append(target)
				no_info.remove(target)
				result.append('1 ' + str(target + 1))
				msgs[0] -= 1
		check = True
		while check:
			check = False
			for item in has_info:
				if msgs[item] > 0:
					for target in no_info:
						if msgs[item] == 0:
							break
						has_info.append(target)
						no_info.remove(target)
						result.append(str(item + 1) + ' ' + str(target + 1))
						msgs[item] -= 1
						check = True
		if len(no_info) > 0:
			print('-1')
		else:
			print(str(len(result)))
			for item in result:
				print(item)
main()


def main():
	n = int(input())
	n_a = []
	inp_str = input().split(' ')
	sum_of_a = 0
	for i in range(1, len(inp_str) + 1):
		sum_of_a += int(inp_str[i - 1])
		n_a.append([i, int(inp_str[i - 1])])
	first_elem = n_a.pop(0)
	n_a.sort(key=lambda x: x[1], reverse=True)
	n_a.insert(0, first_elem)
	if n_a[0][1] == 0:
		return -1
	if sum_of_a < n - 1:
		return -1
	(stack, current_n, stack_n, flag, out_pairs) = ([], 0, 0, False, [])
	while True:
		if n_a[current_n][0] == 1:
			stack.append(n_a[current_n])
			current_n = n_a[current_n][0]
			continue
		stack_n = stack[0][0]
		current_a = current_n + stack[0][1]
		stack.pop(0)
		if current_a >= len(n_a):
			current_a = len(n_a)
			flag = True
		for n_tmp in range(current_n, current_a):
			out_pairs.append([stack_n, n_a[n_tmp][0]])
			if n_a[n_tmp][1] != 0:
				stack.append(n_a[n_tmp])
		current_n = current_a
		if flag == True:
			break
	return out_pairs
res = main()
if res == -1:
	print('-1')
else:
	print(len(res))
	for elem in res:
		print(str(elem[0]) + ' ' + str(elem[1]))


import sys
import operator
n = int(input())
t = list(map(int, sys.stdin.readline().split()))
m = []
for i in range(n - 1):
	m.append([i + 1, t[i + 1]])
m = sorted(m, key=operator.itemgetter(1), reverse=True)
m = [[0, t[0]]] + m
f = 0
c = 1
ans = []
while c < n and m[f][1] != 0:
	ans.append(str(m[f][0] + 1) + ' ' + str(m[c][0] + 1))
	c += 1
	m[f][1] = m[f][1] - 1
	if m[f][1] == 0:
		f += 1
if c != n:
	print(-1)
else:
	print(len(ans))
	print('\n'.join(ans))


from collections import deque
n_inp = input()
an_inp = input()
n = int(n_inp)
an = [(1, int(an_inp.split()[0]))] + sorted([(i + 2, int(a)) for (i, a) in enumerate(an_inp.split()[1:])], key=lambda x: x[1], reverse=True)
students = deque((s for (s, m) in an))
res = []
students.remove(1)
for (cur_st, max_mess) in an:
	if cur_st in students:
		continue
	for i in range(max_mess):
		if not students:
			break
		send_to = students.popleft()
		res.append('{} {}'.format(cur_st, send_to))
	if not students:
		print(len(res))
		for p in res:
			print(p)
		break
else:
	print('-1')


n = int(input())
arr = []
for (i, x) in enumerate(input().split()):
	arr.append((i + 1, int(x)))
a = sorted(arr[1:], key=lambda x: x[1], reverse=True)
res = []
j = arr[0][1]
if j <= 0:
	print(-1)
	exit()
received = set()
for i in range(j):
	if i >= len(a):
		break
	res.append((1, a[i][0]))
	received.add(a[i])
while len(received) > 0 and j < n:
	source = received.pop()
	if source[1] > 0:
		for i in range(j, j + source[1]):
			if i >= n - 1:
				break
			received.add(a[i])
			res.append((source[0], a[i][0]))
		j += source[1]
if len(res) < n - 1:
	print(-1)
else:
	print(len(res))
	for (k, v) in res:
		print(k, v)


n = int(input())
a = input().split()
s = 0
for i in range(n):
	a[i] = [int(a[i]), i + 1]
	s += a[i][0]
ch = a.pop(0)
a.sort(reverse=True)
a.insert(0, ch)
if a[0][0] == 0 or s < n - 1:
	print(-1)
else:
	print(n - 1)
	(i, j) = (0, 0)
	while i < n - 1:
		while a[j][0] > 0 and i < n - 1:
			print(a[j][1], a[i + 1][1], sep=' ')
			i += 1
			a[j][0] -= 1
		j += 1


def listMul(a, b):
	res = [0] * len(a)
	for i in range(len(a)):
		res[i] = a[i] * b[i]
	return res

def listInv(a):
	res = [0] * len(a)
	for i in range(len(a)):
		if a[i] != 0:
			res[i] = 0
		else:
			res[i] = 1
	return res

def listNorm(a):
	res = [0] * len(a)
	for i in range(len(a)):
		if a[i] != 0:
			res[i] = 1
		else:
			res[i] = 0
	return res

def Main():
	n = int(input())
	sa = input().split()
	a = []
	for item in sa:
		a.append(int(item))
	s = [0] * len(a)
	s[0] = 1
	k = 0
	sender = []
	receiver = []
	while s.count(1) != n:
		commonSender = listMul(listNorm(a), s)
		if commonSender.count(0) != n:
			senderIndex = commonSender.index(1)
			sender.append(senderIndex)
			try:
				commonReceiver = listMul(listNorm(a), listInv(s))
				receiveIndex = commonReceiver.index(1)
			except ValueError:
				receiveIndex = s.index(0)
			receiver.append(receiveIndex)
			k += 1
			s[receiveIndex] = 1
			a[senderIndex] -= 1
		else:
			print(-1)
			return
	print(k)
	for i in range(len(sender)):
		print(sender[i] + 1, receiver[i] + 1)
Main()


n = int(input())
b = [[0, 0] for i in range(n - 1)]
p = True
i = 0
j = 1
s = [0 for i in range(n - 1)]
w = 0
q = 0
a = list(map(int, input().split()))
if a[0] == 0:
	print(-1)
else:
	while p:
		if a[i] != 0:
			while a[i] > 0 and j <= n - 1:
				if a[j] != 0:
					b[q][0] = i + 1
					b[q][1] = j + 1
					q += 1
					a[i] -= 1
					j += 1
				else:
					s[w] = j
					w += 1
					j += 1
			if j > n - 1:
				p = False
		else:
			i += 1
	j = 0
	w -= 1
	while w >= 0 and i < n:
		if a[i] != 0:
			b[q][0] = i + 1
			b[q][1] = s[w] + 1
			q += 1
			w -= 1
			a[i] -= 1
		else:
			i += 1
	if q == n - 1:
		print(n - 1)
		for i in range(n - 1):
			print(b[i][0], b[i][1])
	else:
		print(-1)


import sys
n = int(input())
B = list(map(int, input().split()))
A = [[0] * 2 for i in range(n)]
for i in range(n):
	A[i][0] = B[i]
	A[i][1] = i + 1
k = A[0][0]
A[0][0] = 999
A.sort(reverse=True)
A[0][0] = k
F = [0] * n
F[0] = 1
C = [[0] * 2 for i in range(n - 1)]
s = -1
for i in range(n):
	k = i + 1
	while A[i][0] > 0 and k < n:
		if F[k] == 0:
			s += 1
			(C[s][0], C[s][1]) = (A[i][1], A[k][1])
			F[k] = 1
			A[i][0] -= 1
		k += 1
for x in F:
	if x == 0:
		print(-1)
		sys.exit()
print(n - 1)
for i in range(n - 1):
	print(C[i][0], C[i][1])


n = int(input())
A = list(map(int, input().split(' ')))
A = {i: A[i] for i in range(n)}
vis = [False for _ in range(n)]
vis[0] = True
op = [0]
prev = [-1 for _ in range(n)]
messages = list()
while len(op) > 0:
	nxt = op[-1]
	del op[-1]
	cnt = A[nxt]
	targets = [(A[i], i) for i in A if i != nxt and (not vis[i])]
	targets.sort(reverse=True)
	targets = targets[:cnt]
	for (_, to) in targets:
		messages.append((nxt + 1, to + 1))
		prev[to] = nxt
		vis[to] = True
		op.append(to)
for el in vis:
	if not el:
		print(-1)
		break
else:
	print(n - 1)
	for (f, t) in messages:
		print('{} {}'.format(f, t))


def send(id):
	while a[id] > 0:
		if len(g) < n:
			li = a.copy()
			li[id] = -1
			while True:
				k = li.index(max(li))
				if k + 1 in g:
					li[k] = -1
				else:
					break
			g.append(k + 1)
			actions.append('{} {}'.format(id + 1, g[-1]))
			send(k)
			a[id] -= 1
		else:
			break
n = int(input())
a = list(map(int, input().split()))
actions = []
g = [1]
send(0)
if len(g) < n:
	print(-1)
else:
	print(len(actions))
	for line in actions:
		print(line)


def send(who, i):
	isSend[i] = False
	isSend[who] = False
	k = 0
	ans = []
	while k < n and can[i] > 0:
		if isSend[k] and a[k] > 0:
			can[i] -= 1
			ans.append([i + 1, k + 1])
			ans += send(i, k)
		k += 1
	return ans
n = int(input())
a = list(map(int, input().split()))
isSend = [True] * n
can = [x for x in a]
i = 0
while a[i] < 0:
	i += 1
if a[0] == 0:
	print(-1)
	exit()
path = send(0, i)
for i in range(n):
	if isSend[i] and a[i] != 0:
		print(-1)
		exit()
	elif a[i] == 0:
		for j in range(n):
			if can[j] != 0:
				can[j] -= 1
				isSend[i] = False
				path.append([j + 1, i + 1])
				break
		if isSend[i]:
			print(-1)
			exit()
print(len(path))
for i in path:
	print(*i)


n = int(input())
l = [int(i) for i in input().split()]
k = [0] * n
k[0] = 1
m = [1, 1]
ans = chk = 0
if l[0] == 0 or sum(l) + 1 < n:
	print(-1)
	exit()
print(n - 1)
for (a, i) in enumerate(l):
	t = i
	if all(k):
		break
	for x in range(m[0], n):
		if t == 0:
			break
		if l[x] > 0 and k[x] == 0:
			k[x] = 1
			m[0] = x
			t -= 1
			print(a + 1, x + 1)
	if t == 0:
		continue
	for x in range(m[1], n):
		if t == 0:
			break
		if k[x] == 0:
			k[x] = 1
			m[1] = x
			t -= 1
			print(a + 1, x + 1)


n = int(input())
a = [int(x) for x in input().split()]
cs = [(c, i) for (i, c) in enumerate(a[1:], 2)]
cs.sort(key=lambda x: -x[0])
cs = [(a[0], 1)] + cs
nk = 1
pairs = []
for (i, (count, number)) in enumerate(cs, 1):
	if nk == n:
		break
	if i > nk:
		break
	for j in range(count):
		pairs.append((number, cs[nk][1]))
		nk += 1
		if nk == n:
			break
if len(pairs) == n - 1:
	print(len(pairs))
	for (x, y) in pairs:
		print(x, y)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
summ = sum(a)
if summ < n - 1 or a[0] == 0:
	print(-1)
else:
	stud = []
	for i in range(1, n):
		stud.append([a[i], i])
	stud.sort(key=lambda x: (-x[0], x[1]))
	stud = [[a[0], 0]] + stud
	j = 1
	i = 0
	print(n - 1)
	while j < n and i < n:
		while j < n and stud[i][0] > 0:
			print(stud[i][1] + 1, stud[j][1] + 1)
			j += 1
			stud[i][0] -= 1
		i += 1


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a[i] = [a[i], i, False]
a[0][2] = True
c = 1
answer = []
a.sort(reverse=1)
for i in range(n):
	if not a[i][2]:
		for j in range(n):
			if a[j][2] and a[j][0] > 0:
				answer.append([a[j][1] + 1, a[i][1] + 1])
				a[j][0] -= 1
				a[i][2] = True
				c += 1
				break
if c < n:
	print(-1)
else:
	print(len(answer))
	for i in answer:
		print(*i)


n = int(input())
a = list(map(int, input().split()))
if a[0] == 0:
	print(-1)
else:
	x = 1
	b = []
	c = []
	p = []
	k = a[0]
	a[0] = -1
	for i in range(1, n):
		if a[i] != 0:
			k -= 1
			b.append([x, i + 1])
			c.append([i + 1, a[i]])
			a[i] = -1
		else:
			p.append(i + 1)
		if k == 0:
			x = c[0][0]
			k = c[0][1]
			c.pop(0)
	while (c != [] or k != 0) and p != []:
		if k == 0:
			x = c[0][0]
			k = c[0][1]
			c.pop(0)
		y = p.pop()
		a[y - 1] = -1
		b.append([x, y])
		k -= 1
	if a.count(-1) == n:
		print(len(b))
		for i in b:
			print(*i)
	else:
		print(-1)


n = int(input())
messages = input().split(' ')
messages = [int(x) for x in messages]
if messages[0] == 0:
	print(-1)
	quit()
su = 0
for e in messages:
	su += e
if su < n - 1:
	print(-1)
	quit()
students = sorted(range(len(messages)), key=lambda k: messages[k], reverse=True)
tail = 1
count = 0
dic = {}
if students[0] != 0:
	messages[0] = messages[0] - 1
for st in students:
	while messages[st] > 0 and tail < n:
		if students[tail] == 0:
			tail += 1
			continue
		dic[count] = (st + 1, students[tail] + 1)
		tail += 1
		messages[st] -= 1
		count += 1
if students[0] != 0:
	print(count + 1)
	print(str(1) + ' ' + str(students[0] + 1))
else:
	print(count)
for c in range(count):
	temp = dic[c]
	print(str(temp[0]) + ' ' + str(temp[1]))


def notify(xs, xs_sorted, ind_sorted, n, answer):
	if not xs_sorted[ind_sorted][1]:
		return
	ind = xs_sorted[ind_sorted][0]
	i = 0
	while i < n and xs[ind] > 0:
		if i == ind_sorted or xs_sorted[i][1]:
			i += 1
			continue
		xs_sorted[i][1] = True
		xs[ind] -= 1
		answer.append((ind + 1, xs_sorted[i][0] + 1))
		i += 1

def main():
	n = int(input())
	xs = [int(x) for x in input().split()]
	xs_sorted = sorted(([i, i == 0, x] for (i, x) in enumerate(xs)), key=lambda x: x[2], reverse=True)
	answer = []
	f = xs_sorted.index([0, True, xs[0]])
	notify(xs, xs_sorted, f, n, answer)
	for i in range(n):
		if i != f:
			notify(xs, xs_sorted, i, n, answer)
	if all((x[1] for x in xs_sorted)):
		print(len(answer))
		for (a, b) in answer:
			print(a, b)
	else:
		print(-1)

def __starting_point():
	main()
__starting_point()


from collections import deque
n = int(input())
arr1 = list(map(int, input().split()))
arr = []
for _ in range(n):
	arr.append([arr1[_], _ + 1])
d = deque()
p = arr[0][0]
ind = 1
arr = arr[1:]
arr.sort(reverse=True)
ans = []
for i in range(len(arr)):
	if p == 0:
		if len(d) == 0:
			print(-1)
			exit()
		while p == 0:
			if len(d) == 0:
				print(-1)
				exit()
			(p, ind) = d.popleft()
	p -= 1
	d.append([arr[i][0], arr[i][1]])
	ans.append([ind, arr[i][1]])
print(len(ans))
for i in ans:
	print(i[0], i[1])


n = int(input())
arr = list(map(int, input().split()))
used = [0] * n
x = arr[0]
for i in range(n):
	arr[i] = (arr[i], i + 1)
arr = arr[1:]
arr.sort(reverse=True)
now = n - 1
used[0] = 1
ans = []
for i in range(x):
	if i < n - 1:
		used[arr[i][1] - 1] = 1
		now -= 1
		ans.append([1, arr[i][1]])
for i in range(n - 1):
	x = arr[i][0]
	y = arr[i][1]
	ind = i + 1
	while x > 0:
		if now == 0:
			break
		if ind >= n - 1:
			break
		if used[arr[ind][1] - 1] == 0:
			now -= 1
			x -= 1
			used[arr[ind][1] - 1] = 1
			ans.append([y, arr[ind][1]])
		ind += 1
	if now == 0:
		break
if now == 0:
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])
else:
	print(-1)


class P:

	def __init__(self, v, w):
		self.w = w
		self.v = v

	def __repr__(self):
		return '({}, {})'.format(self.v, self.w)
n = int(input())
c = list(map(lambda x: P(*x), enumerate(map(int, input().split()))))
d = [c[0]] + sorted(c[1:], key=lambda x: x.w, reverse=True)
p = 0
t = 1
r = []
u = [False] * n
u[0] = True
for p in range(n):
	if not u[p]:
		print(-1)
		exit()
	while t < n and d[p].w > 0:
		r.append((d[p].v, d[t].v))
		u[t] = True
		t += 1
		d[p].w -= 1
print(len(r))
for pair in r:
	print('{} {}'.format(*map(lambda x: x + 1, pair)))


import sys
import math
studentsNum = int(sys.stdin.readline())
messagesLimit = [int(c) for c in sys.stdin.readline().split()]
firstLimit = messagesLimit[0]
messagesLimit = sorted(enumerate(messagesLimit), key=lambda v: v[1], reverse=True)
messagesLimit.remove((0, firstLimit))
messagesLimit.insert(0, (0, firstLimit))
lastSender = 0
lastReciever = 0
pairs = []
while lastReciever < studentsNum and messagesLimit[lastSender][1] > 0:
	for reciever in range(lastReciever + 1, min(studentsNum, lastReciever + messagesLimit[lastSender][1] + 1)):
		pairs.append((messagesLimit[lastSender][0] + 1, messagesLimit[reciever][0] + 1))
	lastReciever += messagesLimit[lastSender][1]
	lastSender += 1
if lastReciever + 1 < studentsNum:
	print(-1)
else:
	print(len(pairs))
	for p in pairs:
		print(p[0], p[1])


n = int(input())
a = list(map(int, input().split()))
en_a = list(enumerate(a))
l = [en_a[0]] + sorted(en_a[1:], key=lambda x: -x[1])
res = []
s = 0
r = 1
correct = True
k = l[s][1]
if k == 0:
	correct = False
while correct and r < n:
	while k > 0 and r < n:
		res.append([l[s][0] + 1, l[r][0] + 1])
		r += 1
		k -= 1
	s += 1
	k = l[s][1]
	if k == 0 and r < n:
		correct = False
		break
if correct:
	print(len(res))
	for res_i in res:
		print(*res_i)
else:
	print(-1)


input1 = list(map(int, input().split()))
input2 = list(map(int, input().split()))
QofStd = input1[0]
boolStd = []
outputlist = []
allQofmes = 0
for i in range(QofStd):
	boolStd.append(False)
boolStd[0] = True
out = 0
i = 0
while True:
	if input2[i] > 0 and boolStd[i] == True:
		out = 0
		max = 0
		indexmax = -1
		for j in range(QofStd):
			if max <= input2[j] and boolStd[j] == False:
				max = input2[j]
				indexmax = j
		if indexmax == -1:
			break
		boolStd[indexmax] = True
		outputlist.append(str(i + 1) + ' ' + str(indexmax + 1))
		allQofmes += 1
		input2[i] -= 1
	else:
		if i < QofStd - 1:
			i += 1
		else:
			i = 0
		if out > QofStd:
			break
		out += 1
Correct = True
for i in boolStd:
	if i == False:
		Correct = False
if Correct == False:
	print(-1)
else:
	print(allQofmes)
	for i in range(len(outputlist)):
		print(str(outputlist[i]))


def is_all_notified(students_list):
	for val in students_list.values():
		if not val[1]:
			return False
	return True

def get_next_to_notify(students_list):
	list_of = []
	for (idx, value) in students_list.items():
		list_of.append((value[0], idx, value[1]))
	list_of.sort(reverse=True)
	for it in list_of:
		if it[2] == False:
			return it[1]

def get_next_notificator(students_list):
	for (idx, value) in students_list.items():
		if value[0] > 0 and value[1] == True:
			return idx

def notify(students_list, sender, receiver):
	students_list[sender] = (students_list[sender][0] - 1, students_list[sender][1])
	students_list[receiver] = (students_list[receiver][0], True)

def can_notify(students_list, idx):
	return students_list[idx][0] > 0

def solution(students_list):
	current = 1
	messages = []
	if students_list[1][0] == 0:
		return -1
	while not is_all_notified(students_list):
		if students_list[current][0] > 0:
			receiver = get_next_to_notify(students_list)
			messages.append((current, receiver))
			notify(students_list, current, receiver)
		else:
			current = get_next_notificator(students_list)
			if current is None:
				break
	if is_all_notified(students_list):
		return messages
	else:
		return -1

def main():
	count = int(input())
	limits = input().split(' ')
	if count < 2 or count > 100:
		print('-1')
		return
	students = {}
	i = 1
	for limit in [int(l.strip()) for l in limits]:
		if i == 1:
			students[i] = (limit, True)
		else:
			students[i] = (limit, False)
		i += 1
	if i - 1 != count or i - 1 > 100:
		print('-1')
		return
	sol = solution(students)
	if sol == -1:
		print('-1')
	else:
		print(len(sol))
		for (from_, to) in sol:
			print('%s %s' % (from_, to))
main()


n = int(input())
a = [int(i) for i in input().split()]
if sum(a) < n - 1 or a[0] == 0:
	print(-1)
else:
	a = [(a[i], i + 1) for i in range(n)]
	p = a[0]
	a.pop(0)
	a.sort(reverse=True)
	a.insert(0, p)
	ans = []
	ck = 1
	for i in range(n):
		for j in range(a[i][0]):
			if ck >= n:
				break
			ans.append((a[i][1], a[ck][1]))
			ck += 1
	print(len(ans))
	for (i, j) in ans:
		print(i, j)


n = int(input())
know = 1
count = 0
answer = []
newgruop = []
group = list(map(int, input().split()))
for j in range(len(group)):
	newgruop.append([group[j], j + 1, False])
	count += group[j]
new = newgruop[1:]
senderArray = newgruop[0:1]
if newgruop[0][0] == 0:
	print(-1)
elif n == 2:
	print(1)
	print('1 2')
else:
	new.sort(key=lambda x: x[0], reverse=True)
	while know < n and count > n - know - 1:
		sender = senderArray.pop(0)
		while sender[0] > 0 and know < n:
			listing = 0
			while new[listing][2] == True:
				listing += 1
			answer.append(str(sender[1]) + ' ' + str(new[listing][1]))
			sender[0] -= 1
			senderArray.append([new[listing][0], new[listing][1], True])
			new[listing][2] = True
			know += 1
			count -= 1
	if know == n:
		print(len(answer))
		for list in answer:
			print(list)
	else:
		print(-1)


import sys
from collections import deque

def impossible():
	print(-1)
	sys.exit()
n = int(input())
a = list(map(int, input().split()))
if not a[0] or sum(a) < n - 1:
	impossible()
d = deque()
d.append((-1, a[0]))
a = sorted(enumerate(a[1:]), key=lambda x: -x[1])
idx = 0
print(n - 1)
while idx < n - 1:
	(x, cnt) = d.popleft()
	for i in range(idx, min(idx + cnt, n - 1)):
		print(x + 2, a[i][0] + 2)
		d.append(a[i])
	idx = min(idx + cnt, n - 1)


n = int(input())
line = list(map(int, input().split()))
person = []
for i in range(1, n):
	person.append([line[i], i])
person.sort(reverse=True)
person = [[line[0], 0]] + person
send = 0
recv = 1
if line[0] == 0 or sum(line) < n - 1:
	print(-1)
else:
	answer = []
	while recv != n:
		answer.append([person[send][1] + 1, person[recv][1] + 1])
		recv += 1
		person[send][0] -= 1
		if person[send][0] == 0:
			send += 1
	print(len(answer))
	for elem in answer:
		print(*elem)


a = int(input())
b = []
b = input().split(' ')
k = int()
p = [0 for i in range(a)]
p[0] = 1
for i in range(a):
	k = k + int(b[i])
if int(b[0]) == 0 or k < a - 1:
	print(-1)
else:
	print(a - 1)
	for i in range(a):
		for f in range(a):
			if int(b[i]) != 0 and int(b[f]) != 0 and (p[f] == 0):
				p[f] = 1
				b[i] = int(b[i]) - 1
				print(i + 1, ' ', f + 1)
	for i in range(a):
		for f in range(a):
			if int(b[i]) != 0 and int(b[f]) == 0 and (p[f] == 0):
				p[f] = 1
				b[i] = int(b[i]) - 1
				print(i + 1, ' ', f + 1)


def run():
	input()
	a = list(enumerate(list(map(int, input().split()))))
	a = [a[0]] + sorted(a[1:], key=lambda k: k[1], reverse=True)
	(head, tail, ans) = (0, 1, [])
	while head < tail < len(a):
		if a[head][1] > 0:
			ans.append((a[head][0], a[tail][0]))
			a[head] = (a[head][0], a[head][1] - 1)
			tail += 1
		else:
			head += 1
	if tail == len(a):
		print(len(ans))
		for (x, y) in ans:
			print(x + 1, y + 1)
	else:
		print(-1)

def __starting_point():
	run()
__starting_point()


amount_of_students = int(input())
data = input().split(' ')
students = []
for i in range(len(data)):
	data[i] = int(data[i])
	students.append(0)
students[0] = 1

def max_unaware_student():
	global data, students, number_of_messages, output
	max = -1
	student = -1
	for i in range(len(data)):
		if data[i] > max and students[i] == 0:
			max = data[i]
			student = i
	return student

def send_message(student):
	global data, students, number_of_messages, output
	for i in range(data[student]):
		if min(students) == 1:
			break
		number_of_messages += 1
		recipient = max_unaware_student()
		output.append('{0} {1}'.format(student + 1, recipient + 1))
		students[recipient] = 1
		send_message(recipient)
output = []
number_of_messages = 0
send_message(0)
if min(students) == 0:
	print('-1')
else:
	print(number_of_messages)
	for i in output:
		print(i)


n = int(input())
a = list(map(int, input().split()))
know = [0 for i in range(n)]
know[0] = 1
res = []
while True:
	best = 0
	besti = -1
	for i in range(n):
		if know[i] == 1:
			if a[i] > best:
				best = a[i]
				besti = i
	p = besti
	ok = True
	for i in range(n):
		if know[i] == 0:
			ok = False
			break
	if ok == True:
		break
	if p == -1 and ok == False:
		print('-1')
		exit(0)
	while a[p] > 0:
		best = -1
		besti = -1
		for i in range(n):
			if know[i] == 0:
				if a[i] > best:
					best = a[i]
					besti = i
		if besti == -1:
			break
		know[besti] = 1
		a[p] -= 1
		res.append([p + 1, besti + 1])
print(len(res))
for i in range(len(res)):
	print(' '.join(map(str, res[i])))


from collections import Counter
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')
n = int(input())
arr = list(map(int, input().split()))
ls = []
for (i, val) in enumerate(arr[1:]):
	ls.append((val, i + 2))
ls.sort()
ans = []
var = n - 2
for i in range(arr[0]):
	if var < 0:
		break
	ans.append((1, ls[var][1]))
	var -= 1
if arr[0] == 0:
	print(-1)
	exit()
j = n - 2
i = n - arr[0] - 1 - 1
while j > 0:
	if i < 0:
		break
	step = ls[j][0]
	while step > 0 and i >= 0:
		step -= 1
		ans.append((ls[j][1], ls[i][1]))
		i -= 1
	j -= 1
if len(ans) < n - 1:
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		print(ans[i][0], ans[i][1])


n = int(input())
arr = [int(x) for x in input().split()]
users = []
invited_users = []
messages_count = 0
output = ''
for i in range(len(arr)):
	users.append([i, arr[i]])
sender = users[0]
users = users[1:]
users.sort(key=lambda row: row[1])
while messages_count != n - 1 and len(users) > 0:
	invites_count = sender[1]
	person = sender[0]
	if invites_count == 0:
		break
	while invites_count != 0:
		invited_user = users[len(users) - 1]
		invited_users.append(invited_user)
		users = users[:-1]
		output += str(person + 1) + ' ' + str(invited_user[0] + 1) + '\n'
		invites_count -= 1
		messages_count += 1
		if messages_count == n - 1:
			break
	if len(invited_users) > 0:
		sender = invited_users[0]
		invited_users = invited_users[1:]
if messages_count < n - 1:
	print(-1)
else:
	print(messages_count)
	print(output)


from sys import stdin, stdout, maxsize
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
n = I()
ls = lint()
if ls[0] == 0 or sum(ls) < n - 1:
	print(-1)
	exit()
arr = [[ls[0], 1]] + sorted([[ls[i], i + 1] for i in range(1, n)], reverse=True)
print(n - 1)
(i, j) = (0, 1)
while i < n and j < n:
	if arr[i][0] > 0:
		arr[i][0] -= 1
		print(arr[i][1], arr[j][1])
		j += 1
	else:
		i += 1


n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
INF = -100

def max_ind(array):
	return array.index(max(array))
answer_str_arr = []

def dfs(first_index):
	num_we_can_send = arr[first_index]
	arr[first_index] = INF
	for i in range(0, num_we_can_send):
		curr_max_ind = max_ind(arr)
		if arr[curr_max_ind] == INF:
			break
		answer_str_arr.append(str(first_index + 1) + ' ' + str(curr_max_ind + 1))
		dfs(curr_max_ind)
dfs(0)
is_huis = False
for el in arr:
	if el > INF:
		is_huis = True
		break
if is_huis:
	print('-1')
else:
	print(len(answer_str_arr))
	for answer in answer_str_arr:
		print(answer)


n = int(input())
mes = [[int(m), idx] for (idx, m) in enumerate(input().split(), 1)]
if sum((m[0] for m in mes)) < n - 1 or not mes[0][0]:
	print(-1)
	exit(0)
mes = [mes[0]] + sorted(mes[1:], reverse=True)
cur = 0
print(n - 1)
for i in range(1, n):
	while not mes[cur][0]:
		cur += 1
	print(mes[cur][1], mes[i][1])
	mes[cur][0] -= 1


n = int(input())
A = list(map(int, input().split()))
if A[0] == 0 or sum(A) < n - 1:
	print(-1)
else:
	print(n - 1)
	start = 1
	for j in range(n):
		A[j] = [A[j], j]
	A = [A[0]] + sorted(A[1:])[::-1]
	for j in range(n):
		while A[j][0] != 0:
			if start == n:
				break
			print(A[j][1] + 1, A[start][1] + 1)
			A[j][0] -= 1
			start += 1
		if start == n:
			break


def main():
	n = int(input())
	lst2 = input().split()
	lst = [[i + 1, int(lst2[i])] for i in range(n)]
	a = lst[0]
	b = lst[1:]
	b.sort(key=lambda x: x[1], reverse=True)
	lst = [a] + b
	str_b = str(n - 1) + '\n'
	if lst[0][1] == 0:
		return '-1'
	counter = 1
	for ind in range(n):
		if counter == n:
			return str_b.strip()
		while lst[ind][1] > 0 and len(lst) > counter:
			str_b += str(lst[ind][0]) + ' ' + str(lst[counter][0]) + '\n'
			lst[ind][1] -= 1
			counter += 1
	if counter < n:
		return '-1'
	else:
		return str_b.strip()
print(main())


def mx_False(marks, spis):
	flag = False
	mx = 0
	index = 0
	for i in range(len(spis)):
		if flag == False and marks[i] == False:
			mx = spis[i]
			index = i
			flag = True
		if flag == True and marks[i] == False and (spis[i] > mx):
			mx = spis[i]
			index = i
	return [mx, index]
n = int(input())
a = list(map(int, input().split()))
student = a[0]
index = 0
mxs = []
mxind = []
answer = []
s = 0
flag = [False] * (n - 1)
marks = [True] + [False] * (n - 1)
if student == 0 or sum(a) < n - 1:
	print(-1)
else:
	while False in marks:
		while student > 0:
			if False in marks:
				(mx, ind) = mx_False(marks, a)
				mxs.append(mx)
				mxind.append(ind)
				answer.append([index + 1, ind + 1])
				marks[ind] = True
				student = student - 1
				s = s + 1
			else:
				break
		for i in range(len(flag)):
			if flag[i] == False:
				flag[i] = True
				student = mxs[i]
				index = mxind[i]
				break
	print(s)
	for i in range(len(answer)):
		print(answer[i][0], answer[i][1])


import collections as col
import itertools as its
import operator

class Solver:

	def solve(self):
		n = int(input())
		a = list(map(int, input().split()))
		for i in range(len(a)):
			a[i] = [a[i], i + 1]
		a[0][0] += 1000
		a = sorted(a)[::-1]
		a[0][0] -= 1000
		ans = []
		it = 1
		for i in range(len(a)):
			if i == it:
				print(-1)
				return
			(cnt, st) = a[i]
			while it != n and cnt > 0:
				ans.append((st, a[it][1]))
				cnt -= 1
				it += 1
		print(n - 1)
		for p in ans:
			print(' '.join(map(str, p)))
s = Solver()
s.solve()


from collections import deque
N = int(input())
students = [(i, int(el)) for (i, el) in enumerate(input().strip().split())]
res = []
q = deque()
q.append(students[0])
students = [students[0]] + sorted(students[1:], key=lambda x: -x[1])
n = 0
while q:
	(ind, messages) = q.popleft()
	while messages > 0:
		n += 1
		if n < N:
			res.append((ind + 1, students[n][0] + 1))
			q.append(students[n])
		messages -= 1
if len(res) == N - 1:
	print(len(res))
	for el in res:
		print(el[0], el[1])
else:
	print(-1)


n = int(input())
m = [int(s) for s in input().split()]
a = []
data = []
if m[0] == 0:
	print(-1)
else:
	for i in range(n):
		if m[i] == 0:
			a.append(0)
			a[0] = 2
		else:
			a.append(1)
			a[0] = 2
	for i in range(n):
		if m[i] > 1:
			t = 0
			for x in range(m[i]):
				if t < m[i] - 1 and a.count(0) > 0:
					data.append([i + 1, a.index(0) + 1])
					a[a.index(0)] = 2
					t += 1
				elif a.count(1) > 0:
					data.append([i + 1, a.index(1) + 1])
					a[a.index(1)] = 2
				elif a.count(0) > 0:
					data.append([i + 1, a.index(0) + 1])
					a[a.index(0)] = 2
		elif m[i] == 1:
			if a.count(1) > 0:
				data.append([i + 1, a.index(1) + 1])
				a[a.index(1)] = 2
			elif a.count(0) > 0:
				data.append([i + 1, a.index(0) + 1])
				a[a.index(0)] = 2
	if a.count(0) > 0:
		print(-1)
	else:
		print(len(data))
		for i in range(len(data)):
			print(data[i][0], data[i][1])


n = int(input())
students = list(map(int, input().split()))
(a, b) = (1, 0)
students = list(enumerate(students))
p = students[0]
students = list(reversed(list(sorted(students[1:], key=lambda x: x[1]))))
students.insert(0, p)
students = list(map(lambda x: list(x), students))
result = []
while a < n and b < n and (a > b):
	if students[b][1] == 0:
		b += 1
		continue
	students[b][1] -= 1
	result.append('' + str(students[b][0] + 1) + ' ' + str(students[a][0] + 1))
	a += 1
if a == n:
	print(len(result))
	print('\n'.join(result))
else:
	print(-1)


n = int(input())
L = list(map(int, input().split()))
if sum(L) < n - 1 or L[0] == 0:
	print(-1)
else:
	print(n - 1)
	count = 1
	M = [True] + [False] * (n - 1)
	while count < n:
		a = 0
		b = 0
		while L[a] == 0 or M[a] == False:
			a += 1
		boltun = -1
		for i in range(1, n):
			if L[i] > boltun and M[i] == False:
				b = i
				boltun = L[i]
		print(a + 1, b + 1)
		L[a] -= 1
		M[b] = True
		count += 1


n = int(input())
a = list([int(x) for x in input().split(' ')])
a[1:] = sorted(enumerate(a[1:]), key=lambda x: x[1], reverse=1)
a[0] = (0, a[0])
for i in range(1, len(a)):
	a[i] = (a[i][0] + 1, a[i][1])
received = [0] * n
p = 1
pair = []
for i in range(n):
	if i >= p or p >= n:
		break
	for j in range(a[i][1]):
		pair.append((a[i][0], a[p][0]))
		p += 1
		if p == n:
			break
if p < n:
	print(-1)
else:
	print(str(len(pair)) + '\n' + str.join('\n', ['{} {}'.format(p[0] + 1, p[1] + 1) for p in pair]))


a = int(input())
b = list(map(int, input().split()))
if b[0] == 0 or sum(b) < a - 1:
	exit(print(-1))
c = sorted([[j, i + 1] for (i, j) in enumerate(b)], reverse=True)
for i in range(a):
	if c[i][1] == 1:
		c = [c.pop(i)] + c
		break
i = 0
j = 1
print(a - 1)
while j < a:
	print(c[i][1], c[j][1])
	j += 1
	c[i][0] -= 1
	if c[i][0] == 0:
		i += 1


from sys import *
n = int(input())
a = list(map(int, input().strip().split()))
polycarp = a[0]
rest = [(a[i], i + 1) for i in range(1, len(a))]
rest.sort(reverse=True)
head = 0
tail = polycarp
messages = []
for i in range(min(polycarp, len(rest))):
	last = rest[i]
	messages.append((1, last[1]))
while head < tail and tail < len(rest):
	cur = rest[head]
	for i in range(cur[0]):
		last = rest[tail]
		messages.append((cur[1], last[1]))
		tail += 1
		if tail >= len(rest):
			break
	head += 1
if tail < len(rest):
	print(-1)
else:
	print(len(messages))
	for message in messages:
		print(message[0], message[1])


n = int(input())
A = list(map(int, input().split()))
for i in range(n):
	A[i] = (A[i], i)
A = [A[0]] + sorted(A[1:], reverse=True)
B = [0] * n
B[0] = 1
S = []
x = 0
y = 1
while x < n and A[x][0] != 0:
	for i in range(A[x][0]):
		if y < n:
			B[y] = 1
			S.append((A[x][1], A[y][1]))
			y += 1
	x += 1
if y != n:
	print(-1)
else:
	print(len(S))
	for i in S:
		print(i[0] + 1, i[1] + 1)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	sum_know = 1
	cur_outcome = arr[0]
	cur_st = [(arr[0], 0)]
	arr = arr[1:]
	arr = [(arr[i], i + 1) for i in range(n - 1)]
	arr.sort()
	arr = arr[::-1]
	pt = 0
	ans = []
	while pt < n - 1 and len(cur_st) > 0:
		new_s = []
		for i in cur_st:
			x = 0
			num = min(n - 1, pt + i[0])
			for x in range(pt, num):
				pt += 1
				sum_know += 1
				new_s.append(arr[x])
				ans.append((i[1] + 1, arr[x][1] + 1))
		cur_st = new_s
	if sum_know >= n:
		print(len(ans))
		for j in ans:
			print(*j)
	else:
		print(-1)
main()


n = int(input())
l = list(map(int, input().split(' ')))
a = l
sms_n = list(range(1, n, 1))
sms_y = [0]
r = []
c = 0
if l[0] == 0:
	print(-1)
else:
	while len(sms_y) < n and sum(a) > 0:
		i = 0
		for x in range(1, n):
			if a[x] >= a[i] and x in sms_y:
				i = x
		while a[i] > 0 and len(sms_n) > 0:
			for x in range(n):
				if x in sms_n:
					ind_m = x
					break
			for x in range(2, n):
				if a[x] >= a[ind_m] and x in sms_n:
					ind_m = x
			sms_y.append(ind_m)
			sms_n.remove(ind_m)
			a[i] -= 1
			r.append(str(i + 1) + ' ' + str(ind_m + 1))
			c += 1
	if len(sms_n) > 0 and sum(a) == 0:
		print(-1)
	else:
		print(c)
		print('\n'.join(r))


def dfs(v):
	was[v] = 1
	cnt = 0
	for i in range(v + 1, n):
		if cnt >= a[v][0]:
			break
		if not was[i]:
			cnt += 1
			ans.append((a[v][1], a[i][1]))
			dfs(i)
n = int(input())
a = list(map(int, input().split()))
a = [(a[i], i + 1) for i in range(n)]
a = [a[0]] + sorted(a[1:])[::-1]
ans = []
was = [0] * n
dfs(0)
if was.count(0):
	print(-1)
else:
	print(len(ans))
	[print(*i) for i in ans]


n = int(input())
k = list(map(int, input().split()))
if k[0] == 0 or sum(k) < n - 1:
	print(-1)
else:
	print(n - 1)
	l = [i + 1 for i in range(n) if k[i] != 0]
	k1 = [i for i in k if i != 0]
	ind = [i - 1 for i in l]
	m = [i + 1 for i in range(n) if k[i] == 0]
	for j in range(len(l) - 1):
		print(l[j], l[j + 1])
		k1[j] -= 1
	count = 0
	c = 0
	q = k1[0]
	while count < len(m):
		count += 1
		if q == 0:
			while q == 0:
				c += 1
				q = k1[c]
		print(ind[c] + 1, m[count - 1])
		q -= 1


n = int(input())
vals = list(map(int, input().split()))
vals = [(i, vals[i]) for i in range(n)]
vals = [vals[0]] + sorted(vals[1:], key=lambda x: x[1], reverse=True)
most_left_idx = 0
count = 0
output = ''
for i in range(n):
	if most_left_idx >= i:
		for j in range(1, vals[i][1] + 1):
			if most_left_idx + j < n:
				count += 1
				output += '{} {} \n'.format(vals[i][0] + 1, vals[most_left_idx + j][0] + 1)
		most_left_idx += vals[i][1]
if most_left_idx >= n - 1:
	print(count)
	print(output)
else:
	print(-1)


n = int(input())
messages_per_student = [int(num) for num in input().split(' ')]
students = [False] * n
students[0] = True
msgs_sent = 0
sorted_students = sorted(enumerate(messages_per_student), key=lambda s: s[1], reverse=True)

def find_optimal_recipient(sender):
	for (i, _) in sorted_students:
		if not students[i] and i != sender:
			return i
	raise ValueError
sends_log = []
senders = [(0, messages_per_student[0])]
for (sender, count) in senders:
	while count > 0 and msgs_sent < n:
		try:
			recipient = find_optimal_recipient(sender)
			sends_log.append((sender, recipient))
			students[recipient] = True
			senders.append((recipient, messages_per_student[recipient]))
			count -= 1
			msgs_sent += 1
		except ValueError:
			break
if msgs_sent == n - 1:
	print(msgs_sent)
	[print(msg[0] + 1, msg[1] + 1) for msg in sends_log]
else:
	print(-1)


from collections import namedtuple
import operator
n = int(input())
t = 0

def f(x):
	global t
	t += 1
	return [int(x), t]
nums = list(map(f, input().split(' ')))
nums[1:] = sorted(nums[1:], key=operator.itemgetter(0), reverse=True)
received = [False] * len(nums)
received[0] = True
ans = []
for (i, x) in enumerate(nums):
	if received[i]:
		for j in range(i + 1, len(nums)):
			if x[0] > 0 and (not received[j]):
				received[j] = True
				x[0] -= 1
				ans.append((x[1], nums[j][1]))
if not received[-1]:
	print(-1)
else:
	print(len(ans))
	[print(x[0], x[1]) for x in ans]


n = int(input())
ai = input().split()
res = []
prov = [1]
for i in range(0, n):
	ai[i] = int(ai[i])
	prov.append(0)
prov.remove(0)
i = 0
if ai[0] != 0 and sum(ai) >= n - 1:
	it = True
else:
	it = False
if it:
	for j in range(0, n):
		if prov[j] == 1:
			for i in range(0, n):
				if prov[i] == 0 and ai[i] != 0 and (i != j) and (ai[j] != 0):
					res.append(str(j + 1) + ' ' + str(i + 1))
					ai[j] -= 1
					prov[i] = 1
				if ai[j] == 0:
					prov[j] = 2
	for j in range(0, n):
		if prov[j] == 1:
			for i in range(0, n):
				if prov[i] == 0 and ai[i] == 0 and (i != j) and (ai[j] != 0):
					res.append(str(j + 1) + ' ' + str(i + 1))
					ai[j] -= 1
					prov[i] = 2
				if ai[j] == 0:
					prov[j] = 2
if it:
	print(len(res))
	for i in range(0, len(res)):
		V = res[i].split()
		print(V[0], V[1])
else:
	print(-1)


n = int(input())
a = [int(x) for x in input().split()]
if sum(a) < n - 1 or a[0] == 0:
	print(-1)
else:
	print(n - 1)
	l = [(x, i) for (i, x) in enumerate(a[1:])]
	l.sort(key=lambda x: -x[0])
	for i in range(min(a[0], n - 1)):
		print(str(1) + ' ' + str(l[i][1] + 2))
	k = -1
	m = 0
	for i in range(a[0], n - 1):
		if m == 0:
			k += 1
			m = l[k][0]
		m -= 1
		print(l[k][1] + 2, l[i][1] + 2)


input()
power = list(map(int, input().split()))
n = len(power)
ps = [0] + sorted(range(1, n), key=lambda i: -power[i])
out = []
bonus = [0] * power[0]
i = 1
while i < n and bonus:
	out.append((bonus.pop(), ps[i]))
	bonus.extend([ps[i]] * max(0, power[ps[i]]))
	i += 1
if i != n:
	print(-1)
else:
	print(len(out))
	print(*['%s %s' % (a + 1, b + 1) for (a, b) in out], sep='\n')


n = int(input())
rdl = list(map(int, input().split()))
if rdl[0] == 0:
	print(-1)
else:
	summ = 0
	for i in range(len(rdl)):
		summ = summ + rdl[i]
	if summ < n - 1:
		print(-1)
	else:
		b = []
		for i in range(n - 1):
			b.append([0] * 2)
			b[i][0] = rdl[i + 1]
			b[i][1] = i + 2
		b.sort()
		b.reverse()
		b.insert(0, [rdl[0], 1])
		k = 0
		j = 0
		print(n - 1)
		l = j + 1
		while k != n - 1:
			while b[j][0] > 0 and k != n - 1:
				print(b[j][1], b[l][1])
				b[j][0] -= 1
				l += 1
				k += 1
			j += 1


n = int(input())
students = list(map(int, input().split(' ')))
indexes = list(zip(range(n), students))[1:]
indexes.sort(key=lambda x: x[1], reverse=True)
indexes = [(0, students[0])] + indexes
last_informed_index = 0
out = []
last_used = 0
while last_informed_index < n and last_used != n:
	if last_used <= last_informed_index:
		for i in range(last_informed_index + 1, min(last_informed_index + indexes[last_used][1] + 1, n)):
			out.append('%d %d' % (indexes[last_used][0] + 1, indexes[i][0] + 1))
		last_informed_index = min(last_informed_index + indexes[last_used][1], n - 1)
		last_used += 1
	else:
		print(-1)
		return
print(len(out))
print('\n'.join(out))


n = int(input())
a = list(map(int, input().split()))
order = []
pairs = []
l = a[1:]
for i in range(len(l)):
	order.append([l[i], i + 2])
order.sort(reverse=True)
order.insert(0, [a[0], 1])
rm = [False] * n
for i in range(len(order)):
	cnt = order[i][0]
	j = i + 1
	if cnt > 0:
		rm[i] = True
	while cnt > 0 and j < n:
		if rm[j] == True:
			cnt += 1
		elif rm[j] != True:
			pairs.append((order[i][1], order[j][1]))
			rm[j] = True
		j += 1
		cnt -= 1
if False in rm:
	print(-1)
else:
	print(len(pairs))
	for i in pairs:
		print(*i)


n = int(input())
a = list(map(int, input().split()))
obs = []
indo = []
neo = []
indn = []
res = []
kol = []
if a[0] == 0:
	print(-1)
else:
	for i in range(n):
		if a[i] > 0:
			obs.append(a[i])
			indo.append(i)
		else:
			neo.append(0)
			indn.append(i)
	curr = 0
	nuli = 0
	for j in range(len(obs)):
		for k in range(obs[j]):
			if curr + nuli < len(a) - 1:
				res.append(indo[j] + 1)
				if curr < len(obs) - 1:
					curr += 1
					res.append(indo[curr] + 1)
				else:
					res.append(indn[nuli] + 1)
					nuli += 1
	if curr + nuli == len(a) - 1:
		print(len(res) // 2)
		for h in range(0, len(res), 2):
			print(res[h], end=' ')
			print(res[h + 1])
	else:
		print(-1)


n = int(input())
a = [int(i) for i in input().split()]
s = 0
answer = []
for i in a:
	s += i
if a[0] == 0 or s < n - 1:
	print(-1)
else:
	s = 0
	adressing = [[[0, a[0]]]]
	a[0] = a[0] * -1
	while len(adressing[0]) > 0:
		for i in range(len(adressing[0])):
			small_adress = []
			for j in range(adressing[0][i][1]):
				effect = max(a)
				if effect < 0:
					break
				else:
					p = a.index(effect)
					small_adress.append([p, effect])
					a[p] = -1
					answer.append([adressing[0][i][0] + 1, p + 1])
					s += 1
			adressing.append(small_adress)
		adressing.pop(0)
	print(s)
	for i in answer:
		print(i[0], i[1])


studnum = input()
arr = list(map(int, input().split()))
index = 0
bla = list(enumerate(arr))
p = bla[0]
sortedA = sorted(bla[1:], key=lambda x: x[1], reverse=True)
sortedA.insert(0, p)
left = 0
right = 1
result = []
fail = False
while left < len(sortedA) and right < len(sortedA):
	val = sortedA[left][1]
	if val == 0:
		result.append(-1)
		fail = True
		break
	for i in range(val):
		result.append((sortedA[left][0] + 1, sortedA[right][0] + 1))
		right += 1
		if right == len(sortedA):
			break
	left += 1
if fail:
	print(-1)
else:
	print(len(result))
	for i in result:
		print(i[0], i[1])


def multiple_max(lst, count):
	result = []
	for k in range(count):
		max = -1
		max_i = 0
		for i in range(len(lst)):
			if i not in result and (not is_notified[i]):
				if lst[i] > max:
					max = lst[i]
					max_i = i
		if max != -1:
			result.append(max_i)
	return result
n = input()
message_counts = [int(x) for x in input().split(' ')]
is_notified = [False for x in range(len(message_counts))]
is_notified[0] = True
chat = []

def say(idx):
	indices_to_say = multiple_max(message_counts, message_counts[idx])
	if len(indices_to_say) is 0:
		return
	for idx_to_notify in indices_to_say:
		is_notified[idx_to_notify] = True
	for next_idx in indices_to_say:
		message_counts[idx] -= 1
		chat.append(str(idx + 1) + ' ' + str(next_idx + 1))
		say(next_idx)
say(0)
result = True
for x in is_notified:
	if not x:
		result = False
		break
if result:
	print(len(chat))
	for message in chat:
		print(message)
else:
	print(-1)


n = int(input())
l = [[int(i)] for i in input().split()]
for i in range(len(l)):
	l[i].append(i + 1)
zn = []
ansst = []
if l[0][0] == 0:
	print('-1')
else:
	zn.append(l[0])
	del l[0]
	l.sort(key=lambda x: x[0], reverse=True)
	while len(zn) > 0 and len(l) > 0:
		for i in range(min(zn[0][0], len(l))):
			ansst.append([zn[0][1], l[0][1]])
			zn.append(l[0])
			del l[0]
		del zn[0]
	if len(l) == 0:
		print(len(ansst))
		print('\n'.join([' '.join([str(w) for w in q]) for q in ansst]))
	else:
		print(-1)


n = int(input())
a = input()
a = list(map(int, a.split(' ')))
user_index = []
recived = []
for i in range(n):
	user_index.append(i)
	recived.append(0)
recived[0] = 1
count = 0
answer = ''
k = 1
while k < len(a):
	for i in range(1, n - k):
		if a[i] < a[i + 1]:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
			(user_index[i], user_index[i + 1]) = (user_index[i + 1], user_index[i])
	k += 1
if a[0] != 0:
	for i in range(n):
		user = 0
		while a[i] > 0 and sum(recived) != n:
			user += 1
			if user < n and recived[user_index[user]] != 1:
				recived[user_index[user]] = 1
				count += 1
				answer += str(user_index[i] + 1) + ' ' + str(user_index[user] + 1) + '\n'
				a[i] -= 1
	if sum(recived) == n:
		print(count)
		print(answer)
	else:
		print(-1)
else:
	print(-1)


n = int(input())
call = list(map(int, input().split()))
cp = []
ans = []
for i in range(1, n):
	x = call[i]
	cp.append([x, i + 1])
cp.sort(reverse=True)
l = [[call[0], 1]]
j = 0
while len(cp) > 0 and len(l) > 0 and (j < len(cp)):
	s = l[0]
	x = s[0]
	p = s[1]
	for i in range(j, min(j + x, len(cp))):
		ans.append([str(p), str(cp[i][1])])
		l.append(cp[i])
	j = min(j + x, len(cp))
	l.remove(l[0])
if j < len(cp):
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		print(' '.join(ans[i]))


n = int(input())
arr = list(map(int, input().split(' ')))
index = []
rec = []
total = 0
answer = ''
k = 1
for i in range(n):
	index.append(i)
	rec.append(0)
	rec[0] = 1
if arr[0] != 0:
	while k < len(arr):
		for i in range(1, n - k):
			if arr[i] < arr[i + 1]:
				(arr[i], arr[i + 1]) = (arr[i + 1], arr[i])
				(index[i], index[i + 1]) = (index[i + 1], index[i])
		k += 1
	for i in range(n):
		user = 0
		while arr[i] > 0 and sum(rec) != n:
			user += 1
			if user < n and rec[index[user]] != 1:
				answer += str(index[i] + 1) + ' ' + str(index[user] + 1) + '\n'
				arr[i] -= 1
				rec[index[user]] = 1
				total += 1
if sum(rec) == n:
	print(total)
	print(answer)
else:
	print(-1)


from operator import itemgetter
n = int(input())
limits = input().split(' ')
limits = [int(i) for i in limits]
if sum(limits) < len(limits) - 1:
	print(-1)
elif limits[0] == 0:
	print(-1)
else:
	ANSWER = []
	is_know = [True] + (len(limits) - 1) * [False]
	indices = [i[0] for i in sorted(enumerate(limits), key=itemgetter(1))]
	indices.remove(0)
	sender = 0
	while len(indices):
		while limits[sender] > 1 and len(indices):
			receiver = indices[0]
			del indices[0]
			is_know[receiver] = True
			limits[sender] -= 1
			ANSWER.append((sender + 1, receiver + 1))
		if len(indices):
			ANSWER.append((sender + 1, indices[-1] + 1))
			sender = indices[-1]
			del indices[-1]
			is_know[sender] = True
	print(len(ANSWER))
	for (i, j) in ANSWER:
		print(i, j)


def kek(nom, soob):
	global graph
	global a
	global uch
	i = 1
	while i <= soob:
		if len(uch) == 0:
			break
		nom1 = uch[0]
		graph.append([nom + 1, nom1 + 1])
		soob1 = a[nom1]
		uch.pop(0)
		kek(nom1, soob1)
		i += 1
n = int(input())
a = list(map(int, input().split()))
if a[0] == 0 or sum(a) < n - 1:
	print(-1)
	exit()
uch = []
a2 = a.copy()
a2.pop(0)
a1 = a.copy()
a1.pop(0)
a1.sort()
a1.reverse()
graph = []
for i in a1:
	uch.append(a2.index(i) + 1)
	a2[a2.index(i)] = -1
a2.clear()
i = 1
while i <= a[0]:
	if len(uch) == 0:
		break
	nom = uch[0]
	graph.append([1, nom + 1])
	soob = a[nom]
	uch.pop(0)
	kek(nom, soob)
	i += 1
print(len(graph))
i = 0
while i <= len(graph) - 1:
	print(graph[i][0], graph[i][1])
	i += 1


from operator import itemgetter
n = input()
n = int(n)
a = str()
a = input()
a = a.split()
a = list(map(int, a))
asum = sum(a)
if a[0] == 0 or asum < n - 1:
	print(-1)
	return
b1 = [0, a[:1][0]]
a2 = a[1:]
b2 = list()
for i in range(0, n - 1):
	b2.append([i + 1, a2[i]])
b2 = sorted(b2, key=itemgetter(1), reverse=True)
b = [b1] + b2
c = 1
ai = 0
print(n - 1)
for el in b:
	ai += 1
	for i in range(0, el[1]):
		print(el[0] + 1, ' ', b[c][0] + 1)
		c += 1
		if c == n:
			return


n = int(input())
a = list(map(int, input().split()))
if a[0] == 0 or sum(a) < n - 1:
	print(-1)
else:
	print(n - 1)
	e = list(enumerate(a[1:], start=2))
	e.sort(key=lambda x: x[1], reverse=True)
	e = [(1, a[0])] + e
	k = 1
	index = 0
	while k != n:
		for i in range(min(n - k, e[index][1])):
			print(e[index][0], e[k][0])
			k += 1
		index += 1


n = int(input())
a = list(enumerate(list(map(int, input().split())), start=1))
a = [a[0]] + sorted(a[1:], key=lambda x: x[1], reverse=True)
used = [0] * n
used[0] = 1
ans = [list() for i in range(n)]
total = 0
for i in range(n):
	if not 0 in used:
		break
	else:
		cnt = 0
		j = i + 1
		if j != n:
			while j < n and cnt < a[i][1]:
				if not used[j]:
					used[j] = 1
					total += 1
					ans[i].append(a[j])
					cnt += 1
				j += 1
if 0 in used:
	print(-1)
else:
	print(total)
	for i in range(n):
		for j in range(len(ans[i])):
			print(a[i][0], ans[i][j][0])


from collections import deque
n = int(input())
a = list(map(int, input().split()))
ia = [(i, a[i]) for i in range(1, n)]
ia.sort(key=lambda k: k[1], reverse=True)
flag = [False] * n
flag[0] = True
q = deque([0])
ans = []
while q:
	f = q.popleft()
	cnt = 0
	for (t, _) in ia:
		if not flag[t]:
			if cnt == a[f]:
				break
			ans.append((f + 1, t + 1))
			flag[t] = True
			q.append(t)
			cnt += 1
if flag == [True] * n:
	print(len(ans))
	for (f, t) in ans:
		print(f, t)
else:
	print(-1)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] == 0:
		print('-1')
		return
	a = [[a[0], 0]] + sorted([[val, index + 1] for (index, val) in enumerate(a[1:])], reverse=True)
	res = []
	(index, current) = (1, 0)
	while index < n and current < index:
		while a[current][0] > 0:
			res.append((a[current][1], a[index][1]))
			index += 1
			if index == n:
				break
			a[current][0] -= 1
		current += 1
	if index < n:
		print('-1')
		return
	print(len(res))
	print('\n'.join((str(x + 1) + ' ' + str(y + 1) for (x, y) in res)))
main()


import collections
n = int(input())
a = [int(i) for i in input().split()]
deq = collections.deque()
deq.append([a[0], 0])
visited = [False] * n
visited[0] = True
informed = [False] * n
informed[0] = True
pairs = []
while deq:
	(informant, order_num) = deq.popleft()
	if informant != 0:
		for (ind, num_of_messages) in enumerate(a):
			if not visited[ind] and num_of_messages != 0:
				deq.append([num_of_messages, ind])
				visited[ind] = True
				informed[ind] = True
				informant -= 1
				pairs.append([order_num, ind])
			if informant == 0:
				break
	if informant != 0:
		for (ind, num_of_messages) in enumerate(a):
			if not visited[ind]:
				visited[ind] = True
				informed[ind] = True
				informant -= 1
				pairs.append([order_num, ind])
			if informant == 0:
				break
	if all(informed):
		break
if len(pairs) == n - 1:
	print(len(pairs))
	for pair in pairs:
		print(pair[0] + 1, pair[1] + 1)
else:
	print(-1)


n = int(input())
ar = list(map(int, input().split()))
done = [0]
choose = [0]
toprint = []
for i in choose:
	for j in range(ar[i]):
		max = -1
		md = -1
		for d in range(n):
			if d not in choose and ar[d] > max:
				max = ar[d]
				md = d
		if max != -1:
			choose.append(md)
			toprint.append([i + 1, md + 1])
		else:
			break
if len(choose) != n:
	print(-1)
else:
	print(len(toprint))
	for i in toprint:
		print(i[0], i[1])


def f(bl=False):
	global a, b, n, i, t
	for e in range(n):
		if e == t:
			continue
		if not b[e] and (a[e] != 0 if not bl else True):
			print(t + 1, e + 1)
			b[e] = True
			i -= 1
		if i == 0 or False not in b:
			break
n = int(input())
s = input()
a = list(map(int, s.split(' ')))
b = [False] * n
b[0] = True
if a[0] == 0 or sum(a) < n - 1:
	print(-1)
else:
	print(n - 1)
	for t in range(n):
		if not b[t] or a[t] == 0:
			continue
		i = a[t]
		f()
		if i != 0 and False in b:
			f(True)
		if False not in b:
			break


n = int(input())
a = list(map(int, input().split()))
p = a[0]
a = [(p, 0)] + sorted([(a[i], i) for i in range(1, n)], reverse=True)
result = ''
got = {0}
for i in range(n):
	temp_a = a[i][0]
	temp_i = i + 1
	while temp_a > 0 and temp_i < n:
		if temp_i not in got:
			got.add(temp_i)
			temp_a -= 1
			result += str(a[i][1] + 1) + ' ' + str(a[temp_i][1] + 1) + '\n'
		temp_i += 1
if len(got) < n:
	print(-1)
else:
	print(n - 1)
	print(result)


n = int(input())
arr = [[i, int(c)] for (i, c) in enumerate(input().strip().split(' '))]
p = arr[0]
arr = arr[1:]
arr.sort(key=lambda i: i[1], reverse=True)
count = p[1]
i = 0
check = True
while i < len(arr):
	if count == 0:
		print(-1)
		check = False
		break
	count += arr[i][1]
	count -= 1
	i += 1
if check:
	ar = []
	count = 0
	cur = p
	(stock, stock_n) = ([], 0)
	i = 0
	while i < len(arr):
		ar.append([cur[0] + 1, arr[i][0] + 1])
		count += 1
		stock.append(arr[i])
		cur[1] -= 1
		if cur[1] == 0:
			cur = stock[stock_n]
			stock_n += 1
		i += 1
	print(count)
	for i in ar:
		print(i[0], i[1])


class Student:

	def __init__(self, number, messages):
		self.number = number
		self.messages = messages
		self.knowledge = False

	def sent_message(self, another_student):
		if self.knowledge is False or self.messages == 0:
			raise ValueError
		self.messages -= 1
		another_student.knowledge = True
count = int(input())
input_array = input()
input_array = input_array.split(' ')
students = []
for i in range(count):
	new_student = Student(i + 1, int(input_array[i]))
	students.append(new_student)
students[0].knowledge = True
knowledge_count = 1
current_sender = students[0]
log = ''
knowledge = True
messages_count = 0
while knowledge_count < count:
	for i in range(current_sender.messages):
		max_messages = -1
		current_getter = None
		for student in students:
			if student.knowledge is False and student.messages > max_messages:
				current_getter = student
				max_messages = student.messages
		if current_getter is None:
			break
		else:
			current_sender.sent_message(current_getter)
			messages_count += 1
			log += str(current_sender.number) + ' ' + str(current_getter.number) + '\n'
			knowledge_count += 1
	max_messages = 0
	for student in students:
		if student.knowledge is True and student.messages > max_messages:
			current_sender = student
			max_messages = student.messages
	if max_messages == 0 and knowledge_count < count:
		knowledge = False
		break
if knowledge is True:
	print(messages_count)
	log = log[:len(log) - 1]
	print(log)
else:
	print(-1)


import sys
data = sys.stdin.read().split()
data_ptr = 0

def data_next():
	global data_ptr, data
	data_ptr += 1
	return data[data_ptr - 1]
N = int(data_next())
arr = list(zip(map(int, data[2:]), range(2, N + 1)))
arr.sort()
arr.append((int(data[1]), 1))
arr.reverse()
j = 1
good = True
ans = []
for i in range(0, N):
	if j > i:
		for k in range(arr[i][0]):
			if j >= N:
				break
			ans.append((arr[i][1], arr[j][1]))
			j += 1
	else:
		good = False
		break
if good:
	print(len(ans))
	for x in ans:
		print(x[0], x[1])
else:
	print(-1)


def calc_plan(info):
	numbers = len(info) - 1
	first_point = 0
	second_point = 0
	out = []
	info = [[index, value] for (index, value) in enumerate(info, start=1)]
	info = info[0:1] + sorted(info[1:], key=lambda pair: pair[1], reverse=True)
	while True:
		if second_point == numbers:
			return out
		if info[first_point][1] == 0:
			if first_point == second_point:
				return []
			else:
				first_point += 1
				continue
		info[first_point][1] -= 1
		second_point += 1
		out.append((info[first_point][0], info[second_point][0]))
n = int(input())
lst = [int(x) for x in input().split()]
result = calc_plan(lst)
if result:
	print(len(result))
	for data in result:
		print(*data)
else:
	print(-1)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
k = n
c = 0
s = 0
b = [1]
for i in range(n - 1):
	b.append(0)
for j in range(n):
	s += a[j]
if a[0] != 0:
	if s >= n - 1:
		s = n - 1
		print(s, '\n')
	elif s < n - 1:
		print(-1)
	if s >= n - 1:
		for i in range(n):
			for j in range(n):
				if i != j:
					if a[i] != 0 and a[j] != 0 and (j > i) and (b[j] == 0):
						print(i + 1, ' ', j + 1)
						a[i] = a[i] - 1
						b[j] = j
		for i in range(n):
			for j in range(n):
				if i != j:
					if a[i] > 0 and a[j] == 0 and (j > i) and (b[j] == 0):
						print(i + 1, ' ', j + 1)
						a[i] -= 1
						b[j] = j
		for i in range(n):
			for j in range(n):
				if i != j:
					if a[i] > 0 and a[j] == 0 and (j > 0) and (b[j] == 0):
						print(i + 1, ' ', j + 1)
						a[i] -= 1
						b[j] = j
else:
	print(-1)


R = lambda : map(int, input().split())
n = int(input())
l = list(zip(list(R()), range(n)))
(q, r, out) = ([l[0]], sorted(l[1:]), [])
while q and r:
	(a, b) = q.pop()
	while a and r:
		a -= 1
		out.append([b, r[-1][1]])
		q += [r[-1]]
		r.pop()
if len(out) < n - 1:
	print('-1')
else:
	print(len(out))
	for (a, b) in out:
		print(a + 1, b + 1)


n = int(input())
counts = list(map(int, input().split()))
ai = [-1] * n
if counts[0] > 0 and sum(counts) >= n - 1:
	print(n - 1)
	k = sum(counts) - n + 1
	ai[0] = counts[0]
	counts[0] = -1
	boolean = True
	while min(ai) == -1:
		j = 0
		boolean = False
		for j in range(n):
			while ai[j] > 0 and min(ai) == -1:
				i = counts.index(max(counts))
				ai[j] -= 1
				ai[i] = counts[i]
				counts[i] = -1
				print(j + 1, i + 1)
else:
	print(-1)


n = int(input())
a = list(map(int, input().split()))
if a[0] == 0 or sum(a) < n - 1:
	print(-1)
	exit(0)
print(n - 1)
m = [[a[i], i + 1] for i in range(1, len(a))]
m.sort(reverse=True)
m = [[a[0], 1]] + m
(i, j) = (0, 1)
while i < n and j < n:
	if m[i][0] > 0:
		print(m[i][1], m[j][1])
		m[i][0] -= 1
		j += 1
	else:
		i += 1


def sort(letter, n):
	number = []
	for i in range(2, n + 2):
		number.append(i)
	for i in range(1, n):
		for j in range(n - i):
			if letter[j] < letter[j + 1]:
				(number[j], number[1 + j]) = (number[1 + j], number[j])
				(letter[j], letter[1 + j]) = (letter[1 + j], letter[j])
	return (letter, number)

def report(letter, number):
	i = -1
	z = 0
	for j in range(len(letter)):
		if letter[j] != 0 and j + i < len(letter) - 2:
			print(number[j], number[j + 1])
			for a in range(letter[j] - 1):
				i += 1
				if i + j + 2 == len(letter) or number[len(letter) - i - 1] == number[j]:
					z = 1
					break
				print(number[j], number[len(letter) - i - 1])
		if z == 1:
			break
n = int(input())
lettter = list(map(int, input().split()))
summa = 0
for el in lettter:
	summa += el
if summa < n - 1 or lettter[0] == 0:
	print(-1)
else:
	s = lettter[0]
	(letter, number) = sort(lettter[1:], n - 1)
	letter.insert(0, s)
	print(n - 1)
	report(letter, [1] + number)


def solve():
	n = int(input())
	A = list(map(int, input().split()))
	(x, A) = (A[0], A[1:])
	A = [(A[i], i + 2) for i in range(len(A))]
	A.sort(reverse=True)
	cnt = 1
	msg = x
	total = 1
	for a in A:
		if not msg:
			print(-1)
			return
		msg += a[0] - 1
		total += a[0]
		cnt += 1
		if total >= n:
			break
	print(n - 1)
	total = x
	for j in range(min(x, len(A))):
		print(1, A[j][1])
	if total >= n - 1:
		return
	for i in range(len(A)):
		for j in range(total, min(total + A[i][0], len(A))):
			print(A[i][1], A[j][1])
			total += 1
			if total >= n - 1:
				return
solve()


n = int(input())
a = list(map(int, input().split()))
if sum(a) < n - 1 or a[0] == 0:
	print(-1)
else:
	b = []
	for i in range(n):
		b.append(i)
	x = 0
	for i in range(1, n):
		for j in range(i, n):
			if a[i] < a[j]:
				x = a[i]
				a[i] = a[j]
				a[j] = x
				x = b[i]
				b[i] = b[j]
				b[j] = x
	print(n - 1)
	k = 1
	i = -1
	j = 1
	while k < n:
		i += 1
		while a[i] > 0 and j < n:
			print(b[i] + 1, b[j] + 1)
			j += 1
			a[i] -= 1
			k += 1


n = int(input())
A = list(map(int, input().split()))
B = []
for i in range(1, len(A)):
	B.append([A[i], i + 1, 0])
B.sort(key=lambda elem: elem[0], reverse=True)
flag = 0
k = 0
C = []
m = 0
if A[0] == 0:
	print(-1)
	flag += 1
elif A[0] > len(B):
	for i in range(A[0] - 1):
		if i < len(B):
			B[i][2] += 1
			k += 1
			C.append([1, B[i][1]])
			if i == len(B) - 1:
				m += 1
else:
	for i in range(A[0]):
		B[i][2] += 1
		k += 1
		C.append([1, B[i][1]])
j = 0
while j < len(B) and m == 0:
	if B[j][2] == 0:
		if flag == 0:
			print(-1)
		flag += 1
		break
	for x in range(B[j][0]):
		v = j + 1
		for y in range(v, len(B)):
			if B[y][2] == 0:
				B[y][2] += 1
				k += 1
				C.append([B[j][1], B[y][1]])
				if y == len(B) - 1:
					j = len(B)
				break
	j += 1
if flag == 0:
	print(k)
if flag == 0:
	for i in range(len(C)):
		print(C[i][0], C[i][1], sep=' ')


from collections import deque
(n, a) = (int(input()), list(map(int, input().split())))
a_sorted = sorted(([a[i], i + 1] for i in range(1, n)))
messages = []
queue = deque([[a[0], 1]])
while a_sorted and queue:
	cur = queue.popleft()
	while cur[0] and a_sorted:
		recipient = a_sorted.pop()
		messages.append((cur[1], recipient[1]))
		queue.append(recipient)
		cur[0] -= 1
if a_sorted:
	print(-1)
else:
	print(len(messages))
	for message in messages:
		print(*message)


import itertools
n = int(input())
a = list(map(int, input().split()))
a = [(a[0], 1)] + sorted(zip(a[1:], itertools.count(2)), reverse=True)
w = 1
ans = []
for (r, cur) in enumerate(a):
	if r == w:
		print(-1)
		break
	while w != n and cur[0] > 0:
		ans.append('%s %s' % (cur[1], a[w][1]))
		cur = (cur[0] - 1, cur[1])
		w += 1
else:
	print(len(ans))
	print('\n'.join(ans))