Problem:
 Score : 600 points    Problem Statement Snuke has an integer sequence, a , of length N . The i -th element of a ( 1 -indexed) is a_{i} .  He can perform the following operation any number of times:   Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y .   He would like to perform this operation between 0 and 2N times (inclusive) so that a satisfies the condition below. Show one such sequence of operations.
It can be proved that such a sequence of operations always exists under the constraints in this problem.   Condition: a_1 \leq a_2 \leq ...  \leq a_{N}       Constraints  2 \leq N \leq 50  -10^{6} \leq a_i \leq 10^{6}  All input values are integers.         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_{N}       Output Let m be the number of operations in your solution. In the first line, print m .
In the i -th of the subsequent m lines, print the numbers x and y chosen in the i -th operation, with a space in between.
The output will be considered correct if m is between 0 and 2N (inclusive) and a satisfies the condition after the m operations.        Sample Input 1 3
-2 5 -1      Sample Output 1 2
2 3
3 3   After the first operation, a = (-2,5,4) .  After the second operation, a = (-2,5,8) , and the condition is now satisfied.        Sample Input 2 2
-1 -3      Sample Output 2 1
2 1   After the first operation, a = (-4,-3) and the condition is now satisfied.        Sample Input 3 5
0 0 0 0 0      Sample Output 3 0   The condition is satisfied already in the beginning.

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
m=max(l)
m1=min(l)
def all_pos(l1,ans): 
    for i in range(1,n): 
        if l1[i]>=l1[i-1]: 
            pass 
        else: 
            l1[i]+=l1[i-1]
            ans.append([i,i+1])
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
def all_neg(l,ans):
    for i in range(n-2,-1,-1):
        if l[i]<=l[i+1]:
            pass 
        else:
            l[i]+=l[i+1]
            ans.append([i+2,i+1])
    print(len(ans))
    for i in range(len(ans)):
        print(*ans[i])
m=abs(max(l))
m1=abs(min(l))
if m>=m1:
    ans=[] 
    
    ind=l.index(max(l))
    for i in range(n): 
        l[i]+=l[ind]
        ans.append([ind+1,i+1])
    all_pos(l,ans)
else:
    ans=[]
    
    ind=l.index(min(l))
    for i in range(n):
        l[i]+=l[ind]
        ans.append([ind+1,i+1])
    all_neg(l,ans)

Solution (Python):

N = int(input())

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

lis = []


mi = float("inf")
ma = float("-inf")
mi_ind = 0
ma_ind = 0

for i in range(N):

    if mi > a[i]:
        mi = a[i]
        mi_ind = i
    if ma < a[i]:
        ma = a[i]
        ma_ind = i
        
flag = None
if mi < 0 and 0 < ma:

    if abs(mi) <= abs(ma):

        flag = 0

        for i in range(N):

            if a[i] < 0:
                lis.append([ma_ind + 1,i+1])

    else:

        flag = 1

        for i in range(N):

            if a[i] > 0:
                lis.append([mi_ind + 1,i+1])

if mi >= 0 or flag == 0:

    for i in range(N-1):

        lis.append([i+1,i+2])

else:

    for i in range(N-1):

        lis.append([N-i,N-1-i])


print (len(lis))

for i in lis:

    print (i[0],i[1])

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque


def main():
    num = int(input())
    data = list(map(int, input().split()))

    min_num = min(data)
    max_num = max(data)

    ans_list = []
    if max_num + min_num >= 0:
        idx = data.index(max_num)
        for i in range(num):
            if data[i] == max_num:
                continue
            ans_list.append([idx + 1, i + 1])
        for i in range(num - 1):
            ans_list.append([i + 1, i + 2])

    else:
        idx = data.index(min_num)
        for i in range(num):
            if data[i] == min_num:
                continue
            ans_list.append([idx + 1, i + 1])
        for i in range(num - 1)[::-1]:
            ans_list.append([i + 2, i + 1])

    print(len(ans_list))
    for i, j in ans_list:
        print(i, j)





if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N = int(input())
A = np.array([0] + [int(x) for x in input().split()])

A_abs = np.abs(A)

x = A_abs.argmax()
if x == 0:
  x = 1
value = A[x]

answer = []

for j in range(1,N+1):
  if j == x:
    continue
  answer.append((x,j))


if value > 0:
  for j in range(1,N):
    answer.append((j,j+1))
else:
  for j in range(N,1,-1):
    answer.append((j,j-1))
    
print(len(answer))
for a,b in answer:
  print(a,b)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
maxa = max(A)
mina = min(A)
print(2*N-1)
if abs(maxa) > abs(mina):
  k = A.index(maxa)
  for i in range(N):
    print(k+1,i+1)
    A[i] += A[k]
  for i in range(1,N):
    A[i] += A[i-1]
    print(i,i+1)
else:
  k = A.index(mina)
  for i in range(N):
    print(k+1,i+1)
    A[i] += A[k]
  for i in range(N,1,-1):
    print(i,i-1)
    A[i-2] += A[i-1]

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
count = 0
outs = []
max_a = max(a)
max_index = a.index(max(a))
min_a = min(a)
min_index = a.index(min(a))
flag = -1
if 0 <= min_a:
  flag = 0
elif max_a <= 0:
  flag = n
elif max_a > -1 * min_a:
  flag = 0
  for i in range(0,n):
    if a[i] < 0:
      a[i] += max_a
      outs.append(str(max_index + 1) + " " + str(i + 1))
      count += 1
elif max_a <= -1 * min_a:
  flag = n
  for i in range(0,n):
    if a[i] > 0:
      a[i] += min_a
      outs.append(str(min_index + 1) + " " + str(i + 1))
      count += 1

if flag == 0:
  for i in range(0, n-1):
    a[i+1] += a[i]
    outs.append(str(i + 1) + " " + str(i + 1 + 1))
    count += 1
elif flag == n:
  for i in range(1, n):
    a[n-i-1] += a[n-i]
    outs.append(str(n - i + 1) + " " + str(n - i - 1 + 1))
    count += 1
    
print(count)
for out in outs:
  print(out)

Solution (Python):

n = int(input())
ali = list(map(int, input().split()))

log = []
max_ = max(ali)
min_ = min(ali)

if abs(max_) >= abs(min_):
    max_index = ali.index(max_)+1
    for i in range(n):
        log_i = i+1
        log.append((max_index, log_i))
    for j in range(n-1):
        log_j = j+1
        mae = log_j
        ushiro = log_j+1
        log.append((mae, ushiro))
elif abs(max_) < abs(min_):
    min_index = ali.index(min_) + 1
    for i in range(n):
        log_i = i + 1
        log.append((min_index, log_i))
    for j in range(1, n)[::-1]:
        log_j = j+1
        mae = log_j
        ushiro = log_j -1
        log.append((mae, ushiro))

print(len(log))
for v1, v2 in log:
    print(str(v1) + ' ' + str(v2))

Solution (Python):
import numpy as np
N = int(input())
A = np.array([int(x) for x in input().split()])
mi= np.min(A)
ma= np.max(A)
mai = np.where(A==ma)
mii = np.where(A==mi)
ans = []
if ma<=0 and mi<=0:
  for i in range(N,1,-1):
    ans.append((i,i-1))
  print(len(ans))
  for i in range(len(ans)):
    print(*ans[i])
  exit()
if ma>=0 and mi>=0:
  for i in range(1,N):
    ans.append((i,i+1))
  print(len(ans))
  for i in range(len(ans)):
    print(*ans[i])
  exit()

if abs(mi)<=abs(ma):
  ans= [(int(mai[0][0])+1,i) for i in range(1,N+1)]
  for i in range(1,N):
    ans.append((i,i+1))
  print(len(ans))
  for i in range(len(ans)):
    print(*ans[i])
  exit()
else:
  ans= [(int(mii[0][0])+1,i) for i in range(1,N+1)]
  for i in range(N,1,-1):
    ans.append((i,i-1))
  print(len(ans))
  for i in range(len(ans)):
    print(*ans[i])
  exit()

Solution (Python):
n=int(input())
a=list(map(int, input().split()))

print(2*n-1)
if abs(max(a))>=abs(min(a)):
    b=a.index(max(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)
  
else:
    b=a.index(min(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(n-1):
        print(n-i,n-1-i)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
M,m = max(a),min(a)
Mi,mi = a.index(M),a.index(m)
for i in range(n-1):
    if a[i] > a[i+1]:
        break
else:
    print(0)
    quit()
for i in range(n):
    if a[i] < 0:
        break
else:
    print(n-1)
    for i in range(n-1):
        print(i+1,i+2)
    quit()
for i in range(n):
    if a[i] > 0:
        break
else:
    print(n-1)
    for i in range(n-1)[::-1]:
        print(i+2,i+1)
    quit()
if abs(M) >= abs(m):
    print((n-1)*2)
    for i in range(n):
        if i == Mi:
            continue
        print(Mi+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)
else:
    print((n-1)*2)
    for i in range(n):
        if i == mi:
            continue
        print(mi+1,i+1)
    for i in range(n-1)[::-1]:
        print(i+2,i+1)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

s = []

min_Ai, *_, max_Ai = sorted(range(N), key=lambda x: A[x])
min_A, max_A = A[min_Ai], A[max_Ai]
if abs(min_A) < abs(max_A):
    for i in range(N):
        if i == max_Ai:
            continue
        A[i] += max_A
        s.append((max_Ai, i))
    A[max_Ai] += max_A
    s.append((max_Ai, max_Ai))
    
    for i in range(N-1):
        if A[i] > A[i+1]:
            A[i+1] += A[i]
            s.append((i, i+1))
else:
    for i in range(N):
        if i == min_Ai:
            continue
        A[i] += min_A
        s.append((min_Ai, i))
    A[min_Ai] += min_A
    s.append((min_Ai, min_Ai))
    
    for i in range(N-2, -1, -1):
        if A[i] > A[i+1]:
            A[i] += A[i+1]
            s.append((i+1, i))

print(len(s))
for a, b in s:
    print(a+1, b+1)

Solution (Python):
n=int(input())
a=[int(j) for j in input().split()]
maxind=a.index(max(a))+1
minind=a.index(min(a))+1
if min(a)>0:
    print(n-1)
    for i in range(1,n):
        print(i,i+1)
else:
    if max(a)<0:
        print(n-1)
        for i in range(1,n)[::-1]:
            print(i+1,i)
    else:
        if max(a)+min(a)>0:
            ans=[]
            for i in range(n):
                if a[i]<0:
                    ans.append(i+1)
            print(len(ans)+n-1)
            for i in ans:
                print(maxind,i)
            for i in range(1,n):
                print(i,i+1)
        else:
            ans=[]
            for i in range(n):
                if a[i]>0:
                    ans.append(i+1)
            print(len(ans)+n-1)
            for i in ans:
                print(minind,i)
            for i in range(1,n)[::-1]:
                print(i+1,i)

Solution (Python):



import fractions

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    la = rli()
    checkpoints = [0]
    cur = la[0]
    for i in range(1, n):
        if la[i] >= cur:
            cur = la[i]
            continue
        if la[i] + cur*2 >= cur:
            cur = la[i] + cur*2
            continue
        checkpoints.append(i)
        cur = la[i]
    
    ll = checkpoints[-1]
    op = []
    for c in checkpoints[::-1]:
        if c > ll:
            continue
        l = c
        cur = la[l]
        while l > 0:
            if la[l-1] <= cur:
                break
            op.append((l, l-1))
            op.append((l, l-1))
            cur = la[l-1] + cur * 2
            l -= 1
        ll = l-1
    cur = la[checkpoints[-1]]
    for i in range(checkpoints[-1], n-1):
        if la[i+1] >= cur:
            cur  = la[i+1]
        else:
            op.append((i, i+1))
            op.append((i, i+1))
            cur = la[i+1]+cur*2
    print(len(op))
    for o in op:
        print(o[0]+1, o[1]+1)



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

M = max(A)
Mi = A.index(M)
m = min(A)
mi = A.index(m)

cnt = 0
ans = []

if M > 0 and m < 0:
    if abs(m) <= abs(M):
        for i in range(N):
            if Mi == i:
                continue
            x = Mi
            y = i
            A[y] += A[x]
            ans.append((x, y))
            cnt += 1
    else:
        for i in range(N):
            if mi == i:
                continue
            x = mi
            y = i
            A[y] += A[x]
            ans.append((x, y))
            cnt += 1

M = max(A)
m = min(A)

if m >= 0:
    for i in range(N-1):
        x = i
        y = i+1
        A[y] += A[x]
        ans.append((x, y))
        cnt += 1
else:
    for i in range(N-1, 0, -1):
        x = i
        y = i-1
        A[y] += A[x]
        ans.append((x, y))
        cnt += 1

print(cnt)
for x, y in ans:
    print(x+1, y+1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N = int(input())
    A = list(map(int,input().split()))
    big = 0
    I = 0
    for i in range(len(A)):
        if abs(big) < abs(A[i]):
            big = A[i]
            I = i
    
    ansN = 0
    ans = []
    
    if big > 0:
        ansN = 2*N
        ans.append([I+1,I+1])
        ans.append([I+1, 1])
        for i in range(1,N):
            ans.append([i,i+1])
            ans.append([i,i+1])
    elif big < 0:
        ansN = 2*N
        ans.append([I+1, I+1])
        ans.append([I+1, N])
        for i in range(N-1):
            j = N - i
            ans.append([j, j-1])
            ans.append([j, j-1])
    print(ansN)
    for i in ans:
        print(*i)
        j,k = i
        A[k-1] += A[j-1]
    
        
    
    
main()

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
B = [abs(a) for a in A]
absmaxv = -1
absmaxi = -1
for i, v in enumerate(B):
    if v > absmaxv:
        absmaxi, absmaxv = i, v
print(2 * N)
if A[absmaxi] > 0:
    print(absmaxi + 1, 1)
    print(absmaxi + 1, 1)
    for i in range(1, N):
        print(i, i + 1)
        print(i, i + 1)
else:
    print(absmaxi + 1, N)
    print(absmaxi + 1, N)
    for i in range(N, 1, -1):
        print(i, i - 1)
        print(i, i - 1)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
mi = a[0]
mii = 1
ma = a[0]
mai = 1
for i in range(n):
  if a[i] > ma:
    ma = a[i]
    mai = i+1
  if a[i] < mi:
    mi = a[i]
    mii = i+1
if mi >= 0:
  print(n-1)
  for i in range(1,n):
    print(i,i+1)
elif ma <= 0:
  print(n-1)
  for i in range(n,1,-1):
    print(i,i-1)
elif abs(ma) >= abs(mi):
  print(n*2-1)
  for i in range(n):
    print(mai,i+1)
  for i in range(1,n):
    print(i,i+1)
else:
  print(n*2-1)
  for i in range(n):
    print(mii,i+1)
  for i in range(n,1,-1):
    print(i,i-1)

Solution (Python):
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

schedule = []
m = 0
if -min(a) > max(a) :
    mv = min(a)
    mi = a.index(mv)
    
    for i in range(N-2, -1, -1) :
        while a[i] > a[i + 1] :
            a[i] += mv
            schedule.append([mi+1, i+1])
            if a[i] < mv :
                mv = a[i]
                mi = i
            m += 1
else :
    Mv = max(a)
    Mi = a.index(Mv)
    
    for i in range(1, N) :
        while a[i-1] > a[i] :
            a[i] += Mv
            schedule.append([Mi+1, i+1])
            if a[i] > Mv :
                Mv = a[i]
                Mi = i
            m += 1

print(m)
for sch in schedule :
    print(*sch)

Solution (Python):
import sys
import math
from fractions import gcd





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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_a = list(map(int, sys.stdin.readline().split()))

a_max = max(list_a)
a_min = min(list_a)

ans = []

if (a_max == a_min):
    cnt = 0
elif (math.fabs(a_max) > math.fabs(a_min)):
    
    
    newList = [item + a_max for item in list_a]
    
    for i in range(N):
        
        ans.append((list_a.index(max(list_a))+1, i+1))

    newList2 = newList
    for i in range(N-1):
        
            newList2[i+1] += newList2[i]
            ans.append((i+1, i+2))


else:
    
    
    newList = [item + a_min for item in list_a]
    for i in range(N):
        
        ans.append((list_a.index(min(list_a))+1, i+1))

    newList2 = newList
    
    
    
    
    
    for i in range(N-1, 0, -1):
        
            newList2[i-1] += newList2[i]
            ans.append((i+1, i))




print(len(ans))
for i in range(len(ans)):
    s, t = ans[i]
    print(s, t)

Solution (Python):
from operator import itemgetter

N = int(input())
A = list(map(int, input().split()))

i = max(enumerate(map(abs, A)), key=itemgetter(1))[0]
print(2*N)
if A[i]<0:
    print(i+1, N)
    print(i+1, N)
    for j in range(N, 1, -1) :
        print(j, j-1)
        print(j, j-1)
else :
    print(i+1, 1)
    print(i+1, 1)
    for j in range(1, N) :
        print(j, j+1)
        print(j, j+1)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    max_ = a[0]
    max_ind = 0
    min_ = a[0]
    min_ind = 0
    for i in range(len(a)):
        if max_ < a[i]:
            max_ = a[i]
            max_ind = i
        if min_ > a[i]:
            min_ = a[i]
            min_ind = i
    ans = []
    if abs(max_) >= abs(min_):
        all_sei = True
        for i in range(N):
            ans.append((max_ind+1, i+1))
    else:
        all_sei = False
        for i in range(N):
            ans.append((min_ind+1, i+1))
    
    if all_sei:
        for i in range(N-1):
            ans.append((i+1, i+2))
    else:
        for i in range(N-1, 0, -1):
            ans.append((i+1, i))
    
    print(len(ans))
    for i in range(len(ans)):
        s, t = ans[i]
        print(s, t)

    


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np


N = int(input().strip())
alist = list(map(int,input().strip().split()))

alist = np.array(alist)
alistp = np.abs(alist)
maxind = np.where(alistp==alistp.max())[0][0]

if alist[maxind]>0:
	positive = True
else:
	positive = False

count = 0
process = []
for i in range(N):
	if alist[i]*alist[maxind]<0:
		alist[i] = alist[i]+alist[maxind]
		count = count+1
		process.append([maxind,i])

if positive==True:
	for i in range(N-1):
		alist[i+1] = alist[i+1]+alist[i]
		count = count+1
		process.append([i,i+1])
else:
	for i in range(N-1,0,-1):
		alist[i-1] = alist[i-1]+alist[i]
		count = count+1
		process.append([i,i-1])

print(count)
for i in range(count):
	processi = process[i]
	print(processi[0]+1,processi[1]+1)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    return


def B():
    return


def C():
    return





def D():
    n = II()
    a = LI()
    mina = min(a)
    maxa = max(a)
    if mina * maxa >= 0:
        print(n - 1)
        if mina >= 0:
            for i in range(n - 1):
                print(i + 1, i + 2)
        else:
            for i in range(n - 1):
                print(n - i, n - i - 1)
    else:
        print(2 * n - 1)
        if abs(mina) > abs(maxa):
            for i in range(n):
                if a[i] == mina:
                    break
            for k in range(n):
                print(i+1, k+1)
            for i in range(n - 1):
                print(n - i, n - i - 1)
        else:
            for i in range(n):
                if a[i] == maxa:
                    break
            for k in range(n):
                print(i + 1, k + 1)
            for i in range(n - 1):
                print(i + 1, i + 2)
    return



if __name__ == '__main__':
    D()

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
rs = []
n = max(range(N), key=lambda i: abs(As[i]))
for i in range(N):
  rs.append((n, i))
if As[n] > 0:
  for i in range(1, N):
      rs.append((i-1, i))
if As[n] < 0:
  for i in reversed(range(1, N)):
      rs.append((i, i-1))

print(len(rs))
for x, y in rs:
  print(x+1, y+1)

Solution (Python):
import numpy as np
if __name__ == "__main__":
    N = int(input())
    A = [None]*N
    A = list(map(int, input().split()))
    flag_p = True
    max_a = max(A)
    max_idx = A.index(max_a)
    min_a = min(A)
    min_idx = A.index(min_a)
    if max_a < -min_a:
        flag_p = False
    
    print(N+N-1)
    
    if flag_p:
        
        for i in range(N):
            print(max_idx+1, i+1)
        
    else:
        
        for i in range(N):
            print(min_idx+1, i+1)

    if flag_p:
        for i in range(N-1):
            
            print(i+1, i+2)
    
    else:
        for i in range(N-1, 0, -1):
            
            print(i+1, i)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))

print(2*n-1)
if abs(max(a))>=abs(min(a)):
    b=a.index(max(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)
  
else:
    b=a.index(min(a))
    for i in range(n):
        print(b+1,i+1)
    for i in range(n-1):
        print(n-i,n-1-i)

Solution (Python):
N = int(input())
A_arr = [int(x) for x in input().split()]

A_max = max(A_arr)
A_min = min(A_arr)

ans_arr = []
if A_max > -A_min:
    Am = A_arr.index(A_max)
    for i in range(len(A_arr)):
        if i == Am:
            continue
        ans_arr.append((Am+1, i+1))
    for i in range(len(A_arr)-1):
        ans_arr.append((i+1, i+2))
else:
    Am = A_arr.index(A_min)
    for i in range(len(A_arr)):
        if i == Am:
            continue
        ans_arr.append((Am+1, i+1))
    for i in range(len(A_arr)-1, 0, -1):
        ans_arr.append((i+1, i))

print(len(ans_arr))
for i,j in ans_arr:
    print(i,j)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=[]
B=0
P=0
if abs(max(A))>=abs(min(A)):
    
    B=max(A)
    for i in range(N):
        if A[i]==max(A):
            B=A[i]
            P=i
    for i in range(1,N):
        if A[i-1]<=A[i]:
            pass
        else:
            A[i]+=B
            ans.append([P+1,i+1])
            if B<A[i]:
                B=A[i]
                P=i
            if A[i-1]<=A[i]:
                pass
            else:
                A[i]+=B
                ans.append([P+1,i+1])
                if B<A[i]:
                    B=A[i]
                    P=i
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i][0],ans[i][1])
else:
    B=min(A)
    for i in range(N):
        if A[i]==min(A):
            B=A[i]
            P=i
    
    for i in range(N-1):
        
        if A[N-2-i]<=A[N-1-i]:
            pass
        else:
            A[N-2-i]+=B
            ans.append([P+1,N-1-i])
            if B>A[N-2-i]:
                B=A[N-2-i]
                P=N-2-i
            if A[N-2-i]<=A[N-i-1]:
                pass
            else:
                A[N-2-i]+=B
                ans.append([P+1,N-1-i])
                if B>A[N-2-i]:
                    B=A[N-2-i]
                    P=N-2-i
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i][0],ans[i][1])

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=[]
if sum(t for t in a if t>0)>sum(-t for t in a if t<0):
    i=0
    while a[i]<0:i+=1
    for j in range(n):
        if a[j]>0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]<0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(1,n):
        ans+=[(i,i+1)]
else:
    i=0
    while a[i]>0:i+=1
    for j in range(n):
        if a[j]<0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]>0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(n,1,-1):
        ans+=[(i,i-1)]
print(len(ans))
for t in ans:print(*t)

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=[]
if sum(t for t in a if t>0)>sum(-t for t in a if t<0):
    i=0
    while a[i]<0:i+=1
    for j in range(n):
        if a[j]>0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]<0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(1,n):
        ans+=[(i,i+1)]
else:
    i=0
    while a[i]>0:i+=1
    for j in range(n):
        if a[j]<0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]>0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(n,1,-1):
        ans+=[(i,i-1)]
print(len(ans))
for t in ans:print(*t)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
INF = 10**6+1
MIN, MAX = INF, -INF
for i, a in enumerate(A, start=1):
    if a < MIN:
        MIN, MINi = a, i
    if MAX < a:
        MAX, MAXi = a, i
if MAX < 0 or (MAX + MIN < 0):
    print(2*N-1)
    for i in range(1, N+1):
        print(MINi, i)
    for i in range(2, N+1)[::-1]:
        print(i, i-1)
    quit()
flag = 0
if MIN < 0 and MAX + MIN >= 0:
    print(2*N-1)
    flag = 1
    for i in range(N):
        print(MAXi, i+1)
if not flag:
    print(N-1)
for i in range(1, N):
    print(i, i+1)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
M=max(a)
m=min(a)
iM=a.index(M)+1
im=a.index(m)+1
ans=[]
if m>=0:
    flag="+"
elif M<=0:
    flag="-"
elif abs(M)>=abs(m):
    flag="++"
else:
    flag="--"
if flag=="++":
    for i in range(N):
        if a[i]<0:
            a[i]=a[i]+M
            ans.append([iM,i+1])
    flag="+"
if flag=="--":
    for i in range(N):
        if a[i]>0:
            a[i]=a[i]+m
            ans.append([im,i+1])
    flag="-"   
if flag=="+":
    for i in range(N-1):
        M=max(a[:i+1])
        iM=a.index(M)+1
        if a[i]>a[i+1]:
            a[i+1]=a[i+1]+M
            ans.append([iM,i+2])
if flag=="-":
    for i in range(N-2,-1,-1):
        m=min(a[i+1:])
        im=a.index(m)+1
        if a[i]>a[i+1]:
            a[i]=a[i]+m
            ans.append([im,i+1])
print(len(ans))
for i in ans:
    print(i[0],i[1])

Solution (Python):
N = int(input())
A =list(map(int,input().split()))

Ans = []
pre = -10**9
maxi = A.index(max(A))
mini= A.index(min(A))

if abs(A[maxi]) > abs(A[mini]):
    for i in range(N):
        if i != maxi:
            Ans.append([maxi+1,i+1])
    for i in range(1,N):
        Ans.append([i,i+1])
else:
    for i in range(N):
        if i != mini:
            Ans.append([mini+1,i+1])
    for i in range(N-1,0,-1):
        Ans.append([i+1,i])
print(len(Ans))
for ans in Ans:
    print(*ans, sep = " ")

Solution (Python):
N = int(input())
a = list(map(int,input().split()))

m = 10**6+1
M = -10**6-1
j = -1
k = -1
for i in range(N):
    if M < a[i]:
        M = a[i]
        j = i
    if m > a[i]:
        m = a[i]
        k = i

print(2*N-2)
if -m < M:
    for i in range(N):
        if i != j:
            print('{} {}'.format(j+1,i+1))
    for i in range(N-1):
        print('{} {}'.format(i+1,i+2))
else:
    for i in range(N):
        if i != k:
            print('{} {}'.format(k+1,i+1))
    for i in range(N-1,0,-1):
        print('{} {}'.format(i+1,i))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

MAX, MAX_index = 0, 0
positive_flg = True
for i, a in enumerate(A):
    if abs(a) > MAX:
        if a > 0:
            positive_flg = True
        else:
            positive_flg = False
        MAX = abs(a)
        MAX_index = i

ans = []
for i in range(N):
    ans.append((MAX_index, i))
if positive_flg:
    for i in range(N - 1):
        ans.append((i, i + 1))
else:
    for i in reversed(range(N - 1)):
        ans.append((i + 1, i))


print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

a_max = max(a)
a_min = min(a)

if a_max >= abs(a_min):
    flag = True
    index = a.index(a_max)
else:
    flag = False
    index = a.index(a_min)

m = 2 * N -2
print (m)

count = 0
for i in range(N):
    if i != index:
        print (index+1, i+1)
        count += 1

if flag: 
    for i in range(N-1):
        print (i+1, i+2)
        count += 1
else:
    for i in range(N-1,0,-1):
        print (i+1, i)
        count += 1

Solution (Python):
N = int(input())
a = list(map(int, input().split()))

ma = a[0]
mi = a[0]
maN = 0
miN = 0
for i in range(N):
  if a[i] > ma:
    ma = a[i]
    maN = i
  elif a[i] < mi:
    mi = a[i]
    miN = i

if abs(ma) > abs(mi):
  t = maN + 1
  f = 1
else:
  t = miN + 1
  f = -1

print(N * 2 - 1)
for i in range(1, N + 1):
  print(t, i)

if f == 1:
  for i in range(1, N):
    print(i, i + 1)
else:
  for i in range(N, 1, -1):
    print(i, i - 1)

Solution (Python):
import sys
input=sys.stdin.readline

N=int(input())
a=list(map(int,input().split()))
l=0
for i in range(1,N):
	if abs(a[i])>abs(a[l]): l=i

if a[l]==0: print(0),sys.exit()
elif a[l]>0:
	print(N*2)
	for i in range(2):
		print(l+1,1)
	for i in range(1,N):
		for j in range(2):
			print(i,i+1)

else:
	print(N*2)
	for i in range(2):
		print(l+1,N)
	for i in range(N,1,-1):
		for j in range(2):
			print(i,i-1)

Solution (Python):
import sys
import math
from itertools import accumulate as acc

input=sys.stdin.readline

N=int(input())
a=list(map(int,input().split()))
b=[abs(a[i]) for i in range(N)]
l=b.index(max(b))

if a[l]==0: print(0),sys.exit()
elif a[l]>0:
	print(N*2)
	for i in range(2):
		print(l+1,1)
	for i in range(1,N):
		for j in range(2):
			print(i,i+1)

else:
	print(N*2)
	for i in range(2):
		print(l+1,N)
	for i in range(N,1,-1):
		for j in range(2):
			print(i,i-1)

Solution (Python):
N=int(input())
inl = list(map(int,input().split()))

max_v = -100000000
max_i = -1
min_v = 100000000
min_i = -1
for i, num in enumerate(inl):
    if max_v < num: 
        max_v = num 
        max_i = i
    if min_v > num:
        min_v = num
        min_i = i

outl = []
if abs(min_v) > abs(max_v):
    for i in range(N):
        if inl[i] > min_v:
            inl[i] += min_v
            outl.append((min_i, i))
    for i in reversed(range(1, N)):
        if inl[i-1] > inl[i]:
            inl[i-1] += inl[i]
            outl.append((i, i-1))
else:
    for i in range(N):
        if inl[i] < max_v:
            inl[i] += max_v
            outl.append((max_i, i))
    for i in range(1, N):
        if inl[i-1] > inl[i]:
            inl[i] += inl[i-1]
            outl.append((i-1, i))



print(len(outl))
for i,j in outl:
    print(i+1, j+1)