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())
a = list(map(int, input().split()))

max1 = max(a)
min1 = min(a)

if min1 >= 0:
    print(N-1)
    for i in range(N-1):
        print(i+1, i+2)
elif max1 <= 0:
    print(N-1)
    for i in range(N-1):
        print(N-i, N-i-1)
else:
    if -min1 < max1:
        t = a.index(max1) + 1
        print(2*N - 1)
        for i in range(N):
            print(t, i+1)
        for i in range(N-1):
            print(i+1, i+2)
    else:
        t = a.index(min1) + 1
        print(2*N - 1)
        for i in range(N):
            print(t, i+1)
        for i in range(N-1):
            print(N-i, N-i-1)

Solution (Python):
def main():
    import sys
    import numpy as np
    ikimasu = sys.stdin.buffer.readline
    ini = lambda: int(ins())
    ina = lambda: list(map(int, ikimasu().split()))
    ins = lambda: ikimasu().strip()
    
    n = ini()
    tmp = ina()
    num,index = 0,0
    for i in range(n):
        if(abs(tmp[i])>num):
            num,index = abs(tmp[i]),i
    print(2*n-2)
    if(tmp[index]<=0):
        for i in range(n):
            if(i!=index):
                print(index+1,i+1)
        for i in range(n,1,-1):
            print(i,i-1)
    else:
        for i in range(n):
            if(i!=index):
                print(index+1,i+1)
        for i in range(1,n):
            print(i,i+1)


        
        
        


    
        


        


    




















if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
A=[int(i) for i in input().split()]

mode=0
cnt=0

ans=[]

def do(a,b):
    global cnt
    cnt+=1
    A[b]+=A[a]
    ans.append((a+1,b+1))

def doMAX(b):
    if b==-1:
        b+=n
    do(A.index(max(A)),b)

def doMIN(b):
    if b==-1:
        b+=n
    do(A.index(min(A)),b)

if abs(max(A))>=abs(min(A)):
    doMAX(-1)
    mode=0
elif abs(max(A))<abs(min(A)):
    doMIN(0)
    mode=1
else:
    doMAX(-1)
    mode=0

if mode==0:
    old=-10**30
    for i in range(n-1):
        if A[i]>=old:
            old=A[i]
            continue
        while A[i]+A[-1]<old:
            doMAX(-1)
        doMAX(i)
        old=A[i]
    while A[-1]<old:
        doMAX(-1)
    
elif mode==1:
    old=10**30
    for i in range(n-1,0,-1):
        if A[i]<=old:
            old=A[i]
            continue
        while A[i]+A[0]>old:
            doMIN(0)
        doMIN(i)
        old=A[i]
    while A[0]>old:
        doMIN(0)
    
else:
    pass

print(cnt)
for ele in ans:
    print(ele[0],ele[1])

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())

command = []

plus_max = max(As)
minus_min = min(As)
if abs(plus_max)>=abs(minus_min):
    maxi_idx = As.index(plus_max)
    for i in range(N):
        a = As[i]
        if a<0:
            As[i] += plus_max
            command.append((i, maxi_idx))
    for i in range(N-1):
        a = As[i]
        b = As[i+1]
        if a>=0 and a>b:
            command.append((i+1, i))
            As[i+1] += As[i]
else:
    mini_idx = As.index(minus_min)
    for i in range(N):
        a = As[i]
        if a>0:
            As[i] += minus_min
            command.append((i, mini_idx))
    for i in range(N-1, 0, -1):
        a = As[i]
        b = As[i-1]
        if a<0 and b>a:
            command.append((i-1, i))
            As[i-1] += As[i]
print(len(command))
for x, y in command:
    print(y+1, x+1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
amax = 0
ind = -1
for i in range(N):
    if abs(A[i])>amax:
        amax = abs(A[i])
        ind = i
if amax==0:
    print(0)
else:
    m = 2*N-2
    B = []
    if A[ind]>=0:
        for i in range(N):
            if i!=ind:
                B.append((ind+1,i+1))
        for i in range(N-1):
            B.append((i+1,i+2))
    else:
        for i in range(N):
            if i!=ind:
                B.append((ind+1,i+1))
        for i in range(N,1,-1):
            B.append((i,i-1))
    print(m)
    for i in range(m):
        print(B[i][0],B[i][1])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
if min(A) >= 0:
  Flag = True
elif max(A) <= 0:
  Flag = False
else:
  p_max = max(A)
  m_max = min(A)
  if abs(p_max) >= abs(m_max):
    Flag = True
  else:
    Flag = False
if Flag:
  MAX = max(A)
  for i,v in enumerate(A):
    if v == MAX:
      MAX_loc = i
      break
  ans = []; t = 0
  for i in range(N-1):
    if A[i+1] >= A[i]:
      continue
    A[i+1] += 2*MAX
    ans.append([MAX_loc+1,i+1+1])
    ans.append([MAX_loc+1,i+1+1])
    t += 2
    MAX_loc = i+1
    MAX = A[i+1]

else:
  MIN = min(A)
  for i, v in enumerate(A):
    if v == MIN:
      MIN_loc = i
      break
  ans = []; t = 0
  for i in range(N-1):
    if A[N-1-i] >= A[N-2-i]:
      continue
    A[N-2-i] += 2*MIN
    ans.append([MIN_loc+1,N-2-i+1])
    ans.append([MIN_loc+1,N-2-i+1])
    t += 2
    MIN_loc = N-2-i
    MIN = A[N-2-i]
print(t)
for x in ans:
  print(*x)

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

amax = -10**7
maxi = -1
amin = 10**7
mini = -1
for i, a in enumerate(al):
    if a > amax: 
        amax = a
        maxi = i
    if a < amin:
        amin = a
        mini = i

ansl = []
if amin >= 0 or amax >= abs(amin):
    print(2*n-1)
    for i in range(n):
        print(maxi+1,i+1)
    for i in range(n-1):
        print(i+1,i+2)

else:
    print(2*n-1)
    for i in range(n):
        print(mini+1, i+1)
    for i in range(n-1,0,-1):
        print(i+1,i)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    A = in_nl()

    ans = []
    if abs(min(A)) < abs(max(A)):
        ma = max(A)
        ind = A.index(ma)
        for i in range(N):
            if i != ind:
                ans.append((ind + 1, i + 1))
                A[i] += A[ind]
    else:
        ma = min(A)
        ind = A.index(ma)
        for i in range(N):
            if i != ind:
                ans.append((ind + 1, i + 1))
                A[i] += A[ind]

    if min(A) >= 0:
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                max_a = max(A)
                ind = A.index(max_a)
                A[i + 1] += max_a
                ans.append((ind + 1, i + 2))
    else:
        for i in range(N - 1, 0, -1):
            if A[i - 1] > A[i]:
                min_a = min(A)
                ind = A.index(min_a)
                A[i - 1] += min_a
                ans.append((ind + 1, i))

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

    


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
mi, ma = min(A), max(A)
print(2*N)
if abs(mi)<=ma:
    k = A.index(ma)
    print(k+1,1)
    print(k+1,1)
    for i in range(N-1):
        print(i+1,i+2)
        print(i+1,i+2)
else:
    k = A.index(mi)
    print(k+1,N)
    print(k+1,N)
    for i in reversed(range(N-1)):
        print(i+2,i+1)
        print(i+2,i+1)

Solution (Python):



n = int(input())
a = list(map(int, input().split()))
m = 0
for i, ai in enumerate(a):
    if abs(ai) >= m:
        m = abs(ai)
        mi = i
ret= [[mi+1, i+1] for i in range(n)]
if a[mi] >= 0:
    for i in range(n-1):
        ret.append([i+1, i+2])
else:
    for i in range(n-2, -1, -1):
        ret.append([i+2, i+1])  
print(2*n-1)
for x in ret:
    print(" ".join(map(str, x)))

Solution (Python):
import sys
import math
import collections
import bisect
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    n = ni()
    a = na()

    min_num = min(a)
    min_num_idx = a.index(min_num)
    max_num = max(a)
    max_num_idx = a.index(max_num)
    ans = []

    plus_flg = abs(max_num) > abs(min_num)

    if plus_flg:
        for i in range(n - 1):
            while a[i] > a[i + 1]:
                a[i + 1] += max_num
                ans.append((max_num_idx, i + 1))
            if max_num < a[i + 1]:
                max_num_idx = i + 1
                max_num = a[i + 1]

    else:
        for i in range(n - 1, 0, -1):
            while a[i - 1] > a[i]:
                a[i - 1] += min_num
                ans.append((min_num_idx, i - 1))
            if min_num > a[i - 1]:
                min_num_idx = i - 1
                min_num = a[i - 1]

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


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mxn=0
mnn=0
mx=-10**10
mn=10**10
for i in range(n):
  if mx<a[i]:
    mx=a[i]
    mxn=i
  if mn>a[i]:
    mn=a[i]
    mnn=i
print(2*n-1)
if mx+mn>=0:
  for i in range(n):
    print(mxn+1,i+1)
  for i in range(1,n):
    print(i,i+1)
else:
  for i in range(n):
    print(mnn+1,i+1)
  for i in range(n,1,-1):
    print(i,i-1)

Solution (Python):

import sys
def main(N, A):
    mxi = -1
    mxa = 0
    for i, a in enumerate(A):
        if abs(a) >= abs(mxa):
            mxa = a
            mxi = i
    ans = []
    for i in range(N):
        if A[i] * mxa < 0:
            ans.append((mxi + 1, i + 1))
            A[i] += mxa
    if mxa > 0:
        for i in range(1, N):
            if A[i] < A[i - 1]:
                ans.append((i, i + 1))
                A[i] += A[i - 1]
    else:
        for i in range(N - 2, -1, -1):
            if A[i] > A[i + 1]:
                ans.append((i + 2, i + 1))
                A[i] += A[i + 1]
    print(len(ans))
    for a in ans:
        print(*a)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

a_max=max(a)
i_max=a.index(a_max) + 1
a_min=min(a)
i_min=a.index(a_min) + 1
ans=[]

if a_min>=0:
    print(n-1)
    for i in range(1,n):
        print(i,i+1)
elif a_max<0:
    print(n-1)
    for i in range(n,1,-1):
        print(i,i-1)
elif abs(a_max)>abs(a_min):
    print(2*n-2)
    for i in range(1,n+1):
        if i != i_max:
            print(i_max,i)

    for i in range(1,n):
        print(i,i+1)

else:
    print(2*n-2)
    for i in range(1,n+1):
        if i != i_min:
            print(i_min,i)
    for i in range(n,1,-1):
        print(i,i-1)

Solution (Python):
ans = 0
N = int(input())
A = list(map(int, input().split()))
ans = []
M = -float('inf')
m = float('inf')
for i in range(N):
  if A[i]>M:
    M_ind = i+1
    M = A[i]
  if A[i]<m:
    m_ind = i+1
    m = A[i]
if M*m<0:
  for i in range(N):
    if M>=abs(m):
      if i+1!= M_ind:
        ans.append([M_ind,i+1])
        A[i] += M
    else:
      if i+1!= m_ind:
        ans.append([m_ind,i+1])
        A[i] += m
if max(A)>0:
  for i in range(1,N):
    ans.append([i,i+1])
else:
  for i in range(N,1,-1):
    ans.append([i,i-1])
print(len(ans))
for a in ans:
  print(*a)

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]

ans = []
_max = max(A)
_min = min(A)
_min_ptr = A.index(_min)
_max_ptr = A.index(_max)
if _min == _max:
    print(0)
    quit()

if sorted(A) == A:
    print(0)
    quit()

if _max < 0:
    for i in range(n - 1, 0, -1):
        A[i - 1] += A[i]
        ans.append((i, i - 1))

elif _min >= 0:
    for i in range(0, n - 1):
        A[i + 1] += A[i]
        ans.append((i, i + 1))

elif _min < 0 and _max >= 0 and abs(_min) > abs(_max):
    for i in range(n):
        if A[i] >= 0:
            A[i] += _min
            ans.append((_min_ptr, i))
    for i in range(n - 1, 0, -1):
        A[i - 1] += A[i]
        ans.append((i, i - 1))

elif _min < 0 and _max >= 4 and abs(_min) <= abs(_max):
    for i in range(n):
        if A[i] < 0:
            A[i] += _max
            ans.append((_max_ptr, i))
    for i in range(0, n - 1):
        A[i + 1] += A[i]
        ans.append((i, i + 1))


if len(ans) == 0:
    print(0)
    quit()

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
flag = 0
for i in range(N):
    if A[i]!=0:
        flag = 1
        break
if flag==0:
    print(0)
else:
    pmax = 0
    mmin = 0
    indp = -1
    indm = -1
    for i in range(N):
        if A[i]>0:
            if A[i]>pmax:
                pmax = A[i]
                indp = i
        elif A[i]<0:
            if A[i]<mmin:
                mmin = A[i]
                indm = i
    if pmax>=abs(mmin):
        print(2*N-2)
        for i in range(N):
            if i!=indp:
                print(indp+1,i+1)
        for i in range(N-1):
            print(i+1,i+2)
    else:
        print(2*N-2)
        for i in range(N):
            if i!=indm:
                print(indm+1,i+1)
        for i in range(N-1,0,-1):
            print(i+1,i)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
mx = max(A)
mxi = A.index(mx)
mn = min(A)
mni = A.index(mn)

ans = []
if mn >= 0 or mx + mn >= 0:
    for i in range(N):
        if A[i] < 0:
            ans.append((mxi, i))
    for i in range(N-1):
        ans.append((i, i+1))
else:
    for i in range(N):
        if A[i] > 0:
            ans.append((mni, i))
    for i in range(N-1,0,-1):
        ans.append((i, i-1))

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
m = 10**18
M = -10**18
m_idx = -1
M_idx = -1

for i in range(N):
    if a[i]<m:
        m = a[i]
        m_idx = i
    
    if a[i]>M:
        M = a[i]
        M_idx = i
        
ope = []

if abs(m)<=abs(M):
    for i in range(N):
        ope.append((M_idx, i))
    
    for i in range(N-1):
        ope.append((i, i+1))
else:
    for i in range(N):
        ope.append((m_idx, i))
    
    for i in range(N-1, 0, -1):
        ope.append((i, i-1))
    
print(len(ope))

for x, y in ope:
    print(x+1, y+1)

Solution (Python):
import sys

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


if A == sorted(A):
    print(0)
    sys.exit()

min_a = (float("inf"), -1)
max_a = (-float("inf"), -1)
for i in range(N):
    if A[i] < min_a[0]:
        min_a = (A[i], i)
    if A[i] > max_a[0]:
        max_a = (A[i], i)


ops = []

if abs(min_a[0]) > abs(max_a[0]):
    for i in range(N-1, -1, -1):
        
        while A[i] > min_a[0]:
            A[i] += min_a[0]
            ops.append((min_a[1]+1, i+1))
        min_a = (A[i], i)
        
else:
    for i in range(N):
        
        while A[i] < max_a[0]:
            A[i] += max_a[0]
            ops.append((max_a[1]+1, i+1))
        max_a = (A[i], i)


print(len(ops))
for (x, y) in ops:
    print(x, y)

Solution (Python):


import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*a = map(int, read().split())
idx = max(range(n),key=lambda i: abs(a[i]))

print(2*n-1)
for i in range(n):
    print(idx+1,i+1)
if a[idx] >= 0:
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n-2,-1,-1):
        print(i+2,i+1)

Solution (Python):
n = int(input())
A = list(int(x) for x in input().split())
minimum = min(A)
maximum = max(A)

ANS = []
if abs(maximum) >= abs(minimum):  
    index = A.index(maximum)
    for i in range(n):
        ANS.append((index, i))
        
    for i in range(n - 1):
        ANS.append((i, i + 1))
        
else:  
    index = A.index(minimum)
    for i in range(n):
        ANS.append((index, i))
        
    for i in reversed(range(1, n)):
        ANS.append((i, i - 1))
        

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

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

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

m=a[0]
mi=0
for i in range(n):
    if abs(a[i])>abs(m):
        m=a[i]
        mi=i

print(2*n-1)
for i in range(n):
    print(mi+1,i+1)

if m>=0:
    for i in range(n-1):
        print(i+1,i+2)
else:
    for i in range(n-1):
        print(n-i,n-1-i)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))
minv, maxv = min(A), max(A)
mini, maxi = -1, -1

for i in range(N):
    if minv == A[i]:
        mini = i
    if maxv == A[i]:
        maxi = i

if minv * maxv >= 0:
    print(N - 1)
    if minv >= 0:
        for i in range(N - 1):
            print(i + 1, i + 2)
    else:
        for i in range(N, 1, -1):
            print(i, i - 1)
else:
    print(2 * N - 1)
    if abs(minv) < abs(maxv):
        for i in range(N):
            print(maxi + 1, i + 1)
        for i in range(N - 1):
            print(i + 1, i + 2)
    else:
        for i in range(N):
            print(mini + 1, i + 1)
        for i in range(N, 1, -1):
            print(i, i - 1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
amax = max(A)
imax = A.index(amax)
amin = min(A)
imin = A.index(amin)


def make_positive():
    global amax, imax
    ans = []
    assert amax >= 0
    for i in range(N):
        if i > 0 and A[i] < 0:
            ans.append((imax, i))
            A[i] += amax
            assert A[i] >= 0
    for i in range(1, N):
        if A[i] < A[i - 1]:
            ans.append((imax, i))
            A[i] += amax
            assert A[i] >= A[i - 1]
            if A[i] > amax:
                amax = A[i]
                imax = i
    assert len(ans) <= 2 * N
    print(len(ans))
    for x, y in ans:
        print(x + 1, y + 1)


def make_negative():
    global amin, imin
    ans = []
    assert amin <= 0
    for i in range(N):
        if i < N - 1 and A[i] > 0:
            ans.append((imin, i))
            A[i] += amin
            assert A[i] <= 0
    for i in range(N - 2, -1, -1):
        if A[i] > A[i + 1]:
            ans.append((imin, i))
            A[i] += amin
            assert A[i] <= A[i + 1]
            if A[i] < amin:
                amin = A[i]
                imin = i
    assert len(ans) <= 2 * N
    print(len(ans))
    for x, y in ans:
        print(x + 1, y + 1)


def solve():
    if abs(amax) > abs(amin):
        make_positive()
    else:
        make_negative()
    return


solve()

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
if min(A)>=0:
  print(N-1)
  for i in range(1,N):
    print(i,i+1)
elif max(A)<=0:
  print(N-1)
  for i in range(N-1):
    print(N-i,N-1-i)
else:
  a,b=max(A),abs(min(A))
  print((N-1)*2)
  if a>=b:
    d=A.index(a)
    for i in range(N):
      if i!=d:
        print(d+1,i+1)
    for i in range(1,N):
      print(i,i+1)
  else:
    d=A.index(-b)
    for i in range(N):
      if i!=d:
        print(d+1,i+1)
    for i in range(N-1):
      print(N-i,N-1-i)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
M = max(a)
m = min(a)
ans = []
if m >= 0:
    for i in range(1, n):
        a[i] += a[i - 1]
        ans.append([i, i + 1])
else:
    if M <= 0:
        for i in range(n - 1)[::-1]:
            a[i] += a[i + 1]
            ans.append([i + 2, i + 1])
    else:
        if M > -m:
            index = a.index(M)
            for i in range(n):
                if a[i] < 0:
                    a[i] += M
                    ans.append([index + 1, i + 1])
            for i in range(1, n):
                a[i] += a[i - 1]
                ans.append([i, i + 1])
        else:
            index = a.index(m)
            for i in range(n):
                if a[i] > 0:
                    a[i] += m
                    ans.append([index + 1, i + 1])
            for i in range(n - 1)[::-1]:
                a[i] += a[i + 1]
                ans.append([i + 2, i + 1])
print(len(ans))
print('\n'.join([str(i) + ' ' + str(j) for i, j in ans]))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
M = max(a)
m = min(a)
ans = []

if m >= 0:
    for i in range(1,n):
        a[i] += a[i-1]
        ans.append((i,i+1))
else:
    if M <= 0:
        for i in range(n-1)[::-1]:
            a[i] += a[i+1]
            ans.append((i+2,i+1))
    else:
        if M > -m:
            Mi = a.index(M)
            for i in range(n):
                if a[i] < 0:
                    a[i]+=M
                    ans.append((Mi+1,i+1))
            for i in range(1,n):
                a[i] += a[i-1]
                ans.append((i,i+1))
        else:
            mi = a.index(m)
            for i in range(n):
                if a[i] > 0:
                    a[i]+=m
                    ans.append((mi+1,i+1))
            for i in range(n-1)[::-1]:
                a[i] += a[i+1]
                ans.append((i+2,i+1))

print(len(ans))
print('\n'.join([str(i)+' '+str(j) for i,j in ans]))

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    ma = max(a)
    mi = min(a)
    if mi*ma < 0:
        print(2*(n-1))
        if abs(ma) > abs(mi):
            mk = a.index(ma)
            for i in range(n):
                if i == mk:
                    continue
                print(mk+1,i+1)
                a[i] += ma
        else:
            mk = a.index(mi)
            for i in range(n):
                if i == mk:
                    continue
                print(mk+1,i+1)
                a[i] += mi
    else:
        print(n-1)
    ma = max(a)
    mi = min(a)
    if ma <= 0:
        for i in range(n-1):
            print(n-i,n-i-1)
    else:
        for i in range(n-1):
            print(i+1,i+2)


    return

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ma=max(a)
mai=a.index(ma)
mi=min(a)
mii=a.index(mi)
ans=[]
if abs(ma)>=abs(mi):
  for i in range(n):
    a[i]+=ma
    ans.append((mai+1,i+1))
  for i in range(1,n):
    a[i]+=a[i-1]
    ans.append((i,i+1))
else:
  for i in range(n):
    a[i]+=mi
    ans.append((mii+1,i+1))
  for i in range(n-2,-1,-1):
    a[i]+=a[i+1]
    ans.append((i+2,i+1))
print(len(ans))
for i in ans:print(*i)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
print(n * 2 - 1)
ma, mi = max(a), min(a)
ima, imi = a.index(ma), a.index(mi)
if abs(ma) >= abs(mi):
    for i in range(1, n + 1):
        print(ima + 1, i)
    for i in range(1, n):
        print(i, i + 1)
else:
    for i in range(1, n + 1):
        print(imi + 1, i)
    for i in range(1, n)[::-1]:
        print(i + 1, i)

Solution (Python):
import math



def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            

def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))












n = int(input())

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

if(abs(max(a)) >= abs(min(a))):
    idx = -1
    mx = -1
    for i in range(n):
        if(mx<=a[i]):
            idx = i+1
            mx = a[i]
            
    print(n*2)
    print(idx,n)
    print(idx,n)
    for i in range(n-1):
        print(n,i+1)
        print(n,n)

else:
    idx = -1
    mi = 1
    for i in range(n):
        if(mi>=a[i]):
            idx = i+1
            mi = a[i]
            
    print(n*2)
    print(idx,1)
    print(idx,1)
    for i in range(n,1,-1):
        print(1,i)
        print(1,1)

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

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






ans = []
plusmax = 0
minusmax = 0
plusmax_i = -1
minusmax_i = -1
  
target = -1
maxdiff = 0
for i in range(len(A)):
  if A[i] < minusmax:
    minusmax = A[i]
    minusmax_i = i
  if A[i] > plusmax:
    plusmax = A[i]
    plusmax_i = i





  
if abs(plusmax) > abs(minusmax):
  
  maxval = plusmax
  max_i = plusmax_i
  for i in range(1,len(A)):
    if A[i - 1] > A[i]:
      ans.append((max_i + 1,i + 1))
      ans.append((max_i + 1,i + 1))
      A[i] += 2 * maxval
      max_i = i
      maxval = A[i]
else:
  
  minval = minusmax
  min_i = minusmax_i
  for i in range(len(A) - 1, 0,-1):
    if A[i - 1] > A[i]:
      ans.append((min_i + 1, i))
      ans.append((min_i + 1, i))
      A[i - 1] += 2 * minval
      min_i = i - 1
      minval = A[i - 1]
        
print(len(ans))
for a in ans:
  print(*a)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b, idx = zip(*sorted(zip(a, range(1, n + 1))))
if b[-1] < 0:
    print(n - 1)
    
    for i in range(n - 1):
        print(n - i, n - i - 1)
elif b[0] >= 0:
    print(n - 1)
    for i in range(n - 1):
        print(i + 1, i + 2)
else:
    
    print(2 * n - 2)
    if b[-1] > abs(b[0]):
        
        for i in range(n):
            if i + 1 != idx[-1]:
                print(idx[-1], i + 1)
        for i in range(n - 1):
            print(i + 1, i + 2)
    else:
        for i in range(n):
            if i + 1 != idx[0]:
                print(idx[0], i + 1)
        for i in range(n - 1):
            print(n - i, n - i - 1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = []
mx = 0
for i in range(n):
    if abs(a[i])>abs(mx):
        mx = a[i]
        mx_idx = i
for i in range(n):
    if mx*a[i]<0:
        ans.append((mx_idx+1, i+1))
for i in range(n-1):
    if mx>0:
        ans.append((i+1, i+2))
    elif mx<0:
        ans.append((n-i, n-i-1))
print(len(ans))
for x, y in ans:
    print(x, y)

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

ans = []
mx = max(A)
mi = min(A)

if mx * mi < 0:
    if abs(mi) > abs(mx):
        x = A.index(mi)
        for y in range(N):
            if y == x:
                continue
            A[y] += mi
            ans.append((x, y))
    else:
        x = A.index(mx)
        for y in range(N):
            if x == y:
                continue
            A[y] += mx
            ans.append((x, y))

for i in range(N - 1)[::(-1)**(min(A) < 0)]:
    l, r = A[i], A[i + 1]

    if l > r:
        if r >= 0:
            A[i + 1] += l
            ans.append((i, i + 1))
        elif l <= 0:
            A[i] += r
            ans.append((i + 1, i))

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

if list(sorted(A)) != A:
    print(A)
    1 / 0