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: interview

Starter code:

Solutions:
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=[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)

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


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

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

#!/usr/bin/env python3

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]])
    # print(f)
    notify(xs, xs_sorted, f, n, answer)

    for i in range(n):
        if i != f:
            notify(xs, xs_sorted, i, n, answer)

    # print(xs_sorted)
    # print(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()

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

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

#print(a)

received = [0]*n
p = 1
pair = []

for i in range(n):
  #print(i >= p)
  if i >= p or p >= n: break
  #print('-', a[i][0])
  for j in range(a[i][1]):
    #print(p, a[p])
    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]))



'''
4
1 2 1 0

6
2 0 1 3 2 0

6
2 3 2 0 1 0
'''

'''
3
1 0 0
'''


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

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

#!/bin/python3

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

    #     to_send_arr = []
    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)


# for ind in to_send_arr:
#         bfs(ind)

# arr[0] = INF
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)

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


'''
def send_message(student):
	nonlocal data, last_student_that_knows, student_that_sends, number_of_messages, output
	for i in range(data[student]):
		if last_student_that_knows == amount_of_students - 1:
			break
		last_student_that_knows += 1
		number_of_messages += 1
		output.append("{0} {1}".format(student + 1, last_student_that_knows + 1))
		send_message(last_student_that_knows)
'''
############################################
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():
	nonlocal 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):
	nonlocal 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)



""" Created by Shahen Kosyan on 3/4/17 """

def __starting_point():
    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)

__starting_point()

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())
a = list(enumerate(list(map(int, input().split())), start = 1))
a = [a[0]] + sorted(a[1:], key=lambda x: x[1], reverse=True)
#print(a)

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]:
                #print(i, j)
                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])

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

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


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)

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)


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)